### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/BindingResolver.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/BindingResolver.java,v retrieving revision 1.47 diff -u -r1.47 BindingResolver.java --- dom/org/eclipse/jdt/core/dom/BindingResolver.java 16 Mar 2007 18:28:58 -0000 1.47 +++ dom/org/eclipse/jdt/core/dom/BindingResolver.java 24 Apr 2007 14:55:40 -0000 @@ -11,6 +11,7 @@ package org.eclipse.jdt.core.dom; +import org.eclipse.jdt.core.WorkingCopyOwner; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair; @@ -219,9 +220,10 @@ *
* * @param recoveredTypeBinding the recovered type binding + * @param dimensions the dimensions to add the to given type binding dimensions * @return the new type binding */ - ITypeBinding getTypeBinding(RecoveredTypeBinding recoveredTypeBinding) { + ITypeBinding getTypeBinding(RecoveredTypeBinding recoveredTypeBinding, int dimensions) { return null; } @@ -240,6 +242,18 @@ } /** + * Return the working copy owner for the receiver. + *
+ * The default implementation of this method returns null
.
+ * Subclasses may reimplement.
+ *
* The default implementation of this method returns null
Index: dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java,v
retrieving revision 1.3
diff -u -r1.3 RecoveredTypeBinding.java
--- dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java 26 Mar 2007 17:30:23 -0000 1.3
+++ dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java 24 Apr 2007 14:55:42 -0000
@@ -14,8 +14,11 @@
import java.util.List;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
+import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
import org.eclipse.jdt.internal.compiler.util.Util;
+import org.eclipse.jdt.internal.core.CompilationUnit;
/**
* This class represents the recovered binding for a type
@@ -55,17 +58,17 @@
}
}
- RecoveredTypeBinding(BindingResolver resolver, RecoveredTypeBinding typeBinding) {
+ RecoveredTypeBinding(BindingResolver resolver, RecoveredTypeBinding typeBinding, int dimensions) {
this.innerTypeBinding = typeBinding;
- this.dimensions = typeBinding.getDimensions() - 1;
+ this.dimensions = typeBinding.getDimensions() + dimensions;
this.resolver = resolver;
}
/* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ITypeBinding#createArrayType(int)
*/
- public ITypeBinding createArrayType(int dimension) {
- throw new IllegalArgumentException("Cannot be called on a recovered type binding"); //$NON-NLS-1$
+ public ITypeBinding createArrayType(int dims) {
+ return this.resolver.getTypeBinding(this, dims);
}
/* (non-Javadoc)
@@ -87,7 +90,7 @@
*/
public ITypeBinding getComponentType() {
if (this.dimensions == 0) return null;
- return this.resolver.getTypeBinding(this);
+ return this.resolver.getTypeBinding(this, -1);
}
/* (non-Javadoc)
@@ -143,9 +146,13 @@
* @see org.eclipse.jdt.core.dom.ITypeBinding#getElementType()
*/
public ITypeBinding getElementType() {
- if (this.referenceBinding != null && this.referenceBinding.isArrayType()) {
- ArrayBinding arrayBinding = (ArrayBinding) this.referenceBinding;
- return new RecoveredTypeBinding(this.resolver, arrayBinding.leafComponentType);
+ if (this.referenceBinding != null) {
+ if (this.referenceBinding.isArrayType()) {
+ ArrayBinding arrayBinding = (ArrayBinding) this.referenceBinding;
+ return new RecoveredTypeBinding(this.resolver, arrayBinding.leafComponentType);
+ } else {
+ return new RecoveredTypeBinding(this.resolver, this.referenceBinding);
+ }
}
if (this.innerTypeBinding != null) {
return this.innerTypeBinding.getElementType();
@@ -216,6 +223,10 @@
* @see org.eclipse.jdt.core.dom.ITypeBinding#getPackage()
*/
public IPackageBinding getPackage() {
+ CompilationUnitScope scope = this.resolver.scope();
+ if (scope != null) {
+ return this.resolver.getPackageBinding(scope.getCurrentPackage());
+ }
return null;
}
@@ -230,7 +241,7 @@
* @see org.eclipse.jdt.core.dom.ITypeBinding#getSuperclass()
*/
public ITypeBinding getSuperclass() {
- return null;
+ return this.resolver.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
}
/* (non-Javadoc)
@@ -240,7 +251,9 @@
if (this.referenceBinding != null) {
return this.typeArguments = TypeBinding.NO_TYPE_BINDINGS;
}
- if (this.typeArguments != null) return typeArguments;
+ if (this.typeArguments != null) {
+ return typeArguments;
+ }
if (this.innerTypeBinding != null) {
return this.innerTypeBinding.getTypeArguments();
@@ -315,8 +328,11 @@
/* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ITypeBinding#isAssignmentCompatible(org.eclipse.jdt.core.dom.ITypeBinding)
*/
- public boolean isAssignmentCompatible(ITypeBinding variableType) {
- return false;
+ public boolean isAssignmentCompatible(ITypeBinding typeBinding) {
+ if ("java.lang.Object".equals(typeBinding.getQualifiedName())) { //$NON-NLS-1$
+ return true;
+ }
+ return this.isEqualTo(typeBinding);
}
/* (non-Javadoc)
@@ -330,7 +346,10 @@
* @see org.eclipse.jdt.core.dom.ITypeBinding#isCastCompatible(org.eclipse.jdt.core.dom.ITypeBinding)
*/
public boolean isCastCompatible(ITypeBinding typeBinding) {
- return false;
+ if ("java.lang.Object".equals(typeBinding.getQualifiedName())) { //$NON-NLS-1$
+ return true;
+ }
+ return this.isEqualTo(typeBinding);
}
/* (non-Javadoc)
@@ -427,7 +446,10 @@
* @see org.eclipse.jdt.core.dom.ITypeBinding#isSubTypeCompatible(org.eclipse.jdt.core.dom.ITypeBinding)
*/
public boolean isSubTypeCompatible(ITypeBinding typeBinding) {
- return false;
+ if ("java.lang.Object".equals(typeBinding.getQualifiedName())) { //$NON-NLS-1$
+ return true;
+ }
+ return this.isEqualTo(typeBinding);
}
/* (non-Javadoc)
@@ -469,6 +491,11 @@
* @see org.eclipse.jdt.core.dom.IBinding#getJavaElement()
*/
public IJavaElement getJavaElement() {
+ try {
+ return new CompilationUnit(null, this.getInternalName(), this.resolver.getWorkingCopyOwner()).getWorkingCopy(this.resolver.getWorkingCopyOwner(), null);
+ } catch (JavaModelException e) {
+ //ignore
+ }
return null;
}
@@ -476,7 +503,36 @@
* @see org.eclipse.jdt.core.dom.IBinding#getKey()
*/
public String getKey() {
- return null;
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Recovered#"); //$NON-NLS-1$
+ if (this.innerTypeBinding != null) {
+ buffer.append("innerTypeBinding") //$NON-NLS-1$
+ .append(this.innerTypeBinding.getKey());
+ } else if (this.currentType != null) {
+ buffer.append("currentType") //$NON-NLS-1$
+ .append(this.currentType.toString());
+ } else if (this.referenceBinding != null) {
+ buffer.append("referenceBinding") //$NON-NLS-1$
+ .append(this.referenceBinding.computeUniqueKey());
+ } else if (variableDeclaration != null) {
+ buffer
+ .append("variableDeclaration") //$NON-NLS-1$
+ .append(this.variableDeclaration.getClass())
+ .append(this.variableDeclaration.getName().getIdentifier())
+ .append(this.variableDeclaration.getExtraDimensions());
+ }
+ buffer.append(this.getDimensions());
+ if (this.typeArguments != null) {
+ buffer.append('<');
+ for (int i = 0, max = this.typeArguments.length; i < max; i++) {
+ if (i != 0) {
+ buffer.append(',');
+ }
+ buffer.append(this.typeArguments[i].getKey());
+ }
+ buffer.append('>');
+ }
+ return String.valueOf(buffer);
}
/* (non-Javadoc)
@@ -497,7 +553,8 @@
* @see org.eclipse.jdt.core.dom.IBinding#isEqualTo(org.eclipse.jdt.core.dom.IBinding)
*/
public boolean isEqualTo(IBinding other) {
- return false;
+ if (!other.isRecovered() || other.getKind() != IBinding.TYPE) return false;
+ return this.getKey().equals(other.getKey());
}
/* (non-Javadoc)
Index: dom/org/eclipse/jdt/core/dom/ITypeBinding.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ITypeBinding.java,v
retrieving revision 1.66
diff -u -r1.66 ITypeBinding.java
--- dom/org/eclipse/jdt/core/dom/ITypeBinding.java 15 Mar 2007 16:06:40 -0000 1.66
+++ dom/org/eclipse/jdt/core/dom/ITypeBinding.java 24 Apr 2007 14:55:42 -0000
@@ -54,13 +54,11 @@
*
If the receiver is an array binding, then the resulting dimension is the given dimension * plus the dimension of the receiver. Otherwise the resulting dimension is the given * dimension.
- *It cannot be called on a recovered binding.
* * @param dimension the given dimension * @return an array type binding * @throws IllegalArgumentException:getDeclaredModifiers
method
* should be used if the original modifiers are needed.
- * Returns 0 if this type does not represent a class, interface, enum, or annotation
- * type.
+ * Returns 0 if this type does not represent a class, an interface, an enum, an annotation
+ * type or a recovered type.
*
* @return the compiled modifiers for this type binding or 0
- * if this type does not represent a class, interface, enum, or annotation
- * type
+ * if this type does not represent a class, an interface, an enum, an annotation
+ * type or a recovered type.
* @see #getDeclaredModifiers()
*/
public int getModifiers();
@@ -365,11 +363,14 @@
/**
* Returns the binding for the package in which this type is declared.
+ *
+ * The package of a recovered type reference binding is the package of the + * enclosing type.
* * @return the binding for the package in which this class, interface, * enum, or annotation type is declared, ornull
if this type
* binding represents a primitive type, an array type, the null type,
- * a type variable, a wildcard type, a capture binding, or a recovered binding.
+ * a type variable, a wildcard type, a capture binding.
*/
public IPackageBinding getPackage();
@@ -454,8 +455,8 @@
*
* If this type binding represents an interface, an array type, a
* primitive type, the null type, a type variable, an enum type,
- * an annotation type, a wildcard type, a capture binding, or a
- * recovered binding then null
is returned.
+ * an annotation type, a wildcard type, or a capture binding then
+ * null
is returned.
*
If the receiver or the argument is a recovered type, the answer is always false.
+ *If the receiver or the argument is a recovered type, the answer is always false,
+ * unless the two types are identical or the argument is java.lang.Object
.
true
if an expression of this type can be assigned to a
@@ -641,7 +643,8 @@
* A.isCastCompatible(B)
*
*
- * If the receiver or the argument is a recovered type, the answer is always false.
+ *If the receiver or the argument is a recovered type, the answer is always false,
+ * unless the two types are identical or the argument is java.lang.Object
.
true
if this type is cast compatible with the
@@ -651,9 +654,9 @@
public boolean isCastCompatible(ITypeBinding type);
/**
- * Returns whether this type binding represents a class type.
+ * Returns whether this type binding represents a class type or a recovered binding.
*
- * @return true
if this object represents a class,
+ * @return true
if this object represents a class or a recovered binding,
* and false
otherwise
*/
public boolean isClass();
@@ -844,7 +847,8 @@
* as specified in section 4.10 of The Java Language
* Specification, Third Edition (JLS3).
*
- * If the receiver or the argument is a recovered type, the answer is always false.
+ *If the receiver or the argument is a recovered type, the answer is always false,
+ * unless the two types are identical or the argument is java.lang.Object
.
true
if this type is subtype compatible with the
Index: dom/org/eclipse/jdt/core/dom/RecoveredVariableBinding.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/RecoveredVariableBinding.java,v
retrieving revision 1.2
diff -u -r1.2 RecoveredVariableBinding.java
--- dom/org/eclipse/jdt/core/dom/RecoveredVariableBinding.java 21 Mar 2007 18:20:26 -0000 1.2
+++ dom/org/eclipse/jdt/core/dom/RecoveredVariableBinding.java 24 Apr 2007 14:55:42 -0000
@@ -29,10 +29,24 @@
}
public ITypeBinding getDeclaringClass() {
+ ASTNode parent = this.variableDeclaration.getParent();
+ while (parent != null && parent.getNodeType() != ASTNode.TYPE_DECLARATION) {
+ parent = parent.getParent();
+ }
+ if (parent != null) {
+ return ((TypeDeclaration) parent).resolveBinding();
+ }
return null;
}
public IMethodBinding getDeclaringMethod() {
+ ASTNode parent = this.variableDeclaration.getParent();
+ while (parent != null && parent.getNodeType() != ASTNode.METHOD_DECLARATION) {
+ parent = parent.getParent();
+ }
+ if (parent != null) {
+ return ((MethodDeclaration) parent).resolveBinding();
+ }
return null;
}
@@ -73,7 +87,16 @@
}
public String getKey() {
- return null;
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Recovered#"); //$NON-NLS-1$
+ if (variableDeclaration != null) {
+ buffer
+ .append("variableDeclaration") //$NON-NLS-1$
+ .append(this.variableDeclaration.getClass())
+ .append(this.variableDeclaration.getName().getIdentifier())
+ .append(this.variableDeclaration.getExtraDimensions());
+ }
+ return String.valueOf(buffer);
}
public int getKind() {
@@ -89,6 +112,9 @@
}
public boolean isEqualTo(IBinding binding) {
+ if (binding.isRecovered() && binding.getKind() == IBinding.VARIABLE) {
+ return this.getKey().equals(binding.getKey());
+ }
return false;
}
Index: dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java,v
retrieving revision 1.154
diff -u -r1.154 DefaultBindingResolver.java
--- dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java 15 Mar 2007 16:06:40 -0000 1.154
+++ dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java 24 Apr 2007 14:55:41 -0000
@@ -358,17 +358,11 @@
/*
* Method declared on BindingResolver.
*/
- synchronized ITypeBinding getTypeBinding(RecoveredTypeBinding recoveredTypeBinding) {
+ synchronized ITypeBinding getTypeBinding(RecoveredTypeBinding recoveredTypeBinding, int dimensions) {
if (recoveredTypeBinding== null) {
return null;
}
- ITypeBinding binding = (ITypeBinding) this.bindingTables.compilerBindingsToASTBindings.get(recoveredTypeBinding);
- if (binding != null) {
- return binding;
- }
- binding = new RecoveredTypeBinding(this, recoveredTypeBinding);
- this.bindingTables.compilerBindingsToASTBindings.put(recoveredTypeBinding, binding);
- return binding;
+ return new RecoveredTypeBinding(this, recoveredTypeBinding, dimensions);
}
synchronized IVariableBinding getVariableBinding(org.eclipse.jdt.internal.compiler.lookup.VariableBinding variableBinding, VariableDeclaration variableDeclaration) {
@@ -417,6 +411,10 @@
return this.getVariableBinding(variableBinding);
}
+ public WorkingCopyOwner getWorkingCopyOwner() {
+ return this.workingCopyOwner;
+ }
+
/*
* Method declared on BindingResolver.
*/
@@ -1734,8 +1732,7 @@
* @param dimensions the given dimensions
* @return an array type binding with the given type binding and the given
* dimensions
- * @throws IllegalArgumentException if the type binding represents the void
type binding or if the
- * given type binding is a recovered binding
+ * @throws IllegalArgumentException if the type binding represents the void
type binding
*/
ITypeBinding resolveArrayType(ITypeBinding typeBinding, int dimensions) {
if (typeBinding.isRecovered()) throw new IllegalArgumentException("Cannot be called on a recovered type binding"); //$NON-NLS-1$
Index: dom/org/eclipse/jdt/core/dom/IBinding.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/IBinding.java,v
retrieving revision 1.32
diff -u -r1.32 IBinding.java
--- dom/org/eclipse/jdt/core/dom/IBinding.java 21 Mar 2007 17:51:08 -0000 1.32
+++ dom/org/eclipse/jdt/core/dom/IBinding.java 24 Apr 2007 14:55:41 -0000
@@ -274,7 +274,7 @@
*
* Note that the key for annotation bindings and member value pair bindings is
* not yet implemented. This returns null
for these 2 kinds of bindings.
- * null
is also returned for recovered bindings
+ * Recovered bindings have a unique key.
*