Java Code Examples for org.eclipse.jdt.core.compiler.CharOperation#pathMatch()

The following examples show how to use org.eclipse.jdt.core.compiler.CharOperation#pathMatch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessRuleSet.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Select the first access rule which is violated when accessing a given type,
 * or null if no 'non accessible' access rule applies.
 * @param targetTypeFilePath the target type file path, formed as:
 * "org/eclipse/jdt/core/JavaCore"
 * @return the first access restriction that applies if any, null else
 */
public AccessRestriction getViolatedRestriction(char[] targetTypeFilePath) {
	for (int i = 0, length = this.accessRules.length; i < length; i++) {
		AccessRule accessRule = this.accessRules[i];
		if (CharOperation.pathMatch(accessRule.pattern, targetTypeFilePath,
				true/*case sensitive*/, '/')) {
			switch (accessRule.getProblemId()) {
				case IProblem.ForbiddenReference:
				case IProblem.DiscouragedReference:
					return new AccessRestriction(accessRule, this.classpathEntryType, this.classpathEntryName);
				default:
					return null;
			}
		}
	}
	return null;
}
 
Example 2
Source File: XbaseUIValidator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isExcludedPath(IPath resourcePath, IPath[] exclusionPatterns) {
	char[] path = resourcePath.toString().toCharArray();
	for (int i = 0, length = exclusionPatterns.length; i < length; i++) {
		char[] pattern= exclusionPatterns[i].toString().toCharArray();
		if (CharOperation.pathMatch(pattern, path, true, '/')) {
			return true;
		}
	}
	return false;
}
 
Example 4
Source File: Util.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public final static boolean isExcluded(char[] path, char[][] inclusionPatterns, char[][] exclusionPatterns, boolean isFolderPath) {
	if (inclusionPatterns == null && exclusionPatterns == null) return false;

	inclusionCheck: if (inclusionPatterns != null) {
		for (int i = 0, length = inclusionPatterns.length; i < length; i++) {
			char[] pattern = inclusionPatterns[i];
			char[] folderPattern = pattern;
			if (isFolderPath) {
				int lastSlash = CharOperation.lastIndexOf('/', pattern);
				if (lastSlash != -1 && lastSlash != pattern.length-1){ // trailing slash -> adds '**' for free (see http://ant.apache.org/manual/dirtasks.html)
					int star = CharOperation.indexOf('*', pattern, lastSlash);
					if ((star == -1
							|| star >= pattern.length-1
							|| pattern[star+1] != '*')) {
						folderPattern = CharOperation.subarray(pattern, 0, lastSlash);
					}
				}
			}
			if (CharOperation.pathMatch(folderPattern, path, true, '/')) {
				break inclusionCheck;
			}
		}
		return true; // never included
	}
	if (isFolderPath) {
		path = CharOperation.concat(path, new char[] {'*'}, '/');
	}
	if (exclusionPatterns != null) {
		for (int i = 0, length = exclusionPatterns.length; i < length; i++) {
			if (CharOperation.pathMatch(exclusionPatterns[i], path, true, '/')) {
				return true;
			}
		}
	}
	return false;
}
 
Example 5
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Returns whether the given resource path matches one of the exclusion
 * patterns.
 * @param resourcePath the resource path
 * @param exclusionPatterns the exclusion patterns
 * @return returns <code> true</code> if the given resource path matches one of the exclusion
 *
 * @see IClasspathEntry#getExclusionPatterns
 */
public static boolean isExcluded(IPath resourcePath, char[][] exclusionPatterns) {
	if (exclusionPatterns == null) return false;
	char[] path = resourcePath.toString().toCharArray();
	for (int i = 0, length = exclusionPatterns.length; i < length; i++)
		if (CharOperation.pathMatch(exclusionPatterns[i], path, true, '/'))
			return true;
	return false;
}