Search in sources :

Example 1 with MemberMatrix

use of org.eclipse.n4js.validation.validators.utils.MemberMatrix in project n4js by eclipse.

the class N4JSMemberRedefinitionValidator method constraints_41_AbstractClass.

/**
 * Constraints 41 (Abstract Class)
 */
private boolean constraints_41_AbstractClass(TClassifier classifier, MemberCube memberCube) {
    List<TMember> abstractMembers = null;
    if (!classifier.isAbstract() && classifier instanceof TClass) {
        for (Entry<NameStaticPair, MemberMatrix> entry : memberCube.entrySet()) {
            MemberMatrix mm = entry.getValue();
            MemberList<TMember> l = new MemberList<>();
            Iterators.addAll(l, mm.actuallyInheritedAndMixedMembers());
            for (SourceAwareIterator iter = mm.actuallyInheritedAndMixedMembers(); iter.hasNext(); ) {
                TMember m = iter.next();
                if (m.isAbstract()) {
                    if (abstractMembers == null) {
                        abstractMembers = new ArrayList<>();
                    }
                    abstractMembers.add(m);
                }
            }
        }
    }
    if (abstractMembers != null) {
        messageMissingImplementations(abstractMembers);
        return false;
    }
    return true;
}
Also used : NameStaticPair(org.eclipse.n4js.ts.types.util.NameStaticPair) MemberList(org.eclipse.n4js.ts.types.util.MemberList) SourceAwareIterator(org.eclipse.n4js.validation.validators.utils.MemberMatrix.SourceAwareIterator) MemberMatrix(org.eclipse.n4js.validation.validators.utils.MemberMatrix) TMember(org.eclipse.n4js.ts.types.TMember) TClass(org.eclipse.n4js.ts.types.TClass)

Example 2 with MemberMatrix

use of org.eclipse.n4js.validation.validators.utils.MemberMatrix in project n4js by eclipse.

the class N4JSReferenceQueryExecutor method getMemberMatrix.

private MemberMatrix getMemberMatrix(TMember member) {
    TClassifier tclassifier = (TClassifier) member.eContainer();
    MemberCollector memberCollector = containerTypesHelper.fromContext(tclassifier);
    MemberCube memberCube = new MemberCube(tclassifier, memberCollector);
    NameStaticPair nsp = NameStaticPair.of(member);
    Optional<Entry<NameStaticPair, MemberMatrix>> ret = memberCube.entrySet().stream().filter(entry -> entry.getKey().equals(nsp)).findFirst();
    if (ret.isPresent()) {
        Entry<NameStaticPair, MemberMatrix> mmEntry = ret.get();
        return mmEntry.getValue();
    }
    return null;
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) NameStaticPair(org.eclipse.n4js.ts.types.util.NameStaticPair) LabelledReferenceDescription(org.eclipse.n4js.ts.ui.search.LabelledReferenceDescription) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) URI(org.eclipse.emf.common.util.URI) Inject(com.google.inject.Inject) TMember(org.eclipse.n4js.ts.types.TMember) EObject(org.eclipse.emf.ecore.EObject) N4JSPackage(org.eclipse.n4js.n4JS.N4JSPackage) ArrayList(java.util.ArrayList) NameStaticPair(org.eclipse.n4js.ts.types.util.NameStaticPair) List(java.util.List) LiteralOrComputedPropertyName(org.eclipse.n4js.n4JS.LiteralOrComputedPropertyName) LabellingReferenceQueryExecutor(org.eclipse.n4js.ts.ui.search.LabellingReferenceQueryExecutor) ContainerTypesHelper(org.eclipse.n4js.utils.ContainerTypesHelper) TClassifier(org.eclipse.n4js.ts.types.TClassifier) Lists(com.google.common.collect.Lists) JSXElementName(org.eclipse.n4js.n4JS.JSXElementName) MemberMatrix(org.eclipse.n4js.validation.validators.utils.MemberMatrix) N4MemberDeclaration(org.eclipse.n4js.n4JS.N4MemberDeclaration) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) Entry(java.util.Map.Entry) Optional(java.util.Optional) MemberCube(org.eclipse.n4js.validation.validators.utils.MemberCube) MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector) Entry(java.util.Map.Entry) MemberCube(org.eclipse.n4js.validation.validators.utils.MemberCube) MemberMatrix(org.eclipse.n4js.validation.validators.utils.MemberMatrix) MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector)

Example 3 with MemberMatrix

use of org.eclipse.n4js.validation.validators.utils.MemberMatrix in project n4js by eclipse.

the class N4JSReferenceQueryExecutor method getInheritedAndImplementedMembers.

private List<TMember> getInheritedAndImplementedMembers(TMember tmember) {
    List<TMember> ret = new ArrayList<>();
    MemberMatrix mm = getMemberMatrix(tmember);
    if (mm != null) {
        for (TMember member : mm.inherited()) {
            ret.add(member);
        }
        for (TMember member : mm.implemented()) {
            ret.add(member);
        }
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) MemberMatrix(org.eclipse.n4js.validation.validators.utils.MemberMatrix) TMember(org.eclipse.n4js.ts.types.TMember)

Example 4 with MemberMatrix

use of org.eclipse.n4js.validation.validators.utils.MemberMatrix in project n4js by eclipse.

the class N4JSMemberRedefinitionValidator method checkMemberRedefinitions.

/**
 * Checks constraints defined in chapter 5.4. Redefinition of Members.
 */
@Check
public void checkMemberRedefinitions(N4ClassifierDefinition n4ClassifierDefinition) {
    if (!(n4ClassifierDefinition.getDefinedType() instanceof TClassifier)) {
        // wrongly parsed
        return;
    }
    TClassifier tClassifier = (TClassifier) n4ClassifierDefinition.getDefinedType();
    getContext().put(TClassifier.class, tClassifier);
    RuleEnvironment g = RuleEnvironmentExtensions.newRuleEnvironment(tClassifier);
    getContext().put(RuleEnvironment.class, g);
    // the context for type variables
    ParameterizedTypeRef classTypeRef = TypeUtils.createTypeRef(tClassifier);
    getContext().put(TYPE_VAR_CONTEXT, classTypeRef);
    MemberCube memberCube = createMemberValidationList();
    final boolean isClass = tClassifier instanceof TClass;
    final Map<ParameterizedTypeRef, MemberList<TMember>> nonAccessibleAbstractMembersBySuperTypeRef = new HashMap<>();
    for (Entry<NameStaticPair, MemberMatrix> entry : memberCube.entrySet()) {
        MemberMatrix mm = entry.getValue();
        // Set to collect all owned members that are lacking an override annotation.
        Collection<TMember> membersMissingOverrideAnnotation = new HashSet<>();
        if (isClass) {
            constraints_67_MemberOverride_checkEntry(mm, membersMissingOverrideAnnotation);
        }
        if (mm.hasImplemented()) {
            // first mix in
            if (holdConstraints_68_Consumption(mm)) {
                // then check if everything is implemented
                constraints_69_Implementation(mm, membersMissingOverrideAnnotation);
            }
        }
        constraints_60_InheritedConsumedCovariantSpecConstructor(tClassifier, mm);
        constraints_66_NonOverride(mm);
        constraints_42_45_46_AbstractMember(mm, nonAccessibleAbstractMembersBySuperTypeRef);
        unusedGenericTypeVariable(mm);
        checkUnpairedAccessorConsumption(mm, n4ClassifierDefinition);
        checkUnpairedAccessorFilling(mm, n4ClassifierDefinition);
        messageMissingOverrideAnnotation(mm, membersMissingOverrideAnnotation);
    }
    final boolean foundImpossibleExtendsImplements = !nonAccessibleAbstractMembersBySuperTypeRef.isEmpty();
    if (foundImpossibleExtendsImplements) {
        messageImpossibleExtendsImplements(n4ClassifierDefinition, nonAccessibleAbstractMembersBySuperTypeRef);
    }
    if (!foundImpossibleExtendsImplements) {
        // avoid consequential errors
        constraints_41_AbstractClass(tClassifier, memberCube);
    }
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) NameStaticPair(org.eclipse.n4js.ts.types.util.NameStaticPair) MemberList(org.eclipse.n4js.ts.types.util.MemberList) HashMap(java.util.HashMap) MemberMatrix(org.eclipse.n4js.validation.validators.utils.MemberMatrix) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) MemberCube(org.eclipse.n4js.validation.validators.utils.MemberCube) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) TMember(org.eclipse.n4js.ts.types.TMember) TClass(org.eclipse.n4js.ts.types.TClass) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Aggregations

TMember (org.eclipse.n4js.ts.types.TMember)4 MemberMatrix (org.eclipse.n4js.validation.validators.utils.MemberMatrix)4 NameStaticPair (org.eclipse.n4js.ts.types.util.NameStaticPair)3 ArrayList (java.util.ArrayList)2 TClass (org.eclipse.n4js.ts.types.TClass)2 TClassifier (org.eclipse.n4js.ts.types.TClassifier)2 MemberList (org.eclipse.n4js.ts.types.util.MemberList)2 MemberCube (org.eclipse.n4js.validation.validators.utils.MemberCube)2 Lists (com.google.common.collect.Lists)1 Inject (com.google.inject.Inject)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 JSXElementName (org.eclipse.n4js.n4JS.JSXElementName)1 LiteralOrComputedPropertyName (org.eclipse.n4js.n4JS.LiteralOrComputedPropertyName)1 N4JSPackage (org.eclipse.n4js.n4JS.N4JSPackage)1