Skip to content

Commit

Permalink
checkWildcardSupertype for superinterfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Dec 18, 2023
1 parent 54c936b commit d3c3d15
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ private IssueCodes() {
public static final String MISSING_STATIC_MODIFIER = ISSUE_CODE_PREFIX + "missing_static_modifier";
public static final String MODIFIER_DOES_NOT_MATCH_TYPENAME = ISSUE_CODE_PREFIX + "missing_abstract_modifier";

public static final String WILDCARD_IN_SUPERTYPE = ISSUE_CODE_PREFIX + "wildcard_in_supertype";

public static final String INVALID_EXTENSION_TYPE = ISSUE_CODE_PREFIX + "invalid_extension_type";

public static final String INVALID_OPERATOR_SIGNATURE = ISSUE_CODE_PREFIX + "invalid_operator_signature";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,18 +670,10 @@ public void checkSuperTypes(XtendClass xtendClass) {
}
}

@Check
public void checkSuperTypes(XtendInterface xtendInterface) {
for (int i = 0; i < xtendInterface.getExtends().size(); ++i) {
JvmTypeReference extendedType = xtendInterface.getExtends().get(i);
checkWildcardSupertype(xtendInterface, extendedType, XTEND_INTERFACE__EXTENDS, i);
}
}

protected boolean isAnnotation(JvmType jvmType) {
return jvmType instanceof JvmAnnotationType;
}

@Check
public void checkSuperTypes(AnonymousClass anonymousClass) {
JvmGenericType inferredType = associations.getInferredType(anonymousClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ public class IssueCodes extends org.eclipse.xtext.validation.IssueCodes {
* @since 2.34
*/
public static final String INTERFACE_EXPECTED = ISSUE_CODE_PREFIX + "interface_expected";
/**
* @since 2.34
*/
public static final String WILDCARD_IN_SUPERTYPE = ISSUE_CODE_PREFIX + "wildcard_in_supertype";

private IssueCodes() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ protected void checkSuperTypes(JvmGenericType type) {
var superTypes = type.getSuperTypes();
for (int i = 0; i < superTypes.size(); ++i) {
JvmTypeReference extendedType = superTypes.get(i);
var associated = associations.getPrimarySourceElement(extendedType);
var eContainingFeature = associated.eContainingFeature();
if (!isInterface(extendedType.getType()) && !isAnnotation(extendedType.getType())) {
var associated = associations.getPrimarySourceElement(extendedType);
var eContainingFeature = associated.eContainingFeature();
error("Extended interface must be an interface",
primarySourceElement,
eContainingFeature, i, INTERFACE_EXPECTED);
}
// checkWildcardSupertype(xtendInterface, extendedType, XTEND_INTERFACE__EXTENDS, i);
checkWildcardSupertype(primarySourceElement, notNull(type.getSimpleName()),
extendedType,
eContainingFeature, i);
}
}
}
Expand Down Expand Up @@ -117,6 +119,22 @@ protected boolean isAnnotation(JvmType jvmType) {
return jvmType instanceof JvmAnnotationType;
}

protected void checkWildcardSupertype(EObject sourceElement,
String name,
JvmTypeReference superTypeReference,
EStructuralFeature feature, int index) {
if(isInvalidWildcard(superTypeReference))
error("The type "
+ name
+ " cannot extend or implement "
+ superTypeReference.getIdentifier()
+ ". A supertype may not specify any wildcard",
sourceElement,
feature,
index,
WILDCARD_IN_SUPERTYPE);
}

protected boolean isInvalidWildcard(JvmTypeReference typeRef) {
if (typeRef instanceof JvmWildcardTypeReference)
return true;
Expand Down

0 comments on commit d3c3d15

Please sign in to comment.