@Override public String getContent(URI uri, IProgressMonitor monitor) throws CoreException { IClassFile classFile = JDTUtils.resolveClassFile(uri); if (classFile != null) { return getSource(classFile, monitor); } return null; }
/** * Given the uri returns a {@link IClassFile}. * May return null if it can not resolve the uri to a * library. * * @see #toLocation(IClassFile, int, int) * @param uri with 'jdt' scheme * @return class file */ public static IClassFile resolveClassFile(String uriString){ return resolveClassFile(toURI(uriString)); }
@Override public String getContent(URI uri, IProgressMonitor monitor) throws CoreException { IClassFile classFile = JDTUtils.resolveClassFile(uri); if (classFile != null) { return getSource(classFile, monitor); } try { return getContent(Files.readAllBytes(Paths.get(uri)), monitor); } catch (IOException e) { throw new CoreException(new Status(Status.ERROR, "", "Error opening " + uri, e)); } }
/** * Convenience method that combines {@link #resolveClassFile(String)} and * {@link #resolveCompilationUnit(String)}. * * @param uri * @return either a class file or compilation unit */ public static ITypeRoot resolveTypeRoot(String uriString) { URI uri = toURI(uriString); if (uri == null) { return null; } if (JDT_SCHEME.equals(uri.getScheme())) { return resolveClassFile(uri); } return resolveCompilationUnit(uri); }
private static IPackageFragmentRoot getPackageFragmentRoot(String classFileUri) throws CoreException { IClassFile classFile = JDTUtils.resolveClassFile(classFileUri); if (classFile == null) { throw constructCoreException("Cannot find the class file " + classFileUri); } IPackageFragmentRoot root = getPackageFragmentRoot(classFile); if (root == null) { throw constructCoreException("Cannot find the JAR containing this class file " + classFileUri); } return root; }
public List<CodeLens> getCodeLensSymbols(String uri, IProgressMonitor monitor) { if (!preferenceManager.getPreferences().isCodeLensEnabled()) { return Collections.emptyList(); } final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(uri); IClassFile classFile = null; if (unit == null) { classFile = JDTUtils.resolveClassFile(uri); if (classFile == null) { return Collections.emptyList(); } } else { if (!unit.getResource().exists() || monitor.isCanceled()) { return Collections.emptyList(); } } try { ITypeRoot typeRoot = unit != null ? unit : classFile; IJavaElement[] elements = typeRoot.getChildren(); LinkedHashSet<CodeLens> lenses = new LinkedHashSet<>(elements.length); collectCodeLenses(typeRoot, elements, lenses, monitor); if (monitor.isCanceled()) { lenses.clear(); } return new ArrayList<>(lenses); } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem getting code lenses for" + unit.getElementName(), e); } return Collections.emptyList(); }