mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 11:55:40 +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:
parent
a2393bddc7
commit
c8e604403c
5 changed files with 91 additions and 89 deletions
|
@ -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
|
2004-06-21 Alain Magloire
|
||||||
|
|
||||||
Big Patch from Vladimir Hirsl
|
Big Patch from Vladimir Hirsl
|
||||||
|
|
|
@ -5,30 +5,19 @@ import org.eclipse.core.runtime.IPath;
|
||||||
|
|
||||||
public class CoreModelUtil {
|
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.
|
* Returns whether the given path matches one of the exclusion patterns.
|
||||||
*
|
* @param resourcePath
|
||||||
* @see IClasspathEntry#getExclusionPatterns
|
* @param exclusionPatterns
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public final static boolean isExcluded(IPath resourcePath, char[][] exclusionPatterns) {
|
public static boolean isExcludedPath(IPath resourcePath, IPath[] exclusionPatterns) {
|
||||||
if (exclusionPatterns == null)
|
int length = exclusionPatterns.length;
|
||||||
return false;
|
char[][] fullCharExclusionPatterns = new char[length][];
|
||||||
char[] path = resourcePath.toString().toCharArray();
|
for (int i = 0; i < length; i++) {
|
||||||
for (int i = 0, length = exclusionPatterns.length; i < length; i++)
|
fullCharExclusionPatterns[i] = exclusionPatterns[i].toString().toCharArray();
|
||||||
if (pathMatch(exclusionPatterns[i], path, true, '/'))
|
}
|
||||||
return true;
|
return isExcluded(resourcePath, fullCharExclusionPatterns);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -45,6 +34,49 @@ public class CoreModelUtil {
|
||||||
return isExcluded(path, exclusionPatterns);
|
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
|
* Answers true if the pattern matches the given name, false otherwise. This char[] pattern matching accepts wild-cards '*' and
|
||||||
* '?'.
|
* '?'.
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.eclipse.cdt.core.model.IBinary;
|
||||||
import org.eclipse.cdt.core.model.ICContainer;
|
import org.eclipse.cdt.core.model.ICContainer;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
@ -199,7 +200,9 @@ public class CContainer extends Openable implements ICContainer {
|
||||||
}
|
}
|
||||||
if (resources != null) {
|
if (resources != null) {
|
||||||
ICProject cproject = getCProject();
|
ICProject cproject = getCProject();
|
||||||
|
ISourceRoot sroot = getSourceRoot();
|
||||||
for (int i = 0; i < resources.length; i++) {
|
for (int i = 0; i < resources.length; i++) {
|
||||||
|
if (sroot.isOnSourceEntry(resources[i])) {
|
||||||
// Check for Valid C Element only.
|
// Check for Valid C Element only.
|
||||||
ICElement celement = computeChild(resources[i], cproject);
|
ICElement celement = computeChild(resources[i], cproject);
|
||||||
if (celement != null) {
|
if (celement != null) {
|
||||||
|
@ -207,6 +210,7 @@ public class CContainer extends Openable implements ICContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
//System.out.println (e);
|
//System.out.println (e);
|
||||||
//CPlugin.log (e);
|
//CPlugin.log (e);
|
||||||
|
@ -220,12 +224,12 @@ public class CContainer extends Openable implements ICContainer {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ICElement computeChild(IResource resource, ICProject cproject) throws CModelException {
|
protected ICElement computeChild(IResource res, ICProject cproject) throws CModelException {
|
||||||
ICElement celement = null;
|
ICElement celement = null;
|
||||||
switch (resource.getType()) {
|
switch (res.getType()) {
|
||||||
case IResource.FILE :
|
case IResource.FILE :
|
||||||
{
|
{
|
||||||
IFile file = (IFile) resource;
|
IFile file = (IFile) res;
|
||||||
if (CoreModel.isTranslationUnit(file)) {
|
if (CoreModel.isTranslationUnit(file)) {
|
||||||
celement = new TranslationUnit(this, file);
|
celement = new TranslationUnit(this, file);
|
||||||
} else if (cproject.isOnOutputEntry(file)) {
|
} else if (cproject.isOnOutputEntry(file)) {
|
||||||
|
@ -247,7 +251,7 @@ public class CContainer extends Openable implements ICContainer {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IResource.FOLDER :
|
case IResource.FOLDER :
|
||||||
celement = new CContainer(this, resource);
|
celement = new CContainer(this, res);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return celement;
|
return celement;
|
||||||
|
|
|
@ -109,9 +109,8 @@ public abstract class Openable extends Parent implements IOpenable, IBufferChang
|
||||||
buffer = openBuffer(null);
|
buffer = openBuffer(null);
|
||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -309,4 +308,16 @@ public abstract class Openable extends Parent implements IOpenable, IBufferChang
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,17 +11,12 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.model;
|
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.CoreModelUtil;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
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.ISourceEntry;
|
||||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||||
import org.eclipse.core.resources.IContainer;
|
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
import org.eclipse.core.runtime.IPath;
|
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() {
|
public ISourceEntry getSourceEntry() {
|
||||||
return sourceEntry;
|
return sourceEntry;
|
||||||
}
|
}
|
||||||
|
@ -94,24 +50,14 @@ public class SourceRoot extends CContainer implements ISourceRoot {
|
||||||
*/
|
*/
|
||||||
public boolean isOnSourceEntry(ICElement element) {
|
public boolean isOnSourceEntry(ICElement element) {
|
||||||
IPath path = element.getPath();
|
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);
|
return this.isOnSourceEntry(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.model.ISourceRoot#isOnSourceEntry(org.eclipse.core.resources.IResource)
|
* @see org.eclipse.cdt.core.model.ISourceRoot#isOnSourceEntry(org.eclipse.core.resources.IResource)
|
||||||
*/
|
*/
|
||||||
public boolean isOnSourceEntry(IResource resource) {
|
public boolean isOnSourceEntry(IResource res) {
|
||||||
IPath path = resource.getFullPath();
|
IPath path = res.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$
|
|
||||||
}
|
|
||||||
|
|
||||||
return isOnSourceEntry(path);
|
return isOnSourceEntry(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue