Search in sources :

Example 1 with MemberCollector

use of org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector 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 MemberCollector

use of org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector 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 3 with MemberCollector

use of org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector in project n4js by eclipse.

the class JSDoc2ADocSpecProcessor method addMembers.

/**
 * This method iterates through all members of a N4JS type and creates corresponding {@link SpecFile}s from them.
 * During this process, member tests are linked if available.
 */
private void addMembers(SpecInfo specInfo, TN4Classifier classifier, Map<String, SpecSection> specsByKey, TreeMap<String, SpecFile> specChangeSet) {
    MemberCollector memberCollector = containerTypesHelper.fromContext(classifier);
    MemberList<TMember> memberList = memberCollector.allMembers(classifier, false, false, false);
    Stream<TMember> nonPrivMembs = memberList.stream().filter(isNonPrivate());
    // add spec region for new members
    for (TMember member : (Iterable<TMember>) nonPrivMembs::iterator) {
        SpecSection specSection = new SpecIdentifiableElementSection(specInfo, member, rootDir, repoPathHolder);
        if (!specsByKey.containsKey(specSection.getSpecKey())) {
            specSection.setTestInfosForMember(specInfo.getTestsForMember(member));
            insertIntoSpecModuleFile(specChangeSet, specsByKey, (SpecIdentifiableElementSection) specSection);
        }
    }
}
Also used : MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector) TMember(org.eclipse.n4js.ts.types.TMember)

Example 4 with MemberCollector

use of org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector in project n4js by eclipse.

the class ConcreteMembersOrderedForTranspiler method create.

/**
 * Returns a tuple of collections used by transpiler to generate interface or class members.
 */
public static ConcreteMembersOrderedForTranspiler create(ContainerTypesHelper containerTypesHelper, TClassifier type, Script context) {
    MemberCollector collector = containerTypesHelper.fromContext(context);
    List<TMember> concreteInheritedMembers = (type instanceof TClass) ? collector.inheritedMembers((TClass) type) : emptyList();
    List<TMember> ownedAndMixedInConcreteMembers = collector.computeOwnedAndMixedInConcreteMembers(type);
    List<AccessorTuple> concreteAccessorTuples = getConcreteFieldAccessors(ownedAndMixedInConcreteMembers, concreteInheritedMembers);
    MemberList<TField> fieldsOverridingAccessors = getFieldsOverridingAccessor(ownedAndMixedInConcreteMembers, concreteInheritedMembers);
    // compute the list of mixed in fields, which do not override any Accessor (handled separately)
    MemberList<TField> fieldsPurelyMixedInNotOverridingAccessor = new MemberList<>();
    fieldsPurelyMixedInNotOverridingAccessor.addAll(ownedAndMixedInConcreteMembers.stream().filter(it -> it instanceof TField && // must stem from different type
    it.getContainingType() != type).map(it -> (TField) it).filter(// remove the ones overriding get/set
    it -> !fieldsOverridingAccessors.contains(it)).collect(Collectors.toList()));
    return new ConcreteMembersOrderedForTranspiler(concreteInheritedMembers, ownedAndMixedInConcreteMembers, concreteAccessorTuples, fieldsOverridingAccessors, fieldsPurelyMixedInNotOverridingAccessor);
}
Also used : Collections.emptyList(java.util.Collections.emptyList) TField(org.eclipse.n4js.ts.types.TField) Set(java.util.Set) TMember(org.eclipse.n4js.ts.types.TMember) HashMap(java.util.HashMap) Script(org.eclipse.n4js.n4JS.Script) TClass(org.eclipse.n4js.ts.types.TClass) AccessorTuple(org.eclipse.n4js.ts.types.util.AccessorTuple) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TSetter(org.eclipse.n4js.ts.types.TSetter) NameStaticPair(org.eclipse.n4js.ts.types.util.NameStaticPair) HashSet(java.util.HashSet) TGetter(org.eclipse.n4js.ts.types.TGetter) List(java.util.List) ContainerTypesHelper(org.eclipse.n4js.utils.ContainerTypesHelper) TClassifier(org.eclipse.n4js.ts.types.TClassifier) TInterface(org.eclipse.n4js.ts.types.TInterface) Map(java.util.Map) MemberList(org.eclipse.n4js.ts.types.util.MemberList) MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector) TField(org.eclipse.n4js.ts.types.TField) MemberList(org.eclipse.n4js.ts.types.util.MemberList) AccessorTuple(org.eclipse.n4js.ts.types.util.AccessorTuple) MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector) TMember(org.eclipse.n4js.ts.types.TMember) TClass(org.eclipse.n4js.ts.types.TClass)

Example 5 with MemberCollector

use of org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector in project n4js by eclipse.

the class ScriptApiTracker method computeMethodDiff.

/**
 * Find last missing methods, which the implType would have if it would follow the inheritance as defined in the API
 *
 * @param implType
 *            Type of implementation project, calculated from AST
 * @param collector
 *            member collector for the project.
 * @param ownedAndMixedInConcreteMember
 *            already computed for implType
 * @param missingApiMethods2
 *            already computed for implType
 * @return list of virtual Methods
 */
public List<VirtualApiTMethod> computeMethodDiff(TClass implType, MemberCollector collector, List<TMember> ownedAndMixedInConcreteMember, MemberList<TMethod> missingApiMethods2) {
    Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(implType.eResource());
    if (optAdapt.isPresent()) {
        ProjectComparisonEntry compareEntry = optAdapt.get().getEntryFor(EcoreUtil2.getContainerOfType(implType, TModule.class));
        ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(implType);
        if (typeCompare != null && typeCompare.getElementAPI() != null) {
            TClass apiType = (TClass) typeCompare.getElementAPI();
            MemberList<TMember> implMembers = collector.allMembers(implType, false, true);
            MemberList<TMember> apiMembers = collector.allMembers(apiType, false, true);
            final HashSet<String> methodNamesAlreadyDefined = new HashSet<>();
            Stream.concat(implMembers.stream(), Stream.concat(ownedAndMixedInConcreteMember.stream(), missingApiMethods2.stream())).forEach(m -> {
                if (m instanceof TMethod) {
                    methodNamesAlreadyDefined.add(m.getName());
                }
            });
            return apiMembers.stream().filter(t -> t instanceof TMethod).filter(m -> !methodNamesAlreadyDefined.contains(((TMethod) m).getName())).map(m2 -> {
                TMethod m = (TMethod) m2;
                VirtualApiTMethod vMethod = new VirtualApiTMethod(m.getName(), TypeUtils.copyPartial(m, TypesPackage.Literals.SYNTAX_RELATED_TELEMENT__AST_ELEMENT));
                return vMethod;
            }).collect(Collectors.toList());
        }
    }
    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) TMethod(org.eclipse.n4js.ts.types.TMethod) TModule(org.eclipse.n4js.ts.types.TModule) TMember(org.eclipse.n4js.ts.types.TMember) TClass(org.eclipse.n4js.ts.types.TClass) ProjectComparisonEntry(org.eclipse.n4js.compare.ProjectComparisonEntry) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

MemberCollector (org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector)8 TMember (org.eclipse.n4js.ts.types.TMember)7 TClassifier (org.eclipse.n4js.ts.types.TClassifier)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 TClass (org.eclipse.n4js.ts.types.TClass)4 TField (org.eclipse.n4js.ts.types.TField)4 TInterface (org.eclipse.n4js.ts.types.TInterface)4 TSetter (org.eclipse.n4js.ts.types.TSetter)4 MemberList (org.eclipse.n4js.ts.types.util.MemberList)4 ContainerTypesHelper (org.eclipse.n4js.utils.ContainerTypesHelper)4 Inject (com.google.inject.Inject)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 EObject (org.eclipse.emf.ecore.EObject)3 Script (org.eclipse.n4js.n4JS.Script)3 Collections.emptyList (java.util.Collections.emptyList)2 Map (java.util.Map)2