Skip to content

Commit

Permalink
PTBKey is not a ReferenceBinding
Browse files Browse the repository at this point in the history
* Introduces interface TypeBindingWrapper.
* Removes little code from PTBKey that is irrelevant for the wrapper

relates to eclipse-jdt#3412
  • Loading branch information
EcljpseB0T authored and jukzi committed Dec 18, 2024
1 parent ba2adeb commit c3fb568
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
*
* null is NOT a valid value for a non-public field... it just means the field is not initialized.
*/
abstract public class TypeBinding extends Binding {
abstract public class TypeBinding extends Binding implements TypeBindingWrapper {

public int id = TypeIds.NoId;
public long tagBits = 0; // See values in the interface TagBits below
Expand Down Expand Up @@ -1684,6 +1684,7 @@ public char[] signature() {

public abstract char[] sourceName();

@Override
public void swapUnresolved(UnresolvedReferenceBinding unresolvedType,
ReferenceBinding resolvedType, LookupEnvironment environment) {
// subclasses must override if they wrap another type binding
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.eclipse.jdt.internal.compiler.lookup;

interface TypeBindingWrapper {
void swapUnresolved(UnresolvedReferenceBinding unresolvedType, ReferenceBinding resolvedType, LookupEnvironment env);
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class TypeSystem {

public final class HashedParameterizedTypes {

private final class PTBKey extends ReferenceBinding { // extends ReferenceBinding so it can be used as wrapper
private final class PTBKey implements TypeBindingWrapper {
protected ReferenceBinding type; // must ensure the type is resolved
public TypeBinding[] arguments;
private ReferenceBinding enclosingType;
Expand All @@ -87,8 +87,6 @@ public PTBKey(ReferenceBinding type, TypeBinding[] arguments, ReferenceBinding e
TypeBinding argument = arguments[i];
if (argument instanceof UnresolvedReferenceBinding)
((UnresolvedReferenceBinding) argument).addWrapper(this, environment);
if (argument.hasNullTypeAnnotations())
this.tagBits |= TagBits.HasNullTypeAnnotation;
if (argument.getClass() == TypeVariableBinding.class) {
final int idx = i;
TypeVariableBinding typeVariableBinding = (TypeVariableBinding) argument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class UnresolvedReferenceBinding extends ReferenceBinding {

ReferenceBinding resolvedType;
TypeBinding[] wrappers;
TypeBindingWrapper[] wrappers;
UnresolvedReferenceBinding prototype;
ReferenceBinding requestingType;

Expand Down Expand Up @@ -53,18 +53,18 @@ public TypeBinding clone(TypeBinding outerType) {
return copy;
}

void addWrapper(TypeBinding wrapper, LookupEnvironment environment) {
void addWrapper(TypeBindingWrapper wrapper, LookupEnvironment environment) {
if (this.resolvedType != null) {
// the type reference B<B<T>.M> means a signature of <T:Ljava/lang/Object;>LB<LB<TT;>.M;>;
// when the ParameterizedType for Unresolved B is created with args B<T>.M, the Unresolved B is resolved before the wrapper is added
wrapper.swapUnresolved(this, this.resolvedType, environment);
return;
}
if (this.wrappers == null) {
this.wrappers = new TypeBinding[] {wrapper};
this.wrappers = new TypeBindingWrapper[] {wrapper};
} else {
int length = this.wrappers.length;
System.arraycopy(this.wrappers, 0, this.wrappers = new TypeBinding[length + 1], 0, length);
System.arraycopy(this.wrappers, 0, this.wrappers = new TypeBindingWrapper[length + 1], 0, length);
this.wrappers[length] = wrapper;
}
}
Expand Down Expand Up @@ -148,7 +148,7 @@ void setResolvedType(ReferenceBinding targetType, LookupEnvironment environment)
// must ensure to update any other type bindings that can contain the resolved type
// otherwise we could create 2 : 1 for this unresolved type & 1 for the resolved type
if (this.wrappers != null)
for (TypeBinding wrapper : this.wrappers)
for (TypeBindingWrapper wrapper : this.wrappers)
wrapper.swapUnresolved(this, targetType, environment);
}

Expand All @@ -161,7 +161,7 @@ public void swapUnresolved(UnresolvedReferenceBinding unresolvedType, ReferenceB

environment.updateCaches(this, annotatedType);
if (this.wrappers != null)
for (TypeBinding wrapper : this.wrappers)
for (TypeBindingWrapper wrapper : this.wrappers)
wrapper.swapUnresolved(this, annotatedType, environment);
}

Expand Down

0 comments on commit c3fb568

Please sign in to comment.