Search in sources :

Example 1 with MemberList

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

use of org.eclipse.n4js.ts.types.util.MemberList in project n4js by eclipse.

the class N4JSMemberRedefinitionValidator method messageImpossibleExtendsImplements.

private void messageImpossibleExtendsImplements(N4ClassifierDefinition n4ClassifierDefinition, Map<ParameterizedTypeRef, MemberList<TMember>> nonAccessibleAbstractMembersBySuperTypeRef) {
    for (Entry<ParameterizedTypeRef, MemberList<TMember>> entry : nonAccessibleAbstractMembersBySuperTypeRef.entrySet()) {
        final ParameterizedTypeRef superTypeRef = entry.getKey();
        final Type type = superTypeRef.getDeclaredType();
        final String mode = type instanceof TInterface && !(n4ClassifierDefinition instanceof N4InterfaceDeclaration) ? "implement" : "extend";
        final String message = getMessageForCLF_NON_ACCESSIBLE_ABSTRACT_MEMBERS(mode, validatorMessageHelper.description(type), validatorMessageHelper.descriptions(entry.getValue()));
        addIssue(message, superTypeRef.eContainer(), superTypeRef.eContainingFeature(), CLF_NON_ACCESSIBLE_ABSTRACT_MEMBERS);
    }
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) Type(org.eclipse.n4js.ts.types.Type) MemberType(org.eclipse.n4js.ts.types.MemberType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) MemberList(org.eclipse.n4js.ts.types.util.MemberList) TInterface(org.eclipse.n4js.ts.types.TInterface) N4InterfaceDeclaration(org.eclipse.n4js.n4JS.N4InterfaceDeclaration)

Example 3 with MemberList

use of org.eclipse.n4js.ts.types.util.MemberList in project n4js by eclipse.

the class ConcreteMembersOrderedForTranspiler method create.

/**
 * Returns a tuple of collections used by transpiler to generate interface or class members.
 */
public static ConcreteMembersOrderedForTranspiler create(ContainerTypesHelper containerTypesHelper, TClassifier type, Script context) {
    MemberCollector collector = containerTypesHelper.fromContext(context);
    List<TMember> concreteInheritedMembers = (type instanceof TClass) ? collector.inheritedMembers((TClass) type) : emptyList();
    List<TMember> ownedAndMixedInConcreteMembers = collector.computeOwnedAndMixedInConcreteMembers(type);
    List<AccessorTuple> concreteAccessorTuples = getConcreteFieldAccessors(ownedAndMixedInConcreteMembers, concreteInheritedMembers);
    MemberList<TField> fieldsOverridingAccessors = getFieldsOverridingAccessor(ownedAndMixedInConcreteMembers, concreteInheritedMembers);
    // compute the list of mixed in fields, which do not override any Accessor (handled separately)
    MemberList<TField> fieldsPurelyMixedInNotOverridingAccessor = new MemberList<>();
    fieldsPurelyMixedInNotOverridingAccessor.addAll(ownedAndMixedInConcreteMembers.stream().filter(it -> it instanceof TField && // must stem from different type
    it.getContainingType() != type).map(it -> (TField) it).filter(// remove the ones overriding get/set
    it -> !fieldsOverridingAccessors.contains(it)).collect(Collectors.toList()));
    return new ConcreteMembersOrderedForTranspiler(concreteInheritedMembers, ownedAndMixedInConcreteMembers, concreteAccessorTuples, fieldsOverridingAccessors, fieldsPurelyMixedInNotOverridingAccessor);
}
Also used : Collections.emptyList(java.util.Collections.emptyList) TField(org.eclipse.n4js.ts.types.TField) Set(java.util.Set) TMember(org.eclipse.n4js.ts.types.TMember) HashMap(java.util.HashMap) Script(org.eclipse.n4js.n4JS.Script) TClass(org.eclipse.n4js.ts.types.TClass) AccessorTuple(org.eclipse.n4js.ts.types.util.AccessorTuple) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TSetter(org.eclipse.n4js.ts.types.TSetter) NameStaticPair(org.eclipse.n4js.ts.types.util.NameStaticPair) HashSet(java.util.HashSet) TGetter(org.eclipse.n4js.ts.types.TGetter) List(java.util.List) ContainerTypesHelper(org.eclipse.n4js.utils.ContainerTypesHelper) TClassifier(org.eclipse.n4js.ts.types.TClassifier) TInterface(org.eclipse.n4js.ts.types.TInterface) Map(java.util.Map) MemberList(org.eclipse.n4js.ts.types.util.MemberList) MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector) TField(org.eclipse.n4js.ts.types.TField) MemberList(org.eclipse.n4js.ts.types.util.MemberList) AccessorTuple(org.eclipse.n4js.ts.types.util.AccessorTuple) MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector) TMember(org.eclipse.n4js.ts.types.TMember) TClass(org.eclipse.n4js.ts.types.TClass)

Example 4 with MemberList

use of org.eclipse.n4js.ts.types.util.MemberList in project n4js by eclipse.

the class ScriptApiTracker method computeMethodDiff.

/**
 * Find last missing methods, which the implType would have if it would follow the inheritance as defined in the API
 *
 * @param implType
 *            Type of implementation project, calculated from AST
 * @param collector
 *            member collector for the project.
 * @param ownedAndMixedInConcreteMember
 *            already computed for implType
 * @param missingApiMethods2
 *            already computed for implType
 * @return list of virtual Methods
 */
public List<VirtualApiTMethod> computeMethodDiff(TClass implType, MemberCollector collector, List<TMember> ownedAndMixedInConcreteMember, MemberList<TMethod> missingApiMethods2) {
    Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(implType.eResource());
    if (optAdapt.isPresent()) {
        ProjectComparisonEntry compareEntry = optAdapt.get().getEntryFor(EcoreUtil2.getContainerOfType(implType, TModule.class));
        ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(implType);
        if (typeCompare != null && typeCompare.getElementAPI() != null) {
            TClass apiType = (TClass) typeCompare.getElementAPI();
            MemberList<TMember> implMembers = collector.allMembers(implType, false, true);
            MemberList<TMember> apiMembers = collector.allMembers(apiType, false, true);
            final HashSet<String> methodNamesAlreadyDefined = new HashSet<>();
            Stream.concat(implMembers.stream(), Stream.concat(ownedAndMixedInConcreteMember.stream(), missingApiMethods2.stream())).forEach(m -> {
                if (m instanceof TMethod) {
                    methodNamesAlreadyDefined.add(m.getName());
                }
            });
            return apiMembers.stream().filter(t -> t instanceof TMethod).filter(m -> !methodNamesAlreadyDefined.contains(((TMethod) m).getName())).map(m2 -> {
                TMethod m = (TMethod) m2;
                VirtualApiTMethod vMethod = new VirtualApiTMethod(m.getName(), TypeUtils.copyPartial(m, TypesPackage.Literals.SYNTAX_RELATED_TELEMENT__AST_ELEMENT));
                return vMethod;
            }).collect(Collectors.toList());
        }
    }
    return emptyList();
}
Also used : ProjectComparisonEntry(org.eclipse.n4js.compare.ProjectComparisonEntry) Inject(com.google.inject.Inject) TClass(org.eclipse.n4js.ts.types.TClass) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) TSetter(org.eclipse.n4js.ts.types.TSetter) Logger(org.apache.log4j.Logger) TGetterImpl(org.eclipse.n4js.ts.types.impl.TGetterImpl) TMethodImpl(org.eclipse.n4js.ts.types.impl.TMethodImpl) Type(org.eclipse.n4js.ts.types.Type) MemberList(org.eclipse.n4js.ts.types.util.MemberList) N4InterfaceDeclaration(org.eclipse.n4js.n4JS.N4InterfaceDeclaration) TFieldImpl(org.eclipse.n4js.ts.types.impl.TFieldImpl) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) TField(org.eclipse.n4js.ts.types.TField) EObject(org.eclipse.emf.ecore.EObject) PROVIDES_DEFAULT_IMPLEMENTATION(org.eclipse.n4js.AnnotationDefinition.PROVIDES_DEFAULT_IMPLEMENTATION) PROVIDES_INITIALZER(org.eclipse.n4js.AnnotationDefinition.PROVIDES_INITIALZER) TMethod(org.eclipse.n4js.ts.types.TMethod) Collectors(java.util.stream.Collectors) TGetter(org.eclipse.n4js.ts.types.TGetter) List(java.util.List) Stream(java.util.stream.Stream) TClassifier(org.eclipse.n4js.ts.types.TClassifier) Resource(org.eclipse.emf.ecore.resource.Resource) Optional(java.util.Optional) Pair(org.eclipse.xtext.xbase.lib.Pair) TypesFactory(org.eclipse.n4js.ts.types.TypesFactory) Singleton(com.google.inject.Singleton) HashMap(java.util.HashMap) TypeUtils(org.eclipse.n4js.ts.utils.TypeUtils) AccessorTuple(org.eclipse.n4js.ts.types.util.AccessorTuple) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TModule(org.eclipse.n4js.ts.types.TModule) TN4Classifier(org.eclipse.n4js.ts.types.TN4Classifier) TInterface(org.eclipse.n4js.ts.types.TInterface) ProjectCompareHelper(org.eclipse.n4js.compare.ProjectCompareHelper) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) TAnnotableElement(org.eclipse.n4js.ts.types.TAnnotableElement) MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector) LinkedHashSet(java.util.LinkedHashSet) Iterator(java.util.Iterator) TMember(org.eclipse.n4js.ts.types.TMember) Script(org.eclipse.n4js.n4JS.Script) Consumer(java.util.function.Consumer) TypesPackage(org.eclipse.n4js.ts.types.TypesPackage) AdapterImpl(org.eclipse.emf.common.notify.impl.AdapterImpl) TSetterImpl(org.eclipse.n4js.ts.types.impl.TSetterImpl) Collections(java.util.Collections) TMethod(org.eclipse.n4js.ts.types.TMethod) TModule(org.eclipse.n4js.ts.types.TModule) TMember(org.eclipse.n4js.ts.types.TMember) TClass(org.eclipse.n4js.ts.types.TClass) ProjectComparisonEntry(org.eclipse.n4js.compare.ProjectComparisonEntry) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 5 with MemberList

use of org.eclipse.n4js.ts.types.util.MemberList in project n4js by eclipse.

the class N4JSScopingConsumableMethodsDiagnosis method diagnose.

@Override
DiagnosticMessage diagnose(QualifiedName name, ParameterizedPropertyAccessExpression propertyAccess) {
    // determine containing member declaration and classifier definition
    N4MemberDeclaration containingMemberDeclaration = EcoreUtil2.getContainerOfType(propertyAccess, N4MemberDeclaration.class);
    N4ClassifierDefinition classifierDefinition = EcoreUtil2.getContainerOfType(containingMemberDeclaration, N4ClassifierDefinition.class);
    // if ancestors present and non-static context (no super in static context)
    if (containingMemberDeclaration != null && !containingMemberDeclaration.isStatic() && classifierDefinition != null) {
        // Get candidate methods
        MemberList<TMember>.MemberIterable<TMethod> methods = containerTypesHelper.fromContext(propertyAccess).membersOfImplementedInterfacesForConsumption((TClassifier) classifierDefinition.getDefinedType()).methods();
        boolean hasMethod = methods.stream().filter(// Filter for non-static non-abstract methods
        m -> !m.isHasNoBody() && !m.isStatic()).anyMatch(m -> m.getName().equals(name.toString()));
        if (hasMethod) {
            return createMessage(IssueCodes.CLF_CANNOT_REFER_TO_DEFAULT_METHOD_WITH_SUPER, IssueCodes.getMessageForCLF_CANNOT_REFER_TO_DEFAULT_METHOD_WITH_SUPER());
        }
    }
    return null;
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IssueCodes(org.eclipse.n4js.validation.IssueCodes) Inject(com.google.inject.Inject) TMember(org.eclipse.n4js.ts.types.TMember) TMethod(org.eclipse.n4js.ts.types.TMethod) DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage) ContainerTypesHelper(org.eclipse.n4js.utils.ContainerTypesHelper) TClassifier(org.eclipse.n4js.ts.types.TClassifier) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) N4MemberDeclaration(org.eclipse.n4js.n4JS.N4MemberDeclaration) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) MemberList(org.eclipse.n4js.ts.types.util.MemberList) N4ClassifierDefinition(org.eclipse.n4js.n4JS.N4ClassifierDefinition) TMethod(org.eclipse.n4js.ts.types.TMethod) MemberList(org.eclipse.n4js.ts.types.util.MemberList) N4ClassifierDefinition(org.eclipse.n4js.n4JS.N4ClassifierDefinition) N4MemberDeclaration(org.eclipse.n4js.n4JS.N4MemberDeclaration)

Aggregations

MemberList (org.eclipse.n4js.ts.types.util.MemberList)9 TMember (org.eclipse.n4js.ts.types.TMember)8 TClassifier (org.eclipse.n4js.ts.types.TClassifier)7 TClass (org.eclipse.n4js.ts.types.TClass)5 HashSet (java.util.HashSet)4 TInterface (org.eclipse.n4js.ts.types.TInterface)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Script (org.eclipse.n4js.n4JS.Script)3 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)3 TField (org.eclipse.n4js.ts.types.TField)3 TGetter (org.eclipse.n4js.ts.types.TGetter)3 TMethod (org.eclipse.n4js.ts.types.TMethod)3 TSetter (org.eclipse.n4js.ts.types.TSetter)3 AccessorTuple (org.eclipse.n4js.ts.types.util.AccessorTuple)3 NameStaticPair (org.eclipse.n4js.ts.types.util.NameStaticPair)3 ContainerTypesHelper (org.eclipse.n4js.utils.ContainerTypesHelper)3 MemberCollector (org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector)3