Skip to content

Commit

Permalink
Code review driven clean up of sealed types implementation (#3138)
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-sankaran authored Oct 22, 2024
1 parent e000c5a commit f80c910
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,23 +328,26 @@ public int bodyEnd(){
if (this.bodyEnd == 0) return this.typeDeclaration.declarationSourceEnd;
return this.bodyEnd;
}
public boolean bodyStartsAtHeaderEnd(){
if (this.typeDeclaration.superInterfaces == null){
if (this.typeDeclaration.superclass == null){
if(this.typeDeclaration.typeParameters == null) {
return this.typeDeclaration.bodyStart == this.typeDeclaration.sourceEnd+1;

public boolean bodyStartsAtHeaderEnd() {
if (this.typeDeclaration.permittedTypes == null) {
if (this.typeDeclaration.superInterfaces == null) {
if (this.typeDeclaration.superclass == null) {
if (this.typeDeclaration.typeParameters == null) {
return this.typeDeclaration.bodyStart == this.typeDeclaration.sourceEnd + 1;
} else {
return this.typeDeclaration.bodyStart == this.typeDeclaration.typeParameters[this.typeDeclaration.typeParameters.length - 1].sourceEnd + 1;
}
} else {
return this.typeDeclaration.bodyStart == this.typeDeclaration.typeParameters[this.typeDeclaration.typeParameters.length-1].sourceEnd+1;
return this.typeDeclaration.bodyStart == this.typeDeclaration.superclass.sourceEnd + 1;
}
} else {
return this.typeDeclaration.bodyStart == this.typeDeclaration.superclass.sourceEnd+1;
return this.typeDeclaration.bodyStart
== this.typeDeclaration.superInterfaces[this.typeDeclaration.superInterfaces.length - 1].sourceEnd + 1;
}
} else {
if (this.typeDeclaration.permittedTypes != null)
return this.typeDeclaration.bodyStart
== this.typeDeclaration.permittedTypes[this.typeDeclaration.permittedTypes.length-1].sourceEnd+1;
return this.typeDeclaration.bodyStart
== this.typeDeclaration.superInterfaces[this.typeDeclaration.superInterfaces.length-1].sourceEnd+1;
== this.typeDeclaration.permittedTypes[this.typeDeclaration.permittedTypes.length - 1].sourceEnd + 1;
}
}
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public interface IJavaSearchConstants {
int METHOD_REFERENCE_EXPRESSION = 0x10000000;

/**
* Return only type references used as a permit type (Java 15)
* Return only type references used as a permit type (Java 17)
* <p>
* When this flag is set, only {@link TypeReferenceMatch} matches will be
* returned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ public static SearchPattern createPattern(IJavaElement element, int limitTo) {
* <td>Return only method reference expressions (e.g. <code>A :: foo</code>).
* <tr>
* <td>{@link IJavaSearchConstants#PERMITTYPE_TYPE_REFERENCE PERMITTYPE_TYPE_REFERENCE}
* <td>Return only type references used as a permit type.
* <td>Return only type references used as a permitted type.
* </table>
* </li>
* </ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3199,20 +3199,9 @@ protected void reportMatching(TypeDeclaration type, IJavaElement parent, int acc
}
}
TypeReference[] permittedTypes = type.permittedTypes;
if (permittedTypes != null) {
for (int i = 0, l = permittedTypes.length; i < l; i++) {
reportMatchingSuperOrPermit(permittedTypes[i], enclosingElement, type.binding, nodeSet, matchedClassContainer);
TypeReference typeReference = type.permittedTypes[i];
Annotation[][] annotations = typeReference != null ? typeReference.annotations : null;
if (annotations != null) {
for (Annotation[] annotation : annotations) {
if (annotation == null) continue;
reportMatching(annotation, enclosingElement, null, type.binding, nodeSet, matchedClassContainer, enclosesElement);
}
}
}
for (int i = 0, length = permittedTypes == null ? 0 : permittedTypes.length; i < length; i++) {
reportMatchingSuperOrPermit(permittedTypes[i], enclosingElement, type.binding, nodeSet, matchedClassContainer);
}

}

// filter out element not in hierarchy scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,22 +949,17 @@ protected void consumeWildcardBoundsSuper() {
}
}

private void updatePatternLocaterMatch() {
@Override
protected void consumePermittedTypes() {
super.consumePermittedTypes();
if ((this.patternFineGrain & IJavaSearchConstants.PERMITTYPE_TYPE_REFERENCE) != 0) {
TypeDeclaration td = (TypeDeclaration) this.astStack[this.astPtr];
TypeReference[] permittedTypes = td.permittedTypes;
for (TypeReference pt : permittedTypes) {
for (TypeReference pt : td.permittedTypes) {
this.patternLocator.match(pt, this.nodeSet);
}
}
}

@Override
protected void consumePermittedTypes() {
super.consumePermittedTypes();
updatePatternLocaterMatch();
}

@Override
protected TypeReference augmentTypeWithAdditionalDimensions(TypeReference typeRef, int additionalDimensions, Annotation [][] additionalAnnotations, boolean isVarargs) {
TypeReference result = super.augmentTypeWithAdditionalDimensions(typeRef, additionalDimensions, additionalAnnotations, isVarargs);
Expand Down

0 comments on commit f80c910

Please sign in to comment.