Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PTBKey not extend ReferenceBinding #3452

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.impl.Constant;

public final class ArrayBinding extends TypeBinding {
public final class ArrayBinding extends TypeBinding implements HotSwappable {
// creation and initialization of the length field
// the declaringClass of this field is intentionally set to null so it can be distinguished.
public static final FieldBinding ArrayLength = new FieldBinding(TypeConstants.LENGTH, TypeBinding.INT, ClassFileConstants.AccPublic | ClassFileConstants.AccFinal, null, Constant.NotAConstant);
Expand Down
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 HotSwappable {
void swapUnresolved(UnresolvedReferenceBinding unresolvedType, ReferenceBinding resolvedType, LookupEnvironment env);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
/**
* A parameterized type encapsulates a type with type arguments,
*/
public class ParameterizedTypeBinding extends ReferenceBinding implements Substitution {
public class ParameterizedTypeBinding extends ReferenceBinding implements Substitution, HotSwappable {

protected ReferenceBinding type; // must ensure the type is resolved
public TypeBinding[] arguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1685,11 +1685,6 @@ public char[] signature() {

public abstract char[] sourceName();

public void swapUnresolved(UnresolvedReferenceBinding unresolvedType,
ReferenceBinding resolvedType, LookupEnvironment environment) {
// subclasses must override if they wrap another type binding
}

TypeBinding [] typeArguments () {
return null;
}
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 HotSwappable {
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) {
jukzi marked this conversation as resolved.
Show resolved Hide resolved
final int idx = i;
TypeVariableBinding typeVariableBinding = (TypeVariableBinding) argument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

import org.eclipse.jdt.core.compiler.CharOperation;

public class UnresolvedReferenceBinding extends ReferenceBinding {
public class UnresolvedReferenceBinding extends ReferenceBinding implements HotSwappable {

ReferenceBinding resolvedType;
TypeBinding[] wrappers;
HotSwappable[] 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(HotSwappable 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 HotSwappable[] {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 HotSwappable[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 (HotSwappable 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 (HotSwappable wrapper : this.wrappers)
wrapper.swapUnresolved(this, annotatedType, environment);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* abstract parameterized types, e.g. List<String> is not compatible with List<Object>,
* but compatible with List<?>.
*/
public class WildcardBinding extends ReferenceBinding {
public class WildcardBinding extends ReferenceBinding implements HotSwappable{

public ReferenceBinding genericType;
public int rank;
Expand Down
Loading