Example usage for org.eclipse.jdt.core IClasspathEntry getEntryKind

List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry getEntryKind.

Prototype

int getEntryKind();

Source Link

Document

Returns the kind of this classpath entry.

Usage

From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java

License:Open Source License

private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) {
    try {/*from  w ww  .j av a2  s . c o  m*/
        IClasspathEntry rawEntry = root.getRawClasspathEntry();
        if (rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            IClasspathEntry entry = JavaModelUtil.getClasspathEntry(root);
            if (entry.getReferencingEntry() != null) {
                return false; // not the variable entry itself, but a referenced entry
            }
            IPath path = rawEntry.getPath().makeRelative();

            if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) {
                int segements = path.segmentCount();
                if (segements > 0) {
                    fBuffer.append(path.segment(segements - 1));
                    if (segements > 1) {
                        int offset = fBuffer.length();
                        fBuffer.append(JavaElementLabels.CONCAT_STRING);
                        fBuffer.append(path.removeLastSegments(1).toOSString());
                        //                     if (getFlag(flags, JavaElementLabels.COLORIZE)) {
                        //                        fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
                        //                     }
                    }
                } else {
                    fBuffer.append(path.toString());
                }
            } else {
                fBuffer.append(path.toString());
            }
            int offset = fBuffer.length();
            fBuffer.append(JavaElementLabels.CONCAT_STRING);
            if (root.isExternal())
                fBuffer.append(root.getPath().toOSString());
            else
                fBuffer.append(root.getPath().makeRelative().toString());

            //            if (getFlag(flags, JavaElementLabels.COLORIZE)) {
            //               fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
            //            }
            return true;
        }
    } catch (JavaModelException e) {
        // problems with class path, ignore (bug 202792)
        return false;
    }
    return false;
}

From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java

License:Open Source License

private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) {
    IPath path;//from   ww w.ja  v a  2  s  .c  o m
    IClasspathEntry classpathEntry = null;
    try {
        classpathEntry = JavaModelUtil.getClasspathEntry(root);
        IPath rawPath = classpathEntry.getPath();
        if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && !rawPath.isAbsolute())
            path = rawPath;
        else
            path = root.getPath();
    } catch (JavaModelException e) {
        path = root.getPath();
    }
    if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) {
        int segements = path.segmentCount();
        if (segements > 0) {
            fBuffer.append(path.segment(segements - 1));
            int offset = fBuffer.length();
            if (segements > 1 || path.getDevice() != null) {
                fBuffer.append(JavaElementLabels.CONCAT_STRING);
                fBuffer.append(path.removeLastSegments(1).toOSString());
            }
            if (classpathEntry != null) {
                IClasspathEntry referencingEntry = classpathEntry.getReferencingEntry();
                if (referencingEntry != null) {
                    fBuffer.append(
                            Messages.format(JavaUIMessages.JavaElementLabels_onClassPathOf, new Object[] {
                                    Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() }));
                }
            }
            //            if (getFlag(flags, JavaElementLabels.COLORIZE)) {
            //               fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
            //            }
        } else {
            fBuffer.append(path.toOSString());
        }
    } else {
        fBuffer.append(path.toOSString());
    }
}

From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPListElement.java

License:Open Source License

public static CPListElement create(Object parent, IClasspathEntry curr, boolean newElement,
        IJavaProject project) {//from   ww w  . jav  a 2  s .  co  m
    IPath path = curr.getPath();
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    // get the resource
    IResource res = null;
    boolean isMissing = false;
    IPath linkTarget = null;

    switch (curr.getEntryKind()) {
    case IClasspathEntry.CPE_CONTAINER:
        try {
            isMissing = project != null && (JavaCore.getClasspathContainer(path, project) == null);
        } catch (JavaModelException e) {
            isMissing = true;
        }
        break;
    case IClasspathEntry.CPE_VARIABLE:
        IPath resolvedPath = JavaCore.getResolvedVariablePath(path);
        isMissing = root.findMember(resolvedPath) == null && !resolvedPath.toFile().exists();
        break;
    case IClasspathEntry.CPE_LIBRARY:
        res = root.findMember(path);
        if (res == null) {
            if (!ArchiveFileFilter.isArchivePath(path, true)) {
                if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()
                        && root.getProject(path.segment(0)).exists()) {
                    res = root.getFolder(path);
                }
            }

            IPath rawPath = path;
            if (project != null) {
                IPackageFragmentRoot[] roots = project.findPackageFragmentRoots(curr);
                if (roots.length == 1)
                    rawPath = roots[0].getPath();
            }
            isMissing = !rawPath.toFile().exists(); // look for external JARs and folders
        } else if (res.isLinked()) {
            linkTarget = res.getLocation();
        }
        break;
    case IClasspathEntry.CPE_SOURCE:
        path = path.removeTrailingSeparator();
        res = root.findMember(path);
        if (res == null) {
            if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) {
                res = root.getFolder(path);
            }
            isMissing = true;
        } else if (res.isLinked()) {
            linkTarget = res.getLocation();
        }
        break;
    case IClasspathEntry.CPE_PROJECT:
        res = root.findMember(path);
        isMissing = (res == null);
        break;
    }
    CPListElement elem = new CPListElement(parent, project, curr.getEntryKind(), path, newElement, res,
            linkTarget);
    elem.setExported(curr.isExported());
    elem.setAttribute(SOURCEATTACHMENT, curr.getSourceAttachmentPath());
    elem.setAttribute(OUTPUT, curr.getOutputLocation());
    elem.setAttribute(EXCLUSION, curr.getExclusionPatterns());
    elem.setAttribute(INCLUSION, curr.getInclusionPatterns());
    elem.setAttribute(ACCESSRULES, curr.getAccessRules());
    elem.setAttribute(COMBINE_ACCESSRULES, new Boolean(curr.combineAccessRules()));

    IClasspathAttribute[] extraAttributes = curr.getExtraAttributes();
    for (int i = 0; i < extraAttributes.length; i++) {
        IClasspathAttribute attrib = extraAttributes[i];
        CPListElementAttribute attribElem = elem.findAttributeElement(attrib.getName());
        if (attribElem == null) {
            elem.createAttributeElement(attrib.getName(), attrib.getValue(), false);
        } else {
            attribElem.setValue(attrib.getValue());
        }
    }

    elem.setIsMissing(isMissing);
    return elem;
}

From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPListElement.java

License:Open Source License

public static boolean isProjectSourceFolder(CPListElement[] existing, IJavaProject project) {
    IPath projPath = project.getProject().getFullPath();
    for (int i = 0; i < existing.length; i++) {
        IClasspathEntry curr = existing[i].getClasspathEntry();
        if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            if (projPath.equals(curr.getPath())) {
                return true;
            }// w  ww . ja  v a2  s .co m
        }
    }
    return false;
}

From source file:at.component.newcomponentwizard.generator.NewProjectCreationOperation.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
private void addAllSourcePackages(IProject project, Set list) {
    try {//www  .  j a va 2s .c  o m
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] classpath = javaProject.getRawClasspath();
        for (int i = 0; i < classpath.length; i++) {
            IClasspathEntry entry = classpath[i];
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath path = entry.getPath().removeFirstSegments(1);
                if (path.segmentCount() > 0) {
                    IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(project.getFolder(path));
                    IJavaElement[] children = root.getChildren();
                    for (int j = 0; j < children.length; j++) {
                        IPackageFragment frag = (IPackageFragment) children[j];
                        if (frag.getChildren().length > 0 || frag.getNonJavaResources().length > 0)
                            list.add(children[j].getElementName());
                    }
                }
            }
        }
    } catch (JavaModelException e) {
    }
}

From source file:at.spardat.xma.guidesign.presentation.XMAPropertyDescriptor.java

License:Open Source License

private String[] getSourceFolderStrings() {
    IProject project = editor.getResourceFile().getProject();
    File workspaceLocation = project.getWorkspace().getRoot().getLocation().toFile();
    IJavaProject jp = JavaCore.create(project);
    IClasspathEntry[] javacp;/* w ww.  j a  va 2 s.c  o m*/
    try {
        javacp = jp.getResolvedClasspath(true);
    } catch (JavaModelException e) {
        GUIDesignerPlugin.INSTANCE.log(e);
        return new String[] { project.getLocation().toString() + "/src" };
    }
    ArrayList<String> result = new ArrayList<String>();
    for (IClasspathEntry classpathEntry : javacp) {
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            File f = new File(workspaceLocation, classpathEntry.getPath().toString());
            String s = f.getAbsolutePath();
            result.add(s);
        }
    }
    return result.toArray(new String[result.size()]);
}

From source file:bndtools.builder.BndProjectNature.java

License:Open Source License

private void installBndClasspath() throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    for (IClasspathEntry entry : classpath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && BndContainerInitializer.PATH_ID.equals(entry.getPath()))
            return; // already installed
    }//w w  w . j a  v a 2  s. co m

    IClasspathEntry[] newEntries = new IClasspathEntry[classpath.length + 1];
    System.arraycopy(classpath, 0, newEntries, 0, classpath.length);
    newEntries[classpath.length] = JavaCore.newContainerEntry(BndContainerInitializer.PATH_ID);

    javaProject.setRawClasspath(newEntries, null);
}

From source file:bndtools.builder.BndProjectNature.java

License:Open Source License

private void removeBndClasspath() throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(classpath.length);

    boolean changed = false;
    for (IClasspathEntry entry : classpath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && BndContainerInitializer.PATH_ID.equals(entry.getPath())) {
            changed = true;/*from   www .j  a v  a  2  s.co m*/
        } else {
            newEntries.add(entry);
        }
    }

    if (changed)
        javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[newEntries.size()]), null);
}

From source file:bndtools.wizards.project.NewBndProjectWizardPageTwo.java

License:Open Source License

@Override
public boolean isPageComplete() {
    boolean resultFromSuperClass = super.isPageComplete();
    int nr = 0;/*from  ww  w .j  a va  2s.co m*/
    try {
        IClasspathEntry[] entries = getJavaProject().getResolvedClasspath(true);
        for (IClasspathEntry entry : entries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                nr++;
                // here we could do more validation on the paths if we want to
                // for now we just count pages
            }
        }
    } catch (Exception e) {
        // if for some reason we cannot access the resolved classpath
        // we simply set an error message
        setErrorMessage("Could not access resolved classpaths: " + e);
    }
    // we're okay if we have exactly at most two valid source paths
    // most templates use 2 source sets (main + test) but some do not
    // have the test source set
    return resultFromSuperClass && (1 <= nr) && (nr <= 2);
}

From source file:br.ufal.cideei.handlers.DoAnalysisOnClassPath.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    //#ifdef CACHEPURGE
    //@      br.Main.randomLong();
    //#endif// w ww.  ja v a  2s  . c  o  m

    // TODO: exteriorize this number as a configuration parameter. Abstract away the looping.
    try {
        IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
        Object firstElement = selection.getFirstElement();

        if (!(firstElement instanceof IJavaProject)) {
            throw new UnsupportedOperationException("Selected resource is not a java project");
        }

        IJavaProject javaProject = (IJavaProject) firstElement;

        IClasspathEntry[] classPathEntries = null;
        try {
            classPathEntries = javaProject.getResolvedClasspath(true);
        } catch (JavaModelException e) {
            e.printStackTrace();
            throw new ExecutionException("No source classpath identified");
        }

        /*
         * To build the path string variable that will represent Soot's classpath we will first iterate
         * through all libs (.jars) files, then through all source classpaths.
         * 
         * FIXME: WARNING: A bug was found on Soot, in which the FileSourceTag would contain incorrect
         * information regarding the absolute location of the source file. In this workaround, the classpath
         * must be injected into the FeatureModelInstrumentorTransformer class (done through its
         * constructor).
         * 
         * As a consequence, we CANNOT build an string with all classpaths that contains source code for the
         * project and thus one only source code classpath can be analysed at a given time.
         * 
         * This seriously restricts the range of projects that can be analysed with this tool.
         */
        List<IClasspathEntry> sourceClasspathEntries = new ArrayList<IClasspathEntry>();
        StringBuilder libsPaths = new StringBuilder();
        for (IClasspathEntry entry : classPathEntries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                File file = entry.getPath().makeAbsolute().toFile();
                if (file.isAbsolute()) {
                    libsPaths.append(file.getAbsolutePath() + File.pathSeparator);
                } else {
                    libsPaths.append(ResourcesPlugin.getWorkspace().getRoot().getFile(entry.getPath())
                            .getLocation().toOSString() + File.pathSeparator);
                }
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                sourceClasspathEntries.add(entry);
            }
        }

        if (sourceClasspathEntries.size() != 1) {
            throw new UnsupportedOperationException("project must have exactly one source classpath entry");
        }

        IClasspathEntry entry = sourceClasspathEntries.get(0);

        final int times = 10;
        for (int i = 0; i < times; i++) {
            // #ifdef METRICS
            String sinkFile = System.getProperty("user.home") + File.separator
                    + javaProject.getElementName().trim().toLowerCase().replace(' ', '-') + "-fs";
            // #ifdef LAZY
            sinkFile += "-lazy";
            // #endif
            // #ifdef FEATUREMODEL
            //@                  sinkFile += "-fm";
            // #endif
            sink = new MetricsSink(new MetricsTable(new File(sinkFile + ".xls")));
            // #endif

            this.addPacks(javaProject, entry, libsPaths.toString());
            SootManager.reset();
            // #ifdef METRICS
            sink.terminate();
            // #endif
            System.out.println("=============" + (i + 1) + "/" + times + "=============");
        }
        sink.createSummaryFile();
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        SootManager.reset();
        // #ifdef METRICS
        if (sink != null && !sink.terminated()) {
            sink.terminate();
        }
        // #endif
    }

    return null;
}