ITypeRoot typeRoot = JDTUtils.resolveTypeRoot(uri); if (typeRoot != null) { IJavaElement element = JDTUtils.findElementAtSelection(typeRoot, position.getLine(), position.getCharacter(), this.preferenceManager, monitor); if (REFERENCES_TYPE.equals(type)) { try {
public List<? extends Location> findImplementations(TextDocumentPositionParams param, IProgressMonitor monitor) { List<Location> locations = null; IJavaElement elementToSearch = null; try { ITypeRoot typeRoot = JDTUtils.resolveTypeRoot(param.getTextDocument().getUri()); if (typeRoot != null) { elementToSearch = JDTUtils.findElementAtSelection(typeRoot, param.getPosition().getLine(), param.getPosition().getCharacter(), this.preferenceManager, monitor); } if (elementToSearch == null) { return Collections.emptyList(); } int offset = getOffset(param, typeRoot); IRegion region = new Region(offset, 0); IType primaryType = typeRoot.findPrimaryType(); //java.lang.Object is a special case. We need to minimize heavy cost of I/O, // by avoiding opening all files from the Object hierarchy boolean useDefaultLocation = primaryType == null ? false : "java.lang.Object".equals(primaryType.getFullyQualifiedName()); ImplementationToLocationMapper mapper = new ImplementationToLocationMapper(preferenceManager.isClientSupportsClassFileContent(), useDefaultLocation); ImplementationCollector<Location> collector = new ImplementationCollector<>(region, elementToSearch, mapper); locations = collector.findImplementations(monitor); } catch (CoreException e) { JavaLanguageServerPlugin.logException("Find implementations failure ", e); } return locations; }
IJavaElement elementToSearch = JDTUtils.findElementAtSelection(JDTUtils.resolveTypeRoot(param.getTextDocument().getUri()), param.getPosition().getLine(), param.getPosition().getCharacter(), this.preferenceManager, monitor);
private Location computeDefinitionNavigation(ITypeRoot unit, int line, int column, IProgressMonitor monitor) { try { IJavaElement element = JDTUtils.findElementAtSelection(unit, line, column, this.preferenceManager, monitor); 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), unit.getJavaProject()); } if (element instanceof IMember && ((IMember) element).getClassFile() != null) { return fixLocation(element, JDTUtils.toLocation(((IMember) element).getClassFile()), unit.getJavaProject()); } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem computing definition for" + unit.getElementName(), e); } return null; }