Search in sources :

Example 16 with TMember

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

the class MemberCube method addMembers.

private void addMembers(int source, List<TMember> members) {
    for (TMember member : members) {
        NameStaticPair nsp = NameStaticPair.of(member);
        MemberMatrix memberMatrix = memberMatrixesByName.get(nsp);
        if (memberMatrix == null) {
            memberMatrix = new MemberMatrix();
            memberMatrixesByName.put(nsp, memberMatrix);
        }
        memberMatrix.add(source, member);
    }
}
Also used : NameStaticPair(org.eclipse.n4js.ts.types.util.NameStaticPair) TMember(org.eclipse.n4js.ts.types.TMember)

Example 17 with TMember

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

the class JSDoc2ADocSpecProcessor method addMembers.

/**
 * This method iterates through all members of a N4JS type and creates corresponding {@link SpecFile}s from them.
 * During this process, member tests are linked if available.
 */
private void addMembers(SpecInfo specInfo, TN4Classifier classifier, Map<String, SpecSection> specsByKey, TreeMap<String, SpecFile> specChangeSet) {
    MemberCollector memberCollector = containerTypesHelper.fromContext(classifier);
    MemberList<TMember> memberList = memberCollector.allMembers(classifier, false, false, false);
    Stream<TMember> nonPrivMembs = memberList.stream().filter(isNonPrivate());
    // add spec region for new members
    for (TMember member : (Iterable<TMember>) nonPrivMembs::iterator) {
        SpecSection specSection = new SpecIdentifiableElementSection(specInfo, member, rootDir, repoPathHolder);
        if (!specsByKey.containsKey(specSection.getSpecKey())) {
            specSection.setTestInfosForMember(specInfo.getTestsForMember(member));
            insertIntoSpecModuleFile(specChangeSet, specsByKey, (SpecIdentifiableElementSection) specSection);
        }
    }
}
Also used : MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector) TMember(org.eclipse.n4js.ts.types.TMember)

Example 18 with TMember

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

the class SourceEntryFactory method getElementName.

private static String getElementName(IdentifiableElement ie) {
    String elName = ie.getName();
    if (ie instanceof TMember) {
        TMember tm = (TMember) ie;
        @SuppressWarnings("rawtypes") ContainerType ct = tm.getContainingType();
        elName = ct.getName();
    }
    return elName;
}
Also used : ContainerType(org.eclipse.n4js.ts.types.ContainerType) TMember(org.eclipse.n4js.ts.types.TMember)

Example 19 with TMember

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

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

the class ConcreteMembersOrderedForTranspiler method getConcreteFieldAccessors.

/**
 * Helper method, returns all concrete field accessors as tuples of the given classifier, which may even contain
 * fields if they override concrete getters or setter. Since getter/setters can only be defined as pairs, in case of
 * single owned getter with inherited setter, a delegate is created for the setter (and vice versa).
 */
private static List<AccessorTuple> getConcreteFieldAccessors(List<TMember> ownedAndMixedInConcreteMember, List<TMember> concreteInheritedMembers) {
    Set<TField> ownedAndMixedInFields = new HashSet<>();
    Set<TGetter> ownedAndMixedInGetters = new HashSet<>();
    Map<NameStaticPair, TSetter> ownedAndMixedInSetters = new HashMap<>();
    for (TMember m : ownedAndMixedInConcreteMember) {
        if (m instanceof TField) {
            ownedAndMixedInFields.add((TField) m);
        } else if (m instanceof TGetter) {
            ownedAndMixedInGetters.add((TGetter) m);
        } else if (m instanceof TSetter) {
            ownedAndMixedInSetters.put(NameStaticPair.of(m), (TSetter) m);
        }
    }
    Map<NameStaticPair, TGetter> inheritedGetters = new HashMap<>();
    Map<NameStaticPair, TSetter> inheritedSetters = new HashMap<>();
    for (TMember m : concreteInheritedMembers) {
        if (m instanceof TGetter) {
            if (!ownedAndMixedInGetters.contains(m)) {
                inheritedGetters.put(NameStaticPair.of(m), (TGetter) m);
            }
        } else if (m instanceof TSetter) {
            NameStaticPair nsp = NameStaticPair.of(m);
            if (ownedAndMixedInSetters.get(nsp) != m) {
                inheritedSetters.put(nsp, (TSetter) m);
            }
        }
    }
    List<AccessorTuple> ownedOrMixedInAccessorTouples = mapToAccessorTuples(ownedAndMixedInGetters, ownedAndMixedInSetters, ownedAndMixedInFields, inheritedGetters, inheritedSetters);
    return ownedOrMixedInAccessorTouples;
}
Also used : NameStaticPair(org.eclipse.n4js.ts.types.util.NameStaticPair) TSetter(org.eclipse.n4js.ts.types.TSetter) TField(org.eclipse.n4js.ts.types.TField) HashMap(java.util.HashMap) TGetter(org.eclipse.n4js.ts.types.TGetter) AccessorTuple(org.eclipse.n4js.ts.types.util.AccessorTuple) TMember(org.eclipse.n4js.ts.types.TMember) HashSet(java.util.HashSet)

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