List of usage examples for org.eclipse.jdt.core IJavaProject exists
boolean exists();
From source file:org.swingexplorer.eclipseplugin.ActOpenSourceLine.java
License:Open Source License
private IType internalFindType(IJavaProject project, String className, Set<IJavaProject> visitedProjects) throws JavaModelException { if (visitedProjects.contains(project)) return null; IType type = project.findType(className, (IProgressMonitor) null); if (type != null) return type; // fix for bug 87492: visit required projects explicitly to also find // not exported types visitedProjects.add(project);//from w w w . ja v a 2s . c om IJavaModel javaModel = project.getJavaModel(); String[] requiredProjectNames = project.getRequiredProjectNames(); for (int i = 0; i < requiredProjectNames.length; i++) { IJavaProject requiredProject = javaModel.getJavaProject(requiredProjectNames[i]); if (requiredProject.exists()) { type = internalFindType(requiredProject, className, visitedProjects); if (type != null) return type; } } return null; }
From source file:org.talend.designer.runprocess.java.TalendProcessJavaProjectTest.java
License:Open Source License
/** * Test method for {@link org.talend.designer.runprocess.java.TalendProcessJavaProject#getJavaProject()}. *//* w w w .ja v a2 s . c o m*/ @Test public void testGetJavaProject() { IJavaProject javaProject = talendJavaProject.getJavaProject(); Assert.assertNotNull(javaProject); Assert.assertTrue(javaProject.exists()); Assert.assertTrue(javaProject.isOpen()); Assert.assertNotNull(javaProject.getProject()); }
From source file:org.teavm.eclipse.debugger.TeaVMSourceLookupParticipant.java
License:Apache License
@Override public void sourceContainersChanged(ISourceLookupDirector director) { delegateContainers.clear();//from w w w . ja va2 s.c o m ISourceContainer[] containers = director.getSourceContainers(); for (int i = 0; i < containers.length; i++) { ISourceContainer container = containers[i]; if (container.getType().getId().equals(ArchiveSourceContainer.TYPE_ID)) { IFile file = ((ArchiveSourceContainer) container).getFile(); IProject project = file.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { try { IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int j = 0; j < roots.length; j++) { IPackageFragmentRoot root = roots[j]; if (file.equals(root.getUnderlyingResource())) { delegateContainers.put(container, new PackageFragmentRootSourceContainer(root)); } else { IPath path = root.getSourceAttachmentPath(); if (path != null) { if (file.getFullPath().equals(path)) { delegateContainers.put(container, new PackageFragmentRootSourceContainer(root)); } } } } } catch (JavaModelException e) { } } } } }
From source file:org.whole.lang.ui.controls.JavaSourceFolderFilter.java
License:Open Source License
public boolean select(Viewer viewer, Object parent, Object element) { // filter any non container resource if (!(element instanceof IContainer)) return false; IContainer container = (IContainer) element; IProject proj = container.getProject(); try {/*w w w . ja v a 2 s . c o m*/ if (!proj.hasNature(JavaCore.NATURE_ID)) return false; IJavaProject jProject = JavaCore.create(container.getProject()); if (jProject == null || !jProject.exists()) return false; // get any project container if (container == proj) return true; IPackageFragmentRoot sourceLocation = jProject.getPackageFragmentRoot(container); IClasspathEntry cpentry = sourceLocation.getRawClasspathEntry(); if (cpentry != null && cpentry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { return true; } else { return false; } } catch (CoreException ex) { return false; } }
From source file:org.whole.lang.ui.controls.JavaSourceFolderValidator.java
License:Open Source License
private boolean isJavaSourceFolder(Object element) { if (!(element instanceof IContainer)) return false; IContainer container = (IContainer) element; IProject proj = container.getProject(); try {/*from ww w.j av a2 s .c om*/ if (!proj.hasNature(JavaCore.NATURE_ID)) return false; IJavaProject jProject = JavaCore.create(container.getProject()); if (jProject == null || !jProject.exists()) return false; IPackageFragmentRoot sourceLocation = jProject.getPackageFragmentRoot(container); IClasspathEntry cpentry = sourceLocation.getRawClasspathEntry(); if (cpentry != null && cpentry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { return true; } else { return false; } } catch (CoreException ex) { return false; } }
From source file:org.xpect.ui.launching.JUnitJavaElementDelegate.java
License:Open Source License
protected IJavaElement getJavaElementForXtextEditor(IEditorPart editor) { if (!(editor instanceof XtextEditor)) return null; IJavaProject jp = null; if (editor.getEditorInput() instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) editor.getEditorInput()).getFile(); if (new ContentTypeUtil().getContentType(file) != XpectContentType.XPECT) return null; jp = JavaCore.create(file.getProject()); if (jp == null || !jp.exists() || !jp.isOpen()) return null; } else//from ww w .ja va 2 s . c o m return null; XtextEditor xtextEditor = (XtextEditor) editor; ISelection selection = xtextEditor.getSelectionProvider().getSelection(); if (!(selection instanceof ITextSelection)) return null; final int offset = ((ITextSelection) selection).getOffset(); IJavaElement func = xtextEditor.getDocument().readOnly(new IUnitOfWork<IJavaElement, XtextResource>() { public IJavaElement exec(XtextResource state) throws Exception { XtextResource xpectResource = XpectFileAccess.getXpectResource(state); INode node = NodeModelUtils.findLeafNodeAtOffset(xpectResource.getParseResult().getRootNode(), offset); if (node != null) { EObject obj = node.getSemanticElement(); EObject current = obj; while (current != null) { // if (current instanceof XpectInvocation) { // XpectInvocation inv = (XpectInvocation) current; // JvmOperation operation = inv.getElement(); // if (operation != null && !operation.eIsProxy()) // return finder.findElementFor(operation); // return null; // } else if (current instanceof XpectFile) return getTestClassJavaElement((XpectFile) current); current = current.eContainer(); } } return null; } }); return func; }
From source file:org.xpect.ui.util.XpectUtil.java
License:Open Source License
public static XpectFile load(IFile file) { Injector injector = XpectActivator.getInstance().getInjector(XpectActivator.ORG_XPECT_XPECT); XtextResourceSet rs = new XtextResourceSet(); IJavaProject javaProject = JavaCore.create(file.getProject()); if (javaProject != null && javaProject.exists()) { rs.setClasspathURIContext(javaProject); rs.setClasspathUriResolver(new JdtClasspathUriResolver()); }/*from w w w .j a v a 2 s . c om*/ URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true); Resource resource = injector.getInstance(XtextResourceFactory.class).createResource(uri); rs.getResources().add(resource); try { resource.load(Collections.emptyMap()); for (EObject obj : resource.getContents()) if (obj instanceof XpectFile) return (XpectFile) obj; } catch (IOException e) { throw new RuntimeException(e); } return null; }
From source file:org.yakindu.sct.commons.WorkspaceClassLoaderFactory.java
License:Open Source License
protected IJavaProject toJavaProject(IProject project) { IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { return javaProject; }//from ww w . j a v a 2 s . c o m return null; }
From source file:runjettyrun.tabs.action.AddClassFolderAction.java
License:Open Source License
/** * Adds all projects required by <code>proj</code> to the list * <code>res</code>//from w w w . j av a2s .c om * * @param proj the project for which to compute required * projects * @param res the list to add all required projects too */ protected void collectRequiredProjects(IJavaProject proj, List<IJavaProject> res) throws JavaModelException { if (!res.contains(proj)) { res.add(proj); IJavaModel model = proj.getJavaModel(); IClasspathEntry[] entries = proj.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry curr = entries[i]; if (curr.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IJavaProject ref = model.getJavaProject(curr.getPath().segment(0)); if (ref.exists()) { collectRequiredProjects(ref, res); } } } } }
From source file:runjettyrun.tabs.action.AddClassFolderAction.java
License:Open Source License
/** * Adds all exported entries defined by <code>proj</code> to the list * <code>runtimeEntries</code>. * * @param proj//from w w w . ja v a 2 s. com * @param runtimeEntries * @throws JavaModelException */ protected void collectExportedEntries(IJavaProject proj, List<IRuntimeClasspathEntry> runtimeEntries) throws CoreException { IClasspathEntry[] entries = proj.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.isExported()) { IRuntimeClasspathEntry rte = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), proj); int kind = 0; switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: kind = IRuntimeClasspathEntry.USER_CLASSES; break; case IClasspathContainer.K_SYSTEM: kind = IRuntimeClasspathEntry.BOOTSTRAP_CLASSES; break; case IClasspathContainer.K_DEFAULT_SYSTEM: kind = IRuntimeClasspathEntry.STANDARD_CLASSES; break; } rte = JavaRuntime.newRuntimeContainerClasspathEntry(entry.getPath(), kind, proj); break; case IClasspathEntry.CPE_LIBRARY: rte = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()); rte.setSourceAttachmentPath(entry.getSourceAttachmentPath()); rte.setSourceAttachmentRootPath(entry.getSourceAttachmentRootPath()); break; case IClasspathEntry.CPE_PROJECT: String name = entry.getPath().segment(0); IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(name); if (p.exists()) { IJavaProject jp = JavaCore.create(p); if (jp.exists()) { rte = JavaRuntime.newProjectRuntimeClasspathEntry(jp); } } break; case IClasspathEntry.CPE_VARIABLE: rte = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath()); break; default: break; } if (rte != null) { if (!runtimeEntries.contains(rte)) { runtimeEntries.add(rte); } } } } }