public static boolean isSourceAvailable(ISourceReference sourceReference) { try { return SourceRange.isAvailable(sourceReference.getSourceRange()); } catch (JavaModelException e) { return false; } } }
public static boolean isSourceAvailable(ISourceReference sourceReference) { try { return SourceRange.isAvailable(sourceReference.getSourceRange()); } catch (JavaModelException e) { return false; } } }
public static boolean isSourceAvailable(ISourceReference sourceReference) { try { return SourceRange.isAvailable(sourceReference.getSourceRange()); } catch (JavaModelException e) { return false; } } }
private static ISourceRange getNameRange(IJavaElement element) throws JavaModelException { ISourceRange nameRange = null; if (element instanceof IMember) { IMember member = (IMember) element; nameRange = member.getNameRange(); if ((!SourceRange.isAvailable(nameRange))) { nameRange = member.getSourceRange(); } } else if (element instanceof ITypeParameter || element instanceof ILocalVariable) { nameRange = ((ISourceReference) element).getNameRange(); } else if (element instanceof ISourceReference) { nameRange = ((ISourceReference) element).getSourceRange(); } if (!SourceRange.isAvailable(nameRange) && element.getParent() != null) { nameRange = getNameRange(element.getParent()); } return nameRange; }
private int compareInTheSameType(IMethodBinding firstMethodBinding, IMethodBinding secondMethodBinding) { try { IMethod firstMethod= (IMethod)firstMethodBinding.getJavaElement(); IMethod secondMethod= (IMethod)secondMethodBinding.getJavaElement(); if (firstMethod == null || secondMethod == null) { return 0; } ISourceRange firstSourceRange= firstMethod.getSourceRange(); ISourceRange secondSourceRange= secondMethod.getSourceRange(); if (!SourceRange.isAvailable(firstSourceRange) || !SourceRange.isAvailable(secondSourceRange)) { return firstMethod.getElementName().compareTo(secondMethod.getElementName()); } else { return firstSourceRange.getOffset() - secondSourceRange.getOffset(); } } catch (JavaModelException e) { return 0; } } }
private int compareInTheSameType(IMethodBinding firstMethodBinding, IMethodBinding secondMethodBinding) { try { IMethod firstMethod= (IMethod)firstMethodBinding.getJavaElement(); IMethod secondMethod= (IMethod)secondMethodBinding.getJavaElement(); if (firstMethod == null || secondMethod == null) { return 0; } ISourceRange firstSourceRange= firstMethod.getSourceRange(); ISourceRange secondSourceRange= secondMethod.getSourceRange(); if (!SourceRange.isAvailable(firstSourceRange) || !SourceRange.isAvailable(secondSourceRange)) { return firstMethod.getElementName().compareTo(secondMethod.getElementName()); } else { return firstSourceRange.getOffset() - secondSourceRange.getOffset(); } } catch (JavaModelException e) { return 0; } } }
private int compareInTheSameType(IMethodBinding firstMethodBinding, IMethodBinding secondMethodBinding) { try { IMethod firstMethod= (IMethod)firstMethodBinding.getJavaElement(); IMethod secondMethod= (IMethod)secondMethodBinding.getJavaElement(); if (firstMethod == null || secondMethod == null) { return 0; } ISourceRange firstSourceRange= firstMethod.getSourceRange(); ISourceRange secondSourceRange= secondMethod.getSourceRange(); if (!SourceRange.isAvailable(firstSourceRange) || !SourceRange.isAvailable(secondSourceRange)) { return firstMethod.getElementName().compareTo(secondMethod.getElementName()); } else { return firstSourceRange.getOffset() - secondSourceRange.getOffset(); } } catch (JavaModelException e) { return 0; } } }
public static boolean isInlineMethodAvailable(IMethod method) throws JavaModelException { if (method == null) return false; if (!method.exists()) return false; if (!method.isStructureKnown()) return false; if (!method.isBinary()) return true; if (method.isConstructor()) return false; return SourceRange.isAvailable(method.getNameRange()); }
public static boolean isInlineMethodAvailable(IMethod method) throws JavaModelException { if (method == null) return false; if (!method.exists()) return false; if (!method.isStructureKnown()) return false; if (!method.isBinary()) return true; if (method.isConstructor()) return false; return SourceRange.isAvailable(method.getNameRange()); }
private static String getAnnotationSourceFixed(IMember member, IAnnotation annotation, String startSimple) { try { ISourceRange annotSourceRange = annotation.getSourceRange(); ISourceRange ownerSourceRange = member.getSourceRange(); if (SourceRange.isAvailable(ownerSourceRange) && SourceRange.isAvailable(annotSourceRange) && ownerSourceRange.getOffset() > annotSourceRange.getOffset()) { String icuSource = member.getCompilationUnit().getSource(); if (icuSource != null && icuSource.length() >= ownerSourceRange.getOffset()) { String diff = icuSource.substring(annotSourceRange.getOffset(), ownerSourceRange.getOffset()); int offset = diff.lastIndexOf(startSimple); if (offset >= 0) { offset += annotSourceRange.getOffset(); int end = offset + annotSourceRange.getLength(); if (icuSource.length() >= end) { return icuSource.substring(offset, end); } } } } } catch (JavaModelException e) { SdkLog.warning("Unable to find source for annotation '{}' in '{}'.", annotation.getElementName(), member.getElementName(), e); } return null; }
@Override public boolean test(IType candidate) { boolean accept = super.test(candidate); if (!accept) { return false; } try { int flags = candidate.getFlags(); if (Flags.isAbstract(flags)) { return false; } if (SourceRange.isAvailable(candidate.getSourceRange())) { // only accept non-abstract types with source available TextProviderServiceDeclaration d = new TextProviderServiceDeclaration(candidate, getOrder(candidate)); result.add(d); } } catch (JavaModelException e) { // this element seems to be corrupt -> ignore SdkLog.warning("Attempt to access source range of type '{}' failed. Type will be skipped.", candidate.getFullyQualifiedName(), e); } return false; } };
public static boolean isInlineMethodAvailable(IMethod method) throws JavaModelException { if (method == null) { return false; } if (!method.exists()) { return false; } if (!method.isStructureKnown()) { return false; } if (!method.isBinary()) { return true; } if (method.isConstructor()) { return false; } return SourceRange.isAvailable(method.getNameRange()); }
private static ISourceRange getSourceRange(IJavaElement element) throws JavaModelException { ISourceRange sourceRange = null; if (element instanceof IMember) { IMember member = (IMember) element; sourceRange = member.getSourceRange(); } else if (element instanceof ITypeParameter || element instanceof ILocalVariable) { sourceRange = ((ISourceReference) element).getSourceRange(); } else if (element instanceof ISourceReference) { sourceRange = ((ISourceReference) element).getSourceRange(); } if (!SourceRange.isAvailable(sourceRange) && element.getParent() != null) { sourceRange = getSourceRange(element.getParent()); } return sourceRange; }
if (SourceRange.isAvailable(nameRange)) { CompilationUnit cuNode = CoreASTProvider.getInstance().getAST(field.getTypeRoot(), CoreASTProvider.WAIT_YES, new NullProgressMonitor()); if (cuNode != null) {
@Override public int compare(DelegateEntry firstEntry, DelegateEntry secondEntry) { IVariableBinding firstVariable= firstEntry.field; IVariableBinding secondVariable= secondEntry.field; if (firstVariable.equals(secondVariable)) { try { IMethod firstMethod= (IMethod)firstEntry.delegateMethod.getJavaElement(); IMethod secondMethod= (IMethod)secondEntry.delegateMethod.getJavaElement(); ISourceRange firstSourceRange= firstMethod.getSourceRange(); ISourceRange secondSourceRange= secondMethod.getSourceRange(); if (!SourceRange.isAvailable(firstSourceRange) || !SourceRange.isAvailable(secondSourceRange)) { return firstMethod.getElementName().compareTo(secondMethod.getElementName()); } else { return firstSourceRange.getOffset() - secondSourceRange.getOffset(); } } catch (JavaModelException e) { return 0; } } IField firstField= (IField)firstVariable.getJavaElement(); IField secondField= (IField)secondVariable.getJavaElement(); try { return firstField.getSourceRange().getOffset() - secondField.getSourceRange().getOffset(); } catch (JavaModelException e) { return 0; } } }
@Override public int compare(DelegateEntry firstEntry, DelegateEntry secondEntry) { IVariableBinding firstVariable= firstEntry.field; IVariableBinding secondVariable= secondEntry.field; if (firstVariable.equals(secondVariable)) { try { IMethod firstMethod= (IMethod)firstEntry.delegateMethod.getJavaElement(); IMethod secondMethod= (IMethod)secondEntry.delegateMethod.getJavaElement(); ISourceRange firstSourceRange= firstMethod.getSourceRange(); ISourceRange secondSourceRange= secondMethod.getSourceRange(); if (!SourceRange.isAvailable(firstSourceRange) || !SourceRange.isAvailable(secondSourceRange)) { return firstMethod.getElementName().compareTo(secondMethod.getElementName()); } else { return firstSourceRange.getOffset() - secondSourceRange.getOffset(); } } catch (JavaModelException e) { return 0; } } IField firstField= (IField)firstVariable.getJavaElement(); IField secondField= (IField)secondVariable.getJavaElement(); try { return firstField.getSourceRange().getOffset() - secondField.getSourceRange().getOffset(); } catch (JavaModelException e) { return 0; } } }
if (SourceRange.isAvailable(nameRange)) { CompilationUnit cuNode= SharedASTProviderCore.getAST(field.getTypeRoot(), SharedASTProviderCore.WAIT_ACTIVE_ONLY, null); if (cuNode != null) {
/** * Creates a location for a given java element. Unlike {@link #toLocation} this * method can be called to return with a range that contains surrounding * comments (method body), not just the name of the Java element. Element can be * a {@link ICompilationUnit} or {@link IClassFile} * * @param element * @param type the range type. The {@link LocationType#NAME_RANGE name} or {@link LocationType#FULL_RANGE full} range. * @return location or null * @throws JavaModelException */ public static Location toLocation(IJavaElement element, LocationType type) throws JavaModelException { ICompilationUnit unit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); if (unit == null && cf == null) { return null; } if (element instanceof ISourceReference) { ISourceRange nameRange = type.getRange(element); if (SourceRange.isAvailable(nameRange)) { if (cf == null) { return toLocation(unit, nameRange.getOffset(), nameRange.getLength()); } else { return toLocation(cf, nameRange.getOffset(), nameRange.getLength()); } } } return null; }
final IType otherParent = (IType) other.getAncestor(IJavaElement.TYPE); final ISourceRange sourceRange = duplicate.getSourceRange(); if (S2eUtils.exists(otherParent) && SourceRange.isAvailable(sourceRange)) { final IMarker marker = duplicate.getResource().createMarker(CLASS_ID_DUPLICATE_MARKER_ID); marker.setAttribute(IMarker.MESSAGE, "Duplicate @ClassId. Value '" + matches.getKey() + "' of type '" + parent.getFullyQualifiedName()
protected void wellformType(IType type, IWorkingCopyManager workingCopyManager) throws CoreException { ISourceRange typeRange = type.getSourceRange(); if (!SourceRange.isAvailable(typeRange)) { return;