Java Code Examples for org.eclipse.jdt.core.IJavaElement#getPrimaryElement()

The following examples show how to use org.eclipse.jdt.core.IJavaElement#getPrimaryElement() . 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: RenameAnalyzeUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static ISourceRange getOldSourceRange(SearchMatch newMatch) {
	// cannot transfom offset in preview to offset in original -> just show enclosing method
	IJavaElement newMatchElement= (IJavaElement) newMatch.getElement();
	IJavaElement primaryElement= newMatchElement.getPrimaryElement();
	ISourceRange range= null;
	if (primaryElement.exists() && primaryElement instanceof ISourceReference) {
		try {
			range= ((ISourceReference) primaryElement).getSourceRange();
		} catch (JavaModelException e) {
			// can live without source range
		}
	}
	return range;
}
 
Example 2
Source File: RenameAnalyzeUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ISourceRange getOldSourceRange(SearchMatch newMatch) {
	// cannot transfom offset in preview to offset in original -> just show enclosing method
	IJavaElement newMatchElement= (IJavaElement) newMatch.getElement();
	IJavaElement primaryElement= newMatchElement.getPrimaryElement();
	ISourceRange range= null;
	if (primaryElement.exists() && primaryElement instanceof ISourceReference) {
		try {
			range= ((ISourceReference) primaryElement).getSourceRange();
		} catch (JavaModelException e) {
			// can live without source range
		}
	}
	return range;
}