List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE
int K_SOURCE
To view the source code for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE.
Click Source Link
From source file:org.eclipse.andmore.wizards.buildingblocks.ElementTreeViewFilter.java
License:Apache License
@Override public boolean select(Viewer viewer, Object parent, Object element) { boolean select = false; if (element instanceof IPackageFragmentRoot) { try {/*from w w w .j av a2 s. co m*/ select = (((IPackageFragmentRoot) element).getKind() == IPackageFragmentRoot.K_SOURCE); } catch (JavaModelException e) { AndmoreLogger.error(ElementTreeViewFilter.class, e.getLocalizedMessage(), e); } } else { select = super.select(viewer, parent, element); } return select; }
From source file:org.eclipse.andmore.wizards.buildingblocks.NewBuildingBlocksWizardPage.java
License:Apache License
@Override protected IStatus containerChanged() { IStatus superStatus = super.containerChanged(); IStatus status = new Status(superStatus.getSeverity(), CodeUtilsActivator.PLUGIN_ID, superStatus.getMessage());// www . j av a 2 s .co m boolean hasNature = false; if (status.getCode() != IStatus.ERROR) { try { if ((getPackageFragmentRoot() != null) && (getPackageFragmentRoot().getJavaProject() != null)) { hasNature = getPackageFragmentRoot().getJavaProject().getProject() .hasNature(IAndroidConstants.ANDROID_NATURE); } } catch (CoreException ce) { AndmoreLogger.error(NewBuildingBlocksWizardPage.class, "Error getting the project nature.", ce); //$NON-NLS-1$ hasNature = false; } if ((getPackageFragmentRoot() != null) && !hasNature) { status = new Status(IStatus.ERROR, CodeUtilsActivator.PLUGIN_ID, CodeUtilsNLS.ERR_NewBuildingBlocksWizardPage_SelectAnAndroidProject); } else if ((getPackageFragmentRoot() == null) || (getPackageFragmentRoot().getResource().getType() == IResource.PROJECT) || ((getPackageFragmentRoot().getElementType() & IPackageFragmentRoot.K_SOURCE) != IPackageFragmentRoot.K_SOURCE)) { status = new Status(IStatus.ERROR, CodeUtilsActivator.PLUGIN_ID, CodeUtilsNLS.ERR_NewBuildingBlocksWizardPage_SelectAValidSourceFolder); } else if (getPackageFragmentRoot().getElementName().equals(IAndroidConstants.GEN_SRC_FOLDER) && (getPackageFragmentRoot().getParent() instanceof IJavaProject)) { status = new Status(IStatus.ERROR, CodeUtilsActivator.PLUGIN_ID, CodeUtilsNLS.ERR_NewBuildingBlocksWizardPage_CannotUseTheGenFolderAsSourceFolder); } else if (isTooLongOnFileSystem()) { status = new Status(IStatus.ERROR, CodeUtilsActivator.PLUGIN_ID, CodeUtilsNLS.ERR_NewBuildingBlocksWizardPage_FileNameTooLong); } } return status; }
From source file:org.eclipse.andmore.wizards.buildingblocks.NewBuildingBlocksWizardPage.java
License:Apache License
/** * Checks for cross package/class collision among source folders * //from ww w . j a v a 2 s .c o m * @return true if there is any collision or false otherwise */ private boolean packageAndClassExist() { boolean exists = false; try { if ((getJavaProject() != null) && getJavaProject().isOpen()) { IPackageFragmentRoot[] roots = getJavaProject().getPackageFragmentRoots(); if (roots != null) { for (IPackageFragmentRoot root : roots) { if ((root.getKind() & IPackageFragmentRoot.K_SOURCE) == IPackageFragmentRoot.K_SOURCE) { IPackageFragment pack = root.getPackageFragment(getPackageText()); if ((pack != null) && pack.exists()) { IJavaElement classes[] = pack.getChildren(); if (classes != null) { for (IJavaElement clazz : classes) { if (clazz.getElementName().equals(getTypeName() + JAVA_EXTENSION)) { exists = true; break; } } } } } if (exists) { break; } } } } } catch (JavaModelException e) { // Do nothing AndmoreLogger.error(NewBuildingBlocksWizardPage.class, e.getLocalizedMessage(), e); } return exists; }
From source file:org.eclipse.ant.internal.ui.datatransfer.EclipseClasspath.java
License:Open Source License
private void handleSources(IClasspathEntry entry) throws JavaModelException { String projectRoot = ExportUtil.getProjectRoot(project); String defaultClassDir = project.getOutputLocation().toString(); String defaultClassDirAbsolute = ExportUtil.resolve(project.getOutputLocation()); if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // found source path IPath srcDirPath = entry.getPath(); IPath classDirPath = entry.getOutputLocation(); String srcDir = handleLinkedResource(srcDirPath); ExportUtil.removeProjectRoot((srcDirPath != null) ? srcDirPath.toString() : projectRoot, project.getProject());//from ww w . jav a2 s . c o m String classDir = ExportUtil.removeProjectRoot( (classDirPath != null) ? classDirPath.toString() : defaultClassDir, project.getProject()); srcDirs.add(srcDir); classDirs.add(classDir); String classDirAbsolute = (classDirPath != null) ? ExportUtil.resolve(classDirPath) : defaultClassDirAbsolute; rawClassPathEntries.add(classDir); rawClassPathEntriesAbsolute.add(classDirAbsolute); IPath[] inclusions = entry.getInclusionPatterns(); List<String> inclusionList = new ArrayList<>(); for (int j = 0; j < inclusions.length; j++) { if (inclusions[j] != null) { inclusionList.add(ExportUtil.removeProjectRoot(inclusions[j].toString(), project.getProject())); } } inclusionLists.add(inclusionList); IPath[] exclusions = entry.getExclusionPatterns(); List<String> exclusionList = new ArrayList<>(); for (int j = 0; j < exclusions.length; j++) { if (exclusions[j] != null) { exclusionList.add(ExportUtil.removeProjectRoot(exclusions[j].toString(), project.getProject())); } } exclusionLists.add(exclusionList); } }
From source file:org.eclipse.ant.internal.ui.datatransfer.EclipseClasspath.java
License:Open Source License
private void handleVariables(IClasspathEntry entry) { if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { // found variable String e = entry.getPath().toString(); int index = e.indexOf('/'); if (index == -1) { index = e.indexOf('\\'); }/*from w w w.j a v a 2s.co m*/ String variable = e; String path = IAntCoreConstants.EMPTY_STRING; if (index != -1) { variable = e.substring(0, index); path = e.substring(index); } IPath value = JavaCore.getClasspathVariable(variable); if (value != null) { String projectRoot = ExportUtil.getProjectRoot(project); String relativePath = ExportUtil.getRelativePath(value.toString(), projectRoot); variable2valueMap.put(variable, relativePath); } else if (variable2valueMap.get(variable) == null) { // only add empty value, if variable is new variable2valueMap.put(variable, IAntCoreConstants.EMPTY_STRING); } rawClassPathEntriesAbsolute.add(value + path); rawClassPathEntries.add("${" + variable + "}" + path); //$NON-NLS-1$ //$NON-NLS-2$ } }
From source file:org.eclipse.ant.internal.ui.datatransfer.EclipseClasspath.java
License:Open Source License
private void handleLibraries(IClasspathEntry entry) throws JavaModelException { if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { // found library IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); if (container == null) { // jar missing (project not compile clean) return; }/*ww w . j a v a 2 s.co m*/ String jar = entry.getPath().toString(); String refName; if (jar.startsWith(JavaRuntime.JRE_CONTAINER)) { // JRE System Library refName = "${jre.container}"; //$NON-NLS-1$ } else if (jar.startsWith(JavaCore.USER_LIBRARY_CONTAINER_ID)) { // User Library String libraryName = container.getDescription(); refName = "${" + libraryName + ".userclasspath}"; //$NON-NLS-1$ //$NON-NLS-2$ if (container.getKind() == IClasspathContainer.K_SYSTEM) { refName = "${" + libraryName + ".bootclasspath}"; //$NON-NLS-1$ //$NON-NLS-2$ } } else { // Library dependencies: e.g. Plug-in Dependencies String libraryName = container.getDescription(); refName = "${" + libraryName + ".libraryclasspath}"; //$NON-NLS-1$ //$NON-NLS-2$ } userLibraryCache.put(refName, container); srcDirs.add(refName); classDirs.add(refName); rawClassPathEntries.add(refName); rawClassPathEntriesAbsolute.add(refName); inclusionLists.add(new ArrayList<String>()); exclusionLists.add(new ArrayList<String>()); } }
From source file:org.eclipse.ant.internal.ui.datatransfer.EclipseClasspath.java
License:Open Source License
private void handleProjects(IClasspathEntry entry) { if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { // found required project on build path String subProjectRoot = entry.getPath().toString(); IJavaProject subProject = ExportUtil.getJavaProject(subProjectRoot); if (subProject == null) { // project was not loaded in workspace AntUIPlugin.log("project is not loaded in workspace: " + subProjectRoot, null); //$NON-NLS-1$ return; }//from w w w . ja v a 2s .c o m // only add an indicator that this is a project reference String classpathRef = "${" + subProject.getProject().getName() + ".classpath}"; //$NON-NLS-1$ //$NON-NLS-2$ srcDirs.add(classpathRef); classDirs.add(classpathRef); rawClassPathEntries.add(classpathRef); rawClassPathEntriesAbsolute.add(classpathRef); inclusionLists.add(new ArrayList<String>()); exclusionLists.add(new ArrayList<String>()); } }
From source file:org.eclipse.ant.internal.ui.datatransfer.ExportUtil.java
License:Open Source License
private static void addClasspathProjects(List<IJavaProject> projects, IClasspathEntry[] entries) { for (int i = 0; i < entries.length; i++) { IClasspathEntry classpathEntry = entries[i]; if (classpathEntry.getContentKind() == IPackageFragmentRoot.K_SOURCE && classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { // found required project on build path String subProjectRoot = classpathEntry.getPath().toString(); IJavaProject subProject = getJavaProject(subProjectRoot); // is project available in workspace if (subProject != null) { projects.add(subProject); }/*ww w .j a va 2 s . co m*/ } } }
From source file:org.eclipse.buildship.ui.launch.TestLaunchShortcutValidator.java
License:Open Source License
private static boolean isInSourceFolder(IType type) { // if the type is not defined in a source folder or the source folder // type can't be determined, then return false IJavaElement fragmentRoot = type.getPackageFragment().getParent(); if (fragmentRoot instanceof IPackageFragmentRoot) { IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) fragmentRoot; try {/* w ww.ja v a2 s .com*/ return packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE; } catch (JavaModelException e) { return false; } } else { return false; } }
From source file:org.eclipse.che.jdt.core.JavaCore.java
License:Open Source License
/** * Creates and returns a new classpath entry of kind <code>CPE_CONTAINER</code> * for the given path. The path of the container will be used during resolution so as to map this * container entry to a set of other classpath entries the container is acting for. * <p>/*w ww. j a v a 2 s . co m*/ * A container entry allows to express indirect references to a set of libraries, projects and variable entries, * which can be interpreted differently for each Java project where it is used. * A classpath container entry can be resolved using <code>JavaCore.getResolvedClasspathContainer</code>, * and updated with <code>JavaCore.classpathContainerChanged</code> * <p> * A container is exclusively resolved by a <code>ClasspathContainerInitializer</code> registered onto the * extension point "org.eclipse.jdt.core.classpathContainerInitializer". * <p> * A container path must be formed of at least one segment, where: <ul> * <li> the first segment is a unique ID identifying the target container, there must be a container initializer registered * onto this ID through the extension point "org.eclipse.jdt.core.classpathContainerInitializer". </li> * <li> the remaining segments will be passed onto the initializer, and can be used as additional * hints during the initialization phase. </li> * </ul> * <p> * Example of an ClasspathContainerInitializer for a classpath container denoting a default JDK container: * <pre> * containerEntry = JavaCore.newContainerEntry(new Path("MyProvidedJDK/default")); * * <extension * point="org.eclipse.jdt.core.classpathContainerInitializer"> * <containerInitializer * id="MyProvidedJDK" * class="com.example.MyInitializer"/> * </pre> * <p> * The access rules determine the set of accessible source and class files * in the container. If the list of access rules is empty, then all files * in this container are accessible. * See {@link org.eclipse.jdt.core.IAccessRule} for a detailed description of access * rules. Note that if an entry defined by the container defines access rules, * then these access rules are combined with the given access rules. * The given access rules are considered first, then the entry's access rules are * considered. * </p> * <p> * The <code>extraAttributes</code> list contains name/value pairs that must be persisted with * this entry. If no extra attributes are provided, an empty array must be passed in.<br> * Note that this list should not contain any duplicate name. * </p> * <p> * The <code>isExported</code> flag indicates whether this entry is contributed to dependent * projects. If not exported, dependent projects will not see any of the classes from this entry. * If exported, dependent projects will concatenate the accessible files patterns of this entry with the * accessible files patterns of the projects, and they will concatenate the non accessible files patterns of this entry * with the non accessible files patterns of the project. * </p> * <p> * Note that this operation does not attempt to validate classpath containers * or access the resources at the given paths. * </p> * * @param containerPath the path identifying the container, it must be formed of at least * one segment (ID+hints) * @param accessRules the possibly empty list of access rules for this entry * @param extraAttributes the possibly empty list of extra attributes to persist with this entry * @param isExported a boolean indicating whether this entry is contributed to dependent * projects in addition to the output location * @return a new container classpath entry * * @see JavaCore#getClasspathContainer(IPath, org.eclipse.jdt.core.IJavaProject) * @see JavaCore#setClasspathContainer(IPath, org.eclipse.jdt.core.IJavaProject[], org.eclipse.jdt.core.IClasspathContainer[], org.eclipse.core.runtime.IProgressMonitor) * @see JavaCore#newContainerEntry(IPath, boolean) * @see JavaCore#newAccessRule(IPath, int) * @since 3.1 */ public static IClasspathEntry newContainerEntry(IPath containerPath, IAccessRule[] accessRules, IClasspathAttribute[] extraAttributes, boolean isExported) { if (containerPath == null) { throw new ClasspathEntry.AssertionFailedException("Container path cannot be null"); //$NON-NLS-1$ } else if (containerPath.segmentCount() < 1) { throw new ClasspathEntry.AssertionFailedException( "Illegal classpath container path: \'" + containerPath.makeRelative().toString() //$NON-NLS-1$ + "\', must have at least one segment (containerID+hints)"); //$NON-NLS-1$ } if (accessRules == null) { accessRules = ClasspathEntry.NO_ACCESS_RULES; } if (extraAttributes == null) { extraAttributes = ClasspathEntry.NO_EXTRA_ATTRIBUTES; } return new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_CONTAINER, containerPath, ClasspathEntry.INCLUDE_ALL, // inclusion patterns ClasspathEntry.EXCLUDE_NONE, // exclusion patterns null, // source attachment null, // source attachment root null, // specific output folder isExported, accessRules, true, // combine access rules extraAttributes); }