1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Fix the exclusion scheme in IPathEntry.

* model/org/eclipse/cdt/core/mode/CoreModelUtil.java
	* model/org/eclipse/cdt/internal/core/model/CContainer.java
	* model/org/eclipse/cdt/internal/core/model/Openable.java
	* model/org/eclipse/cdt/internal/core/model/SourceRoot.java
This commit is contained in:
Alain Magloire 2004-06-22 19:09:17 +00:00
parent a2393bddc7
commit c8e604403c
5 changed files with 91 additions and 89 deletions

View file

@ -1,3 +1,12 @@
2004-06-22 Alain Magloire
Fix the exclusion scheme in IPathEntry.
* model/org/eclipse/cdt/core/mode/CoreModelUtil.java
* model/org/eclipse/cdt/internal/core/model/CContainer.java
* model/org/eclipse/cdt/internal/core/model/Openable.java
* model/org/eclipse/cdt/internal/core/model/SourceRoot.java
2004-06-21 Alain Magloire
Big Patch from Vladimir Hirsl

View file

@ -5,30 +5,19 @@ import org.eclipse.core.runtime.IPath;
public class CoreModelUtil {
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 (pathMatch(pattern, path, true, '/')) {
return true;
}
}
return false;
}
/*
* Returns whether the given resource path matches one of the exclusion patterns.
*
* @see IClasspathEntry#getExclusionPatterns
* Returns whether the given path matches one of the exclusion patterns.
* @param resourcePath
* @param exclusionPatterns
* @return
*/
public final 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 (pathMatch(exclusionPatterns[i], path, true, '/'))
return true;
return false;
public static boolean isExcludedPath(IPath resourcePath, IPath[] exclusionPatterns) {
int length = exclusionPatterns.length;
char[][] fullCharExclusionPatterns = new char[length][];
for (int i = 0; i < length; i++) {
fullCharExclusionPatterns[i] = exclusionPatterns[i].toString().toCharArray();
}
return isExcluded(resourcePath, fullCharExclusionPatterns);
}
/*
@ -45,6 +34,49 @@ public class CoreModelUtil {
return isExcluded(path, exclusionPatterns);
}
/*
* Returns whether the given resource path matches one of the exclusion patterns.
*
* @see IClasspathEntry#getExclusionPatterns
*/
public final 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 (prefixOfCharArray(exclusionPatterns[i], path)) {
return true;
}
if (pathMatch(exclusionPatterns[i], path, true, '/')) {
return true;
}
}
return false;
}
/*
* if b is a prefix of a return true.
*/
static boolean prefixOfCharArray (char[] a, char[] b) {
if (a == b)
return true;
if (a == null || b == null)
return false;
int len = a.length;
if (len > b.length)
return false;
int i =0;
for (; i < len; ++i) {
if (a[i] != b[i])
return false;
}
if (i < b.length && b[i] != '/') {
return false;
}
return true;
}
/**
* Answers true if the pattern matches the given name, false otherwise. This char[] pattern matching accepts wild-cards '*' and
* '?'.

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
@ -199,11 +200,14 @@ public class CContainer extends Openable implements ICContainer {
}
if (resources != null) {
ICProject cproject = getCProject();
ISourceRoot sroot = getSourceRoot();
for (int i = 0; i < resources.length; i++) {
// Check for Valid C Element only.
ICElement celement = computeChild(resources[i], cproject);
if (celement != null) {
vChildren.add(celement);
if (sroot.isOnSourceEntry(resources[i])) {
// Check for Valid C Element only.
ICElement celement = computeChild(resources[i], cproject);
if (celement != null) {
vChildren.add(celement);
}
}
}
}
@ -220,12 +224,12 @@ public class CContainer extends Openable implements ICContainer {
return true;
}
protected ICElement computeChild(IResource resource, ICProject cproject) throws CModelException {
protected ICElement computeChild(IResource res, ICProject cproject) throws CModelException {
ICElement celement = null;
switch (resource.getType()) {
switch (res.getType()) {
case IResource.FILE :
{
IFile file = (IFile) resource;
IFile file = (IFile) res;
if (CoreModel.isTranslationUnit(file)) {
celement = new TranslationUnit(this, file);
} else if (cproject.isOnOutputEntry(file)) {
@ -247,7 +251,7 @@ public class CContainer extends Openable implements ICContainer {
break;
}
case IResource.FOLDER :
celement = new CContainer(this, resource);
celement = new CContainer(this, res);
break;
}
return celement;

View file

@ -109,9 +109,8 @@ public abstract class Openable extends Parent implements IOpenable, IBufferChang
buffer = openBuffer(null);
}
return buffer;
} else {
return null;
}
return null;
}
/**
@ -308,5 +307,17 @@ public abstract class Openable extends Parent implements IOpenable, IBufferChang
this.makeConsistent(pm); // update the element info of this element
}
}
/**
* Find enclosing package fragment root if any
*/
public SourceRoot getSourceRoot() {
ICElement current = this;
do {
if (current instanceof SourceRoot) return (SourceRoot)current;
current = current.getParent();
} while(current != null);
return null;
}
}

View file

@ -11,17 +11,12 @@
package org.eclipse.cdt.internal.core.model;
import java.util.ArrayList;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceEntry;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
/**
@ -46,45 +41,6 @@ public class SourceRoot extends CContainer implements ISourceRoot {
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.CContainer#computeChildren(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.resources.IResource)
*/
protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException {
ArrayList vChildren = new ArrayList();
try {
IResource[] resources = null;
if (res instanceof IContainer) {
//System.out.println (" Resource: " +
// res.getFullPath().toOSString());
IContainer container = (IContainer) res;
resources = container.members(false);
}
if (resources != null) {
ICProject cproject = getCProject();
for (int i = 0; i < resources.length; i++) {
// Check for Valid C Element only.
ICElement celement = null;
if (isOnSourceEntry(resources[i].getFullPath())) {
celement = computeChild(resources[i], cproject);
}
if (celement != null) {
vChildren.add(celement);
}
}
}
} catch (CoreException e) {
//System.out.println (e);
//CPlugin.log (e);
//e.printStackTrace();
throw new CModelException(e);
}
info.setChildren(vChildren);
if (info instanceof CContainerInfo) {
((CContainerInfo) info).setNonCResources(null);
}
return true;
}
public ISourceEntry getSourceEntry() {
return sourceEntry;
}
@ -94,24 +50,14 @@ public class SourceRoot extends CContainer implements ISourceRoot {
*/
public boolean isOnSourceEntry(ICElement element) {
IPath path = element.getPath();
if (element.getElementType() == ICElement.C_CCONTAINER) {
// ensure that folders are only excluded if all of their children are excluded
path = path.append("*"); //$NON-NLS-1$
}
return this.isOnSourceEntry(path);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ISourceRoot#isOnSourceEntry(org.eclipse.core.resources.IResource)
*/
public boolean isOnSourceEntry(IResource resource) {
IPath path = resource.getFullPath();
// ensure that folders are only excluded if all of their children are excluded
if (resource.getType() == IResource.FOLDER) {
path = path.append("*"); //$NON-NLS-1$
}
public boolean isOnSourceEntry(IResource res) {
IPath path = res.getFullPath();
return isOnSourceEntry(path);
}