### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: model/org/eclipse/jdt/internal/core/SearchableEnvironment.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java,v
retrieving revision 1.74
diff -u -r1.74 SearchableEnvironment.java
--- model/org/eclipse/jdt/internal/core/SearchableEnvironment.java 13 Oct 2008 20:06:01 -0000 1.74
+++ model/org/eclipse/jdt/internal/core/SearchableEnvironment.java 12 Dec 2008 14:27:09 -0000
@@ -24,6 +24,7 @@
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
import org.eclipse.jdt.internal.core.search.BasicSearchEngine;
import org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor;
+import org.eclipse.jdt.internal.core.util.Util;
/**
* This class provides a SearchableBuilderEnvironment
for code assist which
@@ -35,6 +36,7 @@
public NameLookup nameLookup;
protected ICompilationUnit unitToSkip;
protected org.eclipse.jdt.core.ICompilationUnit[] workingCopies;
+ protected WorkingCopyOwner owner;
protected JavaProject project;
protected IJavaSearchScope searchScope;
@@ -58,6 +60,7 @@
*/
public SearchableEnvironment(JavaProject project, WorkingCopyOwner owner) throws JavaModelException {
this(project, owner == null ? null : JavaModelManager.getJavaModelManager().getWorkingCopies(owner, true/*add primary WCs*/));
+ this.owner = owner;
}
private static int convertSearchFilterToModelFilter(int searchFilter) {
@@ -85,6 +88,13 @@
protected NameEnvironmentAnswer find(String typeName, String packageName) {
if (packageName == null)
packageName = IPackageFragment.DEFAULT_PACKAGE_NAME;
+ if (this.owner != null) {
+ String source = this.owner.findSource(typeName, packageName);
+ if (source != null) {
+ ICompilationUnit cu = new BasicCompilationUnit(source.toCharArray(), CharOperation.splitOn('.', packageName.toCharArray()), typeName + Util.defaultJavaExtension());
+ return new NameEnvironmentAnswer(cu, null);
+ }
+ }
NameLookup.Answer answer =
this.nameLookup.findType(
typeName,
@@ -98,7 +108,7 @@
try {
return new NameEnvironmentAnswer((IBinaryType) ((BinaryType) answer.type).getElementInfo(), answer.restriction);
} catch (JavaModelException npe) {
- return null;
+ // fall back to using owner
}
} else { //SourceType
try {
@@ -123,7 +133,7 @@
}
return new NameEnvironmentAnswer(sourceTypes, answer.restriction);
} catch (JavaModelException npe) {
- return null;
+ // fall back to using owner
}
}
}
@@ -501,7 +511,9 @@
pkgName[i] = new String(parentPackageName[i]);
pkgName[length] = new String(subPackageName);
}
- return this.nameLookup.isPackage(pkgName);
+ return
+ (this.owner != null && this.owner.isPackage(pkgName))
+ || this.nameLookup.isPackage(pkgName);
}
/**
Index: model/org/eclipse/jdt/core/WorkingCopyOwner.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/WorkingCopyOwner.java,v
retrieving revision 1.26
diff -u -r1.26 WorkingCopyOwner.java
--- model/org/eclipse/jdt/core/WorkingCopyOwner.java 27 May 2008 23:40:20 -0000 1.26
+++ model/org/eclipse/jdt/core/WorkingCopyOwner.java 12 Dec 2008 14:27:09 -0000
@@ -89,6 +89,80 @@
public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) {
return null;
}
+
+ /**
+ * Returns the source of the compilation unit that defines the given type in
+ * the given package, or null
if the type is unknown to this
+ * owner.
+ *
This method is called before the normal lookup (i.e. before looking + * at the project's classpath and before looking at the working copies of this + * owner.)
+ *This allows to provide types that are not normally available, or to hide + * types that would normally be available by returning an empty source for + * the given type and package.
+ *Example of use: + *
+ * WorkingCopyOwner owner = new WorkingCopyOwner() { + * public String findSource(String typeName, String packageName) { + * if ("to.be".equals(packageName) && "Generated".equals(typeName)) { + * return + * "package to.be;\n" + + * "public class Generated {\n" + + * "}"; + * } + * return super.findSource(typeName, packageName); + * } + * public boolean isPackage(String[] pkg) { + * switch (pkg.length) { + * case 1: + * return "to".equals(pkg[0]); + * case 2: + * return "to".equals(pkg[0]) && "be".equals(pkg[1]); + * } + * return false; + * } + * }; + * // Working copy on X.java with the following contents: + * // public class X extends to.be.Generated { + * // } + * ICompilationUnit workingCopy = ... + * ASTParser parser = ASTParser.newParser(AST.JLS3); + * parser.setSource(workingCopy); + * parser.setResolveBindings(true); + * parser.setWorkingCopyOwner(owner); + * CompilationUnit cu = (CompilationUnit) parser.createAST(null); + * assert cu.getProblems().length == 0; + *+ * + * + * @param typeName the simple name of the type to lookup + * @param packageName the dot-separated name of the package of type + * @return the source of the compilation unit that defines the given type in + * the given package, or
null
if the type is unknown
+ * @see #isPackage(String[])
+ * @since 3.5
+ */
+ public String findSource(String typeName, String packageName) {
+ return null;
+ }
+
+ /**
+ * Returns whether the given package segments represent a package.
+ * This method is called before the normal lookup (i.e. before looking + * at the project's classpath and before looking at the working copies of this + * owner.)
+ *This allows to provide packages that are not normally available.
+ *If false
is returned, then normal lookup is used on
+ * this package.