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
Work on the ResolverModel, we make the Core Model aware of the changes.

View file

@ -8,12 +8,16 @@
* Contributors:
* 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.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.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
@ -22,18 +26,9 @@ import org.eclipse.core.runtime.Path;
public class PathUtil {
private static boolean fGotOS = false;
private static boolean fIsWindows = false;
public static boolean isWindowsSystem() {
if (!fGotOS) {
public static boolean isWindowsFileSystem() {
String os = System.getProperty("os.name"); //$NON-NLS-1$
if (os != null && os.startsWith("Win")) { //$NON-NLS-1$
fIsWindows= true;
}
fGotOS = true;
}
return fIsWindows;
return (os != null && os.startsWith("Win")); //$NON-NLS-1$
}
public static IWorkspaceRoot getWorkspaceRoot() {
@ -44,18 +39,14 @@ public class PathUtil {
return null;
}
public static IPath getCanonicalPath(String fullPath) {
File file = new File(fullPath);
public static IPath getCanonicalPath(IPath fullPath) {
File file = fullPath.toFile();
try {
String canonPath = file.getCanonicalPath();
return new Path(canonPath);
} catch (IOException ex) {
}
return new Path(fullPath);
}
public static IPath getCanonicalPath(IPath fullPath) {
return getCanonicalPath(fullPath.toString());
return null;
}
public static IPath getWorkspaceRelativePath(IPath fullPath) {
@ -87,10 +78,6 @@ public class PathUtil {
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) {
IWorkspaceRoot workspaceRoot = getWorkspaceRoot();
if (workspaceRoot != null && wsRelativePath != null) {
@ -101,4 +88,58 @@ public class PathUtil {
}
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;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
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.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
public class TypeReference implements ITypeReference {
@ -195,27 +191,9 @@ public class TypeReference implements ITypeReference {
public IPath getRelativeIncludePath(IProject project) {
IPath path = getLocation();
if (path != null) {
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(path)) {
int segments = includePath.matchingFirstSegments(path);
if (segments > mostSegments) {
relativePath = path.removeFirstSegments(segments).setDevice(null);
mostSegments = segments;
}
}
}
IPath relativePath = PathUtil.makeRelativePathToProjectIncludes(path, project);
if (relativePath != null)
path = relativePath;
}
}
return relativePath;
}
return path;
}
@ -223,16 +201,9 @@ public class TypeReference implements ITypeReference {
public IPath getRelativePath(IPath relativeToPath) {
IPath path = getPath();
if (path != null) {
int segments = relativeToPath.matchingFirstSegments(path);
if (segments > 0) {
IPath prefix = relativeToPath.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);
}
IPath relativePath = PathUtil.makeRelativePath(path, relativeToPath);
if (relativePath != null)
return relativePath;
}
return path;
}

View file

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

View file

@ -13,8 +13,8 @@ package org.eclipse.cdt.internal.core.browser.cache;
import java.io.IOException;
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.browser.util.PathUtil;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
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.ITypeSearchScope;
import org.eclipse.cdt.core.browser.PathUtil;
import org.eclipse.cdt.core.browser.QualifiedTypeName;
import org.eclipse.cdt.core.browser.TypeInfo;
import org.eclipse.cdt.core.browser.TypeReference;
import org.eclipse.cdt.core.model.ICElement;
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.IIndex;
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.ITypeSearchScope;
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.TypeInfo;
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.IASTVariable;
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.core.resources.IFile;
import org.eclipse.core.resources.IProject;