List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
From source file:org.grails.ide.eclipse.commands.test.GrailsCommandUtilTest.java
License:Open Source License
private IClasspathEntry assertPluginSourceFolder(IClasspathEntry[] cp, String pluginName, String pathString) { for (IClasspathEntry e : cp) { if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { String path = e.getPath().toString(); if (path.contains(pluginName) && path.endsWith(pathString)) { return e; }/*from w w w . j a v a 2s . c o m*/ } } fail("Couldn't find source folder '" + pathString + "' for plugin '" + pluginName); return null; // unreachable }
From source file:org.grails.ide.eclipse.core.internal.classpath.SourceFolderJob.java
License:Open Source License
/** * /* w ww . ja v a 2 s. co m*/ * @return all grails source class path entries. List may be empty or * partial complete if error encountered. */ public static List<IClasspathEntry> getGrailsSourceClasspathEntries(IJavaProject javaProject) { List<IClasspathEntry> oldEntries = new ArrayList<IClasspathEntry>(); try { for (IClasspathEntry entry : javaProject.getRawClasspath()) { // CPE_PROJECT is for in-place plugins that are present as // project entries, as opposed to CPE_SOURCE that are for source // folders if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE || entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { for (IClasspathAttribute attr : entry.getExtraAttributes()) { if (attr.getName().equals(GrailsClasspathContainer.PLUGIN_SOURCEFOLDER_ATTRIBUTE_NAME)) { oldEntries.add(entry); } } } } } catch (JavaModelException e) { GrailsCoreActivator.log(e); } return oldEntries; }
From source file:org.grails.ide.eclipse.core.internal.GrailsResourceUtil.java
License:Open Source License
public static IPackageFragmentRoot[] getGrailsDependencyPackageFragmentRoots(IProject project, IPath path) { if (project == null) { return null; }/*from ww w . j a v a 2 s . c o m*/ IJavaProject javaProject = JavaCore.create(project); try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { for (IClasspathAttribute attr : entry.getExtraAttributes()) { if (attr.getName().equals(GrailsClasspathContainer.PLUGIN_SOURCEFOLDER_ATTRIBUTE_NAME)) { IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(entry.getPath()); if (folder.getLocation().equals(path)) { return javaProject.findPackageFragmentRoots(entry); } } } } } } catch (JavaModelException e) { GrailsCoreActivator.log(e); } return null; }
From source file:org.grails.ide.eclipse.core.internal.GrailsResourceUtil.java
License:Open Source License
public static boolean hasClasspathAttribute(IClasspathEntry entry, String attributeName) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { for (IClasspathAttribute attr : entry.getExtraAttributes()) { if (attr.getName().equals(attributeName)) { return true; }//from w w w .j av a2 s. c o m } } return false; }
From source file:org.grails.ide.eclipse.core.internal.GrailsResourceUtil.java
License:Open Source License
/** * Determines if the given folder corresponds to a Java source folder (i.e. * there is a source class path entry for it). * <p>// www . ja v a 2 s . co m * The folder could be either a package fragment or a package fragment root * </p> * * @param folder * to check if there is a corresponding source class path entry * for it * @return true if there is a corresponding source class path entry for it. * False otherwise. */ public static boolean isSourceFolder(IFolder folder) { if (folder == null) { return false; } IJavaElement possiblePackageFragRoot = JavaCore.create(folder); if (possiblePackageFragRoot == null) { return false; } if (possiblePackageFragRoot instanceof IPackageFragment) { possiblePackageFragRoot = ((IPackageFragment) possiblePackageFragRoot).getParent(); } if (possiblePackageFragRoot instanceof IPackageFragmentRoot) { IPackageFragmentRoot root = (IPackageFragmentRoot) possiblePackageFragRoot; try { if (root.getRawClasspathEntry().getEntryKind() == IClasspathEntry.CPE_SOURCE) { return true; } } catch (JavaModelException e) { GrailsCoreActivator.log(e); } } return false; }
From source file:org.grails.ide.eclipse.core.internal.GrailsResourceUtil.java
License:Open Source License
public static boolean isSourceFolder(IPackageFragmentRoot root) { IJavaProject jp = root.getJavaProject(); try {/*from ww w. j av a2 s .c o m*/ IResource rootRsrc = root.getCorrespondingResource(); if (rootRsrc == null) { return false; } IPath rootPath = rootRsrc.getFullPath(); for (IClasspathEntry entry : jp.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (entry.getPath() != null && entry.getPath().equals(rootPath)) { return true; } } } } catch (JavaModelException e) { e.printStackTrace(); } return false; }
From source file:org.grails.ide.eclipse.core.workspace.GrailsClassPath.java
License:Open Source License
public static boolean isPluginSourceFolder(IClasspathEntry e) { if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { for (IClasspathAttribute attr : e.getExtraAttributes()) { if (attr.getName().equals(GrailsClasspathContainer.PLUGIN_SOURCEFOLDER_ATTRIBUTE_NAME)) { return true; }/* w w w .ja v a2 s . co m*/ } } return false; }
From source file:org.grails.ide.eclipse.editor.groovy.elements.GrailsProject.java
License:Open Source License
/** * Returns all TagLibs supplied by plugins * @return/*from w ww . j ava 2 s.c o m*/ */ public List<TagLibClass> getPluginTagLibClasses() { try { IClasspathEntry[] entries = javaProject.getRawClasspath(); List<TagLibClass> taglibs = new ArrayList<TagLibClass>(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: if (isPluginTagLibSourceFolder(entry.getPath())) { IFolder folder = root.getFolder(entry.getPath()); if (folder.isAccessible()) { taglibs.addAll(findTagLibClassesInFolder(folder)); } } break; default: break; } } return taglibs; } catch (JavaModelException e) { GrailsCoreActivator.log("Problem creating tag libraries from plugins", e); } return Collections.emptyList(); }
From source file:org.grails.ide.eclipse.editor.groovy.elements.GrailsProject.java
License:Open Source License
private Map<String, ClassNode> internalFindGrailsElementsForProject(PerProjectTypeCache typeCache, IJavaProject thisProject, GrailsElementKind kind) throws JavaModelException { Map<String, ClassNode> grailsElementMap = new HashMap<String, ClassNode>(); IClasspathEntry[] rawEntries = thisProject.getRawClasspath(); for (IClasspathEntry entry : rawEntries) { // this may not capture services in plugins because the source folder is linked if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getPath().lastSegment().equals(kind.getSourceFolder())) { //$NON-NLS-1$ IPackageFragmentRoot root = thisProject.findPackageFragmentRoot(entry.getPath()); if (root == null) continue; // something is wrong with this project // all CUs that end in Service are services IJavaElement[] frags = root.getChildren(); for (IJavaElement elt : frags) { if (elt instanceof IPackageFragment) { IPackageFragment frag = (IPackageFragment) elt; ICompilationUnit[] units = frag.getCompilationUnits(); for (ICompilationUnit unit : units) { if (unit instanceof GroovyCompilationUnit && unit.getElementName().endsWith(kind.getNameSuffix())) { //$NON-NLS-1$ IType graileElementType = getPrimaryType(unit); if (graileElementType != null) { grailsElementMap.put(getBeanName(graileElementType), typeCache.getClassNode(graileElementType.getFullyQualifiedName())); }//from www .j a v a 2s . com } } } } } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { // trawl through dependent grails projects IProject project = ResourcesPlugin.getWorkspace().getRoot() .getProject(entry.getPath().lastSegment()); if (GrailsNature.isGrailsPluginProject(project)) { IJavaProject otherProject = JavaCore.create(project); grailsElementMap.putAll(internalFindGrailsElementsForProject(typeCache, otherProject, kind)); } } } return grailsElementMap; }
From source file:org.grails.ide.eclipse.editor.groovy.elements.GrailsProject.java
License:Open Source License
private IType internalFindGrailsElementTypeForProject(String primaryTypeName, PerProjectTypeCache typeCache, IJavaProject thisProject, GrailsElementKind kind) throws JavaModelException { String unitName = primaryTypeName + ".groovy"; IClasspathEntry[] rawEntries = thisProject.getRawClasspath(); for (IClasspathEntry entry : rawEntries) { // this may not capture services in plugins because the source folder is linked if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getPath().lastSegment().equals(kind.getSourceFolder())) { //$NON-NLS-1$ IPackageFragmentRoot root = thisProject.findPackageFragmentRoot(entry.getPath()); if (root == null) continue; // something is wrong with this project // all CUs that end in Service are services IJavaElement[] frags = root.getChildren(); for (IJavaElement elt : frags) { if (elt instanceof IPackageFragment) { IPackageFragment frag = (IPackageFragment) elt; ICompilationUnit[] units = frag.getCompilationUnits(); for (ICompilationUnit unit : units) { if (unit instanceof GroovyCompilationUnit && unit.getElementName().equals(unitName)) { //$NON-NLS-1$ IType grailsElementType = unit.getType(primaryTypeName); if (grailsElementType.exists()) { return grailsElementType; }//from ww w .j a va 2 s.c om } } } } } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { // trawl through dependent grails projects IProject project = ResourcesPlugin.getWorkspace().getRoot() .getProject(entry.getPath().lastSegment()); if (GrailsNature.isGrailsPluginProject(project)) { IJavaProject otherProject = JavaCore.create(project); IType type = internalFindGrailsElementTypeForProject(primaryTypeName, typeCache, otherProject, kind); if (type != null) { return type; } } } } return null; }