Skip to content

Commit

Permalink
Make PTBKey not extend ReferenceBinding
Browse files Browse the repository at this point in the history
PTBKey needs a custom hashCode/equals contract, while ReferenceBinding
should not need any.

* PTBKey not extends ReferenceBinding anymore
* Introduces interface Resolvable.
* Removes little code from PTBKey that is irrelevant for the wrapper

relates to eclipse-jdt#3412
  • Loading branch information
jukzi committed Jan 17, 2025
1 parent 9f348f1 commit cf810f5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2025 SSI and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SSI - initial API and implementation
*******************************************************************************/

package org.eclipse.jdt.internal.compiler.lookup;

interface Resolvable {
void swapUnresolved(UnresolvedReferenceBinding unresolvedType, ReferenceBinding resolvedType, LookupEnvironment env);
}
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 Resolvable {

public int id = TypeIds.NoId;
public long tagBits = 0; // See values in the interface TagBits below
Expand Down Expand Up @@ -1685,6 +1685,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
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 Resolvable {
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;
Resolvable[] 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(Resolvable 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 Resolvable[] {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 Resolvable[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 (Resolvable 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 (Resolvable wrapper : this.wrappers)
wrapper.swapUnresolved(this, annotatedType, environment);
}

Expand Down

0 comments on commit cf810f5

Please sign in to comment.