Java Code Examples for org.eclipse.jdt.core.IClassFile#getSourceRange()

The following examples show how to use org.eclipse.jdt.core.IClassFile#getSourceRange() . 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: CallHierarchyHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Gets the location of the Java {@code element} based on the desired
 * {@code locationType}.
 */
private Location getLocation(IJavaElement element, LocationType locationType) throws JavaModelException {
	Assert.isNotNull(element, "element");
	Assert.isNotNull(locationType, "locationType");

	Location location = locationType.toLocation(element);
	if (location == null && element instanceof IType) {
		IType type = (IType) element;
		ICompilationUnit unit = (ICompilationUnit) type.getAncestor(COMPILATION_UNIT);
		IClassFile classFile = (IClassFile) type.getAncestor(CLASS_FILE);
		if (unit != null || (classFile != null && classFile.getSourceRange() != null)) {
			location = locationType.toLocation(type);
		}
	}
	if (location == null && element instanceof IMember && ((IMember) element).getClassFile() != null) {
		location = JDTUtils.toLocation(((IMember) element).getClassFile());
	}
	return location;
}
 
Example 2
Source File: NavigateToDefinitionHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static Location computeDefinitionNavigation(IJavaElement element, IJavaProject javaProject) throws JavaModelException {
	if (element == null) {
		return null;
	}

	ICompilationUnit compilationUnit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
	IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
	if (compilationUnit != null || (cf != null && cf.getSourceRange() != null)) {
		return fixLocation(element, JDTUtils.toLocation(element), javaProject);
	}

	if (element instanceof IMember && ((IMember) element).getClassFile() != null) {
		return fixLocation(element, JDTUtils.toLocation(((IMember) element).getClassFile()), javaProject);
	}

	return null;
}
 
Example 3
Source File: FindOccurrencesInFileAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IMember getMember(IStructuredSelection selection) {
	if (selection.size() != 1)
		return null;
	Object o= selection.getFirstElement();
	if (o instanceof IMember) {
		IMember member= (IMember)o;
		try {
			if (member.getNameRange() == null)
				return null;
		} catch (JavaModelException ex) {
			return null;
		}

		IClassFile file= member.getClassFile();
		if (file != null) {
			try {
				if (file.getSourceRange() != null)
					return member;
			} catch (JavaModelException e) {
				return null;
			}
		}
		return member;
	}
	return null;
}
 
Example 4
Source File: ClassFileEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private JavaModelException probeInputForSource(IEditorInput input) {
	if (input == null)
		return null;

	IClassFileEditorInput classFileEditorInput= (IClassFileEditorInput) input;
	IClassFile file= classFileEditorInput.getClassFile();

	try {
		file.getSourceRange();
	} catch (JavaModelException e) {
		return e;
	}

	return null;
}