Search in sources :

Example 1 with NameStaticPair

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

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

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

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

the class ConcreteMembersOrderedForTranspiler method mapToAccessorTuples.

/**
 * Maps getters and setters to {@link AccessorTuple}s, used to generate proper setters-getters-pairs for property.
 * The passed maps may be changed!
 *
 * @param getters
 *            list of getters
 * @param fields
 *            list of fields
 * @param io_setters
 *            map with owned getters, this map may be changed by this method
 * @param io_inheritedGetters
 *            map with inherited getters, this map may be changed by this method
 * @param io_inheritedSetters
 *            map with inherited getters, this map may be changed by this method
 * @return list of accessor tuples.
 */
private static List<AccessorTuple> mapToAccessorTuples(Iterable<TGetter> getters, Map<NameStaticPair, TSetter> io_setters, Iterable<TField> fields, Map<NameStaticPair, TGetter> io_inheritedGetters, Map<NameStaticPair, TSetter> io_inheritedSetters) {
    List<AccessorTuple> tuples = new ArrayList<>();
    // add getters (alone & with corresponding setter)
    for (TGetter getter : getters) {
        AccessorTuple tuple = new AccessorTuple(getter.getName(), getter.isStatic());
        tuple.setGetter(getter);
        NameStaticPair nsp = NameStaticPair.of(getter);
        // do not handle the thing twice
        tuple.setSetter(io_setters.remove(nsp));
        if (tuple.getSetter() == null) {
            tuple.setInheritedSetter(io_inheritedSetters.remove(nsp));
        }
        tuples.add(tuple);
    }
    // add setters w/o getter:
    for (TSetter setter : io_setters.values()) {
        AccessorTuple tuple = new AccessorTuple(setter.getName(), setter.isStatic());
        NameStaticPair nsp = NameStaticPair.of(setter);
        tuple.setSetter(setter);
        tuple.setInheritedGetter(io_inheritedGetters.remove(nsp));
        tuples.add(tuple);
    }
    // remove the inherited references - the field will overwrite them.
    for (TField field : fields) {
        NameStaticPair nsp = NameStaticPair.of(field);
        io_inheritedSetters.remove(nsp);
        io_inheritedGetters.remove(nsp);
    }
    // find getters/setters defined in interfaces which need to be combined:
    for (TSetter inhSetter : io_inheritedSetters.values()) {
        TGetter inhGetter = io_inheritedGetters.remove(NameStaticPair.of(inhSetter));
        if (inhGetter != null && inhSetter.getContainingType() != inhGetter.getContainingType() && (inhSetter.getContainingType() instanceof TInterface || inhGetter.getContainingType() instanceof TInterface)) {
            // getter & setter are inherited from different types.
            AccessorTuple tuple = new AccessorTuple(inhSetter.getName(), inhSetter.isStatic());
            tuple.setInheritedGetter(inhGetter);
            tuple.setInheritedSetter(inhSetter);
            tuples.add(tuple);
        }
    }
    return tuples;
}
Also used : NameStaticPair(org.eclipse.n4js.ts.types.util.NameStaticPair) TSetter(org.eclipse.n4js.ts.types.TSetter) TField(org.eclipse.n4js.ts.types.TField) TInterface(org.eclipse.n4js.ts.types.TInterface) TGetter(org.eclipse.n4js.ts.types.TGetter) ArrayList(java.util.ArrayList) AccessorTuple(org.eclipse.n4js.ts.types.util.AccessorTuple)

Example 5 with NameStaticPair

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

NameStaticPair (org.eclipse.n4js.ts.types.util.NameStaticPair)6 TMember (org.eclipse.n4js.ts.types.TMember)5 MemberMatrix (org.eclipse.n4js.validation.validators.utils.MemberMatrix)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 TClass (org.eclipse.n4js.ts.types.TClass)2 TClassifier (org.eclipse.n4js.ts.types.TClassifier)2 TField (org.eclipse.n4js.ts.types.TField)2 TGetter (org.eclipse.n4js.ts.types.TGetter)2 TSetter (org.eclipse.n4js.ts.types.TSetter)2 AccessorTuple (org.eclipse.n4js.ts.types.util.AccessorTuple)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 List (java.util.List)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 URI (org.eclipse.emf.common.util.URI)1