Skip to content

Commit

Permalink
use of expected superclass/superinterface
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Feb 5, 2024
1 parent 7d64585 commit 0bd0219
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ protected void inferClass(MyClass myClass, IJvmDeclaredTypeAcceptor acceptor, bo
acceptor.accept(inferred,
(JvmGenericType it) -> {
jvmTypesBuilder.setDocumentation(it, jvmTypesBuilder.getDocumentation(myClass));
if (myClass.getExtends() != null) {
it.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(myClass.getExtends()));
}
jvmTypesBuilder.setSuperClass(it, myClass.getExtends());
for (var interf : myClass.getImplements()) {
it.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(interf));
jvmTypesBuilder.addSuperInterface(it, interf);
}
inferMembers(myClass, it, acceptor, prelinkingPhase);
});
Expand Down Expand Up @@ -113,7 +111,7 @@ protected void inferInterface(MyInterface myInterface, IJvmDeclaredTypeAcceptor
(JvmGenericType it) -> {
jvmTypesBuilder.setDocumentation(it, jvmTypesBuilder.getDocumentation(myInterface));
for (var interf : myInterface.getExtends()) {
it.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(interf));
jvmTypesBuilder.addSuperInterface(it, interf);
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eclipse.xtext.common.types.JvmTypeReference;
import org.eclipse.xtext.common.types.JvmVoid;
import org.eclipse.xtext.common.types.JvmWildcardTypeReference;
import org.eclipse.xtext.common.types.util.JvmTypeReferenceUtil;
import org.eclipse.xtext.util.JavaVersion;
import org.eclipse.xtext.validation.AbstractDeclarativeValidator;
import org.eclipse.xtext.validation.Check;
Expand Down Expand Up @@ -218,22 +219,18 @@ protected void checkSuperTypes(EObject sourceType, JvmGenericType type) {
if (associated == null)
continue; // synthetic superclass (e.g., Object)
var eContainingFeature = associated.eContainingFeature();
// there's no direct way to tell whether the supertype is meant
// to be an extended class or an implemented interface, so we
// check whether the original source element's containing feature
// is single or multiple, assuming that the source element allows
// for a single extended class
if (eContainingFeature.isMany()) { // assume to be expected as an interface
int featureIndex = INSIGNIFICANT_INDEX;
if (eContainingFeature.isMany()) {
featureIndex = ++expectedInterfaceIndex;
}
if (JvmTypeReferenceUtil.isExpectedAsInterface(extendedType)) {
expectedInterfaceIndex++;
if (!isInterface(extendedType.getType()) && !isAnnotation(extendedType.getType())) {
error("Implemented interface must be an interface",
sourceType,
eContainingFeature, expectedInterfaceIndex, INTERFACE_EXPECTED);
eContainingFeature, featureIndex, INTERFACE_EXPECTED);
}
checkWildcardSupertype(sourceType, notNull(type.getSimpleName()),
extendedType,
eContainingFeature, expectedInterfaceIndex);
} else { // assume to be expected as a class
} else if (JvmTypeReferenceUtil.isExpectedAsClass(extendedType)) {
if (!(extendedType.getType() instanceof JvmGenericType)
|| ((JvmGenericType) extendedType.getType()).isInterface()) {
error("Superclass must be a class",
Expand All @@ -245,11 +242,11 @@ protected void checkSuperTypes(EObject sourceType, JvmGenericType type) {
sourceType,
eContainingFeature, OVERRIDDEN_FINAL);
}
checkWildcardSupertype(sourceType, notNull(type.getSimpleName()),
extendedType,
eContainingFeature, INSIGNIFICANT_INDEX);
}
}
checkWildcardSupertype(sourceType, notNull(type.getSimpleName()),
extendedType,
eContainingFeature, featureIndex);
}
}
}
Expand Down

0 comments on commit 0bd0219

Please sign in to comment.