List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getResource
IResource getResource();
From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java
License:Open Source License
private void appendFolderLabel(IPackageFragmentRoot root, long flags) { IResource resource = root.getResource(); if (resource == null) { appendExternalArchiveLabel(root, flags); return;/*from w w w . j ava2 s. com*/ } boolean rootQualified = getFlag(flags, ROOT_QUALIFIED); boolean referencedQualified = getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED) && isReferenced(root); if (rootQualified) { fBuffer.append(root.getPath().makeRelative().toString()); } else { IPath projectRelativePath = resource.getProjectRelativePath(); if (projectRelativePath.segmentCount() == 0) { fBuffer.append(resource.getName()); referencedQualified = false; } else { fBuffer.append(projectRelativePath.toString()); } int offset = fBuffer.length(); if (referencedQualified) { fBuffer.append(CONCAT_STRING); fBuffer.append(resource.getProject().getName()); } else if (getFlag(flags, ROOT_POST_QUALIFIED)) { fBuffer.append(CONCAT_STRING); fBuffer.append(root.getParent().getElementName()); } else { return; } } }
From source file:com.motorola.studio.android.model.BuildingBlockModel.java
License:Apache License
/** * Extract source folder from selection. * @param selection//w ww.ja v a 2 s . co m * @return * @throws CoreException */ private static IPackageFragmentRoot extractPackageFragmentRoot(IStructuredSelection selection) throws CoreException { IPackageFragmentRoot pack = null; Object selectionElement = selection.getFirstElement(); if (selectionElement instanceof IPackageFragmentRoot) { pack = (IPackageFragmentRoot) selectionElement; } else if (selectionElement instanceof IJavaElement) { pack = (IPackageFragmentRoot) ((IJavaElement) selectionElement) .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (pack == null) { IJavaProject element = ((IJavaElement) selectionElement).getJavaProject(); for (IPackageFragmentRoot root : element.getPackageFragmentRoots()) { if (root.getResource() != null) { boolean isSrc = (root.getElementType() & IPackageFragmentRoot.K_SOURCE) == IPackageFragmentRoot.K_SOURCE; boolean isGen = root.getElementName().equals(IAndroidConstants.GEN_SRC_FOLDER) && (root.getParent() instanceof IJavaProject); if (isSrc && !isGen) { pack = root; break; } } } } } else if (selectionElement instanceof IResource) { IJavaProject element = JavaCore.create(((IResource) selectionElement).getProject()); if (element.isOpen()) { for (IPackageFragmentRoot root : element.getPackageFragmentRoots()) { if (root.getResource() != null) { boolean isSrc = (root.getElementType() & IPackageFragmentRoot.K_SOURCE) == IPackageFragmentRoot.K_SOURCE; boolean isGen = root.getElementName().equals(IAndroidConstants.GEN_SRC_FOLDER) && (root.getParent() instanceof IJavaProject); if (isSrc && !isGen) { pack = root; break; } } } } } else { IJavaProject[] allProjects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()) .getJavaProjects(); if ((allProjects != null) && (allProjects.length > 0)) { for (IJavaProject project : allProjects) { if (project.getResource().getProject().hasNature(IAndroidConstants.ANDROID_NATURE)) { IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); if ((roots != null) && (roots.length > 0)) { boolean found = false; for (IPackageFragmentRoot root : roots) { boolean isSrc = (root.getElementType() & IPackageFragmentRoot.K_SOURCE) == IPackageFragmentRoot.K_SOURCE; boolean isGen = root.getElementName().equals(IAndroidConstants.GEN_SRC_FOLDER) && (root.getParent() instanceof IJavaProject); if (isSrc && !isGen) { found = true; pack = root; break; } } if (found) { break; } } } } } } if (pack != null) { if (!pack.getJavaProject().getProject().hasNature(IAndroidConstants.ANDROID_NATURE)) { pack = extractPackageFragmentRoot(new TreeSelection()); } } return pack; }
From source file:com.mountainminds.eclemma.autoMerge.OldFileAnalyzer.java
License:Open Source License
private IResource getClassfilesLocation(IPackageFragmentRoot root) throws CoreException { // For binary roots the underlying resource directly points to class files: if (root.getKind() == IPackageFragmentRoot.K_BINARY) { return root.getResource(); }/*from w ww. j av a2 s . com*/ // For source roots we need to find the corresponding output folder: IPath path = root.getRawClasspathEntry().getOutputLocation(); if (path == null) { path = root.getJavaProject().getOutputLocation(); } return root.getResource().getWorkspace().getRoot().findMember(path); }
From source file:com.redhat.ceylon.eclipse.code.explorer.PackageExplorerContentProvider.java
License:Open Source License
@Override protected Object[] getPackageFragmentRoots(IJavaProject project) throws JavaModelException { if (!project.getProject().isOpen()) return NO_CHILDREN; List<Object> result = new ArrayList<Object>(); IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { IPackageFragmentRoot root = roots[i]; IClasspathEntry classpathEntry = root.getRawClasspathEntry(); int entryKind = classpathEntry.getEntryKind(); if (entryKind == IClasspathEntry.CPE_CONTAINER) { // all ClassPathContainers are added later } else if (fShowLibrariesNode && (entryKind == IClasspathEntry.CPE_LIBRARY || entryKind == IClasspathEntry.CPE_VARIABLE)) { IResource resource = root.getResource(); if (resource != null && project.getResource().equals(resource.getParent())) { // show resource as child of project, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=141906 result.add(resource);/*from ww w. j a v a 2 s. com*/ } else { // skip: will add the referenced library node later } } else { if (isProjectPackageFragmentRoot(root)) { // filter out package fragments that correspond to projects and // replace them with the package fragments directly Object[] fragments = getPackageFragmentRootContent(root); for (int j = 0; j < fragments.length; j++) { result.add(fragments[j]); } } else { result.add(root); } } } if (fShowLibrariesNode) { result.add(new LibraryContainer(project)); } // separate loop to make sure all containers are on the classpath (even empty ones) IClasspathEntry[] rawClasspath = project.getRawClasspath(); for (int i = 0; i < rawClasspath.length; i++) { IClasspathEntry classpathEntry = rawClasspath[i]; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { result.add(new ClassPathContainer(project, classpathEntry)); } } Object[] resources = project.getNonJavaResources(); for (int i = 0; i < resources.length; i++) { result.add(resources[i]); } return result.toArray(); }
From source file:com.redhat.ceylon.eclipse.code.explorer.PackageExplorerContentProvider.java
License:Open Source License
public Object getHierarchicalPackageParent(IPackageFragment child) { String name = child.getElementName(); IPackageFragmentRoot parent = (IPackageFragmentRoot) child.getParent(); int index = name.lastIndexOf('.'); if (index != -1) { String realParentName = name.substring(0, index); IPackageFragment element = parent.getPackageFragment(realParentName); if (element.exists()) { try { if (fFoldPackages && isEmpty(element) && findSinglePackageChild(element, parent.getChildren()) != null) { return getHierarchicalPackageParent(element); }/*from w ww . j ava 2s . c o m*/ } catch (JavaModelException e) { // ignore } return element; } else { // bug 65240 IResource resource = element.getResource(); if (resource != null) { return resource; } } } if (parent.getResource() instanceof IProject) { return parent.getJavaProject(); } return parent; }
From source file:com.technophobia.substeps.step.ProjectStepImplementationLoader.java
License:Open Source License
/** * Returns the path for this fragment in a OS friendly string. Note that in * windows, the method for getting the absolute path varies for source * folders and jars//w w w. j a va 2 s . co m * * @param fragmentRoot * The fragment containing classes * @return The path of this fragment root, os-friendly */ private String getPathFor(final IPackageFragmentRoot fragmentRoot) { final IResource resource = fragmentRoot.getResource(); final IPath path; if (resource != null) { path = resource.getRawLocation(); } else { path = fragmentRoot.getPath().makeAbsolute(); } return path.toOSString(); }
From source file:com.tsc9526.monalisa.plugin.eclipse.generator.SelectGenerator.java
License:Open Source License
private void writeResultClass(DBExchange exchange) throws JavaModelException { SelectMethod method = methods.get(exchange.getIndex()); String className = method.getResultClassPackage() + "." + method.getResultClassName(); IPackageFragmentRoot pfr = unit.getPackageFragmentRoot(); IResource r = unit.getUnit().getJavaElement().getResource(); String linkMethodUrl = "file://" + unit.getProjectPath() + "/" + r.getProjectRelativePath() + "#" + method.getMd().getName();//from ww w . j a v a2s. c om String linkMethodText = ""; String linkClassUrl = "file://" + unit.getProjectPath() + "/" + pfr.getResource().getProjectRelativePath(); linkClassUrl += "/" + className.replace(".", "/") + ".java"; String linkClassText = className; List<?> params = method.getMd().parameters(); for (Object p : params) { SingleVariableDeclaration svd = (SingleVariableDeclaration) p; String ptype = svd.getType().toString(); linkMethodUrl += "," + ptype; if (linkMethodText.length() > 0) { linkMethodText += ", "; } linkMethodText += ptype; } linkMethodText = method.getMd().getName() + "(" + linkMethodText + ")"; MMC mmc = MMC.getConsole(); mmc.print(MelpDate.now() + " [I] ", SWT.COLOR_BLACK); mmc.print("Create class: ", SWT.COLOR_BLACK); mmc.print(new HyperLink(linkClassUrl, linkClassText), SWT.COLOR_DARK_BLUE); mmc.print(", from: [", SWT.COLOR_BLACK); mmc.print(new HyperLink(linkMethodUrl, linkMethodText), SWT.COLOR_DARK_BLUE); mmc.print("]\r\n", SWT.COLOR_BLACK); String initParameters = (String) exchange.getTag("initParameters"); String failMessages = (String) exchange.getTag("failMessages"); if (failMessages != null) { mmc.warn("Can't init parameters as default:\r\n" + failMessages); } if (initParameters != null) { mmc.code("Init parameters as following:", initParameters); } if (exchange.getSql() != null) { mmc.code("Running SQL:", exchange.getSql()); } IPackageFragment pf = pfr.createPackageFragment(method.getResultClassPackage(), true, null); if (exchange.getErrorString() == null) { String java = method.createResultJavaCode(exchange); pf.createCompilationUnit(method.getResultClassName() + ".java", java, true, new NullProgressMonitor()); } else { mmc.error(exchange.getErrorString()); String java = method.createEmptyCode(exchange.getErrorString()); pf.createCompilationUnit(method.getResultClassName() + ".java", java, true, new NullProgressMonitor()); } }
From source file:com.tsc9526.monalisa.plugin.eclipse.proposal.QueryNamespaceCache.java
License:Open Source License
private void collectMappers(IJavaProject project, final Map<String, IFile> map, final IReporter reporter) { try {/*from w ww . j a v a 2s . c om*/ for (IPackageFragmentRoot root : project.getAllPackageFragmentRoots()) { if (root.getKind() != IPackageFragmentRoot.K_SOURCE) { continue; } root.getResource().accept(new IResourceProxyVisitor() { @Override public boolean visit(IResourceProxy proxy) throws CoreException { if (!proxy.isDerived() && proxy.getType() == IResource.FILE && proxy.getName().endsWith(".xml")) { IFile file = (IFile) proxy.requestResource(); IContentDescription contentDesc = file.getContentDescription(); if (contentDesc != null) { IContentType contentType = contentDesc.getContentType(); if (contentType != null && contentType.isKindOf(queryContentType)) { String namespace = extractNamespace(file); if (namespace != null) { map.put(namespace, file); } return false; } } } return true; } }, IContainer.NONE); } } catch (CoreException e) { Logger.error("Searching MyBatis Mapper xml failed.", e); } }
From source file:com.worldline.awltech.i18ntools.editor.data.model.I18NDataLoader.java
License:Open Source License
private static Map<Locale, IFile> locateResourceBundle(IJavaProject javaProject, String resourceBundlePath) throws CoreException { Map<Locale, IFile> resourceBundles = new LinkedHashMap<>(); for (IPackageFragmentRoot pfr : javaProject.getPackageFragmentRoots()) { if (pfr.getResource() instanceof IContainer) { IContainer container = (IContainer) pfr.getResource(); Path path = new Path(resourceBundlePath); IResource foundMember = container.findMember(path.addFileExtension("properties")); if (foundMember instanceof IFile && foundMember.exists()) { // We have the default resource bundle ! resourceBundles.put(null, (IFile) foundMember); // Now we need to find the other languages... for (IResource resource : container.members()) { // We don't forget to skip the already found default // one. String fileNameBase = path.lastSegment().concat("_"); if (resource != foundMember) { if (resource instanceof IFile && resource.exists()) { // The aim here is to chunk the name of the file // to retrieve the locale and load it. IFile iFile = (IFile) resource; if ("properties".equals(iFile.getFileExtension()) && iFile.getName().startsWith(fileNameBase)) { String localeChunk = iFile.getName().substring(fileNameBase.length(), iFile.getName().length() - ".properties".length()); Locale locale = Locale.forLanguageTag(localeChunk.replace("_", "-")); if (locale != null) { resourceBundles.put(locale, iFile); }// w ww . j av a 2s. c o m } } } } } } } return resourceBundles; }
From source file:de.fxworld.generationgap.GapConfiguration.java
License:Open Source License
public void resetDefault() { final IProject project = getJavaProject().getProject(); final List<String> genModels = new ArrayList<String>(); final List<String> clearSrcPaths = new ArrayList<String>(); setGenerateEdit(false);/*from www . ja v a2 s. c om*/ setGenerateEditor(false); setGenerateCustomClasses(false); // add all generator models try { project.accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if ((resource != null) && (resource instanceof IFile)) { IFile file = (IFile) resource; if ((file.exists()) && ("genmodel".equals(file.getFileExtension()))) { genModels.add(file.getProjectRelativePath().toString()); } } return true; // visit children too } }); } catch (CoreException e) { e.printStackTrace(); } // get all source paths try { boolean found = false; for (IPackageFragmentRoot root : javaProject.getAllPackageFragmentRoots()) { if ((root.getKind() == IPackageFragmentRoot.K_SOURCE) && (root.getJavaProject() == javaProject)) { if (root.getElementName().contains("src-gen")) { clearSrcPaths.add(root.getResource().getProjectRelativePath().toString()); } else if (!found) { setCustomSrcPath(root.getResource().getProjectRelativePath().toString()); found = true; } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } setGenModels(genModels); setSrcPaths(clearSrcPaths); }