Search in sources :

Example 6 with TMember

use of org.eclipse.n4js.ts.types.TMember 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 7 with TMember

use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.

the class N4JSMemberRedefinitionValidator method constraints_66_NonOverride.

/**
 * Constraints 66: Non-Override Declaration
 */
private boolean constraints_66_NonOverride(MemberMatrix mm) {
    if (mm.hasOwned()) {
        boolean bFoundWronglyDeclaredMember = false;
        for (TMember member : mm.owned()) {
            if (member.isDeclaredOverride()) {
                TMember m = mm.possibleOverrideCandidateOrError(member);
                if (m == null) {
                    bFoundWronglyDeclaredMember = true;
                    if (member.isStatic() && mm.hasNonImplemented() && !mm.hasInherited() && !mm.hasImplemented()) {
                        // special case of false @Override annotation: "overriding" a static member of an interface
                        // simply take the first one
                        final TMember other = mm.nonImplemented().iterator().next();
                        String message = getMessageForCLF_OVERRIDE_NON_EXISTENT_INTERFACE(validatorMessageHelper.description(member), validatorMessageHelper.description(other));
                        addIssue(message, member.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, CLF_OVERRIDE_NON_EXISTENT_INTERFACE);
                    } else {
                        // standard case of false @Override annotation
                        String message = getMessageForCLF_OVERRIDE_NON_EXISTENT(keywordProvider.keyword(member), member.getName());
                        addIssue(message, member.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, CLF_OVERRIDE_NON_EXISTENT);
                    }
                }
            }
        }
        return bFoundWronglyDeclaredMember;
    }
    return true;
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember)

Example 8 with TMember

use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.

the class N4JSMemberRedefinitionValidator method unusedGenericTypeVariable.

/**
 * GHOLD-234 add warning for unused type variables in function and method declarations (unless the method overrides
 * any other method).
 */
private void unusedGenericTypeVariable(MemberMatrix mm) {
    for (TMember member : mm.owned()) {
        if (member instanceof TMethod) {
            TMethod method = (TMethod) member;
            if (!mm.hasInherited() && !mm.hasImplemented()) {
                // We need the method declaration from the AST in order to pass it to the internal
                // validation function. This is necessary because we want to attach the warning to the actual unused
                // type variable in the method declaration, and the type variable in the type model is not identical
                // to the one in the AST which we actually need.
                // Since method is owned by the type being validated, we can safely navigate back from the type
                // model to the AST without triggering another parse.
                MethodDeclaration methodDeclaration = (MethodDeclaration) method.getAstElement();
                internalCheckNoUnusedTypeParameters(methodDeclaration);
            }
        }
    }
}
Also used : TMethod(org.eclipse.n4js.ts.types.TMethod) MethodDeclaration(org.eclipse.n4js.n4JS.MethodDeclaration) TMember(org.eclipse.n4js.ts.types.TMember)

Example 9 with TMember

use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.

the class N4JSMemberRedefinitionValidator method messageMissingOverrideAnnotation.

/**
 * Adds a missing override issue with the fitting verb for all members in the given collection.
 *
 * @param mm
 *            The current member matrix
 * @param missingOverrideAnnotationMembers
 *            A collection of overridden members
 */
private void messageMissingOverrideAnnotation(MemberMatrix mm, Collection<TMember> missingOverrideAnnotationMembers) {
    if (mm.hasOwned() && missingOverrideAnnotationMembers.size() > 0) {
        Iterable<TMember> overriddenMembers = Iterables.concat(mm.inherited(), mm.implemented());
        for (TMember overriding : mm.owned()) {
            // skip members with proper annotation
            if (!missingOverrideAnnotationMembers.contains(overriding)) {
                continue;
            }
            // skip constructors
            if (overriding.isConstructor()) {
                continue;
            }
            // skip non-n4js variant members
            if (!jsVariantHelper.checkOverrideAnnotation(overriding)) {
                continue;
            }
            /*
				 * Filter overridden members to only contain metatype compatible members to prevent the generation of
				 * confusing error message
				 */
            Iterable<TMember> filteredOverriddenMembers = MemberRedefinitionUtils.getMetatypeCompatibleOverriddenMembers(overriding, overriddenMembers);
            // choose redefinition verb based on the origin of the overridden members
            String redefinitionVerb = MemberRedefinitionUtils.getRedefinitionVerb(filteredOverriddenMembers, getCurrentClassifier());
            String message = getMessageForCLF_OVERRIDE_ANNOTATION(validatorMessageHelper.descriptionDifferentFrom(overriding, overriddenMembers), redefinitionVerb, validatorMessageHelper.descriptions(filteredOverriddenMembers));
            addIssue(message, overriding.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, CLF_OVERRIDE_ANNOTATION);
        }
    }
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember)

Example 10 with TMember

use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.

the class N4JSMemberRedefinitionValidator method checkUnpairedAccessorConsumption.

/**
 * Checks if any accessor has been consumed for which the counterpart accessor is only inherited.
 */
private void checkUnpairedAccessorConsumption(MemberMatrix mm, N4ClassifierDefinition definition) {
    // validate conflicts between inherited and consumed accessor members only
    if (!mm.hasOwned() && mm.hasInherited() && mm.hasImplemented()) {
        // Collect whether getter and setter were consumed as well as the consumed member
        boolean getterConsumed = false;
        boolean setterConsumed = false;
        TMember consumedAccessor = null;
        for (TMember implementedMember : mm.implemented()) {
            if (implementedMember.isAccessor() && mm.isConsumed(implementedMember)) {
                if (implementedMember.getMemberType() == MemberType.GETTER) {
                    getterConsumed = true;
                } else {
                    setterConsumed = true;
                }
                consumedAccessor = implementedMember;
            }
        }
        // Issue error if getter/setter has been consumed and the counterpart is inherited.
        if ((getterConsumed != setterConsumed) && mm.hasAccessorPair() && null != consumedAccessor) {
            messageMissingOwnedAccessorCorrespondingConsumedAccessor((FieldAccessor) consumedAccessor, definition);
        }
    }
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember)

Aggregations

TMember (org.eclipse.n4js.ts.types.TMember)65 EObject (org.eclipse.emf.ecore.EObject)19 TClassifier (org.eclipse.n4js.ts.types.TClassifier)13 Type (org.eclipse.n4js.ts.types.Type)13 ContainerType (org.eclipse.n4js.ts.types.ContainerType)11 ArrayList (java.util.ArrayList)10 TClass (org.eclipse.n4js.ts.types.TClass)10 TField (org.eclipse.n4js.ts.types.TField)10 TMethod (org.eclipse.n4js.ts.types.TMethod)9 TModule (org.eclipse.n4js.ts.types.TModule)9 MemberList (org.eclipse.n4js.ts.types.util.MemberList)9 RuleEnvironment (org.eclipse.xsemantics.runtime.RuleEnvironment)9 HashSet (java.util.HashSet)8 HashMap (java.util.HashMap)7 NameStaticPair (org.eclipse.n4js.ts.types.util.NameStaticPair)7 MemberCollector (org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector)7 Optional (java.util.Optional)6 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)6 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)6 Inject (com.google.inject.Inject)5