use of org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector in project n4js by eclipse.
the class MissingApiMembersForTranspiler method create.
/**
* Returns a tuple of collections used by transpiler to generate interface or class members.
*/
public static MissingApiMembersForTranspiler create(ContainerTypesHelper containerTypesHelper, ScriptApiTracker apiTracker, TClassifier type, ConcreteMembersOrderedForTranspiler cmoft, Script context) {
MemberCollector collector = containerTypesHelper.fromContext(context);
// IDE-1510 create missing API-methods here.
MemberList<TMethod> missingApiMethods = new MemberList<>();
if (type instanceof TClass) {
List<TMethod> c = apiTracker.computeMissingApiMethods((TClass) type, context);
missingApiMethods.addAll(c);
List<VirtualApiTMethod> missingAPIfromInheritance = apiTracker.computeMethodDiff((TClass) type, collector, cmoft.ownedAndMixedInConcreteMembers, missingApiMethods);
missingApiMethods.addAll(missingAPIfromInheritance);
}
if (type instanceof TInterface) {
List<TMethod> c = apiTracker.computeMissingApiMethods((TInterface) type, context);
missingApiMethods.addAll(c);
}
// IDE-1510 create missing API-fields here.
List<AccessorTuple> missingApiAccessorTuples = new ArrayList<>();
{
List<AccessorTuple> computedMissingApiGetterSetter = apiTracker.computeMissingApiGetterSetter((TN4Classifier) type, cmoft.concreteAccessorTuples);
List<AccessorTuple> computedMissingApiFields = apiTracker.computeMissingApiFields((TN4Classifier) type);
// In case of field vs. getter the implementation should be free to choose the form.
// So filter out all missing set/get pairs which are backed by a field (either concrete or inherited)
List<AccessorTuple> filteredMissingApiGetterSetter = filterOutTuplesImplementedByField(computedMissingApiGetterSetter, cmoft.ownedAndMixedInConcreteMembers, cmoft.concreteInheritedMembers);
// Some logic applies to missing fields which are backed by a getter/setter. The situation here is a
// little bit more complex as the set/get must be processed as a pair and one could be missing or they stem
// from different (super-)types.
// *Beware* not side-effect free since we have to mix in virtual getter/setter into an existing but
// incomplete accessor-pairs
List<AccessorTuple> filteredMissingApiFields0 = filterMissingApiFieldsAndEnrichExistingTuples(computedMissingApiFields, cmoft.concreteAccessorTuples);
List<AccessorTuple> filteredMissingApiFields = filterMissingApiFieldsImplementedBySuperGetSet(filteredMissingApiFields0, cmoft.concreteInheritedMembers);
missingApiAccessorTuples.addAll(filteredMissingApiGetterSetter);
missingApiAccessorTuples.addAll(filteredMissingApiFields);
}
MemberList<TField> fieldsOverridingAccessors = getFieldsOverridingAccessor(cmoft.ownedAndMixedInConcreteMembers, cmoft.concreteInheritedMembers);
// compute the list of mixed in fields, which do not override any Accessor (handled separately)
MemberList<TField> fieldsPurelyMixedInNotOverridingAccessor = new MemberList<>();
fieldsPurelyMixedInNotOverridingAccessor.addAll(cmoft.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 MissingApiMembersForTranspiler(missingApiMethods, missingApiAccessorTuples);
}
use of org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method addIssueToMemberOrInterfaceReference.
private void addIssueToMemberOrInterfaceReference(RedefinitionType redefinitionType, TMember overriding, TMember implemented, String message, String issueCode, String... issueData) {
if (redefinitionType == RedefinitionType.overridden && overriding.getContainingType() != getCurrentClassifier()) {
throw new IllegalStateException("must not happen as member is not consumed");
}
TClassifier currentClassifier = getCurrentClassifier();
if (overriding.getContainingType() == currentClassifier) {
addIssue(message, overriding.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, issueCode, issueData);
} else {
MemberCollector memberCollector = containerTypesHelper.fromContext(getCurrentClassifierDefinition());
ContainerType<?> bequestingType = memberCollector.directSuperTypeBequestingMember(currentClassifier, implemented);
Optional<ParameterizedTypeRef> optRef = StreamSupport.stream(getCurrentClassifierDefinition().getImplementedOrExtendedInterfaceRefs().spliterator(), false).filter(ref -> ref.getDeclaredType() == bequestingType).findAny();
ParameterizedTypeRef ref = optRef.get();
EStructuralFeature feature = ref.eContainingFeature();
List<?> list = (List<?>) getCurrentClassifierDefinition().eGet(feature);
int index = list.indexOf(ref);
addIssue(message, getCurrentClassifierDefinition(), feature, index, issueCode, issueData);
}
}
use of org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector in project n4js by eclipse.
the class N4JSDReader method getRefMember.
// TODO fqn of getter vs setter, fqn of static vs instance
private TMember getRefMember(ContainerType<?> ct, FullMemberReference ref) {
TMember member = null;
String memberName = ref.getMemberName();
boolean _static = ref.isStaticMember();
MemberCollector memberCollector = containerTypesHelper.fromContext(ct);
member = memberCollector.findMember(ct, memberName, false, _static);
if (member == null) {
member = memberCollector.findMember(ct, memberName, false, !_static);
if (member == null) {
member = memberCollector.findMember(ct, memberName, true, _static);
if (member == null) {
member = memberCollector.findMember(ct, memberName, true, !_static);
}
}
}
return member;
}
Aggregations