List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot exists
boolean exists();
From source file:ar.com.tadp.xml.rinzo.jdt.wizards.NewPackageContainerWizardPage.java
License:Open Source License
protected IPackageFragment choosePackage() { IPackageFragmentRoot froot = getPackageFragmentRoot(); IJavaElement[] packages = null;//from w ww. ja v a 2 s .c o m try { if (froot != null && froot.exists()) { packages = froot.getChildren(); } } catch (JavaModelException e) { XMLEditorPlugin.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; }
From source file:ca.ecliptical.pde.ds.search.DescriptorQueryParticipant.java
License:Open Source License
private void searchBundle(final IPluginModelBase model, IJavaProject javaProject, IProgressMonitor monitor) throws CoreException { // note: there's no getBundleDescription().getBundle() so we have to parse the manifest ourselves Map<String, String> headers = ManifestUtils.loadManifest(new File(model.getInstallLocation())); String header = headers.get(SERVICE_COMPONENT_HEADER); if (header == null) { if (debug.isDebugging()) debug.trace(String.format("No Service-Component header in bundle: %s", //$NON-NLS-1$ model.getUnderlyingResource().getFullPath())); return;// www. ja v a 2s . com } File bundleRoot = new File(model.getInstallLocation()); IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(bundleRoot.getAbsolutePath()); final HashSet<IStorage> files = new HashSet<IStorage>(); String[] elements = header.split("\\s*,\\s*"); //$NON-NLS-1$ for (String element : elements) { if (element.length() == 0) continue; final IPath path = new Path(element).makeRelative(); String lastSegment = path.lastSegment(); if (lastSegment.indexOf('*') >= 0) { // wildcard path; get all entries in directory final Filter filter; try { filter = FrameworkUtil.createFilter("(filename=" + sanitizeFilterValue(lastSegment) + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (InvalidSyntaxException e) { // ignore continue; } IPath folderPath = path.removeLastSegments(1); if (packageRoot.exists()) { IJarEntryResource folderEntry = findJarEntry(packageRoot, folderPath); if (folderEntry != null) { IJarEntryResource[] fileEntries = findMatchingJarEntries(folderEntry, filter); for (IJarEntryResource fileEntry : fileEntries) { files.add(fileEntry); } } } else { File entryDir = folderPath.isEmpty() ? bundleRoot : new File(bundleRoot, folderPath.toString()); entryDir.listFiles(new FileFilter() { public boolean accept(File pathname) { if (filter.matches(Collections.singletonMap("filename", pathname.getName()))) { //$NON-NLS-1$ try { files.add(new ExternalDescriptorFile(path, pathname.toURI().toURL())); } catch (MalformedURLException e) { if (debug.isDebugging()) debug.trace(String.format("Unable to create URL for file: %s", pathname), //$NON-NLS-1$ e); } } return false; } }); } } else { if (packageRoot.exists()) { IJarEntryResource jarEntry = findJarEntry(packageRoot, path); if (jarEntry != null) files.add(jarEntry); } else { URL url; try { if (bundleRoot.isDirectory()) url = new File(bundleRoot, path.toString()).toURI().toURL(); else url = new URL("jar:" + bundleRoot.toURI() + "!/" + path); //$NON-NLS-1$ //$NON-NLS-2$ } catch (IOException e) { if (debug.isDebugging()) debug.trace(String.format("Error creating JAR URL for file '%s' in bundle '%s'.", path, //$NON-NLS-1$ bundleRoot), e); continue; } files.add(new ExternalDescriptorFile(path, url)); } } } // process each descriptor file monitor.beginTask(model.getBundleDescription().getSymbolicName(), files.size()); try { for (IStorage file : files) { if (monitor.isCanceled()) throw new OperationCanceledException(); searchFile(file, javaProject, new SubProgressMonitor(monitor, 1)); } } finally { monitor.done(); } }
From source file:com.codenvy.ide.ext.java.server.javadoc.JavaDocLocations.java
License:Open Source License
/** * 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/* w w w .j av a 2 s. c o m*/ */ 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; LOG.error(message, e); } return message; }
From source file:com.google.gdt.eclipse.appengine.rpc.wizards.RPCWizardUISupport.java
License:Open Source License
protected IPackageFragment choosePackage(IPackageFragmentRoot containerRoot) { IJavaElement[] packages = null;/* w w w . ja v a2 s.c o m*/ try { if (containerRoot != null && containerRoot.exists()) { packages = containerRoot.getChildren(); } } catch (JavaModelException e) { AppEngineRPCPlugin.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; }
From source file:com.google.gdt.eclipse.core.java.ClasspathResourceUtilities.java
License:Open Source License
private static IPackageFragmentRoot getPackageFragmentRootForResource(IResource resource, IJavaProject javaProject) throws JavaModelException { while (resource != null) { IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(resource); /*// w ww.ja v a2 s. com * 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; }
From source file:com.google.gdt.eclipse.designer.wizards.ui.JUnitWizardPage.java
License:Open Source License
private IPackageFragmentRoot handleTestSourceFolder(IJavaProject javaProject) throws Exception { String testSourceFolderName = com.google.gdt.eclipse.designer.Activator.getStore() .getString(Constants.P_GWT_TESTS_SOURCE_FOLDER); IFolder testSourceFolder = javaProject.getProject().getFolder(testSourceFolderName); IPackageFragmentRoot testSourceFragmentRoot = (IPackageFragmentRoot) JavaCore.create(testSourceFolder); // check create if (!testSourceFolder.exists() || testSourceFragmentRoot == null || !testSourceFragmentRoot.exists()) { // create folder if (!testSourceFolder.exists()) { testSourceFolder.create(true, false, null); }/* w ww . j a va 2s . co m*/ IClasspathEntry[] classpath = javaProject.getRawClasspath(); // find last source entry int insertIndex = -1; for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { insertIndex = i + 1; } } // insert new source to entries IClasspathEntry testSourceEntry = JavaCore.newSourceEntry(testSourceFolder.getFullPath()); if (insertIndex == -1) { classpath = (IClasspathEntry[]) ArrayUtils.add(classpath, testSourceEntry); } else { classpath = (IClasspathEntry[]) ArrayUtils.add(classpath, insertIndex, testSourceEntry); } // modify classpath javaProject.setRawClasspath(classpath, javaProject.getOutputLocation(), null); testSourceFragmentRoot = (IPackageFragmentRoot) JavaCore.create(testSourceFolder); } // setPackageFragmentRoot(testSourceFragmentRoot, true); return testSourceFragmentRoot; }
From source file:com.google.gwt.eclipse.core.speedtracer.ViewSourceServlet.java
License:Open Source License
private IEditorPart openEditorForFileInJar(String jarPathString, String classpathRelativeFilePathString, String preferredProjectName) { IPackageFragmentRoot jarPackageFragmentRoot; try {/*from w ww .ja va 2 s .c o m*/ jarPackageFragmentRoot = getPackageFragmentRoot(jarPathString, preferredProjectName); } catch (IOException e) { GWTPluginLog.logError(e); return null; } if (jarPackageFragmentRoot == null || !jarPackageFragmentRoot.exists()) { GWTPluginLog.logError("Could not view source because the file at \"" + jarPathString + "\" may not be a valid JAR, or may not contain java elements"); return null; } IPath classpathRelativeFilePath = new Path(classpathRelativeFilePathString); IPath packagePath = classpathRelativeFilePath.removeLastSegments(1); String packageName = JavaUtilities.getPackageNameFromPath(packagePath); IPackageFragment packageFragment = jarPackageFragmentRoot.getPackageFragment(packageName); if (!packageFragment.exists()) { GWTPluginLog.logError("Could not view source because the package " + packageName + " inside " + jarPathString + " could not be found"); return null; } String fileName = classpathRelativeFilePath.lastSegment(); String classFileName; if (ResourceUtils.endsWith(fileName, ".java")) { classFileName = fileName.substring(0, fileName.length() - ".java".length()) + ".class"; } else if (ResourceUtils.endsWith(fileName, ".class")) { classFileName = fileName; } else { GWTPluginLog.logError( "Could not view source because cannot handle file type of " + fileName + " inside a JAR"); return null; } try { final IPackageFragment pf = packageFragment; final String finalClassFileName = classFileName; final IEditorPart[] part = new IEditorPart[1]; Display.getDefault().syncExec(new Runnable() { public void run() { try { part[0] = EditorUtility.openInEditor(pf.getClassFile(finalClassFileName), true); } catch (Throwable e) { GWTPluginLog.logError(e, "Could not open java editor"); } } }); return part[0]; } catch (Throwable e) { GWTPluginLog.logError(e, "Could not get files from the package " + packageFragment); return null; } }
From source file:com.google.gwt.eclipse.core.wizards.NewModuleWizardPage.java
License:Open Source License
private IPackageFragment choosePackage() { IPackageFragmentRoot root = getPackageFragmentRoot(); IJavaElement[] packages = null;/*from ww w . ja v a2 s . co m*/ 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; }
From source file:com.gwtplatform.plugin.wizard.NewActionWizardPage.java
License:Apache License
protected IPackageFragment chooseActionHandler() { IPackageFragmentRoot froot = getPackageFragmentRoot(); IJavaElement[] packages = null;/* ww w. ja v a 2 s. co m*/ try { if (froot != null && froot.exists()) { packages = froot.getChildren(); } } catch (JavaModelException e) { e.printStackTrace(); } if (packages == null) { packages = new IJavaElement[0]; } ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT)); dialog.setIgnoreCase(false); dialog.setTitle("ActionHandler Package Selection"); dialog.setMessage("Choose a folder:"); dialog.setEmptyListMessage("Cannot find packages to select."); dialog.setElements(packages); dialog.setHelpAvailable(false); dialog.setFilter("*server"); if (dialog.open() == Window.OK) { return (IPackageFragment) dialog.getFirstResult(); } return null; }
From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonProjectModulesContainer.java
License:Apache License
public static boolean isProjectModule(IJavaProject javaProject, Module module) throws JavaModelException { boolean isSource = false; for (IPackageFragmentRoot s : javaProject.getPackageFragmentRoots()) { if (s.exists() && javaProject.isOnClasspath(s) && s.getKind() == IPackageFragmentRoot.K_SOURCE && s.getPackageFragment(module.getNameAsString()).exists()) { isSource = true;/*from w w w. j a v a2 s. c o m*/ break; } } return isSource; }