Java源码示例:org.eclipse.jdt.internal.core.ClasspathAccessRule

示例1
protected RestrictionKind computeRestriction(IJavaProject project, IType type) {
	try {
		IPackageFragmentRoot root = (IPackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
		if (root == null) {
			return RestrictionKind.VALID;
		}
		IClasspathEntry entry = getResolvedClasspathEntry(project, root);
		if (entry == null) {
			return RestrictionKind.VALID;
		}
		IAccessRule[] rules = entry.getAccessRules();
		String typePath = type.getFullyQualifiedName().replace('.', '/');
		char[] typePathAsArray = typePath.toCharArray();
		for(IAccessRule rule: rules) {
			char[] patternArray = ((ClasspathAccessRule)rule).pattern;
			if (CharOperation.pathMatch(patternArray, typePathAsArray, true, '/')) {
				if (rule.getKind() == IAccessRule.K_DISCOURAGED) {
					return RestrictionKind.DISCOURAGED;
				} else if (rule.getKind() == IAccessRule.K_NON_ACCESSIBLE) {
					return RestrictionKind.FORBIDDEN;
				}
				return RestrictionKind.VALID;
			}
		}
	} catch(JavaModelException jme) {
		// ignore
	}
	return RestrictionKind.VALID;
}
 
示例2
private static AccessRuleSet readRestriction(DataInputStream in) throws IOException {
	int length = in.readInt();
	if (length == 0) return null; // no restriction specified
	AccessRule[] accessRules = new AccessRule[length];
	for (int i = 0; i < length; i++) {
		char[] pattern = readName(in);
		int problemId = in.readInt();
		accessRules[i] = new ClasspathAccessRule(pattern, problemId);
	}
	JavaModelManager manager = JavaModelManager.getJavaModelManager();
	return new AccessRuleSet(accessRules, in.readByte(), manager.intern(in.readUTF()));
}
 
示例3
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:innerassignment" })
private static IAccessRule[] decodeAccessRules(NodeList list) {
    if (list == null) {
        return null;
    }
    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".equals(elementAccessRule.getAttribute(ClasspathEntry.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;
}