List of usage examples for org.eclipse.jdt.core IJavaElement CLASS_FILE
int CLASS_FILE
To view the source code for org.eclipse.jdt.core IJavaElement CLASS_FILE.
Click Source Link
From source file:org.jboss.tools.vscode.java.internal.handlers.NavigateToDefinitionHandler.java
License:Open Source License
private Location computeDefinitonNavigation(ITypeRoot unit, int line, int column) { try {/*from w ww. ja v a 2 s.com*/ IJavaElement[] elements = unit.codeSelect(JsonRpcHelpers.toOffset(unit.getBuffer(), line, column), 0); if (elements == null || elements.length != 1) return null; IJavaElement element = elements[0]; 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 JDTUtils.toLocation(element); } return null; } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem with codeSelect for" + unit.getElementName(), e); } return null; }
From source file:org.jboss.tools.vscode.java.internal.handlers.ReferencesHandler.java
License:Open Source License
@Override public List<org.jboss.tools.langs.Location> handle(org.jboss.tools.langs.ReferenceParams param) { SearchEngine engine = new SearchEngine(); String uri = param.getTextDocument().getUri(); if (MODE_SOURCEGRAPH) { // SOURCEGRAPH: URI is expected to be in form file:///foo/bar, // but we need to construct absolute file URI uri = new File(connection.getWorkpaceRoot(), uri.substring(8)).toURI().toString(); }//from w ww. ja va2 s. c o m ITypeRoot unit = JDTUtils.resolveTypeRoot(uri); if (unit == null) { return null; } try { IJavaElement elementToSearch = findElementAtSelection(unit, param.getPosition().getLine().intValue(), param.getPosition().getCharacter().intValue()); if (elementToSearch == null) return Collections.emptyList(); SearchPattern pattern = SearchPattern.createPattern(elementToSearch, IJavaSearchConstants.REFERENCES); List<org.jboss.tools.langs.Location> locations = new ArrayList<org.jboss.tools.langs.Location>(); engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object o = match.getElement(); if (o instanceof IJavaElement) { IJavaElement element = (IJavaElement) o; ICompilationUnit compilationUnit = (ICompilationUnit) element .getAncestor(IJavaElement.COMPILATION_UNIT); Location location = null; if (compilationUnit != null) { location = JDTUtils.toLocation(compilationUnit, match.getOffset(), match.getLength()); } else { IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); if (cf != null && cf.getSourceRange() != null) { location = JDTUtils.toLocation(cf, match.getOffset(), match.getLength()); } } if (location != null) if (MODE_SOURCEGRAPH) { // SOURCEGRAPH: transforming location's URI back from file://WORKSPACE/foo/bar to file:///foo/bar File file = new File(URI.create(location.getUri()).getPath()); File root = new File(connection.getWorkpaceRoot()); location.setUri("file:///" + root.toPath().relativize(file.toPath()) .toString().replace(File.separatorChar, '/')); } locations.add(location); } } }, new NullProgressMonitor()); return locations; } catch (CoreException e) { JavaLanguageServerPlugin.logException("Find references failure ", e); } return null; }
From source file:org.jboss.tools.vscode.java.internal.JDTUtils.java
License:Open Source License
/** * Given the uri returns a {@link IClassFile}. * May return null if it can not resolve the uri to a * library.//from w w w . j av a 2s.c om * * @see #toLocation(IClassFile, int, int) * @param uri with 'jdt' scheme * @return class file */ public static IClassFile resolveClassFile(String uriString) { URI uri = null; try { uri = new URI(uriString); } catch (URISyntaxException e) { JavaLanguageServerPlugin.logException("Failed to resolve " + uriString, e); } if (uri != null && "jdt".equals(uri.getScheme()) && "contents".equals(uri.getAuthority())) { String handleId = uri.getQuery(); IJavaElement element = JavaCore.create(handleId); IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); return cf; } return null; }
From source file:org.jboss.tools.vscode.java.internal.JDTUtils.java
License:Open Source License
/** * Creates a location for a given java element. * Element can be a {@link ICompilationUnit} or {@link IClassFile} * * @param element//from ww w .j a v a2s.co m * @return location or null * @throws JavaModelException */ public static Location toLocation(IJavaElement element) 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 = ((ISourceReference) element).getNameRange(); if (cf == null) { return toLocation(unit, nameRange.getOffset(), nameRange.getLength()); } else { return toLocation(cf, nameRange.getOffset(), nameRange.getLength()); } } return null; }
From source file:org.parallelj.designer.launching.internal.ParallelJPropertyTester.java
License:Open Source License
private boolean canLaunchAsParallelJ(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: case IJavaElement.TYPE: return isParallelJProgram(element); default:// w ww. j ava2s .co m return false; } }
From source file:org.seasar.diigu.eclipse.operation.NameEnhanceJob.java
License:Apache License
void enhance(IResource resource, IProgressMonitor monitor) throws CoreException { try {/*from w w w . j av a2 s .c o m*/ if (resource instanceof IFile) { if (monitor == null) { monitor = new NullProgressMonitor(); } if ("java".equals(resource.getFileExtension())) { ICompilationUnit unit = JavaCore.createCompilationUnitFrom((IFile) resource); enhance(unit, monitor); } else if ("class".equals(resource.getFileExtension())) { IJavaElement elem = JavaCore.create(resource); if (elem.getElementType() == IJavaElement.CLASS_FILE) { IResource src = toSource((IClassFile) elem); if (src != null) { enhance(src, monitor); } } } } } catch (Exception e) { DiiguPlugin.log(e); throw new CoreException(StatusUtil.createError(IStatus.ERROR, e)); } }
From source file:org.springframework.ide.eclipse.beans.ui.model.BeansModelLabelDecorator.java
License:Open Source License
protected void decorateJavaElement(IJavaElement element, IDecoration decoration) { int type = element.getElementType(); if (type == IJavaElement.PACKAGE_FRAGMENT_ROOT || type == IJavaElement.CLASS_FILE || type == IJavaElement.COMPILATION_UNIT) { IBeansModel model = BeansCorePlugin.getModel(); IBeansProject project = model.getProject(element.getJavaProject().getProject()); if (project instanceof ILazyInitializedModelElement && ((ILazyInitializedModelElement) project).isInitialized()) { try { if (type == IJavaElement.PACKAGE_FRAGMENT_ROOT) { // Decorate JAR file IResource resource = ((IPackageFragmentRoot) element).getResource(); if (resource instanceof IFile) { for (IBeansConfig config : project.getConfigs()) { if (config.getElementResource().equals(resource)) { decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING); break; }/*from w w w. ja va 2 s .co m*/ } } } else if (type == IJavaElement.CLASS_FILE) { // Decorate Java class file IType javaType = ((IClassFile) element).getType(); if (BeansModelUtils.isBeanClass(javaType)) { decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING); } } else if (type == IJavaElement.COMPILATION_UNIT) { // Decorate Java source file for (IType javaType : ((ICompilationUnit) element).getTypes()) { if (BeansModelUtils.isBeanClass(javaType)) { decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING); break; } } } } catch (JavaModelException e) { // Ignore } } } }
From source file:org.springframework.ide.eclipse.data.beans.ui.model.RepositoriesModelLabelDecorator.java
License:Open Source License
@Override protected void decorateJavaElement(IJavaElement element, IDecoration decoration) { IJavaProject javaProject = element.getJavaProject(); if (javaProject != null) { int type = element.getElementType(); IProject project = javaProject.getProject(); try {/*from w w w . ja va 2s . c o m*/ if (type == IJavaElement.CLASS_FILE) { // Decorate Java class file IType javaType = ((IClassFile) element).getType(); if (javaType.isInterface() && SpringDataUtils.hasRepositoryBeanFor(project, javaType)) { decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING); } } else if (type == IJavaElement.COMPILATION_UNIT) { // Decorate Java source file for (IType javaType : ((ICompilationUnit) element).getTypes()) { if (javaType.isInterface() && SpringDataUtils.hasRepositoryBeanFor(project, javaType)) { decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING); break; } } } } catch (JavaModelException e) { // ignore } } }
From source file:org.springframework.tooling.jdt.ls.extension.JavaLocationHandler.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*w ww .j av a2 s . c o m*/ public Object executeCommand(String commandId, List<Object> arguments, IProgressMonitor monitor) throws Exception { Location location = null; Map<String, Object> obj = (Map<String, Object>) arguments.get(0); String uri = (String) obj.get("projectUri"); URI projectUri = URI.create(uri); String bindingKey = (String) obj.get("bindingKey"); Boolean lookInOtherProjects = (Boolean) obj.get("lookInOtherProjects"); IJavaElement element = JavaData.findElement(projectUri, bindingKey, lookInOtherProjects); if (element != null) { location = JDTUtils.toLocation(element); if (location == null) { IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); if (cf != null) { location = JDTUtils.toLocation(cf); } } } return location; }
From source file:org.synyx.hades.eclipse.beans.ui.model.HadesModelLabelDecorator.java
License:Apache License
@Override protected void decorateJavaElement(IJavaElement element, IDecoration decoration) { int type = element.getElementType(); IProject project = element.getJavaProject().getProject(); try {//from w w w .j av a 2s. c o m if (type == IJavaElement.CLASS_FILE) { // Decorate Java class file IType javaType = ((IClassFile) element).getType(); if (HadesUtils.hasDaoBeanFor(project, javaType)) { decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING); } } else if (type == IJavaElement.COMPILATION_UNIT) { // Decorate Java source file for (IType javaType : ((ICompilationUnit) element).getTypes()) { if (HadesUtils.hasDaoBeanFor(project, javaType)) { decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING); break; } } } } catch (JavaModelException e) { // ignore } super.decorateJavaElement(element, decoration); }