Skip to content

Commit

Permalink
some refactoring in JvmGenericTypeValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Feb 5, 2024
1 parent 2f6192b commit 11c8515
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations;
import org.eclipse.xtext.xbase.jvmmodel.ILogicalContainerProvider;
import org.eclipse.xtext.xbase.jvmmodel.JvmTypeExtensions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.typesystem.override.ConflictingDefaultOperation;
import org.eclipse.xtext.xbase.typesystem.override.IOverrideCheckResult.OverrideCheckDetails;
import org.eclipse.xtext.xbase.typesystem.override.IResolvedConstructor;
Expand Down Expand Up @@ -127,32 +128,39 @@ protected void checkJvmGenericTypes(List<? extends EObject> contents) {

/**
* Whether the element is to be considered for validation from this
* validator. The default implementation checks whether there is a
* source element associated to the the passed {@link JvmIdentifiableElement} element, using {@link IJvmModelAssociations#getSourceElements(EObject)}.
* validator. The default implementation checks whether there is a source
* element associated to the the passed {@link JvmIdentifiableElement}
* element, using {@link IJvmModelAssociations#getSourceElements(EObject)}.
* This strategy should not be completely overridden, since some of the
* other methods assume that the checked Jvm model element is associated to
* a source.
*
* @param element
*/
protected boolean shouldBeValidated(JvmIdentifiableElement element) {
return !associations.getSourceElements(element).isEmpty();
}

/**
* The method assumes that the passed {@link JvmGenericType} has an associated source.
*/
protected void checkJvmGenericType(JvmGenericType type) {
var sourceType = getPrimarySourceElement(type);
handleExceptionDuringValidation(() -> checkDefaultSuperConstructor(sourceType, type));
handleExceptionDuringValidation(() -> checkSuperTypes(sourceType, type));
type.getDeclaredFields().forEach(field -> {
if (shouldBeValidated(field))
handleExceptionDuringValidation(() -> checkField(field));
});
IterableExtensions.toList(type.getDeclaredFields()).stream()
.filter(this::shouldBeValidated)
.forEach(field -> handleExceptionDuringValidation(() -> checkField(field)));
handleExceptionDuringValidation(() -> checkMemberNamesAreUnique(type));
handleExceptionDuringValidation(() -> checkDuplicateAndOverriddenFunctions(sourceType, type));
var members = type.getMembers();
handleExceptionDuringValidation(() -> checkJvmExecutables(members));
if (isAnonymous(type))
handleExceptionDuringValidation(() -> checkAnonymousClassStaticMembers(type));
members.forEach(member -> {
EcoreUtil2.eAllOfType(member, JvmGenericType.class).
forEach(nestedType ->
EcoreUtil2.eAllOfType(member, JvmGenericType.class).stream()
.filter(this::shouldBeValidated)
.forEach(nestedType ->
handleExceptionDuringValidation(() -> checkJvmGenericType(nestedType)));
});
}
Expand All @@ -170,8 +178,6 @@ protected void checkJvmExecutables(List<? extends JvmMember> contents) {
}

protected void checkSuperTypes(EObject sourceType, JvmGenericType type) {
if (sourceType == null)
return;
if (hasCycleInHierarchy(type, new HashSet<>())) {
error("The inheritance hierarchy of " + notNull(type.getSimpleName()) + " contains cycles",
sourceType,
Expand Down

0 comments on commit 11c8515

Please sign in to comment.