Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/InternalParserUtil.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java28
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java18
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/LocationAdapter.java24
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/PathCanonicalizationStrategy.java50
5 files changed, 95 insertions, 34 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/InternalParserUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/InternalParserUtil.java
index d6e30fa5dd7..96c9d03588b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/InternalParserUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/InternalParserUtil.java
@@ -18,6 +18,7 @@ import java.io.InputStream;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.internal.core.resources.PathCanonicalizationStrategy;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceStatus;
@@ -49,10 +50,10 @@ public class InternalParserUtil extends ParserFactory {
public static CodeReader createExternalFileReader(String externalLocation, CodeReaderLRUCache cache) throws IOException {
File includeFile = new File(externalLocation);
if (includeFile.isFile()) {
- //use the canonical path so that in case of non-case-sensitive OSs
- //the CodeReader always has the same name as the file on disk with
- //no differences in case.
- final String path = includeFile.getCanonicalPath();
+ // Use the canonical path so that in case of non-case-sensitive OSs
+ // the CodeReader always has the same name as the file on disk with
+ // no differences in case.
+ final String path = PathCanonicalizationStrategy.getCanonicalPath(includeFile);
if (cache != null) {
CodeReader result= cache.get(path);
if (result != null)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
index d7c4d04c59b..9c11bbb352b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
@@ -82,6 +82,7 @@ import org.eclipse.cdt.internal.core.pdom.indexer.PDOMUpdateTask;
import org.eclipse.cdt.internal.core.pdom.indexer.ProjectIndexerInputAdapter;
import org.eclipse.cdt.internal.core.pdom.indexer.TranslationUnitCollector;
import org.eclipse.cdt.internal.core.pdom.indexer.TriggerNotificationTask;
+import org.eclipse.cdt.internal.core.resources.PathCanonicalizationStrategy;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -150,6 +151,14 @@ public class PDOMManager implements IWritableIndexManager, IListener {
};
/**
+ * Boolean preference controlling whether paths to non-workspace files are stored in canonical
+ * form or not.
+ */
+ // TODO(sprigogin): Move to CPreferencesConstants and add UI support.
+ public static final String PREFERENCES_CONSTANT_PATH_CANONICALIZATION =
+ CCorePlugin.PLUGIN_ID + ".path_canonicalization"; //$NON-NLS-1$
+
+ /**
* Protects fIndexerJob, fCurrentTask and fTaskQueue.
*/
private final LinkedList<IPDOMIndexerTask> fTaskQueue = new LinkedList<IPDOMIndexerTask>();
@@ -158,7 +167,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
private int fSourceCount, fHeaderCount, fTickCount;
/**
- * Stores mapping from pdom to project, used to serialize\ creation of new pdoms.
+ * Stores mapping from pdom to project, used to serialize creation of new pdoms.
*/
private Map<IProject, IPDOM> fProjectToPDOM= new HashMap<IProject, IPDOM>();
private Map<File, ICProject> fFileToProject= new HashMap<File, ICProject>();
@@ -187,6 +196,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
private ArrayList<IndexerSetupParticipant> fSetupParticipants= new ArrayList<IndexerSetupParticipant>();
private HashSet<ICProject> fPostponedProjects= new HashSet<ICProject>();
private int fLastNotifiedState= IndexerStateEvent.STATE_IDLE;
+ private PathCanonicalizationStrategy fPathCanonicalizationStrategy;
public PDOMManager() {
PDOM.sDEBUG_LOCKS= "true".equals(Platform.getDebugOption(CCorePlugin.PLUGIN_ID + "/debug/index/locks")); //$NON-NLS-1$//$NON-NLS-2$
@@ -225,6 +235,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
new InstanceScope().getNode(CCorePlugin.PLUGIN_ID).addPreferenceChangeListener(fPreferenceChangeListener);
Job.getJobManager().addJobChangeListener(fJobChangeListener);
adjustCacheSize();
+ updatePathCanonicalizationStrategy();
fIndexProviderManager.startup();
final CoreModel model = CoreModel.getDefault();
@@ -273,6 +284,9 @@ public class PDOMManager implements IWritableIndexManager, IListener {
prop.equals(CCorePreferenceConstants.TODO_TASK_PRIORITIES) ||
prop.equals(CCorePreferenceConstants.TODO_TASK_CASE_SENSITIVE)) {
reindexAll();
+ } else if (prop.equals(PREFERENCES_CONSTANT_PATH_CANONICALIZATION)) {
+ updatePathCanonicalizationStrategy();
+ reindexAll();
}
}
@@ -287,6 +301,18 @@ public class PDOMManager implements IWritableIndexManager, IListener {
ChunkCache.getSharedInstance().setMaxSize(m2);
}
+ private void updatePathCanonicalizationStrategy() {
+ IPreferencesService prefs = Platform.getPreferencesService();
+ boolean canonicalize = prefs.getBoolean(CCorePlugin.PLUGIN_ID, PREFERENCES_CONSTANT_PATH_CANONICALIZATION, true, null);
+ synchronized (this) {
+ fPathCanonicalizationStrategy = PathCanonicalizationStrategy.getStrategy(canonicalize);
+ }
+ }
+
+ public synchronized PathCanonicalizationStrategy getPathCanonicalizationStrategy() {
+ return fPathCanonicalizationStrategy;
+ }
+
public IndexProviderManager getIndexProviderManager() {
return fIndexProviderManager;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java
index 18924c31dc1..052bbce203f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java
@@ -7,11 +7,11 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.indexer;
import java.io.File;
-import java.io.IOException;
import java.util.HashMap;
import org.eclipse.cdt.core.CCorePlugin;
@@ -29,6 +29,7 @@ import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.internal.core.pdom.IndexerInputAdapter;
+import org.eclipse.cdt.internal.core.resources.PathCanonicalizationStrategy;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -99,16 +100,11 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter {
if (result == null) {
result = doResolveASTPath(includePath);
if (result.getFullPath() == null) {
- try {
- File location= new File(includePath);
- String canonicalPath= location.getCanonicalPath();
- if (!includePath.equals(canonicalPath)) {
- result= IndexLocationFactory.getExternalIFL(canonicalPath);
- fIflCache.put(canonicalPath, result);
- }
- }
- catch (IOException e) {
- // just use the original
+ File location= new File(includePath);
+ String canonicalPath= PathCanonicalizationStrategy.getCanonicalPath(location);
+ if (!includePath.equals(canonicalPath)) {
+ result= IndexLocationFactory.getExternalIFL(canonicalPath);
+ fIflCache.put(canonicalPath, result);
}
}
fIflCache.put(includePath, result);
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/LocationAdapter.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/LocationAdapter.java
index 17f88396154..a2fb63a2a2f 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/LocationAdapter.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/LocationAdapter.java
@@ -7,11 +7,10 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.resources;
-import java.io.File;
-import java.io.IOException;
import java.net.URI;
import org.eclipse.core.filesystem.URIUtil;
@@ -47,13 +46,7 @@ abstract class LocationAdapter<T> {
@Override
public String getCanonicalPath(IPath location) {
- final File file= location.toFile();
- try {
- return file.getCanonicalPath();
- } catch (IOException e) {
- // use non-canonical version
- return file.getAbsolutePath();
- }
+ return PathCanonicalizationStrategy.getCanonicalPath(location.toFile());
}
@Override
@@ -67,7 +60,7 @@ abstract class LocationAdapter<T> {
public String extractName(URI location) {
String path= location.getPath();
int idx= path.lastIndexOf('/');
- return path.substring(idx+1);
+ return path.substring(idx + 1);
}
@Override
@@ -77,16 +70,11 @@ abstract class LocationAdapter<T> {
@Override
public String getCanonicalPath(URI location) {
- if (!"file".equals(location.getScheme())) //$NON-NLS-1$
+ IPath path = URIUtil.toPath(location);
+ if (path == null) {
return null;
-
- String path= location.getPath();
- try {
- return new File(path).getCanonicalPath();
- } catch (IOException e) {
- // use non-canonical version
- return path;
}
+ return PathCanonicalizationStrategy.getCanonicalPath(path.toFile());
}
@Override
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/PathCanonicalizationStrategy.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/PathCanonicalizationStrategy.java
new file mode 100644
index 00000000000..edca0f6de96
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/PathCanonicalizationStrategy.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Google, Inc and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.resources;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.internal.core.pdom.PDOMManager;
+
+public abstract class PathCanonicalizationStrategy {
+
+ public static String getCanonicalPath(File file) {
+ PathCanonicalizationStrategy strategy =
+ ((PDOMManager) CCorePlugin.getIndexManager()).getPathCanonicalizationStrategy();
+ return strategy.getCanonicalPathInternal(file);
+ }
+
+ public static PathCanonicalizationStrategy getStrategy(boolean canonicalize) {
+ if (canonicalize) {
+ return new PathCanonicalizationStrategy() {
+ @Override
+ protected String getCanonicalPathInternal(File file) {
+ try {
+ return file.getCanonicalPath();
+ } catch (IOException e) {
+ return file.getAbsolutePath();
+ }
+ }
+ };
+ } else {
+ return new PathCanonicalizationStrategy() {
+ @Override
+ protected String getCanonicalPathInternal(File file) {
+ return file.getAbsolutePath();
+ }
+ };
+ }
+ }
+
+ protected abstract String getCanonicalPathInternal(File file);
+}

Back to the top