Search in sources :

Example 1 with Type

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

the class N4JSDReader method addTestInfoForCodeElement.

/**
 * Adds test info to an identified element.
 */
private void addTestInfoForCodeElement(RepoRelativePath rrp, Doclet testMethodDoclet, FullMemberReference ref, TMember testMember, Multimap<String, SpecInfo> typesByName) {
    String fullTypeName = ref.fullTypeName();
    String regionName = KeyUtils.getSpecKeyWithoutProjectFolder(rrp, fullTypeName);
    Collection<SpecInfo> specInfos = typesByName.get(regionName);
    boolean testeeMemberFound = false;
    for (SpecInfo specInfo : specInfos) {
        for (Type testee : specInfo.specElementRef.getTypes()) {
            if (testee instanceof ContainerType<?> && ref.memberNameSet()) {
                TMember testeeMember = getRefMember((ContainerType<?>) testee, ref);
                if (testeeMember != null) {
                    String testeeName = testeeMember.getName();
                    SpecTestInfo testSpecInfo = createTestSpecInfo(testeeName, testMethodDoclet, testMember, rrp);
                    specInfo.addMemberTestInfo(testeeMember, testSpecInfo);
                }
                testeeMemberFound = true;
            }
        }
    }
    if (!testeeMemberFound) {
        for (SpecInfo specInfo : specInfos) {
            // Type, TFunction of TVariable
            String elementName = specInfo.specElementRef.identifiableElement.getName();
            SpecTestInfo testSpecInfo = createTestSpecInfo(elementName, testMethodDoclet, testMember, rrp);
            specInfo.addTypeTestInfo(testSpecInfo);
        }
        if (specInfos.isEmpty()) {
            issueAcceptor.addWarning("Testee " + fullTypeName + " not found", testMember);
        }
    }
}
Also used : ContainerType(org.eclipse.n4js.ts.types.ContainerType) Type(org.eclipse.n4js.ts.types.Type) TMember(org.eclipse.n4js.ts.types.TMember)

Example 2 with Type

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

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

the class PolyfillValidatorFragment method holdsPolyfill.

/**
 * Checks polyfill constraints on given class declaration using validator to issue errors. Constraints (Polyfill
 * Class) 156: Polyfill
 */
public boolean holdsPolyfill(N4JSClassValidator validator, N4ClassDeclaration n4Class) {
    boolean isStaticPolyFill = isStaticPolyfill(n4Class);
    if (isStaticPolyFill || isPolyfill(n4Class)) {
        PolyfillValidationState state = new PolyfillValidationState();
        state.host = validator;
        state.n4Class = n4Class;
        state.name = n4Class.getName();
        if (state.name == null || !(n4Class.getDefinedType() instanceof TClass)) {
            // consequential error, AST corrupt
            return true;
        }
        state.polyType = (TClass) n4Class.getDefinedType();
        if (state.polyType == null || state.name == null) {
            // consequential error
            return true;
        }
        if (!holdsExpliciteExtends(state)) {
            return false;
        }
        final Type superType = n4Class.getSuperClassRef().getDeclaredType();
        if (!(superType instanceof TClassifier)) {
            // consequential error
            return true;
        }
        state.filledType = (TClassifier) superType;
        // Different rules for static/non-static polyfills:
        if (!isStaticPolyFill) {
            if (!(// 
            holdPolyfillName(state) && // 
            holdsProvidedByRuntime(state) && // 
            holdsNoImplementsOrConsumes(state) && // 
            holdsEqualModifiers(state) && // 
            holdsEqualTypeVariables(state) && // 
            holdsSinglePolyfillSource(state))) {
                return false;
            }
        } else {
            // static polyfill case, IDE-1735
            if (!(// 
            holdPolyfillName(state) && // && holdsNoImplementsOrConsumes(state) //
            holdsFilledClassIsStaticPolyfillAware(// 
            state) && // 
            holdsSameJavascriptVariant(state) && // 
            holdsEqualModifiers(state) && // 
            holdsEqualTypeVariables(state) && // 
            holdsSinglePolyfillSource(state))) {
                return false;
            }
        }
    }
    // ยง 140.1 only polyfills are allowed in StaticPolyfillModule.
    if (!isStaticPolyFill && isContainedInStaticPolyfillModule(n4Class)) {
        // n4Class is toplevel by default
        validator.addIssue(getMessageForPOLY_STATIC_POLYFILL_MODULE_ONLY_FILLING_CLASSES(), n4Class, N4_TYPE_DECLARATION__NAME, POLY_STATIC_POLYFILL_MODULE_ONLY_FILLING_CLASSES);
        return false;
    }
    return true;
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) Type(org.eclipse.n4js.ts.types.Type) TClass(org.eclipse.n4js.ts.types.TClass)

Example 4 with Type

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

the class InferenceContext method containsInterestingLowerBound.

private boolean containsInterestingLowerBound(TypeRef[] typeRefs) {
    final Type undefinedType = RuleEnvironmentExtensions.undefinedType(G);
    final Type nullType = RuleEnvironmentExtensions.nullType(G);
    for (int i = 0; i < typeRefs.length; i++) {
        final TypeRef curr = typeRefs[i];
        if (curr instanceof ParameterizedTypeRef) {
            // for ParameterizedTypeRefs, it depends on the declared type:
            final Type currDeclType = curr.getDeclaredType();
            if (currDeclType != null && currDeclType != undefinedType && currDeclType != nullType) {
                // wow, that bound is interesting!
                return true;
            }
        } else {
            // all non-ParameterizedTypeRefs are interesting, except UnknownTypeRef:
            if (!(curr instanceof UnknownTypeRef)) {
                // wow, that bound looks intriguing!
                return true;
            }
        }
    }
    // no interesting bounds encountered
    return false;
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) Type(org.eclipse.n4js.ts.types.Type) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)

Example 5 with Type

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

the class VisibilityAwareTypeScope method isAccepted.

@Override
protected boolean isAccepted(IEObjectDescription description) {
    EObject proxyOrInstance = description.getEObjectOrProxy();
    if (proxyOrInstance instanceof Type) {
        Type type = (Type) proxyOrInstance;
        if (type.eIsProxy() && contextResource != null) {
            // we found a proxy. Only valid precondition for a proxy that was returned from a
            // UserDataAwareScope is that the resource that contains the real instance is already
            // available in the resource set and loaded.
            // thus it's save to use resourceSet.getEObject(uri, false) and it has to return a proper instance
            // 
            ResourceSet resourceSet = contextResource.getResourceSet();
            // don't load on demand
            EObject fromResourceSet = resourceSet.getEObject(description.getEObjectURI(), false);
            if (fromResourceSet instanceof Type) {
                type = (Type) fromResourceSet;
            } else {
                // assume the unresolved proxy to be visible to reduce number of follow-up problems.
                return true;
            }
        }
        // paranoid double check - object from resource set should never be a proxy
        if (!type.eIsProxy()) {
            TypeVisibility typeVisibility = checker.isVisible(contextResource, type);
            if (typeVisibility.visibility) {
                accessModifierSuggestionStore.put(description.getEObjectURI().toString(), typeVisibility.accessModifierSuggestion);
            }
            return typeVisibility.visibility;
        } else {
            throw new IllegalStateException("Unexpected proxy:" + type);
        }
    }
    return true;
}
Also used : Type(org.eclipse.n4js.ts.types.Type) TypeVisibility(org.eclipse.n4js.scoping.accessModifiers.AbstractTypeVisibilityChecker.TypeVisibility) EObject(org.eclipse.emf.ecore.EObject) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Aggregations

Type (org.eclipse.n4js.ts.types.Type)84 ContainerType (org.eclipse.n4js.ts.types.ContainerType)32 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)28 TStructuralType (org.eclipse.n4js.ts.types.TStructuralType)26 EObject (org.eclipse.emf.ecore.EObject)21 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)21 PrimitiveType (org.eclipse.n4js.ts.types.PrimitiveType)19 AnyType (org.eclipse.n4js.ts.types.AnyType)18 UndefinedType (org.eclipse.n4js.ts.types.UndefinedType)18 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)17 NullType (org.eclipse.n4js.ts.types.NullType)17 VoidType (org.eclipse.n4js.ts.types.VoidType)17 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)16 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)16 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)16 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)16 ModuleNamespaceVirtualType (org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType)16 StructuralTypingResult (org.eclipse.n4js.typesystem.StructuralTypingResult)16 Result (org.eclipse.xsemantics.runtime.Result)16 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)15