Java Code Examples for org.eclipse.jdt.core.IJavaProject#isOpen()
The following examples show how to use
org.eclipse.jdt.core.IJavaProject#isOpen() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportPlatformWizard.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 6 votes |
protected void fixRuntimeEnvironment( String platformDir ) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( "platform" ); IJavaProject javaProject = JavaCore.create( project ); IVMInstall javaInstall = null; try { if(javaProject.isOpen()) { javaInstall = JavaRuntime.getVMInstall( javaProject ); } } catch( CoreException e ) { throw new IllegalStateException( e ); } if( javaInstall != null ) { setHeapSize( javaInstall ); } }
Example 2
Source File: SARLProposalProvider.java From sarl with Apache License 2.0 | 6 votes |
private static String extractProjectPath(IPath fileWorkspacePath, IJavaProject javaProject) { if (javaProject != null && javaProject.exists() && javaProject.isOpen()) { try { for (final IPackageFragmentRoot root: javaProject.getPackageFragmentRoots()) { if (!root.isArchive() && !root.isExternal()) { final IResource resource = root.getResource(); if (resource != null) { final IPath sourceFolderPath = resource.getFullPath(); if (sourceFolderPath.isPrefixOf(fileWorkspacePath)) { final IPath claspathRelativePath = fileWorkspacePath.makeRelativeTo(sourceFolderPath); return claspathRelativePath.removeLastSegments(1) .toString().replace("/", "."); //$NON-NLS-1$//$NON-NLS-2$ } } } } } catch (JavaModelException e) { Logger.getLogger(SARLProposalProvider.class).error(e.getLocalizedMessage(), e); } } return null; }
Example 3
Source File: JavaElementDelegate.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
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 (!fileExtensionProvider.isValid(file.getFileExtension())) { return null; } jp = JavaCore.create(file.getProject()); if (jp == null || !jp.exists() || !jp.isOpen()) return null; } else { 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().tryReadOnly(new IUnitOfWork<IJavaElement, XtextResource>() { @Override public IJavaElement exec(XtextResource state) throws Exception { return findJavaElement(state, offset); } }); return func; }
Example 4
Source File: XbaseResourceForEditorInputFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected boolean isValidationDisabled(URI uri, IStorage storage) { if (storage instanceof IFile) { IFile file = (IFile) storage; IJavaProject javaProject = JavaCore.create(file.getProject()); if (javaProject == null || !javaProject.exists() || !javaProject.isOpen()) { return true; } if (!canBuild(uri, storage)) { return true; } } return super.isValidationDisabled(uri, storage); }
Example 5
Source File: XtendUIValidator.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected String getExpectedPackageName(XtendFile xtendFile) { URI fileURI = xtendFile.eResource().getURI(); for(Pair<IStorage, IProject> storage: storage2UriMapper.getStorages(fileURI)) { if(storage.getFirst() instanceof IFile) { IPath fileWorkspacePath = storage.getFirst().getFullPath(); IJavaProject javaProject = JavaCore.create(storage.getSecond()); if(javaProject != null && javaProject.exists() && javaProject.isOpen()) { try { for(IPackageFragmentRoot root: javaProject.getPackageFragmentRoots()) { if(!root.isArchive() && !root.isExternal()) { IResource resource = root.getResource(); if(resource != null) { IPath sourceFolderPath = resource.getFullPath(); if(sourceFolderPath.isPrefixOf(fileWorkspacePath)) { IPath claspathRelativePath = fileWorkspacePath.makeRelativeTo(sourceFolderPath); return claspathRelativePath.removeLastSegments(1).toString().replace("/", "."); } } } } } catch (JavaModelException e) { LOG.error("Error resolving expected path for XtendFile", e); } } } } return null; }
Example 6
Source File: JavadocOptionsManager.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IJavaProject getSingleProjectFromInitialSelection() { IJavaProject res= null; for (int i= 0; i < fInitialElements.length; i++) { IJavaProject curr= fInitialElements[i].getJavaProject(); if (res == null) { res= curr; } else if (!res.equals(curr)) { return null; } } if (res != null && res.isOpen()) { return res; } return null; }
Example 7
Source File: JdtUtils.java From java-debug with Eclipse Public License 1.0 | 4 votes |
private static ISourceContainer[] getSourceContainers(IJavaProject project, Set<IRuntimeClasspathEntry> calculated) { if (project == null || !project.exists()) { return new ISourceContainer[0]; } try { IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(project); List<IRuntimeClasspathEntry> resolved = new ArrayList<>(); for (IRuntimeClasspathEntry entry : unresolved) { for (IRuntimeClasspathEntry resolvedEntry : JavaRuntime.resolveRuntimeClasspathEntry(entry, project)) { if (!calculated.contains(resolvedEntry)) { calculated.add(resolvedEntry); resolved.add(resolvedEntry); } } } Set<ISourceContainer> containers = new LinkedHashSet<>(); containers.addAll(Arrays.asList( JavaRuntime.getSourceContainers(resolved.toArray(new IRuntimeClasspathEntry[0])))); // Due to a known jdt java 9 support bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=525840, // it would miss some JRE libraries source containers when the debugger is running on JDK9. // As a workaround, recompute the possible source containers for JDK9 jrt-fs.jar libraries. IRuntimeClasspathEntry jrtFs = resolved.stream().filter(entry -> { return entry.getType() == IRuntimeClasspathEntry.ARCHIVE && entry.getPath().lastSegment().equals("jrt-fs.jar"); }).findFirst().orElse(null); if (jrtFs != null && project.isOpen()) { IPackageFragmentRoot[] allRoots = project.getPackageFragmentRoots(); for (IPackageFragmentRoot root : allRoots) { if (root.getPath().equals(jrtFs.getPath()) && isSourceAttachmentEqual(root, jrtFs)) { containers.add(new PackageFragmentRootSourceContainer(root)); } } } return containers.toArray(new ISourceContainer[0]); } catch (CoreException ex) { // do nothing. } return new ISourceContainer[0]; }
Example 8
Source File: JavadocOptionsManager.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private boolean isValidProject(IJavaProject project) { if (project != null && project.exists() && project.isOpen()) { return true; } return false; }