Search in sources :

Example 11 with TMember

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

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

the class ComposedMemberFactory method create.

@Override
public TMember create(String name) {
    if (specialMemberFactory == null)
        return null;
    TMember composedMember = specialMemberFactory.create(name);
    composedMember.getConstituentMembers().addAll(getConstituentMembers());
    return composedMember;
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember)

Example 13 with TMember

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

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

Example 15 with TMember

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

the class N4JSReferenceQueryExecutor method getInheritedAndImplementedMembers.

private List<TMember> getInheritedAndImplementedMembers(TMember tmember) {
    List<TMember> ret = new ArrayList<>();
    MemberMatrix mm = getMemberMatrix(tmember);
    if (mm != null) {
        for (TMember member : mm.inherited()) {
            ret.add(member);
        }
        for (TMember member : mm.implemented()) {
            ret.add(member);
        }
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) MemberMatrix(org.eclipse.n4js.validation.validators.utils.MemberMatrix) TMember(org.eclipse.n4js.ts.types.TMember)

Aggregations

TMember (org.eclipse.n4js.ts.types.TMember)65 EObject (org.eclipse.emf.ecore.EObject)19 TClassifier (org.eclipse.n4js.ts.types.TClassifier)13 Type (org.eclipse.n4js.ts.types.Type)13 ContainerType (org.eclipse.n4js.ts.types.ContainerType)11 ArrayList (java.util.ArrayList)10 TClass (org.eclipse.n4js.ts.types.TClass)10 TField (org.eclipse.n4js.ts.types.TField)10 TMethod (org.eclipse.n4js.ts.types.TMethod)9 TModule (org.eclipse.n4js.ts.types.TModule)9 MemberList (org.eclipse.n4js.ts.types.util.MemberList)9 RuleEnvironment (org.eclipse.xsemantics.runtime.RuleEnvironment)9 HashSet (java.util.HashSet)8 HashMap (java.util.HashMap)7 NameStaticPair (org.eclipse.n4js.ts.types.util.NameStaticPair)7 MemberCollector (org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector)7 Optional (java.util.Optional)6 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)6 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)6 Inject (com.google.inject.Inject)5