private CompilationUnitSourceContext(ICompilationUnit cunit, ISourceRange range) { fCUnit= cunit; fSourceRange= range; if (fSourceRange == null) fSourceRange= new SourceRange(0,0); } @Override
public static boolean isSourceAvailable(ISourceReference sourceReference) { try { return SourceRange.isAvailable(sourceReference.getSourceRange()); } catch (JavaModelException e) { return false; } } }
/** * Finds the deepest <code>IJavaElement</code> in the hierarchy of * <code>elt</elt>'s children (including <code>elt</code> itself) * which has a source range that encloses <code>position</code> * according to <code>mapper</code>. */ protected IJavaElement findElement(IJavaElement elt, int position, SourceMapper mapper) { SourceRange range = mapper.getSourceRange(elt); if (range == null || position < range.getOffset() || range.getOffset() + range.getLength() - 1 < position) { return null; } if (elt instanceof IParent) { try { IJavaElement[] children = ((IParent) elt).getChildren(); for (int i = 0; i < children.length; i++) { IJavaElement match = findElement(children[i], position, mapper); if (match != null) { return match; } } } catch (JavaModelException npe) { // elt doesn't exist: return the element } } return elt; } /**
private ClassFileSourceContext(IClassFile classFile, ISourceRange range) { fClassFile= classFile; fSourceRange= range; if (fSourceRange == null) fSourceRange= new SourceRange(0,0); } @Override
public static boolean isSourceAvailable(ISourceReference sourceReference) { try { return SourceRange.isAvailable(sourceReference.getSourceRange()); } catch (JavaModelException e) { return false; } } }
@Override public void enterModule(ModuleInfo moduleInfo) { this.moduleNameRange = new SourceRange(moduleInfo.nameSourceStart, moduleInfo.nameSourceEnd - moduleInfo.nameSourceStart + 1); this.moduleDeclarationStart = moduleInfo.declarationStart; // module type modifiers this.moduleModifiers = moduleInfo.modifiers; }
public static boolean isSourceAvailable(ISourceReference sourceReference) { try { return SourceRange.isAvailable(sourceReference.getSourceRange()); } catch (JavaModelException e) { return false; } } }
protected ISourceRange getSourceRange() { return new SourceRange(0, this.sourceLength); } /**
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 CompilationUnitSourceContext(ICompilationUnit cunit, ISourceRange range) { fCUnit= cunit; fSourceRange= range; if (fSourceRange == null) fSourceRange= new SourceRange(0,0); } @Override
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 ClassFileSourceContext(IClassFile classFile, ISourceRange range) { fClassFile= classFile; fSourceRange= range; if (fSourceRange == null) fSourceRange= new SourceRange(0,0); } @Override
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; } } }
protected ISourceRange getSourceRange() { return new SourceRange(this.sourceRangeStart, this.sourceRangeEnd - this.sourceRangeStart + 1); } protected void setSourceRangeEnd(int end) {
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; } } }
protected ISourceRange getSourceRange() { return new SourceRange(this.sourceRangeStart, this.sourceRangeEnd - this.sourceRangeStart + 1); } protected void setSourceRangeEnd(int end) {
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()); }
protected ISourceRange getNameRange() { return new SourceRange(this.nameStart, this.nameEnd - this.nameStart + 1); } }
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()); }
protected ISourceRange getSourceRange() { return new SourceRange(this.sourceRangeStart, this.sourceRangeEnd - this.sourceRangeStart + 1); } protected void setSourceRangeEnd(int end) {