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

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

Introduction

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

Prototype

int CPE_VARIABLE

To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_VARIABLE.

Click Source Link

Document

Entry kind constant describing a classpath entry defined using a path that begins with a classpath variable reference.

Usage

From source file:at.bestsolution.fxide.jdt.corext.javadoc.JavaDocLocations.java

License:Open Source License

public static URL getJavadocBaseLocation(IJavaElement element) throws JavaModelException {
    if (element.getElementType() == IJavaElement.JAVA_PROJECT) {
        return getProjectJavadocLocation((IJavaProject) element);
    }//from w  ww .j a v  a  2  s  .  c  o m

    IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(element);
    if (root == null) {
        return null;
    }

    if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
        IClasspathEntry entry = root.getResolvedClasspathEntry();
        URL javadocLocation = getLibraryJavadocLocation(entry);
        if (javadocLocation != null) {
            return getLibraryJavadocLocation(entry);
        }
        entry = root.getRawClasspathEntry();
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
        case IClasspathEntry.CPE_VARIABLE:
            return getLibraryJavadocLocation(entry);
        default:
            return null;
        }
    } else {
        return getProjectJavadocLocation(root.getJavaProject());
    }
}

From source file:at.bestsolution.fxide.jdt.corext.javadoc.JavaDocLocations.java

License:Open Source License

public static URL getLibraryJavadocLocation(IClasspathEntry entry) {
    if (entry == null) {
        throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$
    }/*from   ww w  .j a  va 2s .c  om*/

    int kind = entry.getEntryKind();
    if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) {
        throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); //$NON-NLS-1$
    }

    IClasspathAttribute[] extraAttributes = entry.getExtraAttributes();
    for (int i = 0; i < extraAttributes.length; i++) {
        IClasspathAttribute attrib = extraAttributes[i];
        if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) {
            return parseURL(attrib.getValue());
        }
    }
    return null;
}

From source file:at.bestsolution.fxide.jdt.corext.util.JavaModelUtil.java

License:Open Source License

/**
 * Returns the classpath entry of the given package fragment root. This is the raw entry, except
 * if the root is a referenced library, in which case it's the resolved entry.
 *
 * @param root a package fragment root/*from  w  w  w .  j a v a 2s .  com*/
 * @return the corresponding classpath entry
 * @throws JavaModelException if accessing the entry failed
 * @since 3.6
 */
public static IClasspathEntry getClasspathEntry(IPackageFragmentRoot root) throws JavaModelException {
    IClasspathEntry rawEntry = root.getRawClasspathEntry();
    int rawEntryKind = rawEntry.getEntryKind();
    switch (rawEntryKind) {
    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_VARIABLE:
    case IClasspathEntry.CPE_CONTAINER: // should not happen, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=305037
        if (root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) {
            IClasspathEntry resolvedEntry = root.getResolvedClasspathEntry();
            if (resolvedEntry.getReferencingEntry() != null)
                return resolvedEntry;
            else
                return rawEntry;
        }
    }
    return rawEntry;
}

From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java

License:Open Source License

private static String getSourceAttachmentEncoding(IPackageFragmentRoot root) throws JavaModelException {
    String encoding = ResourcesPlugin.getEncoding();
    IClasspathEntry entry = root.getRawClasspathEntry();

    if (entry != null) {
        int kind = entry.getEntryKind();
        if (kind == IClasspathEntry.CPE_LIBRARY || kind == IClasspathEntry.CPE_VARIABLE) {
            IClasspathAttribute[] extraAttributes = entry.getExtraAttributes();
            for (int i = 0; i < extraAttributes.length; i++) {
                IClasspathAttribute attrib = extraAttributes[i];
                if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attrib.getName())) {
                    return attrib.getValue();
                }/*from   w  w w. jav  a2 s  .c o m*/
            }
        }
    }

    return encoding;
}

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  w w . j  a  va2  s.co 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.javafx.ide.jdt.internal.jdt.CPListElement.java

License:Open Source License

public CPListElement(Object parent, IJavaProject project, int entryKind, IPath path, boolean newElement,
        IResource res, IPath linkTarget) {
    fProject = project;// www .  j  a v a2 s .  c  o m

    fEntryKind = entryKind;
    fPath = path;
    fOrginalPath = newElement ? null : path;
    fLinkTarget = linkTarget;
    fOrginalLinkTarget = linkTarget;
    fChildren = new ArrayList<Object>();
    fResource = res;
    fIsExported = false;

    fIsMissing = false;
    fCachedEntry = null;
    fParentContainer = parent;

    switch (entryKind) {
    case IClasspathEntry.CPE_SOURCE:
        createAttributeElement(OUTPUT, null, true);
        createAttributeElement(INCLUSION, new Path[0], true);
        createAttributeElement(EXCLUSION, new Path[0], true);
        createAttributeElement(NATIVE_LIB_PATH, null, false);
        createAttributeElement(IGNORE_OPTIONAL_PROBLEMS, null, false);
        break;
    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_VARIABLE:
        createAttributeElement(SOURCEATTACHMENT, null, true);
        createAttributeElement(JAVADOC, null, false);
        createAttributeElement(SOURCE_ATTACHMENT_ENCODING, null, false);
        createAttributeElement(NATIVE_LIB_PATH, null, false);
        createAttributeElement(ACCESSRULES, new IAccessRule[0], true);
        break;
    case IClasspathEntry.CPE_PROJECT:
        createAttributeElement(ACCESSRULES, new IAccessRule[0], true);
        createAttributeElement(COMBINE_ACCESSRULES, Boolean.FALSE, true); // not rendered
        createAttributeElement(NATIVE_LIB_PATH, null, false);
        break;
    case IClasspathEntry.CPE_CONTAINER:
        createAttributeElement(ACCESSRULES, new IAccessRule[0], true);
        try {
            IClasspathContainer container = JavaCore.getClasspathContainer(fPath, fProject);
            if (container != null) {
                IClasspathEntry[] entries = container.getClasspathEntries();
                if (entries != null) { // catch invalid container implementation
                    for (int i = 0; i < entries.length; i++) {
                        IClasspathEntry entry = entries[i];
                        if (entry != null) {
                            CPListElement curr = createFromExisting(this, entry, fProject);
                            fChildren.add(curr);
                        } else {
                            JavaPlugin.logErrorMessage("Null entry in container '" + fPath + "'"); //$NON-NLS-1$//$NON-NLS-2$
                        }
                    }
                } else {
                    JavaPlugin.logErrorMessage("container returns null as entries: '" + fPath + "'"); //$NON-NLS-1$//$NON-NLS-2$
                }
            }
        } catch (JavaModelException e) {
        }
        createAttributeElement(NATIVE_LIB_PATH, null, false);
        break;
    default:
    }
}

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

License:Open Source License

private IClasspathEntry newClasspathEntry() {

    IClasspathAttribute[] extraAttributes = getClasspathAttributes();
    switch (fEntryKind) {
    case IClasspathEntry.CPE_SOURCE:
        IPath[] inclusionPattern = (IPath[]) getAttribute(INCLUSION);
        IPath[] exclusionPattern = (IPath[]) getAttribute(EXCLUSION);
        IPath outputLocation = (IPath) getAttribute(OUTPUT);
        return JavaCore.newSourceEntry(fPath, inclusionPattern, exclusionPattern, outputLocation,
                extraAttributes);/*from   w  w w . j a v  a 2s  .  c o m*/
    case IClasspathEntry.CPE_LIBRARY: {
        IPath attach = (IPath) getAttribute(SOURCEATTACHMENT);
        IAccessRule[] accesRules = (IAccessRule[]) getAttribute(ACCESSRULES);
        return JavaCore.newLibraryEntry(fPath, attach, null, accesRules, extraAttributes, isExported());
    }
    case IClasspathEntry.CPE_PROJECT: {
        IAccessRule[] accesRules = (IAccessRule[]) getAttribute(ACCESSRULES);
        boolean combineAccessRules = ((Boolean) getAttribute(COMBINE_ACCESSRULES)).booleanValue();
        return JavaCore.newProjectEntry(fPath, accesRules, combineAccessRules, extraAttributes, isExported());
    }
    case IClasspathEntry.CPE_CONTAINER: {
        IAccessRule[] accesRules = (IAccessRule[]) getAttribute(ACCESSRULES);
        return JavaCore.newContainerEntry(fPath, accesRules, extraAttributes, isExported());
    }
    case IClasspathEntry.CPE_VARIABLE: {
        IPath varAttach = (IPath) getAttribute(SOURCEATTACHMENT);
        IAccessRule[] accesRules = (IAccessRule[]) getAttribute(ACCESSRULES);
        return JavaCore.newVariableEntry(fPath, varAttach, null, accesRules, extraAttributes, isExported());
    }
    default:
        return null;
    }
}

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

License:Open Source License

public boolean isDeprecated() {
    if (fEntryKind != IClasspathEntry.CPE_VARIABLE) {
        return false;
    }/*  w  ww .  j ava  2 s  . co m*/
    if (fPath.segmentCount() > 0) {
        return JavaCore.getClasspathVariableDeprecationMessage(fPath.segment(0)) != null;
    }
    return false;
}

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

License:Open Source License

public String getDeprecationMessage() {
    if (fEntryKind != IClasspathEntry.CPE_VARIABLE) {
        return null;
    }//www . java 2s. co  m
    if (fPath.segmentCount() > 0) {
        String varName = fPath.segment(0);
        return BuildPathSupport.getDeprecationMessage(varName);
    }
    return null;
}

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) {/*  w  w  w .  j a  v  a2  s  .  c o  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;
}