Skip to content

Commit

Permalink
Simplification / bugfix(?)
Browse files Browse the repository at this point in the history
+ nobody ever expected the null returned from TypeBinding.actualType()
  • Loading branch information
stephan-herrmann committed Jul 14, 2024
1 parent d2e82ac commit 2de63d4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public boolean canBeSeenBy(PackageBinding invocationPackage) {
public boolean canBeSeenBy(ReferenceBinding receiverType, ReferenceBinding invocationType) {
if (isPublic()) return true;

if (isStatic() && (receiverType.isRawType() || receiverType.isParameterizedType()))
if (isStatic())
receiverType = receiverType.actualType(); // outer generics are irrelevant

if (TypeBinding.equalsEquals(invocationType, this) && TypeBinding.equalsEquals(invocationType, receiverType)) return true;
Expand Down Expand Up @@ -1063,6 +1063,11 @@ public final ReferenceBinding enclosingTypeAt(int relativeDepth) {
return current;
}

@Override
public ReferenceBinding actualType() {
return this;
}

public int enumConstantCount() {
int count = 0;
FieldBinding[] fields = fields();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5709,9 +5709,7 @@ public TypeBinding getMatchingUninitializedType(TypeBinding targetClass, boolean
SourceTypeBinding enclosingType = currentEnclosing.referenceContext.binding;
TypeBinding currentTarget = targetClass;
while (currentTarget != null) {
if (currentTarget instanceof ParameterizedTypeBinding)
currentTarget = currentTarget.actualType();
if (TypeBinding.equalsEquals(enclosingType, currentTarget)) {
if (TypeBinding.equalsEquals(enclosingType, currentTarget.actualType())) {
if (currentEnclosing.insideEarlyConstructionContext)
return enclosingType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ else if (this.isInterface())
continue;
if (this.isClass()) {
ReferenceBinding permSuperType = permittedType.superclass();
permSuperType = getActualType(permSuperType);
permSuperType = permSuperType.actualType();
if (!TypeBinding.equalsEquals(this, permSuperType)) {
this.scope.problemReporter().sealedNotDirectSuperClass(permittedType, permittedTypeRef, this);
continue;
Expand All @@ -1237,7 +1237,7 @@ else if (this.isInterface())
boolean foundSuperInterface = false;
if (permSuperInterfaces != null) {
for (ReferenceBinding psi : permSuperInterfaces) {
psi = getActualType(psi);
psi = psi.actualType();
if (TypeBinding.equalsEquals(this, psi)) {
foundSuperInterface = true;
break;
Expand Down Expand Up @@ -1298,9 +1298,6 @@ private void reportSealedSuperTypeDoesNotPermitProblem(TypeReference superTypeRe
}
}

private ReferenceBinding getActualType(ReferenceBinding ref) {
return ref.isParameterizedType() || ref.isRawType() ? ref.actualType(): ref;
}
public List<SourceTypeBinding> collectAllTypeBindings(TypeDeclaration typeDecl, CompilationUnitScope unitScope) {
class TypeBindingsCollector extends ASTVisitor {
List<SourceTypeBinding> types = new ArrayList<>();
Expand Down Expand Up @@ -1341,10 +1338,10 @@ private boolean checkPermitsAndAdd(ReferenceBinding superType) {
|| !superType.isSealed())
return true;
if (superType.isSealed()) {
superType = getActualType(superType);
superType = superType.actualType();
ReferenceBinding[] superPermittedTypes = superType.permittedTypes();
for (ReferenceBinding permittedType : superPermittedTypes) {
permittedType = getActualType(permittedType);
permittedType = permittedType.actualType();
if (permittedType.isValidBinding() && TypeBinding.equalsEquals(this, permittedType))
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ public static final TypeBinding wellKnownBaseType(int id) {
}

public ReferenceBinding actualType() {
return null; // overridden in ParameterizedTypeBinding & WildcardBinding
assert false : "Invocation on non-ReferenceBinding not expected"; //$NON-NLS-1$
return null; // overridden in ReferenceBinding, ParameterizedTypeBinding & WildcardBinding
}

TypeBinding [] additionalBounds() {
Expand Down

0 comments on commit 2de63d4

Please sign in to comment.