aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-11-12 01:59:29 (EST)
committerzzhongwei2012-11-12 01:59:29 (EST)
commit2c3d97b2a391762e7ed41d994eced15a8af0206f (patch)
tree2f0d0f07d948cf48c14ce69a4c1262afda4a1d45
parent418e04003d25d7007b255fef26386186a435b36c (diff)
downloadorg.eclipse.pdt-2c3d97b2a391762e7ed41d994eced15a8af0206f.zip
org.eclipse.pdt-2c3d97b2a391762e7ed41d994eced15a8af0206f.tar.gz
org.eclipse.pdt-2c3d97b2a391762e7ed41d994eced15a8af0206f.tar.bz2
394069: Have two projects whose files have identical names - Content
Assist suggests the wrong file https://bugs.eclipse.org/bugs/show_bug.cgi?id=394069
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/filenetwork/FileNetworkUtility.java16
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/util/PHPSearchEngine.java34
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/hyperlink/IncludeHyperlinkDetector.java172
3 files changed, 206 insertions, 16 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/filenetwork/FileNetworkUtility.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/filenetwork/FileNetworkUtility.java
index 9ffa1a8..a36c984 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/filenetwork/FileNetworkUtility.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/filenetwork/FileNetworkUtility.java
@@ -29,7 +29,7 @@ import org.eclipse.php.internal.core.filenetwork.ReferenceTree.Node;
import org.eclipse.php.internal.core.language.LanguageModelInitializer;
import org.eclipse.php.internal.core.model.IncludeField;
import org.eclipse.php.internal.core.model.PhpModelAccess;
-import org.eclipse.php.internal.core.util.PHPSearchEngine;
+import org.eclipse.php.internal.core.util.*;
import org.eclipse.php.internal.core.util.PHPSearchEngine.IncludedFileResult;
import org.eclipse.php.internal.core.util.PHPSearchEngine.IncludedPharFileResult;
import org.eclipse.php.internal.core.util.PHPSearchEngine.ResourceResult;
@@ -158,8 +158,7 @@ public class FileNetworkUtility {
}
IModelElement parentElement = (file instanceof ExternalSourceModule) ? ((ExternalSourceModule) file)
- .getProjectFragment()
- : file.getScriptProject();
+ .getProjectFragment() : file.getScriptProject();
IField[] includes = includesCache.get(parentElement);
if (includes == null) {
@@ -171,8 +170,8 @@ public class FileNetworkUtility {
for (IField include : includes) {
String filePath = ((IncludeField) include).getFilePath();
String lastSegment = filePath;
- int i = Math.max(filePath.lastIndexOf('/'), filePath
- .lastIndexOf('\\'));
+ int i = Math.max(filePath.lastIndexOf('/'),
+ filePath.lastIndexOf('\\'));
if (i > 0) {
lastSegment = lastSegment.substring(i + 1);
}
@@ -299,13 +298,18 @@ public class FileNetworkUtility {
}
public static ISourceModule findSourceModule(ISourceModule from, String path) {
+ return findSourceModule(from, path, null);
+ }
+
+ public static ISourceModule findSourceModule(ISourceModule from,
+ String path, Set<String> exclusiveFiles) {
ISourceModule sourceModule = null;
IProject currentProject = from.getScriptProject().getProject();
String currentScriptDir = from.getParent().getPath().toString();
String currentWorkingDir = currentScriptDir; // currentProject.getFullPath().toString();
Result<?, ?> result = PHPSearchEngine.find(path, currentWorkingDir,
- currentScriptDir, currentProject);
+ currentScriptDir, currentProject, exclusiveFiles);
if (result instanceof ResourceResult) {
// workspace file
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/util/PHPSearchEngine.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/util/PHPSearchEngine.java
index bafd048..52358c6 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/util/PHPSearchEngine.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/util/PHPSearchEngine.java
@@ -81,8 +81,22 @@ public class PHPSearchEngine implements IIncludepathListener {
currentScriptDir, currentProject);
}
+ public static Result<?, ?> find(String path, String currentWorkingDir,
+ String currentScriptDir, IProject currentProject,
+ Set<String> exclusiveFiles) {
+ return getInstance().internalFind(path, currentWorkingDir,
+ currentScriptDir, currentProject, exclusiveFiles);
+ }
+
private Result<?, ?> internalFind(String path, String currentWorkingDir,
String currentScriptDir, IProject currentProject) {
+ return internalFind(path, currentWorkingDir, currentScriptDir,
+ currentProject, null);
+ }
+
+ private Result<?, ?> internalFind(String path, String currentWorkingDir,
+ String currentScriptDir, IProject currentProject,
+ Set<String> exclusiveFiles) {
if (path == null || currentWorkingDir == null
|| currentScriptDir == null || currentProject == null) {
throw new NullPointerException("Parameters can't be null");
@@ -99,6 +113,7 @@ public class PHPSearchEngine implements IIncludepathListener {
// ./ or ../
return searchExternalOrWorkspaceFile(currentWorkingDir, path);
}
+ List<Result> list = new ArrayList<PHPSearchEngine.Result>();
// look into include path:
IncludePath[] includePaths = buildIncludePath(currentProject);
@@ -113,11 +128,22 @@ public class PHPSearchEngine implements IIncludepathListener {
} else {
IContainer container = (IContainer) includePath.getEntry();
IResource resource = container.findMember(path);
- if (resource instanceof IFile) {
- return new ResourceResult((IFile) resource);
+ if ((resource instanceof IFile)) {
+ Result result = new ResourceResult((IFile) resource);
+ if (exclusiveFiles == null
+ || !exclusiveFiles.contains(resource.getLocation()
+ .toOSString())) {
+ return result;
+ } else {
+ list.add(result);
+ }
+
}
}
}
+ if (!list.isEmpty()) {
+ return list.get(0);
+ }
// look at current script directory:
return searchExternalOrWorkspaceFile(currentScriptDir, path);
@@ -279,7 +305,9 @@ public class PHPSearchEngine implements IIncludepathListener {
private static Result<?, ?> searchExternalOrWorkspaceFile(File file) {
if (file.exists()) {
- IFile res = ResourcesPlugin.getWorkspace().getRoot()
+ IFile res = ResourcesPlugin
+ .getWorkspace()
+ .getRoot()
.getFileForLocation(
Path.fromOSString(file.getAbsolutePath()));
if (res != null) {
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/hyperlink/IncludeHyperlinkDetector.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/hyperlink/IncludeHyperlinkDetector.java
index b91a4d8..8efd93f 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/hyperlink/IncludeHyperlinkDetector.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/hyperlink/IncludeHyperlinkDetector.java
@@ -11,15 +11,30 @@
*******************************************************************************/
package org.eclipse.php.internal.ui.editor.hyperlink;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileInfo;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.filesystem.URIUtil;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.ast.ASTVisitor;
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.ast.expressions.Expression;
-import org.eclipse.dltk.core.IModelElement;
-import org.eclipse.dltk.core.ISourceModule;
-import org.eclipse.dltk.core.ModelException;
-import org.eclipse.dltk.core.SourceParserUtil;
+import org.eclipse.dltk.compiler.problem.IProblem;
+import org.eclipse.dltk.core.*;
+import org.eclipse.dltk.internal.ui.editor.DocumentAdapter;
import org.eclipse.dltk.internal.ui.editor.ModelElementHyperlink;
+import org.eclipse.dltk.launching.ScriptRuntime;
+import org.eclipse.dltk.ui.DLTKUIPlugin;
import org.eclipse.dltk.ui.actions.OpenAction;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
@@ -33,6 +48,8 @@ import org.eclipse.php.internal.core.compiler.ast.parser.ASTUtils;
import org.eclipse.php.internal.core.filenetwork.FileNetworkUtility;
import org.eclipse.php.internal.ui.editor.PHPStructuredEditor;
import org.eclipse.php.internal.ui.util.EditorUtility;
+import org.eclipse.ui.IURIEditorInput;
+import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.wst.jsdt.web.ui.internal.Logger;
public class IncludeHyperlinkDetector extends AbstractHyperlinkDetector {
@@ -106,12 +123,23 @@ public class IncludeHyperlinkDetector extends AbstractHyperlinkDetector {
if (!inclusive(region, selectRegion[0]))
return null;
+ Set<String> set = new HashSet<String>();
+ set.add(sourceModule.getResource().getLocation().toOSString());
ISourceModule includedSourceModule = FileNetworkUtility
- .findSourceModule(sourceModule, file[0]);
+ .findSourceModule(sourceModule, file[0], set);
+ if (includedSourceModule == null) {
+ includedSourceModule = createFakeSourceModule(file[0]);
+ }
if (includedSourceModule != null) {
return new IHyperlink[] { new ModelElementHyperlink(
selectRegion[0], includedSourceModule, new OpenAction(
editor)) };
+ } else {
+ includedSourceModule = createFakeSourceModule(file[0]);
+
+ return new IHyperlink[] { new ModelElementHyperlink(
+ selectRegion[0], includedSourceModule, new OpenAction(
+ editor)) };
}
}
return null;
@@ -123,7 +151,137 @@ public class IncludeHyperlinkDetector extends AbstractHyperlinkDetector {
private boolean inclusive(IRegion region1, Region region2) {
return (region1.getOffset() >= region2.getOffset())
&& (region1.getOffset() + region1.getLength() <= region2
- .getOffset()
- + region2.getLength());
+ .getOffset() + region2.getLength());
+ }
+
+ private ISourceModule createFakeSourceModule(String filePath) {
+ // filePath = normalize(filePath);
+ try {
+ final IFileStore fileStore = EFS.getLocalFileSystem().getStore(
+ new Path(filePath));
+ IFileInfo fetchInfo = fileStore.fetchInfo();
+ if (!fetchInfo.isDirectory() && fetchInfo.exists()) {
+ IURIEditorInput editorInput = new FileStoreEditorInput(
+ fileStore);
+ final URI uri = editorInput.getURI();
+ // final IFileStore fileStore = EFS.getStore(uri);
+ final IPath path = URIUtil.toPath(uri);
+ final String fileStoreName = fileStore.getName();
+ if (fileStoreName == null || path == null)
+ return null;
+
+ WorkingCopyOwner woc = new WorkingCopyOwner() {
+ /*
+ * @see
+ * org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org
+ * .eclipse .jdt.core.ICompilationUnit)
+ *
+ * @since 3.2
+ */
+ public IBuffer createBuffer(ISourceModule workingCopy) {
+ return new DocumentAdapter(workingCopy, fileStore, path);
+ }
+ };
+
+ IBuildpathEntry[] cpEntries = null;
+ IScriptProject jp = findScriptProject(path);
+ if (jp != null)
+ cpEntries = jp.getResolvedBuildpath(true);
+
+ if (cpEntries == null || cpEntries.length == 0)
+ cpEntries = new IBuildpathEntry[] { ScriptRuntime
+ .getDefaultInterpreterContainerEntry() };
+
+ final ISourceModule cu = woc.newWorkingCopy(fileStoreName,
+ cpEntries, new IProblemRequestor() {
+
+ public void acceptProblem(IProblem problem) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void beginReporting() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void endReporting() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean isActive() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ }, new NullProgressMonitor());
+
+ // if (!isModifiable(editorInput))
+ ScriptModelUtil.reconcile(cu);
+
+ return cu;
+
+ }
+ } catch (CoreException ex) {
+ return null;
+ }
+ return null;
}
+
+ private String normalize(String filePath) {
+ // TODO Auto-generated method stub
+ IPath path = new Path(filePath);
+ List<String> segmentList = new ArrayList<String>();
+ for (int i = path.segments().length - 1; i >= 0; i--) {
+ String segment = path.segments()[i];
+ int j = 0;
+ while (segment.equals("..") && i - j > 0) {
+ // i--;
+ j++;
+ segment = path.segments()[i - j];
+ }
+ if (i - 2 * j >= 0) {
+ segment = path.segments()[i - 2 * j];
+ segmentList.add(segment);
+ }
+ }
+ IPath newPath = new Path(path.getDevice(), "");
+ for (int i = segmentList.size() - 1; i >= 0; i--) {
+ newPath.append(segmentList.get(i));
+ }
+ return null;
+ }
+
+ /**
+ * Fuzzy search for script project in the workspace that matches the given
+ * path.
+ *
+ * @param path
+ * the path to match
+ * @return the matching script project or <code>null</code>
+ *
+ */
+ private IScriptProject findScriptProject(IPath path) {
+ if (path == null)
+ return null;
+
+ String[] pathSegments = path.segments();
+ IScriptModel model = DLTKCore.create(DLTKUIPlugin.getWorkspace()
+ .getRoot());
+ IScriptProject[] projects;
+ try {
+ projects = model.getScriptProjects();
+ } catch (ModelException e) {
+ return null; // ignore - use default RE
+ }
+ for (int i = 0; i < projects.length; i++) {
+ IPath projectPath = projects[i].getProject().getFullPath();
+ String projectSegment = projectPath.segments()[0];
+ for (int j = 0; j < pathSegments.length; j++)
+ if (projectSegment.equals(pathSegments[j]))
+ return projects[i];
+ }
+ return null;
+ }
+
}