Example usage for org.eclipse.jdt.core IAccessRule K_DISCOURAGED

List of usage examples for org.eclipse.jdt.core IAccessRule K_DISCOURAGED

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IAccessRule K_DISCOURAGED.

Prototype

int K_DISCOURAGED

To view the source code for org.eclipse.jdt.core IAccessRule K_DISCOURAGED.

Click Source Link

Document

Constant indicating that access to the files matching the rule's pattern is discouraged.

Usage

From source file:at.bestsolution.efxclipse.tooling.pde.java7.JavaFXClassPathExtender.java

License:Open Source License

private IClasspathEntry getEntry(IVMInstall vm, BundleDescription project) {
    IPath[] paths = BuildPathSupport.getFxJarPath(vm);
    if (paths == null) {
        return null;
    } else {/*from w ww  .j ava  2s. com*/
        List<IAccessRule> l = new ArrayList<IAccessRule>();
        for (ImportPackageSpecification i : project.getImportPackages()) {
            if (i.getName().startsWith("javafx")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_ACCESSIBLE));
            } else if (i.getName().startsWith("com.sun.browser")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.deploy")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.glass")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.javafx")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.media")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.openpisces")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.prism")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.scenario")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.t2k")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.webpane")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("netscape.javascript")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            }
        }

        IClasspathAttribute[] extraAttributes = {
                JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                        paths[1] == null || !paths[1].toFile().exists() ? BuildPathSupport.WEB_JAVADOC_LOCATION
                                : paths[1].toFile().toURI().toString()) };

        return JavaCore.newLibraryEntry(paths[0], null, null, l.toArray(new IAccessRule[0]), extraAttributes,
                false);
    }
}

From source file:at.bestsolution.efxclipse.tooling.pde.ui.classpath.JavaFXClassPathExtender.java

License:Open Source License

@Override
public List<IClasspathEntry> getInitialEntries(BundleDescription project) {
    for (String e : project.getExecutionEnvironments()) {
        IExecutionEnvironment env = EnvironmentsManager.getDefault().getEnvironment(e);

        if (env == null) {
            continue;
        }/*  w w w  .  j  a v  a 2 s .c  o  m*/

        IVMInstall vm = env.getDefaultVM();

        if (vm == null) {
            for (IVMInstall i : env.getCompatibleVMs()) {
                vm = i;
                break;
            }
        }

        if (vm != null) {
            IPath[] paths = BuildPathSupport.getFxJarPath(vm);
            if (paths == null) {
                return Collections.emptyList();
            } else {
                List<IAccessRule> l = new ArrayList<IAccessRule>();
                for (ImportPackageSpecification i : project.getImportPackages()) {
                    if (i.getName().startsWith("javafx")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_ACCESSIBLE));
                    } else if (i.getName().startsWith("com.sun.browser")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.deploy")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.glass")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.javafx")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.media")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.openpisces")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.prism")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.scenario")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.t2k")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.webpane")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("netscape.javascript")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    }
                }

                IClasspathAttribute[] extraAttributes = {
                        JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                                paths[1] == null || !paths[1].toFile().exists()
                                        ? BuildPathSupport.WEB_JAVADOC_LOCATION
                                        : paths[1].toFile().toURI().toString()) };

                return Collections.singletonList(JavaCore.newContainerEntry(paths[0],
                        l.toArray(new IAccessRule[0]), extraAttributes, false));
            }
        }
    }
    return Collections.emptyList();
}

From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java

License:Open Source License

static IAccessRule[] decodeAccessRules(NodeList list) {
    if (list == null)
        return null;
    int length = list.getLength();
    if (length == 0)
        return null;
    IAccessRule[] result = new IAccessRule[length];
    int index = 0;
    for (int i = 0; i < length; i++) {
        Node accessRule = list.item(i);
        if (accessRule.getNodeType() == Node.ELEMENT_NODE) {
            Element elementAccessRule = (Element) accessRule;
            String pattern = elementAccessRule.getAttribute(TAG_PATTERN);
            if (pattern == null)
                continue;
            String tagKind = elementAccessRule.getAttribute(TAG_KIND);
            int kind;
            if (TAG_ACCESSIBLE.equals(tagKind))
                kind = IAccessRule.K_ACCESSIBLE;
            else if (TAG_NON_ACCESSIBLE.equals(tagKind))
                kind = IAccessRule.K_NON_ACCESSIBLE;
            else if (TAG_DISCOURAGED.equals(tagKind))
                kind = IAccessRule.K_DISCOURAGED;
            else/*from w  w  w. j a v a  2 s  .c  o m*/
                continue;
            boolean ignoreIfBetter = "true".equals(elementAccessRule.getAttribute(TAG_IGNORE_IF_BETTER)); //$NON-NLS-1$
            result[index++] = new ClasspathAccessRule(new Path(pattern),
                    ignoreIfBetter ? kind | IAccessRule.IGNORE_IF_BETTER : kind);
        }
    }
    if (index != length)
        System.arraycopy(result, 0, result = new IAccessRule[index], 0, index);
    return result;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.TypeNameMatchRequestorWrapper.java

License:Open Source License

public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames,
        String path, AccessRestriction access) {

    // Get type//from w w  w .j  ava2s  .c  o m
    try {
        IType type = null;
        if (this.handleFactory != null) {
            //todo openable
            Openable openable = null;//this.handleFactory.createOpenable(path, this.scope);
            if (openable == null)
                return;
            switch (openable.getElementType()) {
            case IJavaElement.COMPILATION_UNIT:
                ICompilationUnit cu = (ICompilationUnit) openable;
                if (enclosingTypeNames != null && enclosingTypeNames.length > 0) {
                    type = cu.getType(new String(enclosingTypeNames[0]));
                    for (int j = 1, l = enclosingTypeNames.length; j < l; j++) {
                        type = type.getType(new String(enclosingTypeNames[j]));
                    }
                    type = type.getType(new String(simpleTypeName));
                } else {
                    type = cu.getType(new String(simpleTypeName));
                }
                break;
            case IJavaElement.CLASS_FILE:
                type = ((IClassFile) openable).getType();
                break;
            }
        } else {
            int separatorIndex = path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
            type = separatorIndex == -1
                    ? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames)
                    : createTypeFromJar(path, separatorIndex);
        }

        // Accept match if the type has been found
        if (type != null) {
            // hierarchy scopes require one more check:
            if (!(this.scope instanceof org.eclipse.jdt.internal.core.search.HierarchyScope)
                    || ((HierarchyScope) this.scope).enclosesFineGrained(type)) {

                // Create the match
                final JavaSearchTypeNameMatch match = new JavaSearchTypeNameMatch(type, modifiers);

                // Update match accessibility
                if (access != null) {
                    switch (access.getProblemId()) {
                    case IProblem.ForbiddenReference:
                        match.setAccessibility(IAccessRule.K_NON_ACCESSIBLE);
                        break;
                    case IProblem.DiscouragedReference:
                        match.setAccessibility(IAccessRule.K_DISCOURAGED);
                        break;
                    }
                }

                // Accept match
                this.requestor.acceptTypeNameMatch(match);
            }
        }
    } catch (JavaModelException e) {
        // skip
    }
}

From source file:com.siteview.mde.internal.core.MDEClasspathContainer.java

License:Open Source License

private static synchronized IAccessRule getDiscouragedRule(IPath path) {
    IAccessRule rule = (IAccessRule) DISCOURAGED_RULES.get(path);
    if (rule == null) {
        rule = JavaCore.newAccessRule(path, IAccessRule.K_DISCOURAGED);
        DISCOURAGED_RULES.put(path, rule);
    }//from w  w  w  . jav a2 s. c  om
    return rule;
}

From source file:io.sarl.eclipse.util.JavaClasspathParser.java

License:Apache License

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:innerassignment" })
private static IAccessRule[] decodeAccessRules(NodeList list) {
    if (list == null) {
        return null;
    }//from  w ww .j  a va2 s . c  om
    final int length = list.getLength();
    if (length == 0) {
        return null;
    }
    IAccessRule[] result = new IAccessRule[length];
    int index = 0;
    for (int i = 0; i < length; i++) {
        final Node accessRule = list.item(i);
        if (accessRule.getNodeType() == Node.ELEMENT_NODE) {
            final Element elementAccessRule = (Element) accessRule;
            final String pattern = elementAccessRule.getAttribute(ClasspathEntry.TAG_PATTERN);
            if (pattern == null) {
                continue;
            }
            final String tagKind = elementAccessRule.getAttribute(ClasspathEntry.TAG_KIND);
            final int kind;
            if (ClasspathEntry.TAG_ACCESSIBLE.equals(tagKind)) {
                kind = IAccessRule.K_ACCESSIBLE;
            } else if (ClasspathEntry.TAG_NON_ACCESSIBLE.equals(tagKind)) {
                kind = IAccessRule.K_NON_ACCESSIBLE;
            } else if (ClasspathEntry.TAG_DISCOURAGED.equals(tagKind)) {
                kind = IAccessRule.K_DISCOURAGED;
            } else {
                continue;
            }
            final boolean ignoreIfBetter = "true" //$NON-NLS-1$
                    .equals(elementAccessRule.getAttribute(ClasspathEntry.TAG_IGNORE_IF_BETTER));
            result[index++] = new ClasspathAccessRule(new Path(pattern),
                    ignoreIfBetter ? kind | IAccessRule.IGNORE_IF_BETTER : kind);
        }
    }
    if (index != length) {
        System.arraycopy(result, 0, result = new IAccessRule[index], 0, index);
    }
    return result;
}

From source file:org.codehaus.groovy.eclipse.codeassist.processors.GroovyProposalTypeSearchRequestor.java

License:Apache License

public void acceptConstructor(int modifiers, char[] simpleTypeName, int parameterCount, char[] signature,
        char[][] parameterTypes, char[][] parameterNames, int typeModifiers, char[] packageName, int extraFlags,
        String path, AccessRestriction accessRestriction) {

    if (shouldAcceptConstructors) {

        // does not check cancellation for every types to avoid performance
        // loss/*w ww .j ava 2s . c om*/
        if ((this.foundConstructorsCount % (CHECK_CANCEL_FREQUENCY)) == 0)
            checkCancel();
        this.foundConstructorsCount++;

        if ((typeModifiers & ClassFileConstants.AccEnum) != 0)
            return;

        int accessibility = IAccessRule.K_ACCESSIBLE;
        if (accessRestriction != null) {
            switch (accessRestriction.getProblemId()) {
            case IProblem.ForbiddenReference:
                // forbidden references are removed
                return;
            case IProblem.DiscouragedReference:
                // discouraged references have lower priority
                accessibility = IAccessRule.K_DISCOURAGED;
                break;
            }
        }

        if (signature == null) {
            // signature = Signature.createArraySignature(typeSignature,
            // arrayCount)
        }

        if (this.acceptedConstructors == null) {
            this.acceptedConstructors = new ObjectVector();
        }
        this.acceptedConstructors
                .add(new AcceptedConstructor(modifiers, simpleTypeName, parameterCount, signature,
                        parameterTypes, parameterNames, typeModifiers, packageName, extraFlags, accessibility));
    }

}

From source file:org.codehaus.groovy.eclipse.codeassist.processors.GroovyProposalTypeSearchRequestor.java

License:Apache License

public void acceptType(char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, int modifiers,
        AccessRestriction accessRestriction) {
    // does not check cancellation for every types to avoid performance
    // loss/*  w w w  .j a  v a  2s.com*/
    if ((this.foundTypesCount % CHECK_CANCEL_FREQUENCY) == 0)
        checkCancel();
    this.foundTypesCount++;

    // ignore synthetic
    if (CharOperation.contains('$', simpleTypeName)) {
        return;
    }

    int accessibility = IAccessRule.K_ACCESSIBLE;
    if (accessRestriction != null) {
        switch (accessRestriction.getProblemId()) {
        case IProblem.ForbiddenReference:
            // forbidden references are removed
            return;
        case IProblem.DiscouragedReference:
            // discouraged references have a lower priority
            accessibility = IAccessRule.K_DISCOURAGED;
            break;
        }
    }

    if (this.acceptedTypes == null) {
        this.acceptedTypes = new ObjectVector();
    }
    this.acceptedTypes
            .add(new AcceptedType(packageName, simpleTypeName, enclosingTypeNames, modifiers, accessibility));
}

From source file:org.eclipse.che.jdt.internal.core.search.TypeNameMatchRequestorWrapper.java

License:Open Source License

public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames,
        String path, AccessRestriction access) {

    // Get type//from   w w  w.j  av a  2 s.  c  o m
    try {
        IType type = null;
        if (this.handleFactory != null) {
            Openable openable = this.handleFactory.createOpenable(path, this.scope);
            if (openable == null)
                return;
            switch (openable.getElementType()) {
            case IJavaElement.COMPILATION_UNIT:
                ICompilationUnit cu = (ICompilationUnit) openable;
                if (enclosingTypeNames != null && enclosingTypeNames.length > 0) {
                    type = cu.getType(new String(enclosingTypeNames[0]));
                    for (int j = 1, l = enclosingTypeNames.length; j < l; j++) {
                        type = type.getType(new String(enclosingTypeNames[j]));
                    }
                    type = type.getType(new String(simpleTypeName));
                } else {
                    type = cu.getType(new String(simpleTypeName));
                }
                break;
            case IJavaElement.CLASS_FILE:
                type = ((IClassFile) openable).getType();
                break;
            }
        } else {
            int separatorIndex = path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
            type = separatorIndex == -1
                    ? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames)
                    : createTypeFromJar(path, separatorIndex);
        }

        // Accept match if the type has been found
        if (type != null) {
            // hierarchy scopes require one more check:
            if (!(this.scope instanceof HierarchyScope)
                    || ((HierarchyScope) this.scope).enclosesFineGrained(type)) {

                // Create the match
                final JavaSearchTypeNameMatch match = new JavaSearchTypeNameMatch(type, modifiers);

                // Update match accessibility
                if (access != null) {
                    switch (access.getProblemId()) {
                    case IProblem.ForbiddenReference:
                        match.setAccessibility(IAccessRule.K_NON_ACCESSIBLE);
                        break;
                    case IProblem.DiscouragedReference:
                        match.setAccessibility(IAccessRule.K_DISCOURAGED);
                        break;
                    }
                }

                // Accept match
                this.requestor.acceptTypeNameMatch(match);
            }
        }
    } catch (JavaModelException e) {
        // skip
    }
}

From source file:org.eclipse.fx.ide.pde.core.JavaFXClassPathExtender.java

License:Open Source License

private IClasspathEntry getJavaFX2RuntimeEntry(IVMInstall vm, BundleDescription project) {
    IPath[] paths = BuildPathSupport.getFxJarPath(vm);
    if (paths == null) {
        return null;
    } else {/*from w w  w .j  ava  2s  .co  m*/
        List<IAccessRule> l = new ArrayList<IAccessRule>();
        for (ImportPackageSpecification i : project.getImportPackages()) {
            if (i.getName().startsWith("javafx")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_ACCESSIBLE));
            } else if (i.getName().startsWith("com.sun.browser")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.deploy")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.glass")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.javafx")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.media")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.openpisces")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.prism")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.scenario")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.t2k")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.webpane")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("netscape.javascript")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.javafx.scene.text")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            }
        }

        IClasspathAttribute[] extraAttributes = {
                JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                        paths[1] == null || !paths[1].toFile().exists() ? BuildPathSupport.WEB_JAVADOC_LOCATION
                                : paths[1].toFile().toURI().toString()) };

        return JavaCore.newLibraryEntry(paths[0], null, null, l.toArray(new IAccessRule[0]), extraAttributes,
                false);
    }
}