From d3c3d15d39185a13feb778b3c31ea65cf52e677d Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Mon, 18 Dec 2023 20:54:47 +0100 Subject: [PATCH] checkWildcardSupertype for superinterfaces --- .../xtend/core/validation/IssueCodes.java | 2 -- .../xtend/core/validation/XtendValidator.java | 10 +------- .../xtext/xbase/validation/IssueCodes.java | 4 ++++ .../validation/JvmGenericTypeValidator.java | 24 ++++++++++++++++--- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/org.eclipse.xtend.core/src/org/eclipse/xtend/core/validation/IssueCodes.java b/org.eclipse.xtend.core/src/org/eclipse/xtend/core/validation/IssueCodes.java index b40b2ce2d89..01e29834909 100644 --- a/org.eclipse.xtend.core/src/org/eclipse/xtend/core/validation/IssueCodes.java +++ b/org.eclipse.xtend.core/src/org/eclipse/xtend/core/validation/IssueCodes.java @@ -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"; diff --git a/org.eclipse.xtend.core/src/org/eclipse/xtend/core/validation/XtendValidator.java b/org.eclipse.xtend.core/src/org/eclipse/xtend/core/validation/XtendValidator.java index ec7e7a6bb2a..feb3b166645 100644 --- a/org.eclipse.xtend.core/src/org/eclipse/xtend/core/validation/XtendValidator.java +++ b/org.eclipse.xtend.core/src/org/eclipse/xtend/core/validation/XtendValidator.java @@ -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); diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/validation/IssueCodes.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/validation/IssueCodes.java index e99cc80bfd5..4edad5ab992 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/validation/IssueCodes.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/validation/IssueCodes.java @@ -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() { } diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/validation/JvmGenericTypeValidator.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/validation/JvmGenericTypeValidator.java index e4afe2ef7ac..3cb65337188 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/validation/JvmGenericTypeValidator.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/validation/JvmGenericTypeValidator.java @@ -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); } } } @@ -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;