List of usage examples for org.eclipse.jdt.internal.core SourceRefElement getSourceRange
@Override public ISourceRange getSourceRange() throws JavaModelException
From source file:com.codenvy.ide.ext.java.server.internal.core.JavaElement.java
License:Open Source License
/** * Returns the element that is located at the given source position * in this element. This is a helper method for <code>ICompilationUnit#getElementAt</code>, * and only works on compilation units and types. The position given is * known to be within this element's source range already, and if no finer * grained element is found at the position, this element is returned. *///from w w w .jav a 2 s. c o m protected IJavaElement getSourceElementAt(int position) throws JavaModelException { if (this instanceof ISourceReference) { IJavaElement[] children = getChildren(); for (int i = children.length - 1; i >= 0; i--) { IJavaElement aChild = children[i]; if (aChild instanceof SourceRefElement) { SourceRefElement child = (SourceRefElement) children[i]; ISourceRange range = child.getSourceRange(); int start = range.getOffset(); int end = start + range.getLength(); if (start <= position && position <= end) { if (child instanceof IField) { // check muti-declaration case (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=39943) int declarationStart = start; SourceRefElement candidate = null; do { // check name range range = ((IField) child).getNameRange(); if (position <= range.getOffset() + range.getLength()) { candidate = child; } else { return candidate == null ? child.getSourceElementAt(position) : candidate.getSourceElementAt(position); } child = --i >= 0 ? (SourceRefElement) children[i] : null; } while (child != null && child.getSourceRange().getOffset() == declarationStart); // position in field's type: use first field return candidate.getSourceElementAt(position); } else if (child instanceof IParent) { return child.getSourceElementAt(position); } else { return child; } } } } } else { // should not happen Assert.isTrue(false); } return this; }
From source file:org.springframework.ide.eclipse.quickfix.jdt.computers.AnnotationArgumentProposalComputer.java
License:Open Source License
private boolean isWithinRange(SourceRefElement element, int invocationOffset) throws JavaModelException { int startPosition = element.getSourceRange().getOffset(); int length = element.getSourceRange().getLength(); return startPosition < invocationOffset && startPosition + length >= invocationOffset; }