1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

2004-08-20 Chris Wiebe

make PathUtil visible
	* browser/org/eclipse/cdt/internal/core/browser/PathUtil.java
	* browser/org/eclipse/cdt/internal/core/browser/TypeReference.java
	* browser/org/eclipse/cdt/internal/core/browser/TypeSearchScope.java
This commit is contained in:
Chris Wiebe 2004-08-21 01:26:50 +00:00
parent 010c8c429a
commit 50906ed31f
7 changed files with 86 additions and 63 deletions

View file

@ -1,3 +1,10 @@
2004-08-20 Chris Wiebe
make PathUtil visible
* browser/org/eclipse/cdt/internal/core/browser/PathUtil.java
* browser/org/eclipse/cdt/internal/core/browser/TypeReference.java
* browser/org/eclipse/cdt/internal/core/browser/TypeSearchScope.java
2004-08-18 Alain Magloire 2004-08-18 Alain Magloire
Work on the ResolverModel, we make the Core Model aware of the changes. Work on the ResolverModel, we make the Core Model aware of the changes.

View file

@ -8,12 +8,16 @@
* Contributors: * Contributors:
* QNX Software Systems - initial API and implementation * QNX Software Systems - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.browser.util; package org.eclipse.cdt.core.browser;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
@ -22,18 +26,9 @@ import org.eclipse.core.runtime.Path;
public class PathUtil { public class PathUtil {
private static boolean fGotOS = false; public static boolean isWindowsFileSystem() {
private static boolean fIsWindows = false; String os = System.getProperty("os.name"); //$NON-NLS-1$
return (os != null && os.startsWith("Win")); //$NON-NLS-1$
public static boolean isWindowsSystem() {
if (!fGotOS) {
String os = System.getProperty("os.name"); //$NON-NLS-1$
if (os != null && os.startsWith("Win")) { //$NON-NLS-1$
fIsWindows= true;
}
fGotOS = true;
}
return fIsWindows;
} }
public static IWorkspaceRoot getWorkspaceRoot() { public static IWorkspaceRoot getWorkspaceRoot() {
@ -44,18 +39,14 @@ public class PathUtil {
return null; return null;
} }
public static IPath getCanonicalPath(String fullPath) { public static IPath getCanonicalPath(IPath fullPath) {
File file = new File(fullPath); File file = fullPath.toFile();
try { try {
String canonPath = file.getCanonicalPath(); String canonPath = file.getCanonicalPath();
return new Path(canonPath); return new Path(canonPath);
} catch (IOException ex) { } catch (IOException ex) {
} }
return new Path(fullPath); return null;
}
public static IPath getCanonicalPath(IPath fullPath) {
return getCanonicalPath(fullPath.toString());
} }
public static IPath getWorkspaceRelativePath(IPath fullPath) { public static IPath getWorkspaceRelativePath(IPath fullPath) {
@ -87,10 +78,6 @@ public class PathUtil {
return getWorkspaceRelativePath(new Path(fullPath)); return getWorkspaceRelativePath(new Path(fullPath));
} }
public static IPath getProjectRelativePath(String fullPath, IProject project) {
return getProjectRelativePath(new Path(fullPath), project);
}
public static IPath getRawLocation(IPath wsRelativePath) { public static IPath getRawLocation(IPath wsRelativePath) {
IWorkspaceRoot workspaceRoot = getWorkspaceRoot(); IWorkspaceRoot workspaceRoot = getWorkspaceRoot();
if (workspaceRoot != null && wsRelativePath != null) { if (workspaceRoot != null && wsRelativePath != null) {
@ -101,4 +88,58 @@ public class PathUtil {
} }
return wsRelativePath; return wsRelativePath;
} }
public static IPath makeRelativePath(IPath path, IPath relativeTo) {
int segments = relativeTo.matchingFirstSegments(path);
if (segments > 0) {
IPath prefix = relativeTo.removeFirstSegments(segments).removeLastSegments(1);
IPath suffix = path.removeFirstSegments(segments);
IPath relativePath = new Path(""); //$NON-NLS-1$
for (int i = 0; i < prefix.segmentCount(); ++i) {
relativePath = relativePath.append(".." + IPath.SEPARATOR); //$NON-NLS-1$
}
return relativePath.append(suffix);
}
return null;
}
public static IPath makeRelativePathToProjectIncludes(IPath fullPath, IProject project) {
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
if (provider != null) {
IScannerInfo info = provider.getScannerInformation(project);
if (info != null) {
String[] includePaths = info.getIncludePaths();
IPath relativePath = null;
int mostSegments = 0;
for (int i = 0; i < includePaths.length; ++i) {
IPath includePath = new Path(includePaths[i]);
if (includePath.isPrefixOf(fullPath)) {
int segments = includePath.matchingFirstSegments(fullPath);
if (segments > mostSegments) {
relativePath = fullPath.removeFirstSegments(segments).setDevice(null);
mostSegments = segments;
}
}
}
if (relativePath != null)
return relativePath;
}
}
return null;
}
public static IProject getEnclosingProject(IPath fullPath) {
IWorkspaceRoot root = getWorkspaceRoot();
if (root != null) {
IPath path = getWorkspaceRelativePath(fullPath);
while (!path.isEmpty()) {
IResource res = root.findMember(path);
if (res != null)
return res.getProject();
path = path.removeLastSegments(1);
}
}
return null;
}
} }

View file

@ -10,19 +10,15 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.browser; package org.eclipse.cdt.core.browser;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
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.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
public class TypeReference implements ITypeReference { public class TypeReference implements ITypeReference {
@ -195,27 +191,9 @@ public class TypeReference implements ITypeReference {
public IPath getRelativeIncludePath(IProject project) { public IPath getRelativeIncludePath(IProject project) {
IPath path = getLocation(); IPath path = getLocation();
if (path != null) { if (path != null) {
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project); IPath relativePath = PathUtil.makeRelativePathToProjectIncludes(path, project);
if (provider != null) { if (relativePath != null)
IScannerInfo info = provider.getScannerInformation(project); return relativePath;
if (info != null) {
String[] includePaths = info.getIncludePaths();
IPath relativePath = null;
int mostSegments = 0;
for (int i = 0; i < includePaths.length; ++i) {
IPath includePath = new Path(includePaths[i]);
if (includePath.isPrefixOf(path)) {
int segments = includePath.matchingFirstSegments(path);
if (segments > mostSegments) {
relativePath = path.removeFirstSegments(segments).setDevice(null);
mostSegments = segments;
}
}
}
if (relativePath != null)
path = relativePath;
}
}
} }
return path; return path;
} }
@ -223,16 +201,9 @@ public class TypeReference implements ITypeReference {
public IPath getRelativePath(IPath relativeToPath) { public IPath getRelativePath(IPath relativeToPath) {
IPath path = getPath(); IPath path = getPath();
if (path != null) { if (path != null) {
int segments = relativeToPath.matchingFirstSegments(path); IPath relativePath = PathUtil.makeRelativePath(path, relativeToPath);
if (segments > 0) { if (relativePath != null)
IPath prefix = relativeToPath.removeFirstSegments(segments).removeLastSegments(1); return relativePath;
IPath suffix = path.removeFirstSegments(segments);
IPath relativePath = new Path(""); //$NON-NLS-1$
for (int i = 0; i < prefix.segmentCount(); ++i) {
relativePath = relativePath.append(".." + IPath.SEPARATOR); //$NON-NLS-1$
}
return relativePath.append(suffix);
}
} }
return path; return path;
} }

View file

@ -52,6 +52,10 @@ public class TypeSearchScope implements ITypeSearchScope {
add(scope); add(scope);
} }
public TypeSearchScope(IProject project) {
add(project);
}
public Collection pathSet() { public Collection pathSet() {
return fPathSet; return fPathSet;
} }

View file

@ -13,8 +13,8 @@ package org.eclipse.cdt.internal.core.browser.cache;
import java.io.IOException; import java.io.IOException;
import org.eclipse.cdt.core.browser.ITypeSearchScope; import org.eclipse.cdt.core.browser.ITypeSearchScope;
import org.eclipse.cdt.core.browser.PathUtil;
import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.browser.util.PathUtil;
import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.impl.BlocksIndexInput; import org.eclipse.cdt.internal.core.index.impl.BlocksIndexInput;

View file

@ -14,12 +14,12 @@ import java.io.IOException;
import org.eclipse.cdt.core.browser.ITypeInfo; import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.browser.ITypeSearchScope; import org.eclipse.cdt.core.browser.ITypeSearchScope;
import org.eclipse.cdt.core.browser.PathUtil;
import org.eclipse.cdt.core.browser.QualifiedTypeName; import org.eclipse.cdt.core.browser.QualifiedTypeName;
import org.eclipse.cdt.core.browser.TypeInfo; import org.eclipse.cdt.core.browser.TypeInfo;
import org.eclipse.cdt.core.browser.TypeReference; import org.eclipse.cdt.core.browser.TypeReference;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.browser.util.PathUtil;
import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.impl.BlocksIndexInput; import org.eclipse.cdt.internal.core.index.impl.BlocksIndexInput;

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.browser.ITypeReference; import org.eclipse.cdt.core.browser.ITypeReference;
import org.eclipse.cdt.core.browser.ITypeSearchScope; import org.eclipse.cdt.core.browser.ITypeSearchScope;
import org.eclipse.cdt.core.browser.IWorkingCopyProvider; import org.eclipse.cdt.core.browser.IWorkingCopyProvider;
import org.eclipse.cdt.core.browser.PathUtil;
import org.eclipse.cdt.core.browser.QualifiedTypeName; import org.eclipse.cdt.core.browser.QualifiedTypeName;
import org.eclipse.cdt.core.browser.TypeInfo; import org.eclipse.cdt.core.browser.TypeInfo;
import org.eclipse.cdt.core.browser.TypeReference; import org.eclipse.cdt.core.browser.TypeReference;
@ -92,7 +93,6 @@ import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.ast.IASTVariableReference; import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
import org.eclipse.cdt.internal.core.browser.util.PathUtil;
import org.eclipse.cdt.internal.core.browser.util.SimpleStack; import org.eclipse.cdt.internal.core.browser.util.SimpleStack;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;