Skip to content

Commit

Permalink
Simplify error messages related to sealed types. (eclipse-jdt#3160)
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-sankaran authored Oct 25, 2024
1 parent 185d23b commit 25d4b54
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ void connectPermittedTypes() {

for (int j = 0; j < i; j++) {
if (TypeBinding.equalsEquals(permittedTypeBindings[j], permittedType)) {
problemReporter().duplicatePermittedType(sourceType, permittedTypeRef, permittedType);
problemReporter().duplicatePermittedType(permittedTypeRef, permittedType);
continue nextPermittedType;
}
}
Expand All @@ -1336,7 +1336,7 @@ void connectPermittedTypes() {
sourceType.setPermittedTypes(Binding.NO_PERMITTED_TYPES);
if (sourceType.isSealed()) {
if (!sourceType.isLocalType() && !sourceType.isRecord() && !sourceType.isEnum()) // error flagged alread
problemReporter().sealedTypeMissingPermits(sourceType, this.referenceContext);
problemReporter().missingPermitsClause(sourceType, this.referenceContext);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12198,15 +12198,11 @@ public void missingSealedModifier(SourceTypeBinding type, ASTNode node) {
node.sourceEnd);
}

public void duplicatePermittedType(SourceTypeBinding type, TypeReference reference, ReferenceBinding superType) {
public void duplicatePermittedType(TypeReference reference, ReferenceBinding superType) {
this.handle(
IProblem.SealedDuplicateTypeInPermits,
new String[] {
new String(superType.readableName()),
new String(type.sourceName())},
new String[] {
new String(superType.shortReadableName()),
new String(type.sourceName())},
new String[] { new String(superType.readableName()) },
new String[] { new String(superType.shortReadableName()) },
reference.sourceStart,
reference.sourceEnd);
}
Expand Down Expand Up @@ -12245,7 +12241,7 @@ public void permittedTypeOutsideOfPackage(ReferenceBinding permType, ReferenceBi
node.sourceEnd);
}

public void sealedTypeMissingPermits(SourceTypeBinding type, ASTNode node) {
public void missingPermitsClause(SourceTypeBinding type, ASTNode node) {
String name = new String(type.sourceName());
this.handle(IProblem.SealedSealedTypeMissingPermits, new String[] { name }, new String[] { name }, node.sourceStart,
node.sourceEnd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,19 +1132,19 @@
1820 = {0} is a value-based type which is a discouraged argument for the synchronized statement

# Sealed types - Java 17
1850 = The class {1} with a sealed direct superclass or a sealed direct superinterface {0} should be declared either final, sealed, or non-sealed
1851 = A class {0} declared as non-sealed should have either a sealed direct superclass or a sealed direct superinterface
1852 = The type {0} extending a sealed class {1} should be a permitted subtype of {1}
1853 = The type {0} that {2} a sealed interface {1} should be a permitted subtype of {1}
1850 = The class {1} with a sealed direct supertype {0} should be declared either final, sealed, or non-sealed
1851 = The non-sealed class {0} must have a sealed direct supertype
1852 = The class {0} cannot extend the class {1} as it is not a permitted subtype of {1}
1853 = The type {0} that {2} the sealed interface {1} should be a permitted subtype of {1}
1854 = A type declaration {0} that has a permits clause should have a sealed modifier
1855 = The interface {1} with a sealed direct superinterface {0} should be declared either sealed or non-sealed
1856 = Duplicate type {0} for the type {1} in the permits clause
1856 = Duplicate permitted type {0}
1857 = Permitted class {0} does not declare {1} as direct super class
1858 = Permitted type {0} in a named module {1} should be declared in the same module {1} of declaring type {2}
1859 = Permitted type {0} in an unnamed module should be declared in the same package {1} of declaring type {2}
1860 = Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares {0} as its direct superclass or superinterface
1860 = Sealed type {0} lacks a permits clause and no type from the same compilation unit declares {0} as its direct supertype
###[obsolete] 1861 = An interface {0} is declared both sealed and non-sealed
1862 = An interface {0} declared as non-sealed should have a sealed direct superinterface
1862 = The non-sealed interface {0} must have a sealed direct superinterface
1863 = Permitted type {0} does not declare {1} as direct super interface
1864 = The local type {1} may not have a sealed supertype {0}
1865 = An anonymous class cannot subclass a sealed type {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ public void testBug564047_001(){
"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 2)\n" +
" public class X extends Y {\n" +
" ^\n" +
"The class X with a sealed direct superclass or a sealed direct superinterface Y should be declared either final, sealed, or non-sealed\n" +
"The class X with a sealed direct supertype Y should be declared either final, sealed, or non-sealed\n" +
"----------\n" +
"2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 2)\n" +
" public class X extends Y {\n" +
" ^\n" +
"The type X extending a sealed class Y should be a permitted subtype of Y\n" +
"The class X cannot extend the class Y as it is not a permitted subtype of Y\n" +
"----------\n" +
"2 problems (2 errors)\n",
true);
Expand Down
Loading

0 comments on commit 25d4b54

Please sign in to comment.