Search in sources :

Example 1 with TClassifier

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

the class N4JSMemberRedefinitionValidator method createMemberValidationList.

private MemberCube createMemberValidationList() {
    MemberCollector memberCollector = containerTypesHelper.fromContext(getCurrentClassifierDefinition());
    TClassifier tClassifier = getCurrentClassifier();
    return new MemberCube(tClassifier, memberCollector);
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) MemberCube(org.eclipse.n4js.validation.validators.utils.MemberCube) MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector)

Example 2 with TClassifier

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

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

the class PolyfillValidatorFragment method holdsSinglePolyfillSource.

/**
 * Constraints 129 (Applying Polyfills) No member must be filled by more than one polyfill.
 */
private boolean holdsSinglePolyfillSource(PolyfillValidationState state) {
    EList<TMember> myPolyMember = state.polyType.getOwnedMembers();
    // a) find references to the filled type
    // b) check, that they are in the same Project
    // c) search for clashing contributions.
    XtextResource res = (XtextResource) state.polyType.eResource();
    IResourceDescriptions index = resourceDescriptionsProvider.getResourceDescriptions(res);
    // a+b) all polyfills to same calssifier in same project:
    IContainer container = containerManager.getContainer(res.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res), index);
    // Iterable over all exported Polyfills
    Iterable<IEObjectDescription> iterEObj = container.getExportedObjects(TypesPackage.Literals.TCLASSIFIER, N4TSQualifiedNameProvider.getPolyfillFQN(state.filledType, qualifiedNameProvider), false);
    // collection of involved TModules for each Member.
    ListMultimap<TMember, TModule> clashProviders = LinkedListMultimap.create();
    for (IEObjectDescription pivotObjectDescription : iterEObj) {
        EObject eob = pivotObjectDescription.getEObjectOrProxy();
        // Resolve
        if (eob.eIsProxy()) {
            eob = EcoreUtil.resolve(eob, res);
        }
        if (eob == state.polyType) {
            // saw myself .-.
            continue;
        }
        EList<TMember> pivotPolyMember = ((TClassifier) eob).getOwnedMembers();
        ListMultimap<TMember, TMember> clashing = findClashingMembersByName(myPolyMember, pivotPolyMember);
        for (TMember myMember : clashing.keySet()) {
            // only interested in the module, so first is sufficient
            clashProviders.put(myMember, clashing.get(myMember).get(0).getContainingModule());
        }
    }
    List<TMember> sortedMembers = clashProviders.keySet().stream().sorted().collect(Collectors.toList());
    for (TMember myMember : sortedMembers) {
        // Combine list of Modules involved in the polyfill clash.
        String uris = Stream.concat(Stream.of(myMember.getContainingModule()), clashProviders.get(myMember).stream()).map(u -> u.getQualifiedName().toString()).sorted().reduce("", (a, b) -> a + PREFIX_LIST + b);
        if (uris.startsWith(PREFIX_LIST))
            uris = uris.substring(PREFIX_LIST.length());
        int lastPrefix_idx = uris.lastIndexOf(PREFIX_LIST);
        if (lastPrefix_idx >= 0) {
            StringBuffer sb = new StringBuffer(uris);
            uris = sb.replace(lastPrefix_idx, lastPrefix_idx + PREFIX_LIST.length(), " and ").toString();
        }
        // give Qualified name filled in Property.
        String memberAxis = myMember.getContainingType().getName() + "." + myMember.getName();
        // Issue on filled Member-name declaration:
        String msg = IssueCodes.getMessageForCLF_POLYFILL_MULTIPOLYFILLS_MEMBER_CONFLICT(uris, memberAxis);
        state.host.addIssue(msg, myMember.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, IssueCodes.CLF_POLYFILL_MULTIPOLYFILLS_MEMBER_CONFLICT);
    }
    return true;
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) XtextResource(org.eclipse.xtext.resource.XtextResource) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) EObject(org.eclipse.emf.ecore.EObject) TMember(org.eclipse.n4js.ts.types.TMember) IContainer(org.eclipse.xtext.resource.IContainer) TModule(org.eclipse.n4js.ts.types.TModule)

Example 4 with TClassifier

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

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

the class N4JSReferenceQueryExecutor method getTargetURIs.

/**
 * Here, we add overridden/overriding members or super/subclasses if needed depending on user preferences when
 * finding references.
 */
@Override
protected Iterable<URI> getTargetURIs(EObject primaryTarget) {
    @SuppressWarnings("restriction") Iterable<URI> originalResult = super.getTargetURIs(primaryTarget);
    List<URI> newResult = Lists.newArrayList(originalResult);
    if (primaryTarget instanceof LiteralOrComputedPropertyName) {
        primaryTarget = primaryTarget.eContainer();
    }
    // Handling for various configurations e.g. consider overriden members
    List<EObject> realTargets = new ArrayList<>();
    if (primaryTarget instanceof TMember && ((TMember) primaryTarget).isComposed()) {
        // In case of composed member, add the constituent members instead.
        List<TMember> constituentMembers = ((TMember) primaryTarget).getConstituentMembers();
        for (TMember constituentMember : constituentMembers) {
            realTargets.add(constituentMember);
        }
    } else {
        // Standard case
        realTargets.add(primaryTarget);
    }
    for (EObject realTarget : realTargets) {
        if (N4JSReferenceQueryExecutor.considerOverridenMethods) {
            // Add overriden members
            if (realTarget instanceof N4MemberDeclaration || // Only consider members within a classifier.Ignore TStructMember.
            (realTarget instanceof TMember && realTarget.eContainer() instanceof TClassifier)) {
                TMember tmember;
                if (primaryTarget instanceof N4MemberDeclaration) {
                    tmember = ((N4MemberDeclaration) primaryTarget).getDefinedTypeElement();
                } else {
                    tmember = (TMember) primaryTarget;
                }
                for (TMember inheritedOrImplementedMember : getInheritedAndImplementedMembers(tmember)) {
                    URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(inheritedOrImplementedMember);
                    newResult.add(uri);
                }
            }
        }
    }
    return newResult;
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) LiteralOrComputedPropertyName(org.eclipse.n4js.n4JS.LiteralOrComputedPropertyName) N4MemberDeclaration(org.eclipse.n4js.n4JS.N4MemberDeclaration) TMember(org.eclipse.n4js.ts.types.TMember) URI(org.eclipse.emf.common.util.URI)

Aggregations

TClassifier (org.eclipse.n4js.ts.types.TClassifier)29 TMember (org.eclipse.n4js.ts.types.TMember)12 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)11 EObject (org.eclipse.emf.ecore.EObject)10 Type (org.eclipse.n4js.ts.types.Type)10 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)9 TClass (org.eclipse.n4js.ts.types.TClass)8 ContainerType (org.eclipse.n4js.ts.types.ContainerType)7 TMethod (org.eclipse.n4js.ts.types.TMethod)7 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)6 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)6 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)6 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)6 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)6 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)6 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)6 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)6 TInterface (org.eclipse.n4js.ts.types.TInterface)6 RuleEnvironment (org.eclipse.xsemantics.runtime.RuleEnvironment)6 ArrayList (java.util.ArrayList)5