org.eclipse.jdt.core.ISourceReference Java Examples

The following examples show how to use org.eclipse.jdt.core.ISourceReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StructureSelectNextAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
ISourceRange internalGetNewSelectionRange(ISourceRange oldSourceRange, ISourceReference sr, SelectionAnalyzer selAnalyzer) throws JavaModelException{
	if (oldSourceRange.getLength() == 0 && selAnalyzer.getLastCoveringNode() != null) {
		ASTNode previousNode= NextNodeAnalyzer.perform(oldSourceRange.getOffset(), selAnalyzer.getLastCoveringNode());
		if (previousNode != null)
			return getSelectedNodeSourceRange(sr, previousNode);
	}
	ASTNode first= selAnalyzer.getFirstSelectedNode();
	if (first == null)
		return getLastCoveringNodeRange(oldSourceRange, sr, selAnalyzer);

	ASTNode parent= first.getParent();
	if (parent == null)
		return getLastCoveringNodeRange(oldSourceRange, sr, selAnalyzer);

	ASTNode lastSelectedNode= selAnalyzer.getSelectedNodes()[selAnalyzer.getSelectedNodes().length - 1];
	ASTNode nextNode= getNextNode(parent, lastSelectedNode);
	if (nextNode == parent)
		return getSelectedNodeSourceRange(sr, first.getParent());
	int offset= oldSourceRange.getOffset();
	int end= Math.min(sr.getSourceRange().getLength(), nextNode.getStartPosition() + nextNode.getLength() - 1);
	return StructureSelectionAction.createSourceRange(offset, end);
}
 
Example #2
Source File: JDTUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: JDTUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public 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;
}
 
Example #4
Source File: RenameElementsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see MultiOperation
 */
protected void verify(IJavaElement element) throws JavaModelException {
	if (element == null || !element.exists())
		error(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);

	if (element.isReadOnly())
		error(IJavaModelStatusConstants.READ_ONLY, element);

	if (!(element instanceof ISourceReference))
		error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);

	int elementType = element.getElementType();
	if (elementType < IJavaElement.TYPE || elementType == IJavaElement.INITIALIZER)
		error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);

	verifyRenaming(element);
}
 
Example #5
Source File: JavaCodeFormatterImpl.java    From jenerate with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Evaluates the indentation used by a Java element. (in tabulators)
 */
private int getUsedIndentation(IJavaElement elem) throws JavaModelException {
    if (elem instanceof ISourceReference) {
        ICompilationUnit cu = (ICompilationUnit) elem.getAncestor(IJavaElement.COMPILATION_UNIT);
        if (cu != null) {
            IBuffer buf = cu.getBuffer();
            int offset = ((ISourceReference) elem).getSourceRange().getOffset();
            int i = offset;
            // find beginning of line
            while (i > 0 && !isLineDelimiterChar(buf.getChar(i - 1))) {
                i--;
            }
            return computeIndent(buf.getText(i, offset - i), getTabWidth());
        }
    }
    return 0;
}
 
Example #6
Source File: JavaBrowsingContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Object[] getPackageContents(IPackageFragment fragment) throws JavaModelException {
	ISourceReference[] sourceRefs;
	if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) {
		sourceRefs= fragment.getCompilationUnits();
	}
	else {
		IClassFile[] classFiles= fragment.getClassFiles();
		List<IClassFile> topLevelClassFile= new ArrayList<IClassFile>();
		for (int i= 0; i < classFiles.length; i++) {
			IType type= classFiles[i].getType();
			if (type != null && type.getDeclaringType() == null && !type.isAnonymous() && !type.isLocal())
				topLevelClassFile.add(classFiles[i]);
		}
		sourceRefs= topLevelClassFile.toArray(new ISourceReference[topLevelClassFile.size()]);
	}

	Object[] result= new Object[0];
	for (int i= 0; i < sourceRefs.length; i++)
		result= concatenate(result, removeImportAndPackageDeclarations(getChildren(sourceRefs[i])));
	return concatenate(result, fragment.getNonJavaResources());
}
 
Example #7
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private ArrayList<IJavaElement> getSortedChildren(IType parent) throws JavaModelException {
	IJavaElement[] children= parent.getChildren();
	ArrayList<IJavaElement> sortedChildren= new ArrayList<IJavaElement>(Arrays.asList(children));
	Collections.sort(sortedChildren, new Comparator<IJavaElement>() {
		public int compare(IJavaElement e1, IJavaElement e2) {
			if (!(e1 instanceof ISourceReference))
				return 0;
			if (!(e2 instanceof ISourceReference))
				return 0;

			try {
				ISourceRange sr1= ((ISourceReference)e1).getSourceRange();
				ISourceRange sr2= ((ISourceReference)e2).getSourceRange();
				if (sr1 == null || sr2 == null)
					return 0;

				return sr1.getOffset() - sr2.getOffset();

			} catch (JavaModelException e) {
				return 0;
			}
		}
	});
	return sortedChildren;
}
 
Example #8
Source File: GenerateMethodAbstractAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
static RefactoringStatusContext createRefactoringStatusContext(IJavaElement element) {
	if (element instanceof IMember) {
		return JavaStatusContext.create((IMember) element);
	}
	if (element instanceof ISourceReference) {
		IOpenable openable= element.getOpenable();
		try {
			if (openable instanceof ICompilationUnit) {
				return JavaStatusContext.create((ICompilationUnit) openable, ((ISourceReference) element).getSourceRange());
			} else if (openable instanceof IClassFile) {
				return JavaStatusContext.create((IClassFile) openable, ((ISourceReference) element).getSourceRange());
			}
		} catch (JavaModelException e) {
			// ignore
		}
	}
	return null;
}
 
Example #9
Source File: JavaCompareAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected boolean isEnabled(ISelection selection) {
	if (selection instanceof IStructuredSelection) {
		Object[] sel= ((IStructuredSelection) selection).toArray();
		if (sel.length == 2) {
			for (int i= 0; i < 2; i++) {
				Object o= sel[i];
				if (!(o instanceof ISourceReference))
					return false;
			}
			fLeft= (ISourceReference) sel[0];
			fRight= (ISourceReference) sel[1];
			return true;
		}
	}
	return false;
}
 
Example #10
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private int getErrorTicksFromAnnotationModel(IAnnotationModel model, ISourceReference sourceElement) throws CoreException {
	int info= 0;
	Iterator<Annotation> iter= model.getAnnotationIterator();
	while ((info != ERRORTICK_ERROR) && iter.hasNext()) {
		Annotation annot= iter.next();
		IMarker marker= isAnnotationInRange(model, annot, sourceElement);
		if (marker != null) {
			int priority= marker.getAttribute(IMarker.SEVERITY, -1);
			if (priority == IMarker.SEVERITY_WARNING) {
				info= ERRORTICK_WARNING;
			} else if (priority == IMarker.SEVERITY_ERROR) {
				info= ERRORTICK_ERROR;
			}
		}
	}
	return info;
}
 
Example #11
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Makes the breadcrumb visible. Creates its content
 * if this is the first time it is made visible.
 *
 * @since 3.4
 */
private void showBreadcrumb() {
	if (fBreadcrumb == null)
		return;

	if (fBreadcrumbComposite.getChildren().length == 0) {
		fBreadcrumb.createContent(fBreadcrumbComposite);
	}

	((GridData) fBreadcrumbComposite.getLayoutData()).exclude= false;
	fBreadcrumbComposite.setVisible(true);

	ISourceReference selection= computeHighlightRangeSourceReference();
	if (selection == null)
		selection= getInputJavaElement();
	setBreadcrumbInput(selection);
	fBreadcrumbComposite.getParent().layout(true, true);
}
 
Example #12
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void setSelection(IJavaElement element) {

		if (element == null || element instanceof ICompilationUnit || element instanceof IClassFile) {
			/*
			 * If the element is an ICompilationUnit this unit is either the input
			 * of this editor or not being displayed. In both cases, nothing should
			 * happened. (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128)
			 */
			return;
		}

		IJavaElement corresponding= getCorrespondingElement(element);
		if (corresponding instanceof ISourceReference) {
			ISourceReference reference= (ISourceReference) corresponding;
			// set highlight range
			setSelection(reference, true);
			// set outliner selection
			if (fOutlinePage != null)
				fOutlinePage.select(reference);
		}
	}
 
Example #13
Source File: JavaOutlinePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void select(ISourceReference reference) {
	if (fOutlineViewer != null) {

		ISelection s= fOutlineViewer.getSelection();
		if (s instanceof IStructuredSelection) {
			IStructuredSelection ss= (IStructuredSelection) s;
			List<?> elements= ss.toList();
			if (!elements.contains(reference)) {
				s= (reference == null ? StructuredSelection.EMPTY : new StructuredSelection(reference));
				fOutlineViewer.setSelection(s, true);
			}
		}
	}
}
 
Example #14
Source File: SelectionConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static IJavaElement resolveEnclosingElement(IJavaElement input, ITextSelection selection) throws JavaModelException {
	IJavaElement atOffset= null;
	if (input instanceof ICompilationUnit) {
		ICompilationUnit cunit= (ICompilationUnit)input;
		JavaModelUtil.reconcile(cunit);
		atOffset= cunit.getElementAt(selection.getOffset());
	} else if (input instanceof IClassFile) {
		IClassFile cfile= (IClassFile)input;
		atOffset= cfile.getElementAt(selection.getOffset());
	} else {
		return null;
	}
	if (atOffset == null) {
		return input;
	} else {
		int selectionEnd= selection.getOffset() + selection.getLength();
		IJavaElement result= atOffset;
		if (atOffset instanceof ISourceReference) {
			ISourceRange range= ((ISourceReference)atOffset).getSourceRange();
			while (range.getOffset() + range.getLength() < selectionEnd) {
				result= result.getParent();
				if (! (result instanceof ISourceReference)) {
					result= input;
					break;
				}
				range= ((ISourceReference)result).getSourceRange();
			}
		}
		return result;
	}
}
 
Example #15
Source File: TopLevelTypeProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
	protected boolean isInside(int pos, ISourceReference sourceElement) throws CoreException {
//		XXX: Work in progress for problem decorator being a workbench decorator
//		IDecoratorManager decoratorMgr= PlatformUI.getWorkbench().getDecoratorManager();
//		if (!decoratorMgr.getEnabled("org.eclipse.jdt.ui.problem.decorator")) //$NON-NLS-1$
//			return false;

		if (!(sourceElement instanceof IType) || ((IType)sourceElement).getDeclaringType() != null)
			return false;

		ICompilationUnit cu= ((IType)sourceElement).getCompilationUnit();
		if (cu == null)
			return false;
		IType[] types= cu.getTypes();
		if (types.length < 1)
			return false;

		int firstTypeStartOffset= -1;
		ISourceRange range= types[0].getSourceRange();
		if (range != null)
			firstTypeStartOffset= range.getOffset();

		int lastTypeEndOffset= -1;
		range= types[types.length-1].getSourceRange();
		if (range != null)
			lastTypeEndOffset= range.getOffset() + range.getLength() - 1;

		return pos < firstTypeStartOffset || pos > lastTypeEndOffset || isInside(pos, sourceElement.getSourceRange());
	}
 
Example #16
Source File: Utils.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
public static ILineRange getLineRange(IJavaElement element, IDocument document)
		throws JavaModelException, BadLocationException {
	ISourceRange r = ((ISourceReference) element).getSourceRange();
	int offset = r.getOffset();
	int startLine = document.getLineOfOffset(offset);
	int endLine = document.getLineOfOffset(offset + r.getLength());
	return new LineRange(startLine, endLine - startLine);
}
 
Example #17
Source File: EditorUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Selects a Java Element in an editor.
 *
 * @param part the editor part
 * @param element the Java element to reveal
 */
public static void revealInEditor(IEditorPart part, IJavaElement element) {
	if (element == null)
		return;

	if (part instanceof JavaEditor) {
		((JavaEditor) part).setSelection(element);
		return;
	}

	// Support for non-Java editor
	try {
		ISourceRange range= null;
		if (element instanceof ICompilationUnit)
			return;
		else if (element instanceof IClassFile)
			return;

		if (element instanceof ISourceReference)
			range= ((ISourceReference)element).getNameRange();

		if (range != null)
			revealInEditor(part, range.getOffset(), range.getLength());
	} catch (JavaModelException e) {
		// don't reveal
	}
}
 
Example #18
Source File: StructureSelectEnclosingAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
ISourceRange internalGetNewSelectionRange(ISourceRange oldSourceRange, ISourceReference sr, SelectionAnalyzer selAnalyzer) throws JavaModelException{
	ASTNode first= selAnalyzer.getFirstSelectedNode();
	if (first == null || first.getParent() == null)
		return getLastCoveringNodeRange(oldSourceRange, sr, selAnalyzer);

	return getSelectedNodeSourceRange(sr, first.getParent());
}
 
Example #19
Source File: GoToNextPreviousMemberAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void update() {
	boolean enabled= false;
	ISourceReference ref= getSourceReference();
	if (ref != null) {
		ISourceRange range;
		try {
			range= ref.getSourceRange();
			enabled= range != null && range.getLength() > 0;
		} catch (JavaModelException e) {
			// enabled= false;
		}
	}
	setEnabled(enabled);
}
 
Example #20
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static String getUnindentedSource(ISourceReference sourceReference) throws JavaModelException {

			String[] lines= Strings.convertIntoLines(sourceReference.getSource());
			final IJavaProject project= ((IJavaElement) sourceReference).getJavaProject();
			Strings.trimIndentation(lines, project, false);
			return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed((IJavaElement) sourceReference));
		}
 
Example #21
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * React to changed selection.
 *
 * @since 3.0
 */
protected void selectionChanged() {
	if (getSelectionProvider() == null)
		return;
	ISourceReference element= computeHighlightRangeSourceReference();
	if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
		synchronizeOutlinePage(element);
	if (fIsBreadcrumbVisible && fBreadcrumb != null && !fBreadcrumb.isActive())
		setBreadcrumbInput(element);
	setSelection(element, false);
	if (!fSelectionChangedViaGotoAnnotation)
		updateStatusLine();
	fSelectionChangedViaGotoAnnotation= false;
}
 
Example #22
Source File: CompilationUnitEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the length of the given Java element.
 *
 * @param element	Java element
 * @return Length of the given Java element
 */
private int getLength(IJavaElement element) {
	if (element instanceof ISourceReference) {
		ISourceReference sr= (ISourceReference) element;
		try {
			ISourceRange srcRange= sr.getSourceRange();
			if (srcRange != null)
				return srcRange.getLength();
		} catch (JavaModelException e) {
		}
	}
	return -1;
}
 
Example #23
Source File: CompilationUnitEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the offset of the given Java element.
 *
 * @param element	Java element
 * @return Offset of the given Java element
 */
private int getOffset(IJavaElement element) {
	if (element instanceof ISourceReference) {
		ISourceReference sr= (ISourceReference) element;
		try {
			ISourceRange srcRange= sr.getSourceRange();
			if (srcRange != null)
				return srcRange.getOffset();
		} catch (JavaModelException e) {
		}
	}
	return -1;
}
 
Example #24
Source File: JavaSourceHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Deprecated
public String getHoverInfo(ITextViewer textViewer, IRegion region) {
	IJavaElement[] result= getJavaElementsAt(textViewer, region);

	fUpwardShiftInLines= 0;
	fBracketHoverStatus= null;

	if (result == null || result.length == 0) {
		return getBracketHoverInfo(textViewer, region);
	}

	if (result.length > 1)
		return null;

	IJavaElement curr= result[0];
	if ((curr instanceof IMember || curr instanceof ILocalVariable || curr instanceof ITypeParameter) && curr instanceof ISourceReference) {
		try {
			String source= ((ISourceReference) curr).getSource();

			String[] sourceLines= getTrimmedSource(source, curr);
			if (sourceLines == null)
				return null;

			String delim= StubUtility.getLineDelimiterUsed(curr);
			source= Strings.concatenate(sourceLines, delim);

			return source;
		} catch (JavaModelException ex) {
			//do nothing
		}
	}
	return null;
}
 
Example #25
Source File: SourceView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts the given selection to a structured selection
 * containing Java elements.
 *
 * @param selection the selection
 * @return a structured selection with Java elements
 */
private IStructuredSelection convertToJavaElementSelection(ISelection selection) {

	if (!(selection instanceof ITextSelection && fCurrentViewInput instanceof ISourceReference))
		return StructuredSelection.EMPTY;

	ITextSelection textSelection= (ITextSelection)selection;

	Object codeAssist= fCurrentViewInput.getAncestor(IJavaElement.COMPILATION_UNIT);
	if (codeAssist == null)
		codeAssist= fCurrentViewInput.getAncestor(IJavaElement.CLASS_FILE);

	if (codeAssist instanceof ICodeAssist) {
		IJavaElement[] elements= null;
		try {
			ISourceRange range= ((ISourceReference)fCurrentViewInput).getSourceRange();
			elements= ((ICodeAssist)codeAssist).codeSelect(range.getOffset() + getOffsetInUnclippedDocument(textSelection), textSelection.getLength());
		} catch (JavaModelException e) {
			return StructuredSelection.EMPTY;
		}
		if (elements != null && elements.length > 0) {
			return new StructuredSelection(elements[0]);
		} else
			return StructuredSelection.EMPTY;
	}

	return StructuredSelection.EMPTY;
}
 
Example #26
Source File: SourceActionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public int getInsertOffset() throws JavaModelException {
	IJavaElement elementPosition= getElementPosition();
	if (elementPosition instanceof ISourceReference) {
		return ((ISourceReference) elementPosition).getSourceRange().getOffset();
	}
	return -1;
}
 
Example #27
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tests if a position is inside the source range of an element.
 * @param pos Position to be tested.
 * @param sourceElement Source element (must be a IJavaElement)
 * @return boolean Return <code>true</code> if position is located inside the source element.
 * @throws CoreException Exception thrown if element range could not be accessed.
 *
 * @since 2.1
 */
protected boolean isInside(int pos, ISourceReference sourceElement) throws CoreException {
	if (fCachedRange == null) {
		fCachedRange= sourceElement.getSourceRange();
	}
	ISourceRange range= fCachedRange;
	if (range != null) {
		int rangeOffset= range.getOffset();
		return (rangeOffset <= pos && rangeOffset + range.getLength() > pos);
	}
	return false;
}
 
Example #28
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IMarker isAnnotationInRange(IAnnotationModel model, Annotation annot, ISourceReference sourceElement) throws CoreException {
	if (annot instanceof MarkerAnnotation) {
		if (sourceElement == null || isInside(model.getPosition(annot), sourceElement)) {
			IMarker marker= ((MarkerAnnotation) annot).getMarker();
			if (marker.exists() && marker.isSubtypeOf(IMarker.PROBLEM)) {
				return marker;
			}
		}
	}
	return null;
}
 
Example #29
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isMarkerInRange(IMarker marker, ISourceReference sourceElement) throws CoreException {
	if (marker.isSubtypeOf(IMarker.TEXT)) {
		int pos= marker.getAttribute(IMarker.CHAR_START, -1);
		return isInside(pos, sourceElement);
	}
	return false;
}
 
Example #30
Source File: JavaOutlinePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks if element has an enclosing parent among other selected elements.
 * 
 * @param element the element to be checked for overlap against all elements
 * @param allElements the list of all elements
 * @return <code>true</code> if the element has a parent in the list of all elements
 */
private boolean isElementOverlapping(IJavaElement element, List<?> allElements) {
	element= element.getParent();
	while (element != null) {
		if (element instanceof ISourceReference) {
			if (allElements.contains(element))
				return true;
		} else {
			return false;
		}
		element= element.getParent();
	}
	return false;
}