List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot exists
boolean exists();
From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewTypeWizardPageListener.java
License:Open Source License
private IPackageFragment choosePackage() { IPackageFragmentRoot froot = getObservedPage().getPackageFragmentRoot(); IJavaElement[] packages = null;//from w w w . jav a 2 s.co m try { if (froot != null && froot.exists()) { packages = froot.getChildren(); } } catch (JavaModelException ex) { OTDTUIPlugin.logException(null, ex); } if (packages == null) { packages = new IJavaElement[0]; } ElementListSelectionDialog dialog = new ElementListSelectionDialog(getObservedPage().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); IPackageFragment pack = getObservedPage().getPackageFragment(); if (pack != null) { dialog.setInitialSelections(new Object[] { pack }); } if (dialog.open() == ElementListSelectionDialog.OK) { return (IPackageFragment) dialog.getFirstResult(); } return null; }
From source file:org.eclipse.objectteams.otdt.ui.tests.core.CompletionTestSetup.java
License:Open Source License
public static IPackageFragment getAbsoluteTestPackage(IJavaProject project, String packageName) throws CoreException { IPackageFragmentRoot root = project.getPackageFragmentRoot("src"); if (!root.exists()) root = JavaProjectHelper.addSourceContainer(project, "src"); IPackageFragment fragment = root.getPackageFragment(packageName); if (!fragment.exists()) fragment = root.createPackageFragment(packageName, false, null); return fragment; }
From source file:org.eclipse.objectteams.otdt.ui.tests.core.CompletionTestSetup.java
License:Open Source License
public static IPackageFragment getAnonymousTestPackage(IJavaProject project) throws CoreException { String sourceFolder = "src" + fAnonymousSoureFolderCounter++; IPackageFragmentRoot root = project.getPackageFragmentRoot(sourceFolder); if (!root.exists()) root = JavaProjectHelper.addSourceContainer(project, sourceFolder); IPackageFragment fragment = root.getPackageFragment("test1"); if (!fragment.exists()) fragment = root.createPackageFragment("test1", false, null); return fragment; }
From source file:org.eclipse.pde.api.tools.internal.model.ProjectComponent.java
License:Open Source License
/** * Finds and returns an {@link IApiTypeContainer} for the specified source * folder, or <code>null</code> if it does not exist. If the source folder * shares an output location with a previous source folder, the output * location is shared (a new one is not created). * //from w ww . j av a2s. co m * @param location project relative path to the source folder * @return {@link IApiTypeContainer} or <code>null</code> */ private IApiTypeContainer getApiTypeContainer(String location, IApiComponent component) throws CoreException { if (this.fOutputLocationToContainer == null) { baselineDisposed(getBaseline()); } IResource res = fProject.getProject().findMember(new Path(location)); if (res != null) { IPackageFragmentRoot root = fProject.getPackageFragmentRoot(res); if (root.exists()) { if (root.getKind() == IPackageFragmentRoot.K_BINARY) { if (res.getType() == IResource.FOLDER) { // class file folder IPath location2 = res.getLocation(); IApiTypeContainer cfc = fOutputLocationToContainer.get(location2); if (cfc == null) { cfc = new ProjectTypeContainer(component, (IContainer) res); fOutputLocationToContainer.put(location2, cfc); } return cfc; } } else { IClasspathEntry entry = root.getRawClasspathEntry(); IPath outputLocation = entry.getOutputLocation(); if (outputLocation == null) { outputLocation = fProject.getOutputLocation(); } IApiTypeContainer cfc = fOutputLocationToContainer.get(outputLocation); if (cfc == null) { IPath projectFullPath = fProject.getProject().getFullPath(); IContainer container = null; if (projectFullPath.equals(outputLocation)) { // The project is its own output location container = fProject.getProject(); } else { container = fProject.getProject().getWorkspace().getRoot().getFolder(outputLocation); } cfc = new ProjectTypeContainer(component, container); fOutputLocationToContainer.put(outputLocation, cfc); } return cfc; } } } return null; }
From source file:org.eclipse.pde.api.tools.tests.AbstractApiTest.java
License:Open Source License
/** * Creates a project with the given name and adds the default 'src' folder * /*w w w .j ava 2 s. com*/ * @param name * @param packages an optional list of packages to add to the project when * it is created * @throws Exception */ protected void createProject(final String name, String[] packages) throws Exception { if (name == null) { return; } // create project and import source IJavaProject jproject = ProjectUtils.createPluginProject(name, new String[] { PDE.PLUGIN_NATURE, ApiPlugin.NATURE_ID }); assertNotNull("The java project must have been created", jproject); //$NON-NLS-1$ IPackageFragmentRoot root = jproject .getPackageFragmentRoot(jproject.getProject().getFolder(ProjectUtils.SRC_FOLDER)); assertTrue("the src root must have been created", root.exists()); //$NON-NLS-1$ if (packages != null) { IPackageFragment fragment = null; for (int i = 0; i < packages.length; i++) { fragment = root.createPackageFragment(packages[i], true, new NullProgressMonitor()); assertNotNull("the package fragment " + packages[i] + " cannot be null", fragment); //$NON-NLS-1$ //$NON-NLS-2$ } } PluginRegistry.getWorkspaceModels(); IApiBaseline baseline = getWorkspaceBaseline(); assertNotNull("the workspace baseline cannot be null", baseline); //$NON-NLS-1$ // This assertion caused intermittant failures, skipping it hasn't // caused any problems in the tests (Bug 368458) // IApiComponent component = baseline.getApiComponent(name); // assertNotNull("the test project api component must exist in the workspace baseline", // component); }
From source file:org.eclipse.pde.internal.core.ClasspathComputer.java
License:Open Source License
private static void addSourceFolder(IBuildEntry buildEntry, IProject project, HashSet<IPath> paths, ArrayList<IClasspathEntry> result) throws CoreException { String[] folders = buildEntry.getTokens(); for (int j = 0; j < folders.length; j++) { String folder = folders[j]; IPath path = project.getFullPath().append(folder); if (paths.add(path)) { if (project.findMember(folder) == null) { CoreUtility.createFolder(project.getFolder(folder)); } else { IPackageFragmentRoot root = JavaCore.create(project).getPackageFragmentRoot(path.toString()); if (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY) { result.add(root.getRawClasspathEntry()); continue; }/* w ww.ja v a 2 s . c o m*/ } result.add(JavaCore.newSourceEntry(path)); } } }
From source file:org.eclipse.pde.internal.core.ClasspathComputer.java
License:Open Source License
private static void addLibraryEntry(IProject project, IPluginLibrary library, IPath sourceAttachment, IClasspathAttribute[] attrs, ArrayList<IClasspathEntry> result) throws JavaModelException { String name = ClasspathUtilCore.expandLibraryName(library.getName()); IResource jarFile = project.findMember(name); if (jarFile == null) return;//from ww w . ja va 2 s . c o m IPackageFragmentRoot root = JavaCore.create(project).getPackageFragmentRoot(jarFile); if (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry oldEntry = root.getRawClasspathEntry(); // If we have the same binary root but new or different source, we should recreate the entry if ((sourceAttachment == null && oldEntry.getSourceAttachmentPath() != null) || (sourceAttachment != null && sourceAttachment.equals(oldEntry.getSourceAttachmentPath()))) { if (!result.contains(oldEntry)) { result.add(oldEntry); return; } } } IClasspathEntry entry = createClasspathEntry(project, jarFile, name, sourceAttachment, attrs, library.isExported()); if (!result.contains(entry)) result.add(entry); }
From source file:org.eclipse.pde.internal.core.util.ManifestUtils.java
License:Open Source License
public static IPackageFragmentRoot[] findPackageFragmentRoots(IManifestHeader header, IProject project) { IJavaProject javaProject = JavaCore.create(project); String[] libs;/* w w w . j a v a 2 s .com*/ if (header == null || header.getValue() == null) libs = new String[] { "." }; //$NON-NLS-1$ else libs = header.getValue().split(","); //$NON-NLS-1$ IBuild build = getBuild(project); if (build == null) { try { return javaProject.getPackageFragmentRoots(); } catch (JavaModelException e) { return new IPackageFragmentRoot[0]; } } List<IPackageFragmentRoot> pkgFragRoots = new LinkedList<IPackageFragmentRoot>(); for (int j = 0; j < libs.length; j++) { String lib = libs[j]; //https://bugs.eclipse.org/bugs/show_bug.cgi?id=230469 IPackageFragmentRoot root = null; if (!lib.equals(".")) { //$NON-NLS-1$ try { root = javaProject.getPackageFragmentRoot(project.getFile(lib)); } catch (IllegalArgumentException e) { return new IPackageFragmentRoot[0]; } } if (root != null && root.exists()) { pkgFragRoots.add(root); } else { IBuildEntry entry = build.getEntry("source." + lib); //$NON-NLS-1$ if (entry == null) continue; String[] tokens = entry.getTokens(); for (int i = 0; i < tokens.length; i++) { IResource resource = project.findMember(tokens[i]); if (resource == null) continue; root = javaProject.getPackageFragmentRoot(resource); if (root != null && root.exists()) pkgFragRoots.add(root); } } } return pkgFragRoots.toArray(new IPackageFragmentRoot[pkgFragRoots.size()]); }
From source file:org.eclipse.stardust.modeling.validation.util.TypeRequestor.java
License:Open Source License
private IType getJarIType(IJavaModel model, char[] packageName, String qualifiedName, String path, int index) throws JavaModelException { String jar = path.substring(0, index); String rest = path.substring(index + 1); index = rest.lastIndexOf(SEPARATOR); if (index != -1) { rest = rest.substring(index + 1); }/*from w w w . j a va 2s. co m*/ index = rest.lastIndexOf(EXTENSION_SEPARATOR); if (index != -1) { String file = rest.substring(0, index); String extension = rest.substring(index + 1); IPath[] enclosedPaths = scope.enclosingProjectsAndJars(); for (int i = 0; i < enclosedPaths.length; i++) { IPath curr = enclosedPaths[i]; if (curr.segmentCount() == 1) { IJavaProject project = model.getJavaProject(curr.segment(0)); IPackageFragmentRoot root = project.getPackageFragmentRoot(jar); if (root.exists()) { IPackageFragment fragment = root.getPackageFragment(String.valueOf(packageName)); if (fragment.exists()) { if ("class".equals(extension)) //$NON-NLS-1$ { IClassFile classFile = fragment.getClassFile(file + ".class"); //$NON-NLS-1$ if (classFile.exists()) { return classFile.getType(); } } else if ("java".equals(extension)) //$NON-NLS-1$ { ICompilationUnit unit = fragment.getCompilationUnit(file + ".java"); //$NON-NLS-1$ IType[] types = unit.getAllTypes(); for (int j = 0; j < types.length; j++) { if (qualifiedName.equals(types[j].getTypeQualifiedName('.'))) { return types[j]; } } } } break; } } } } return null; }
From source file:org.eclipse.wb.internal.core.nls.bundle.AbstractBundleSourceNewComposite.java
License:Open Source License
/** * Validate property fields.//from www.j ava 2s . c om */ protected void validatePropertyFields() { // validate source folder { IPackageFragmentRoot root = m_propertyPackageField.getRoot(); if (root == null || !root.exists()) { setInvalid(KEY_PROPERTY_FOLDER, Messages.AbstractBundleSourceNewComposite_validatePropertiesInvalidSourceFolder); } else { setValid(KEY_PROPERTY_FOLDER); } } // validate package { IPackageFragment fragment = m_propertyPackageField.getPackage(); if (fragment == null || !fragment.exists()) { setInvalid(KEY_PROPERTY_PACKAGE, Messages.AbstractBundleSourceNewComposite_validatePropertiesInvalidPackage); } else { setValid(KEY_PROPERTY_PACKAGE); } } // validate file name { String fileName = m_propertyFileField.getText(); if (fileName.length() == 0) { setInvalid(KEY_PROPERTY_FILE, Messages.AbstractBundleSourceNewComposite_validatePropertiesFileEmpty); } else if (!fileName.endsWith(".properties")) { setInvalid(KEY_PROPERTY_FILE, Messages.AbstractBundleSourceNewComposite_validatePropertiesFileExtension); } else { setValid(KEY_PROPERTY_FILE); } } }