Search in sources :

Example 11 with TInterface

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

the class ScriptApiTracker method computeMissingApiFields.

/**
 * Computes the list of virtual AccessorTuples for missing static fields on Interfaces
 *
 * @return List of {@link VirtualApiTField}
 */
private List<AccessorTuple> computeMissingApiFields(TInterface declaration) {
    Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(declaration.eResource());
    if (optAdapt.isPresent()) {
        ProjectComparisonAdapter projectComparisonAdapter = optAdapt.get();
        ProjectComparisonEntry compareEntry = projectComparisonAdapter.getEntryFor(EcoreUtil2.getContainerOfType(declaration, TModule.class));
        ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(declaration);
        if (typeCompare != null) {
            ArrayList<AccessorTuple> collectedMissingFields = new ArrayList<>();
            Predicate<ProjectComparisonEntry> filter = (pce -> pce.getElementAPI() instanceof TField);
            filter = filter.and(pce -> pce.getElementImpl()[0] == null).and(pce -> PROVIDES_INITIALZER.hasAnnotation((TField) pce.getElementAPI()));
            Function<TInterface, Consumer<? super ProjectComparisonEntry>> actionProvider = pivot -> pce -> {
                TField apiField = ((TField) pce.getElementAPI());
                VirtualApiMissingFieldAccessorTuple ret = createVirtFieldAccessorTuple(apiField);
                collectedMissingFields.add(ret);
            };
            if (!checkInterfaceImplementsInterface(declaration, typeCompare.getElementAPI())) {
                return emptyList();
            }
            // Call the supertype iterations scaffolding:
            interfaceApiSupertypeWalker(filter, actionProvider, projectComparisonAdapter, (TInterface) typeCompare.getElementAPI(), TInterface.class);
            return collectedMissingFields;
        }
    }
    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) TField(org.eclipse.n4js.ts.types.TField) TInterface(org.eclipse.n4js.ts.types.TInterface) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) AccessorTuple(org.eclipse.n4js.ts.types.util.AccessorTuple) TModule(org.eclipse.n4js.ts.types.TModule) ProjectComparisonEntry(org.eclipse.n4js.compare.ProjectComparisonEntry)

Example 12 with TInterface

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

the class TMemberWithAccessModifierImpl method getMemberAccessModifier.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public MemberAccessModifier getMemberAccessModifier() {
    MemberAccessModifier _declaredMemberAccessModifier = this.getDeclaredMemberAccessModifier();
    boolean _tripleEquals = (_declaredMemberAccessModifier == MemberAccessModifier.UNDEFINED);
    if (_tripleEquals) {
        final EObject parent = this.eContainer();
        if ((parent instanceof TInterface)) {
            final MemberAccessModifier modifierDerivedFromType = AccessModifiers.toMemberModifier(((Type) parent).getTypeAccessModifier());
            if ((modifierDerivedFromType != MemberAccessModifier.PRIVATE)) {
                return modifierDerivedFromType;
            }
        }
        return MemberAccessModifier.PROJECT;
    }
    return this.getDeclaredMemberAccessModifier();
}
Also used : TInterface(org.eclipse.n4js.ts.types.TInterface) EObject(org.eclipse.emf.ecore.EObject) MemberAccessModifier(org.eclipse.n4js.ts.types.MemberAccessModifier)

Example 13 with TInterface

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

the class ConsumptionUtils method findInterfaceDefiningConsumedMember.

/**
 * Returns the directly consumed (or otherwise inherited) classifier which indirectly provides the consumed member
 * (or null, if interface is found). Usually the returned classifier is a TInterface.
 *
 * @param consumingClassifier
 *            the consuming classifier
 * @param consumedMember
 *            the member consumed by the classifier
 */
public static TClassifier findInterfaceDefiningConsumedMember(TClassifier consumingClassifier, TMember consumedMember) {
    if (consumedMember == null || !(consumedMember.eContainer() instanceof TInterface)) {
        return null;
    }
    TInterface tinterface = (TInterface) consumedMember.eContainer();
    List<TClassifier> path = findPathToInterface(consumingClassifier, tinterface);
    if (path.isEmpty()) {
        return null;
    }
    return path.get(0);
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) TInterface(org.eclipse.n4js.ts.types.TInterface)

Example 14 with TInterface

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

the class TypeUtils method isRawSuperType.

private static boolean isRawSuperType(Type type, Type superTypeCandidate, RecursionGuard<Type> guard) {
    if (type == superTypeCandidate) {
        return true;
    }
    if (type == null) {
        return false;
    }
    if (guard.tryNext(type)) {
        if (type instanceof TClass) {
            final TClass c = (TClass) type;
            if (isRawSuperType(c.getSuperClassRef(), superTypeCandidate, guard)) {
                return true;
            }
            if (isRawSuperType(c.getImplementedInterfaceRefs(), superTypeCandidate, guard)) {
                return true;
            }
            return false;
        }
        if (type instanceof TInterface) {
            final TInterface r = (TInterface) type;
            if (isRawSuperType(r.getSuperInterfaceRefs(), superTypeCandidate, guard)) {
                return true;
            }
            return false;
        }
        if (type instanceof TypeVariable) {
            TypeVariable v = (TypeVariable) type;
            TypeRef ub = v.getDeclaredUpperBound();
            if (ub != null && isRawSuperType(ub, superTypeCandidate, guard)) {
                return true;
            }
            return false;
        }
        if (type instanceof PrimitiveType) {
            PrimitiveType assignmentCompatible = ((PrimitiveType) type).getAssignmentCompatible();
            if (isRawSuperType(assignmentCompatible, superTypeCandidate, guard)) {
                return true;
            }
        }
    }
    return false;
}
Also used : TInterface(org.eclipse.n4js.ts.types.TInterface) TypeVariable(org.eclipse.n4js.ts.types.TypeVariable) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) DeferredTypeRef(org.eclipse.n4js.ts.typeRefs.DeferredTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) TClass(org.eclipse.n4js.ts.types.TClass)

Example 15 with TInterface

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

the class TypeUtils method declaredSuperTypes.

/**
 * Convenience method, returns directly declared super types (class, role, interface) of a classifier. May return an
 * empty list but never null. Order is always super class, super roles, super interfaces. For all non-classifiers
 * this method returns an empty list.
 */
@SuppressWarnings("unchecked")
public static Iterable<? extends ParameterizedTypeRef> declaredSuperTypes(final Type type) {
    if (type instanceof TClass) {
        final TClass c = (TClass) type;
        if (c.getSuperClassRef() != null) {
            return Iterables.concat(concat(singletonList(c.getSuperClassRef()), c.getImplementedInterfaceRefs()));
        } else {
            return c.getImplementedInterfaceRefs();
        }
    }
    if (type instanceof TInterface) {
        final TInterface r = (TInterface) type;
        return r.getSuperInterfaceRefs();
    }
    if (type instanceof PrimitiveType) {
        PrimitiveType assignmentCompatible = ((PrimitiveType) type).getAssignmentCompatible();
        if (assignmentCompatible != null) {
            ParameterizedTypeRef typeRef = TypeRefsFactory.eINSTANCE.createParameterizedTypeRef();
            typeRef.setDeclaredType(assignmentCompatible);
            return Collections.singletonList(typeRef);
        }
    }
    if (type instanceof TObjectPrototype) {
        // IDE-1221 string based enums: traversing super types for object prototypes as well
        TObjectPrototype tObjectPrototype = (TObjectPrototype) type;
        if (tObjectPrototype.getSuperType() != null) {
            return singletonList(tObjectPrototype.getSuperType());
        }
    }
    return Collections.emptyList();
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) TInterface(org.eclipse.n4js.ts.types.TInterface) TObjectPrototype(org.eclipse.n4js.ts.types.TObjectPrototype) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) TClass(org.eclipse.n4js.ts.types.TClass)

Aggregations

TInterface (org.eclipse.n4js.ts.types.TInterface)16 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)9 Type (org.eclipse.n4js.ts.types.Type)8 EObject (org.eclipse.emf.ecore.EObject)7 TClass (org.eclipse.n4js.ts.types.TClass)7 TClassifier (org.eclipse.n4js.ts.types.TClassifier)6 TField (org.eclipse.n4js.ts.types.TField)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4 PrimitiveType (org.eclipse.n4js.ts.types.PrimitiveType)4 TGetter (org.eclipse.n4js.ts.types.TGetter)4 TMember (org.eclipse.n4js.ts.types.TMember)4 TSetter (org.eclipse.n4js.ts.types.TSetter)4 AccessorTuple (org.eclipse.n4js.ts.types.util.AccessorTuple)4 MemberList (org.eclipse.n4js.ts.types.util.MemberList)4 HashSet (java.util.HashSet)3 Optional (java.util.Optional)3 N4InterfaceDeclaration (org.eclipse.n4js.n4JS.N4InterfaceDeclaration)3