Java Code Examples for org.eclipse.jdt.core.IPackageFragmentRoot#exists()
The following examples show how to use
org.eclipse.jdt.core.IPackageFragmentRoot#exists() .
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: Storage2UriMapperJavaImpl.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.5 */ @Override public URI getUri(/* @NonNull */ IStorage storage) { if (storage instanceof IJarEntryResource) { final IJarEntryResource casted = (IJarEntryResource) storage; IPackageFragmentRoot packageFragmentRoot = casted.getPackageFragmentRoot(); Map<URI, IStorage> data = getAllEntries(packageFragmentRoot); for (Map.Entry<URI, IStorage> entry : data.entrySet()) { if (entry.getValue().equals(casted)) return entry.getKey(); } if (packageFragmentRoot.exists() && packageFragmentRoot.isArchive()) { IPath jarPath = packageFragmentRoot.getPath(); URI jarURI; if (packageFragmentRoot.isExternal()) { jarURI = URI.createFileURI(jarPath.toOSString()); } else { jarURI = URI.createPlatformResourceURI(jarPath.toString(), true); } URI result = URI.createURI("archive:" + jarURI + "!" + storage.getFullPath()); return result; } } return null; }
Example 2
Source File: SourceFolderSelectionDialogButtonField.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * tries to build a packagefragmentroot out of a string and sets the string into this * packagefragmentroot. * * @param rootString */ private IPackageFragmentRoot getRootFromString(String rootString) { if (rootString.length() == 0) { return null; } IPath path= new Path(rootString); IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot(); IResource res= workspaceRoot.findMember(path); if (res == null) { return null; } int resType= res.getType(); if (resType == IResource.PROJECT || resType == IResource.FOLDER) { IProject proj= res.getProject(); if (!proj.isOpen()) { return null; } IJavaProject jproject= JavaCore.create(proj); IPackageFragmentRoot root= jproject.getPackageFragmentRoot(res); if (root.exists()) { return root; } } return null; }
Example 3
Source File: ClasspathResourceUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
private static IPackageFragmentRoot getPackageFragmentRootForResource(IResource resource, IJavaProject javaProject) throws JavaModelException { while (resource != null) { IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(resource); /* * Not using JavaModelSearch.isValidElement since checking for exclusions from the buildpath is the caller's * responsibility. */ if (root != null && root.exists()) { return root; } resource = resource.getParent(); } return null; }
Example 4
Source File: PackageFragmentRootWalker.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public T traverse(IPackageFragmentRoot root, boolean stopOnFirstResult) throws JavaModelException { T result = null; if (root.exists() && existsPhysically(root)) { Object[] resources = root.getNonJavaResources(); TraversalState state = new TraversalState(root); for (Object object : resources) { if (object instanceof IJarEntryResource) { result = traverse((IJarEntryResource) object, stopOnFirstResult, state); if (stopOnFirstResult && result != null) return result; } } IJavaElement[] children = root.getChildren(); for (IJavaElement javaElement : children) { if (javaElement instanceof IPackageFragment) { result = traverse((IPackageFragment) javaElement, stopOnFirstResult, state); if (stopOnFirstResult && result != null) return result; } } } return result; }
Example 5
Source File: Storage2UriMapperJavaImpl.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private Object computeModificationStamp(IPackageFragmentRoot root) { try { if (root.exists()) { IResource resource = root.getUnderlyingResource(); if (resource != null) { Object result = getLastModified(resource); if (result != null) { return result; } } return root.getPath().toFile().lastModified(); } } catch (CoreException e) { log.error(e.getMessage(), e); } return new Object(); }
Example 6
Source File: NewModuleWizardPage.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
private IPackageFragment choosePackage() { IPackageFragmentRoot root = getPackageFragmentRoot(); IJavaElement[] packages = null; try { if (root != null && root.exists()) { packages = root.getChildren(); } } catch (JavaModelException e) { JavaPlugin.log(e); } if (packages == null) { packages = new IJavaElement[0]; } ElementListSelectionDialog dialog = new ElementListSelectionDialog( getShell(), new JavaElementLabelProvider( JavaElementLabelProvider.SHOW_DEFAULT)); dialog.setIgnoreCase(false); dialog.setTitle(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_title); dialog.setMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_description); dialog.setEmptyListMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_empty); dialog.setElements(packages); dialog.setHelpAvailable(false); if (dialog.open() == Window.OK) { return (IPackageFragment) dialog.getFirstResult(); } return null; }
Example 7
Source File: JavaDeleteProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean skipDeletingReferencedRoot(IConfirmQuery query, IPackageFragmentRoot root, List<IJavaProject> referencingProjects) throws OperationCanceledException { if (referencingProjects.isEmpty() || root == null || ! root.exists() ||! root.isArchive()) return false; String label= JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT); String question= referencingProjects.size() == 1 ? Messages.format(RefactoringCoreMessages.DeleteRefactoring_3_singular, label) : Messages.format( RefactoringCoreMessages.DeleteRefactoring_3_plural, label); return ! query.confirm(question, referencingProjects.toArray()); }
Example 8
Source File: RenameSourceFolderChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static RefactoringStatus checkIfModifiable(IPackageFragmentRoot root) throws CoreException { RefactoringStatus result= new RefactoringStatus(); if (root == null) { result.addFatalError(RefactoringCoreMessages.DynamicValidationStateChange_workspace_changed); return result; } if (!root.exists()) { result.addFatalError(Messages.format(RefactoringCoreMessages.Change_does_not_exist, getRootLabel(root))); return result; } if (result.hasFatalError()) return result; if (root.isArchive()) { result.addFatalError(Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_rename_archive, getRootLabel(root))); return result; } if (root.isExternal()) { result.addFatalError(Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_rename_external, getRootLabel(root))); return result; } IResource correspondingResource= root.getCorrespondingResource(); if (correspondingResource == null || !correspondingResource.exists()) { result.addFatalError(Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_error_underlying_resource_not_existing, getRootLabel(root))); return result; } if (correspondingResource.isLinked()) { result.addFatalError(Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_rename_linked, getRootLabel(root))); return result; } return result; }
Example 9
Source File: JavaSourcePackageFragmentRootCompletionProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * @param prefix prefixString with thatthe sourcepackagefragmentroots must begin * @param replacementLength length of the text to replace * @return array with sourcepackagefragmentroots */ private ICompletionProposal[] createSourcePackageFragmentRootProposals(String prefix, int replacementLength) { List<JavaCompletionProposal> proposals= new ArrayList<JavaCompletionProposal>(); try { IJavaProject[] projects= fRoot.getJavaProjects(); for (int i= 0; i < projects.length; i++) { IJavaProject project= projects[i]; IPackageFragmentRoot[] roots= project.getPackageFragmentRoots(); for (int j= 0; j < roots.length; j++) { IPackageFragmentRoot root= roots[j]; if (root.exists() && (root.getKind() == IPackageFragmentRoot.K_SOURCE)) { String name= root.getPath().toString(); if (name.length() > 1) { name= name.substring(1); } if (name.startsWith(prefix)) { Image image= fLabelProvider.getImage(root); JavaCompletionProposal proposal= new JavaCompletionProposal(name, 0, replacementLength, image, name, 0); proposals.add(proposal); } } } } } catch (JavaModelException e) { // nothing to do } return proposals.toArray(new ICompletionProposal[proposals.size()]); }
Example 10
Source File: PasteAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean isWritable(IPackageFragmentRoot packageFragmentRoot) { try { return packageFragmentRoot.exists() && ! packageFragmentRoot.isArchive() && ! packageFragmentRoot.isReadOnly() && packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE; } catch (JavaModelException e) { return false; } }
Example 11
Source File: PackageBrowseAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
static boolean canAddPackageRoot(IPackageFragmentRoot root) throws JavaModelException{ if (! root.exists()) return false; if (root.isArchive()) return false; if (root.isExternal()) return false; if (root.isReadOnly()) return false; if (! root.isStructureKnown()) return false; return true; }
Example 12
Source File: PackageSelectionStringButtonAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void changeControlPressed(DialogField field) { IPackageFragmentRoot root= fPackageSelectionField.getSelectedFragmentRoot(); IJavaElement[] packages= null; try { if (root != null && root.exists()) { packages= root.getChildren(); } } catch (JavaModelException e) { // no need to react } if (packages == null) { packages= new IJavaElement[0]; } ElementListSelectionDialog dialog= new ElementListSelectionDialog(field.getLabelControl(null).getShell(), new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT)); dialog.setIgnoreCase(true); dialog.setTitle(fTitle); dialog.setMessage(fMessage); dialog.setEmptyListMessage(fEmtpyListMessage); dialog.setElements(packages); // TODO initial selection // List selection = new ArrayList(); // selection.add(fPackageSelectionField.fPackageSelection.getPackageFragment()); // dialog.setInitialElementSelections(selection); if (dialog.open() == Window.OK) { IPackageFragment fragment= (IPackageFragment)dialog.getFirstResult(); fPackageSelectionField.setSelected(fragment); } }
Example 13
Source File: NLSAccessorConfigurationDialog.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void checkPackageFragment() { IPackageFragmentRoot root= fAccessorPackage.getSelectedFragmentRoot(); if ((root == null) || !root.exists()) { setInvalid(IDX_ACCESSOR_PACKAGE, NLSUIMessages.NLSAccessorConfigurationDialog_accessor_package_root_invalid); return; } IPackageFragment fragment= fAccessorPackage.getSelected(); if ((fragment == null) || !fragment.exists()) { setInvalid(IDX_ACCESSOR_PACKAGE, NLSUIMessages.NLSAccessorConfigurationDialog_accessor_package_invalid); return; } setValid(IDX_ACCESSOR_PACKAGE); }
Example 14
Source File: JavaDocLocations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the reason for why the Javadoc of the Java element could not be retrieved. * * @param element whose Javadoc could not be retrieved * @param root the root of the Java element * @return the String message for why the Javadoc could not be retrieved for the Java element or * <code>null</code> if the Java element is from a source container * @since 3.9 */ public static String getExplanationForMissingJavadoc(IJavaElement element, IPackageFragmentRoot root) { String message= null; try { boolean isBinary= (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY); if (isBinary) { boolean hasAttachedJavadoc= JavaDocLocations.getJavadocBaseLocation(element) != null; boolean hasAttachedSource= root.getSourceAttachmentPath() != null; IOpenable openable= element.getOpenable(); boolean hasSource= openable.getBuffer() != null; // Provide hint why there's no Java doc if (!hasAttachedSource && !hasAttachedJavadoc) message= CorextMessages.JavaDocLocations_noAttachments; else if (!hasAttachedJavadoc && !hasSource) message= CorextMessages.JavaDocLocations_noAttachedJavadoc; else if (!hasAttachedSource) message= CorextMessages.JavaDocLocations_noAttachedSource; else if (!hasSource) message= CorextMessages.JavaDocLocations_noInformation; } } catch (JavaModelException e) { message= CorextMessages.JavaDocLocations_error_gettingJavadoc; JavaPlugin.log(e); } return message; }
Example 15
Source File: NewTypeWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Checks if the package field has to be pre-filled in this page and returns the package * fragment to be used for that. The package fragment has the name of the project if the source * folder does not contain any package and if the project name is a valid package name. If the * source folder contains exactly one package then the name of that package is used as the * package fragment's name. <code>null</code> is returned if none of the above is applicable. * * @param javaProject the containing Java project of the selection used to initialize this page * * @return the package fragment to be pre-filled in this page or <code>null</code> if no * suitable package can be suggested for the given project * * @since 3.9 */ private IPackageFragment getPackage(IJavaProject javaProject) { String packName= null; final IPackageFragmentRoot pkgFragmentRoot= getPackageFragmentRoot(); IJavaElement[] packages= null; try { if (pkgFragmentRoot != null && pkgFragmentRoot.exists()) { packages= pkgFragmentRoot.getChildren(); if (packages.length == 1) { // only default package -> use Project name packName= javaProject.getElementName(); // validate package name IStatus status= validatePackageName(packName, javaProject); if (status.getSeverity() == IStatus.OK) { return pkgFragmentRoot.getPackageFragment(packName); } } else { int noOfPackages= 0; IPackageFragment thePackage= null; for (final IJavaElement pack : packages) { IPackageFragment pkg= (IPackageFragment) pack; // ignoring empty parent packages and default package if ((!pkg.hasSubpackages() || pkg.hasChildren()) && !pkg.isDefaultPackage()) { noOfPackages++; thePackage= pkg; if (noOfPackages > 1) { return null; } } } if (noOfPackages == 1) { // use package name packName= thePackage.getElementName(); return pkgFragmentRoot.getPackageFragment(packName); } } } } catch (JavaModelException e) { // fall through } return null; }
Example 16
Source File: NewTypeWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Opens a selection dialog that allows to select a package. * * @return returns the selected package or <code>null</code> if the dialog has been canceled. * The caller typically sets the result to the package input field. * <p> * Clients can override this method if they want to offer a different dialog. * </p> * * @since 3.2 */ protected IPackageFragment choosePackage() { IPackageFragmentRoot froot= getPackageFragmentRoot(); IJavaElement[] packages= null; try { if (froot != null && froot.exists()) { packages= froot.getChildren(); } } catch (JavaModelException e) { JavaPlugin.log(e); } if (packages == null) { packages= new IJavaElement[0]; } ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT)); dialog.setIgnoreCase(false); dialog.setTitle(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_title); dialog.setMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_description); dialog.setEmptyListMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_empty); dialog.setElements(packages); dialog.setHelpAvailable(false); IPackageFragment pack= getPackageFragment(); if (pack != null) { dialog.setInitialSelections(new Object[] { pack }); } if (dialog.open() == Window.OK) { return (IPackageFragment) dialog.getFirstResult(); } return null; }
Example 17
Source File: NLSAccessorConfigurationDialog.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void validatePropertyPackage() { IPackageFragmentRoot root= fResourceBundlePackage.getSelectedFragmentRoot(); if ((root == null) || !root.exists()) { setInvalid(IDX_BUNDLE_PACKAGE, NLSUIMessages.NLSAccessorConfigurationDialog_property_package_root_invalid); return; } IPackageFragment fragment= fResourceBundlePackage.getSelected(); if ((fragment == null) || !fragment.exists()) { setInvalid(IDX_BUNDLE_PACKAGE, NLSUIMessages.NLSAccessorConfigurationDialog_property_package_invalid); return; } String pkgName= fragment.getElementName(); IStatus status= JavaConventionsUtil.validatePackageName(pkgName, root); if ((pkgName.length() > 0) && (status.getSeverity() == IStatus.ERROR)) { setInvalid(IDX_BUNDLE_PACKAGE, status.getMessage()); return; } IPath pkgPath= new Path(pkgName.replace('.', IPath.SEPARATOR)).makeRelative(); IJavaProject project= fRefactoring.getCu().getJavaProject(); try { IJavaElement element= project.findElement(pkgPath); if (element == null || !element.exists()) { setInvalid(IDX_BUNDLE_PACKAGE, NLSUIMessages.NLSAccessorConfigurationDialog_must_exist); return; } IPackageFragment fPkgFragment= (IPackageFragment) element; if (!PackageBrowseAdapter.canAddPackage(fPkgFragment)) { setInvalid(IDX_BUNDLE_PACKAGE, NLSUIMessages.NLSAccessorConfigurationDialog_incorrect_package); return; } if (!PackageBrowseAdapter.canAddPackageRoot((IPackageFragmentRoot) fPkgFragment.getParent())) { setInvalid(IDX_BUNDLE_PACKAGE, NLSUIMessages.NLSAccessorConfigurationDialog_incorrect_package); return; } } catch (JavaModelException e) { setInvalid(IDX_BUNDLE_PACKAGE, e.getStatus().getMessage()); return; } setValid(IDX_BUNDLE_PACKAGE); }
Example 18
Source File: NewPackageWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * The wizard owning this page is responsible for calling this method with the * current selection. The selection is used to initialize the fields of the wizard * page. * * @param selection used to initialize the fields */ public void init(IStructuredSelection selection) { IJavaElement jelem= getInitialJavaElement(selection); initContainerPage(jelem); String pName= ""; //$NON-NLS-1$ if (jelem != null) { IPackageFragment pf= (IPackageFragment) jelem.getAncestor(IJavaElement.PACKAGE_FRAGMENT); if (pf != null && !pf.isDefaultPackage()) { pName= pf.getElementName(); } else { if (jelem.getJavaProject() != null) { final IPackageFragmentRoot pkgFragmentRoot= getPackageFragmentRoot(); if (pkgFragmentRoot != null && pkgFragmentRoot.exists()) { try { IJavaElement[] packages= pkgFragmentRoot.getChildren(); if (packages.length == 1) { // only default package String prName= jelem.getJavaProject().getElementName(); IStatus status= getPackageStatus(prName); if (status.getSeverity() == IStatus.OK) { pName= prName; } } } catch (JavaModelException e) { // fall through } } } } } setPackageText(pName, true); IDialogSettings dialogSettings= getDialogSettings(); if (dialogSettings != null) { IDialogSettings section= dialogSettings.getSection(PAGE_NAME); if (section != null) { boolean createPackageDocumentation= section.getBoolean(SETTINGS_CREATEPACKAGE_INFO_JAVA); fCreatePackageInfoJavaDialogField.setSelection(createPackageDocumentation); } } updateStatus(new IStatus[] { fContainerStatus, fPackageStatus }); }