List of usage examples for org.eclipse.jdt.core IJavaElement getResource
IResource getResource();
From source file:org.eclipse.jpt.jaxb.core.internal.JavaElementAdapterFactory.java
License:Open Source License
private Object getAdapter(IJavaElement javaElement, Class<?> adapterType) { if (adapterType == JaxbPlatformConfig.class) { return javaElement.getResource().getAdapter(JaxbPlatformConfig.class); }//w ww . ja v a2 s . com return null; }
From source file:org.eclipse.jpt.jpa.core.internal.platform.JavaElementAdapterFactory.java
License:Open Source License
private Object getAdapter(IJavaElement javaElement, Class<?> adapterType) { if (adapterType == JpaPlatform.Config.class) { return javaElement.getResource().getAdapter(JpaPlatform.Config.class); }/*from w w w . jav a 2s .c om*/ return null; }
From source file:org.eclipse.mylyn.internal.java.ui.JavaStructureBridge.java
License:Open Source License
/** * Some copying from:/*from ww w. ja v a2 s . co m*/ * * @see org.eclipse.jdt.ui.ProblemsLabelDecorator */ public boolean containsProblem(IInteractionElement node) { try { IJavaElement element = (IJavaElement) getObjectForHandle(node.getHandleIdentifier()); switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: return getErrorTicksFromMarkers(element.getResource(), IResource.DEPTH_INFINITE, null); case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: return getErrorTicksFromMarkers(element.getResource(), IResource.DEPTH_ONE, null); case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.TYPE: case IJavaElement.INITIALIZER: case IJavaElement.METHOD: case IJavaElement.FIELD: case IJavaElement.LOCAL_VARIABLE: ICompilationUnit cu = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) { return getErrorTicksFromMarkers(element.getResource(), IResource.DEPTH_ONE, null); } } } catch (CoreException e) { // ignore } return false; }
From source file:org.eclipse.objectteams.otdt.core.ext.MarkableFactory.java
License:Open Source License
public static IMarkableJavaElement createMarkable(IJavaElement javaElement) { IClassFile classFile = (IClassFile) javaElement.getAncestor(IJavaElement.CLASS_FILE); if (classFile != null) return new JavaElementMarkable(classFile); else/*from w ww . ja v a 2s .c o m*/ return new ResourceMarkable(javaElement.getResource()); }
From source file:org.eclipse.objectteams.otdt.internal.core.ext.ResourceMarkable.java
License:Open Source License
public boolean containsElement(IJavaElement element) { return this.fResource.equals(element.getResource()); }
From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests that removing a source file from an API aware project causes the * workspace description to be updated// w w w . j a v a 2s . c om */ public void testWPUpdateSourceRemoved() throws Exception { IJavaProject project = getTestingProject(); assertNotNull("The testing project must exist", project); //$NON-NLS-1$ IPackageFragmentRoot root = project.findPackageFragmentRoot( new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute()); assertNotNull("the 'src' package fragment root must exist", root); //$NON-NLS-1$ assertTestSource(root, TESTING_PACKAGE, "TestClass1"); //$NON-NLS-1$ IJavaElement element = project.findElement(new Path("a/b/c/TestClass1.java")); //$NON-NLS-1$ assertNotNull("the class a.b.c.TestClass1 must exist in the project", element); //$NON-NLS-1$ element.getResource().delete(true, new NullProgressMonitor()); IApiDescription desc = getTestProjectApiDescription(); assertNotNull("the testing project api description must exist", desc); //$NON-NLS-1$ IApiAnnotations annot = desc.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass1")); //$NON-NLS-1$ assertNull("the annotations for a.b.c.TestClass1 should no longer be present", annot); //$NON-NLS-1$ }
From source file:org.eclipse.pde.ds.internal.annotations.DSAnnotationCompilationParticipant.java
License:Open Source License
@Override public void buildFinished(IJavaProject project) { ProjectContext projectContext = processingContext.remove(project); if (projectContext != null) { ProjectState state = projectContext.getState(); // check if unprocessed CUs still exist; if not, their mapped files are now abandoned HashSet<String> abandoned = new HashSet<>(projectContext.getAbandoned()); for (String cuKey : projectContext.getUnprocessed()) { boolean exists = false; try { IJavaElement cu = project.findElement(new Path(cuKey)); IResource file;// w ww. ja va 2s. c o m if (cu != null && cu.getElementType() == IJavaElement.COMPILATION_UNIT && (file = cu.getResource()) != null && file.exists()) exists = true; } catch (JavaModelException e) { Activator.log(e); } if (!exists) { if (debug.isDebugging()) debug.trace(String.format("Mapped CU %s no longer exists.", cuKey)); //$NON-NLS-1$ Collection<String> dsKeys = state.removeMappings(cuKey); if (dsKeys != null) abandoned.addAll(dsKeys); } } // retain abandoned files that are still mapped elsewhere HashSet<String> retained = new HashSet<>(); for (String cuKey : state.getCompilationUnits()) { Collection<String> dsKeys = state.getModelFiles(cuKey); if (dsKeys != null) retained.addAll(dsKeys); } abandoned.removeAll(retained); if (projectContext.isChanged()) { try { saveState(project.getProject(), state); } catch (IOException e) { Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error saving file mappings.", e)); //$NON-NLS-1$ } } // delete all abandoned files ArrayList<IStatus> deleteStatuses = new ArrayList<>(2); for (String dsKey : abandoned) { IPath path = Path.fromPortableString(dsKey); if (debug.isDebugging()) debug.trace(String.format("Deleting %s", path)); //$NON-NLS-1$ IFile file = PDEProject.getBundleRelativeFile(project.getProject(), path); if (file.exists()) { try { file.delete(true, null); } catch (CoreException e) { deleteStatuses.add(e.getStatus()); } } } if (!deleteStatuses.isEmpty()) Activator.log(new MultiStatus(Activator.PLUGIN_ID, 0, deleteStatuses.toArray(new IStatus[deleteStatuses.size()]), "Error deleting generated files.", null)); //$NON-NLS-1$ if (!retained.isEmpty() || !abandoned.isEmpty()) updateProject(project.getProject(), retained, abandoned); } if (debug.isDebugging()) debug.trace(String.format("Build finished for project: %s", project.getElementName())); //$NON-NLS-1$ }
From source file:org.eclipse.recommenders.codesearch.rcp.index.indexer.ResourcePathIndexer.java
License:Open Source License
public static File getFile(final IJavaElement e) { final IResource resource = e.getResource(); final IPath path; if (resource == null) { path = e.getPath();//from w w w . j a v a 2 s .c o m } else { path = resource.getRawLocation(); if (path == null) { final URI uri = resource.getLocationURI(); if (uri != null) { return new File(uri); } } } return path.toFile(); }
From source file:org.eclipse.umlgen.reverse.java.AbstractJava2UMLConverter.java
License:Open Source License
/** * Convert an Package or a Java project into a UML2 model. * * @param javaElement// w w w .j av a 2s. c o m * the JavaElement * @param actGen * @return The UML2 model or <code>null</code> if the IJavaElement is not a Package or a Java Project. * @throws CoreException * , if the resource is null or some critical error occur while importing. */ private Package convert(IJavaElement javaElement, ActivityGeneration actGen) throws CoreException { String path = null; IResource res = javaElement.getResource(); if (res != null) { path = res.getLocation().toOSString(); } else { path = javaElement.getPath().toString(); } File dir = new File(path); Java2UMLLogListener listener = new Java2UMLLogListener(dir, modelName); logger.addLogListener(listener); LogUtils.resetTabbing(); if (emfResource == null) { throwCoreException("The resource can't be null."); } switch (javaElement.getElementType()) { case IJavaElement.JAVA_PROJECT: javaProject = (IJavaProject) javaElement; return doConvertion((IJavaProject) javaElement, actGen); case IJavaElement.PACKAGE_FRAGMENT: javaProject = ((IPackageFragment) javaElement).getJavaProject(); return doConvertion((IPackageFragment) javaElement, actGen); case IJavaElement.PACKAGE_FRAGMENT_ROOT: javaProject = ((IPackageFragmentRoot) javaElement).getJavaProject(); return doConvertion((IPackageFragmentRoot) javaElement, actGen); default: return null; } }
From source file:org.eclipse.vjet.eclipse.javalaunch.utils.EclipseResourceUtils.java
License:Open Source License
public static File getSourceRoot(IJavaProject project, IJavaElement e) { try {//from www .j a v a 2 s .c om IPackageFragment frag = project.findPackageFragment(e.getPath()); while (frag.isDefaultPackage() == false) { e = e.getParent(); frag = project.findPackageFragment(e.getPath()); } File f = e.getResource().getLocation().toFile(); return f; } catch (JavaModelException e1) { throw new RuntimeException(e1); } }