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);
}
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;
}
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);
}
}
}
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);
}
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();
}
Aggregations