Search in sources :

Example 1 with TGetter

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

the class InternalTypeSystem method applyRuleTypeGetterDeclaration.

protected Result<TypeRef> applyRuleTypeGetterDeclaration(final RuleEnvironment G, final RuleApplicationTrace _trace_, final GetterDeclaration getter) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    TypeRef _declaredTypeRef = getter.getDeclaredTypeRef();
    boolean _tripleNotEquals = (_declaredTypeRef != null);
    if (_tripleNotEquals) {
        T = getter.getDeclaredTypeRef();
    } else {
        TGetter _definedGetter = getter.getDefinedGetter();
        TypeRef _declaredTypeRef_1 = null;
        if (_definedGetter != null) {
            _declaredTypeRef_1 = _definedGetter.getDeclaredTypeRef();
        }
        boolean _tripleNotEquals_1 = (_declaredTypeRef_1 != null);
        if (_tripleNotEquals_1) {
            T = getter.getDefinedGetter().getDeclaredTypeRef();
        } else {
            T = RuleEnvironmentExtensions.anyTypeRef(G);
        }
    }
    return new Result<TypeRef>(T);
}
Also used : ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) TGetter(org.eclipse.n4js.ts.types.TGetter) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 2 with TGetter

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

the class GetterDeclarationImpl method setDefinedGetter.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setDefinedGetter(TGetter newDefinedGetter) {
    TGetter oldDefinedGetter = definedGetter;
    definedGetter = newDefinedGetter;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.GETTER_DECLARATION__DEFINED_GETTER, oldDefinedGetter, definedGetter));
}
Also used : TGetter(org.eclipse.n4js.ts.types.TGetter) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 3 with TGetter

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

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

Example 5 with TGetter

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

the class ScriptApiTracker method createVirtFieldAccessorTuple.

private VirtualApiMissingFieldAccessorTuple createVirtFieldAccessorTuple(TField apiField) {
    boolean statiC = apiField.isStatic();
    String name = apiField.getName();
    AccessorTuple copy = new AccessorTuple(name, statiC);
    TSetter tset = TypesFactory.eINSTANCE.createTSetter();
    tset.setName(name);
    tset.setDeclaredStatic(statiC);
    copy.setSetter(tset);
    TGetter tget = TypesFactory.eINSTANCE.createTGetter();
    tget.setName(name);
    tget.setDeclaredStatic(statiC);
    copy.setGetter(tget);
    VirtualApiMissingFieldAccessorTuple ret = new VirtualApiMissingFieldAccessorTuple(copy);
    ret.setGetter(new VirtualApiTGetter(name, tget));
    ret.setSetter(new VirtualApiTSetter(name, tset));
    return ret;
}
Also used : TSetter(org.eclipse.n4js.ts.types.TSetter) TGetter(org.eclipse.n4js.ts.types.TGetter) AccessorTuple(org.eclipse.n4js.ts.types.util.AccessorTuple)

Aggregations

TGetter (org.eclipse.n4js.ts.types.TGetter)10 TSetter (org.eclipse.n4js.ts.types.TSetter)7 TField (org.eclipse.n4js.ts.types.TField)5 AccessorTuple (org.eclipse.n4js.ts.types.util.AccessorTuple)4 TMember (org.eclipse.n4js.ts.types.TMember)3 TMethod (org.eclipse.n4js.ts.types.TMethod)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 EObject (org.eclipse.emf.ecore.EObject)2 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)2 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)2 TInterface (org.eclipse.n4js.ts.types.TInterface)2 NameStaticPair (org.eclipse.n4js.ts.types.util.NameStaticPair)2 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Iterator (java.util.Iterator)1