Java Code Examples for org.eclipse.jdt.core.IClasspathEntry#getExclusionPatterns()

The following examples show how to use org.eclipse.jdt.core.IClasspathEntry#getExclusionPatterns() . 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: NewSourceFolderWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void addExclusionPatterns(IClasspathEntry newEntry, List<IClasspathEntry> existing, Set<IClasspathEntry> modifiedEntries) {
	IPath entryPath= newEntry.getPath();
	for (int i= 0; i < existing.size(); i++) {
		IClasspathEntry curr= existing.get(i);
		IPath currPath= curr.getPath();
		if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE && currPath.isPrefixOf(entryPath)) {
			IPath[] exclusionFilters= curr.getExclusionPatterns();
			if (!JavaModelUtil.isExcludedPath(entryPath, exclusionFilters)) {
				IPath pathToExclude= entryPath.removeFirstSegments(currPath.segmentCount()).addTrailingSeparator();
				IPath[] newExclusionFilters= new IPath[exclusionFilters.length + 1];
				System.arraycopy(exclusionFilters, 0, newExclusionFilters, 0, exclusionFilters.length);
				newExclusionFilters[exclusionFilters.length]= pathToExclude;

				IClasspathEntry updated= JavaCore.newSourceEntry(currPath, newExclusionFilters, curr.getOutputLocation());
				existing.set(i, updated);
				modifiedEntries.add(updated);
			}
		}
	}
}
 
Example 2
Source File: BinaryRefactoringHistoryWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Updates the new classpath with exclusion patterns for the specified path.
 *
 * @param entries
 *            the classpath entries
 * @param path
 *            the path
 */
private static void addExclusionPatterns(final List<IClasspathEntry> entries, final IPath path) {
	for (int index= 0; index < entries.size(); index++) {
		final IClasspathEntry entry= entries.get(index);
		if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getPath().isPrefixOf(path)) {
			final IPath[] patterns= entry.getExclusionPatterns();
			if (!JavaModelUtil.isExcludedPath(path, patterns)) {
				final IPath[] filters= new IPath[patterns.length + 1];
				System.arraycopy(patterns, 0, filters, 0, patterns.length);
				filters[patterns.length]= path.removeFirstSegments(entry.getPath().segmentCount()).addTrailingSeparator();
				entries.set(index, JavaCore.newSourceEntry(entry.getPath(), filters, entry.getOutputLocation()));
			}
		}
	}
}
 
Example 3
Source File: ClasspathModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check whether the input parameter of type <code>
 * IPackageFragmentRoot</code> has either it's inclusion or
 * exclusion filter or both set (that means they are
 * not empty).
 *
 * @param root the fragment root to be inspected
 * @return <code>true</code> inclusion or exclusion filter set,
 * <code>false</code> otherwise.
 * @throws JavaModelException
 */
public static boolean filtersSet(IPackageFragmentRoot root) throws JavaModelException {
	if (root == null)
		return false;
	IClasspathEntry entry= root.getRawClasspathEntry();
	IPath[] inclusions= entry.getInclusionPatterns();
	IPath[] exclusions= entry.getExclusionPatterns();
	if (inclusions != null && inclusions.length > 0)
		return true;
	if (exclusions != null && exclusions.length > 0)
		return true;
	return false;
}
 
Example 4
Source File: ResetAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean canHandle(IStructuredSelection elements) {
	try {
        for (Iterator<?> iterator= elements.iterator(); iterator.hasNext();) {
            Object element= iterator.next();
            if (element instanceof IJavaProject) {
            	IJavaProject project= (IJavaProject)element;
            	if (!project.isOnClasspath(project))
            		return false;

            	IClasspathEntry entry= ClasspathModifier.getClasspathEntryFor(project.getPath(), project, IClasspathEntry.CPE_SOURCE);
                if (entry.getInclusionPatterns().length == 0 && entry.getExclusionPatterns().length == 0)
                    return false;

        		return true;
            } else if (element instanceof IPackageFragmentRoot) {
            	if (ClasspathModifier.filtersSet((IPackageFragmentRoot)element))
            		return true;
            } else if (element instanceof CPListElementAttribute) {
            	if (!ClasspathModifier.isDefaultOutputFolder((CPListElementAttribute)element))
            		return true;
            } else {
            	return false;
            }
        }
       } catch (JavaModelException e) {
        return false;
       }
	return false;
}
 
Example 5
Source File: ClasspathChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private int classpathContains(IClasspathEntry[] list, IClasspathEntry entry) {
	IPath[] exclusionPatterns = entry.getExclusionPatterns();
	IPath[] inclusionPatterns = entry.getInclusionPatterns();
	int listLen = list == null ? 0 : list.length;
	nextEntry: for (int i = 0; i < listLen; i++) {
		IClasspathEntry other = list[i];
		if (other.getContentKind() == entry.getContentKind()
			&& other.getEntryKind() == entry.getEntryKind()
			&& other.isExported() == entry.isExported()
			&& other.getPath().equals(entry.getPath())) {
				// check custom outputs
				IPath entryOutput = entry.getOutputLocation();
				IPath otherOutput = other.getOutputLocation();
				if (entryOutput == null) {
					if (otherOutput != null)
						continue;
				} else {
					if (!entryOutput.equals(otherOutput))
						continue;
				}

				// check inclusion patterns
				IPath[] otherIncludes = other.getInclusionPatterns();
				if (inclusionPatterns != otherIncludes) {
				    if (inclusionPatterns == null) continue;
					int includeLength = inclusionPatterns.length;
					if (otherIncludes == null || otherIncludes.length != includeLength)
						continue;
					for (int j = 0; j < includeLength; j++) {
						// compare toStrings instead of IPaths
						// since IPath.equals is specified to ignore trailing separators
						if (!inclusionPatterns[j].toString().equals(otherIncludes[j].toString()))
							continue nextEntry;
					}
				}
				// check exclusion patterns
				IPath[] otherExcludes = other.getExclusionPatterns();
				if (exclusionPatterns != otherExcludes) {
				    if (exclusionPatterns == null) continue;
					int excludeLength = exclusionPatterns.length;
					if (otherExcludes == null || otherExcludes.length != excludeLength)
						continue;
					for (int j = 0; j < excludeLength; j++) {
						// compare toStrings instead of IPaths
						// since IPath.equals is specified to ignore trailing separators
						if (!exclusionPatterns[j].toString().equals(otherExcludes[j].toString()))
							continue nextEntry;
					}
				}
				return i;
		}
	}
	return -1;
}