Skip to content

Commit

Permalink
removed check for cycle in the hierarchy
Browse files Browse the repository at this point in the history
implied by JvmGenericTypeValidator
  • Loading branch information
LorenzoBettini committed May 22, 2024
1 parent 0c4fff5 commit a44b5b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class EmfParsleyDslValidatorTest extends EmfParsleyDslAbstractTest {
'''
module my.first extends my.first.FirstEmfParsleyGuiceModule {
}
'''.parse.assertHierarchyCycle("FirstEmfParsleyGuiceModule")
'''.parse.assertHierarchyCycle(ModelPackage.eINSTANCE.module, "FirstEmfParsleyGuiceModule")
}

@Test
Expand All @@ -218,9 +218,9 @@ class EmfParsleyDslValidatorTest extends EmfParsleyDslAbstractTest {
}
'''.parse(m2.eResource.resourceSet)

m1.assertHierarchyCycle("SecondEmfParsleyGuiceModule")
m2.assertHierarchyCycle("ThirdEmfParsleyGuiceModule")
m3.assertHierarchyCycle("FirstEmfParsleyGuiceModule")
m1.assertHierarchyCycle(ModelPackage.eINSTANCE.module, "FirstEmfParsleyGuiceModule")
m2.assertHierarchyCycle(ModelPackage.eINSTANCE.module, "SecondEmfParsleyGuiceModule")
m3.assertHierarchyCycle(ModelPackage.eINSTANCE.module, "ThirdEmfParsleyGuiceModule")
}

@Test
Expand All @@ -243,9 +243,9 @@ class EmfParsleyDslValidatorTest extends EmfParsleyDslAbstractTest {
}
'''.parse(m2.eResource.resourceSet)

m1.assertHierarchyCycle("SecondLabelProvider")
m2.assertHierarchyCycle("ThirdLabelProvider")
m3.assertHierarchyCycle("FirstLabelProvider")
m1.assertHierarchyCycle(ModelPackage.eINSTANCE.labelProvider, "FirstLabelProvider")
m2.assertHierarchyCycle(ModelPackage.eINSTANCE.labelProvider, "SecondLabelProvider")
m3.assertHierarchyCycle(ModelPackage.eINSTANCE.labelProvider, "ThirdLabelProvider")
}

@Test
Expand Down Expand Up @@ -801,10 +801,10 @@ class EmfParsleyDslValidatorTest extends EmfParsleyDslAbstractTest {
)
}

def private assertHierarchyCycle(EObject e, String className) {
def private assertHierarchyCycle(EObject e, EClass type, String className) {
e.assertError(
ModelPackage.eINSTANCE.extendsClause,
CYCLIC_INHERITANCE,
type,
IssueCodes.CYCLIC_INHERITANCE,
'''The inheritance hierarchy of «className» contains cycles'''
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package org.eclipse.emf.parsley.dsl.validation
import com.google.common.collect.ListMultimap
import com.google.inject.Inject
import java.util.List
import java.util.Set
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EStructuralFeature
Expand All @@ -23,7 +22,6 @@ import org.eclipse.emf.parsley.dsl.model.ModelPackage
import org.eclipse.emf.parsley.dsl.model.Module
import org.eclipse.emf.parsley.dsl.model.PartSpecification
import org.eclipse.emf.parsley.dsl.model.ViewSpecification
import org.eclipse.emf.parsley.dsl.model.WithExtendsClause
import org.eclipse.emf.parsley.dsl.util.EmfParsleyDslGuiceModuleHelper
import org.eclipse.xtext.common.types.JvmGenericType
import org.eclipse.xtext.common.types.JvmTypeReference
Expand All @@ -34,6 +32,7 @@ import org.eclipse.xtext.validation.CheckType
import org.eclipse.xtext.validation.ComposedChecks
import org.eclipse.xtext.xbase.typesystem.util.Multimaps2
import org.eclipse.xtext.xbase.validation.JvmGenericTypeValidator
import org.eclipse.emf.parsley.dsl.model.WithExtendsClause

//import org.eclipse.xtext.validation.Check

Expand All @@ -46,11 +45,9 @@ import org.eclipse.xtext.xbase.validation.JvmGenericTypeValidator
class EmfParsleyDslValidator extends AbstractEmfParsleyDslValidator {

public static val TYPE_MISMATCH = "org.eclipse.emf.parsley.dsl.TypeMismatch";

public static val CYCLIC_INHERITANCE = "org.eclipse.emf.parsley.dsl.CyclicInheritance";

public static val FINAL_FIELD_NOT_INITIALIZED = "org.eclipse.emf.parsley.dsl.FinalFieldNotInitialized";

public static val TOO_LITTLE_TYPE_INFORMATION = "org.eclipse.emf.parsley.dsl.TooLittleTypeInformation";

public static val DUPLICATE_ELEMENT = "org.eclipse.emf.parsley.dsl.DuplicateElement";
Expand Down Expand Up @@ -111,9 +108,7 @@ class EmfParsleyDslValidator extends AbstractEmfParsleyDslValidator {

@Check
def void checkExtendsClause(WithExtendsClause withExtendsClause) {
if (withExtendsClause.getExtendsClause() !== null && !withExtendsClause.hasCycleInHierarchy()) {
// it makes no sense to check for type conformance if there's a cycle in the
// hierarchy: there will always be a type mismatch in that case
if (withExtendsClause.getExtendsClause() !== null) {
checkType(withExtendsClause.extendsClause,
withExtendsClause.extendsClause.superType, withExtendsClause.expectedSupertype,
ModelPackage.Literals.EXTENDS_CLAUSE__SUPER_TYPE)
Expand Down Expand Up @@ -218,35 +213,6 @@ class EmfParsleyDslValidator extends AbstractEmfParsleyDslValidator {
}
}

def protected boolean hasCycleInHierarchy(WithExtendsClause withExtendsClause) {
val superType = withExtendsClause.extendsClause.superType?.type

if (superType instanceof JvmGenericType) {
if (superType.hasCycleInHierarchy(newHashSet())) {
error("The inheritance hierarchy of " + superType.simpleName + " contains cycles",
withExtendsClause.extendsClause,
ModelPackage.Literals.EXTENDS_CLAUSE__SUPER_TYPE,
CYCLIC_INHERITANCE);
return true
}
}

return false
}

def protected boolean hasCycleInHierarchy(JvmGenericType type, Set<JvmGenericType> processedSuperTypes) {
if (processedSuperTypes.contains(type)) {
return true;
}
processedSuperTypes.add(type);
for (genericType : type.superTypes.map[getType].filter(JvmGenericType)) {
if (hasCycleInHierarchy(genericType, processedSuperTypes))
return true;
}
processedSuperTypes.remove(type);
return false;
}

def private <K, T> duplicatesMultimap() {
return Multimaps2.<K, T> newLinkedHashListMultimap();
}
Expand Down

0 comments on commit a44b5b1

Please sign in to comment.