use of org.eclipse.n4js.ts.types.TClass in project n4js by eclipse.
the class TestDiscoveryHelper method collectSuitsForModule.
private Collection<TestSuite> collectSuitsForModule(final TModule module) {
final List<TestSuite> suites = newArrayList();
// Collect all top level non-abstract exported classes, exclude everything else.
for (final TClass clazz : from(module.getTopLevelTypes()).filter(TClass.class).filter(c -> !c.isAbstract() && c.isExported())) {
final TestSuite testSuite = new TestSuite(getClassName(clazz));
for (final TMethod method : getAllTestMethodsOfClass(clazz)) {
final TestCase testCase = createTestCase(method, module, getClassName(clazz));
testSuite.add(testCase);
}
if (!isEmpty(testSuite)) {
suites.add(testSuite);
}
}
return suites;
}
use of org.eclipse.n4js.ts.types.TClass 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.ts.types.TClass in project n4js by eclipse.
the class TClassImpl method getSuperClass.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TClass getSuperClass() {
ParameterizedTypeRef _superClassRef = this.getSuperClassRef();
Type _declaredType = null;
if (_superClassRef != null) {
_declaredType = _superClassRef.getDeclaredType();
}
final Type superType = _declaredType;
TClass _xifexpression = null;
if ((superType instanceof TClass)) {
_xifexpression = ((TClass) superType);
} else {
_xifexpression = null;
}
return _xifexpression;
}
use of org.eclipse.n4js.ts.types.TClass in project n4js by eclipse.
the class TypeUtils method isRawSuperType.
private static boolean isRawSuperType(Type type, Type superTypeCandidate, RecursionGuard<Type> guard) {
if (type == superTypeCandidate) {
return true;
}
if (type == null) {
return false;
}
if (guard.tryNext(type)) {
if (type instanceof TClass) {
final TClass c = (TClass) type;
if (isRawSuperType(c.getSuperClassRef(), superTypeCandidate, guard)) {
return true;
}
if (isRawSuperType(c.getImplementedInterfaceRefs(), superTypeCandidate, guard)) {
return true;
}
return false;
}
if (type instanceof TInterface) {
final TInterface r = (TInterface) type;
if (isRawSuperType(r.getSuperInterfaceRefs(), superTypeCandidate, guard)) {
return true;
}
return false;
}
if (type instanceof TypeVariable) {
TypeVariable v = (TypeVariable) type;
TypeRef ub = v.getDeclaredUpperBound();
if (ub != null && isRawSuperType(ub, superTypeCandidate, guard)) {
return true;
}
return false;
}
if (type instanceof PrimitiveType) {
PrimitiveType assignmentCompatible = ((PrimitiveType) type).getAssignmentCompatible();
if (isRawSuperType(assignmentCompatible, superTypeCandidate, guard)) {
return true;
}
}
}
return false;
}
use of org.eclipse.n4js.ts.types.TClass in project n4js by eclipse.
the class TypeUtils method declaredSuperTypes.
/**
* Convenience method, returns directly declared super types (class, role, interface) of a classifier. May return an
* empty list but never null. Order is always super class, super roles, super interfaces. For all non-classifiers
* this method returns an empty list.
*/
@SuppressWarnings("unchecked")
public static Iterable<? extends ParameterizedTypeRef> declaredSuperTypes(final Type type) {
if (type instanceof TClass) {
final TClass c = (TClass) type;
if (c.getSuperClassRef() != null) {
return Iterables.concat(concat(singletonList(c.getSuperClassRef()), c.getImplementedInterfaceRefs()));
} else {
return c.getImplementedInterfaceRefs();
}
}
if (type instanceof TInterface) {
final TInterface r = (TInterface) type;
return r.getSuperInterfaceRefs();
}
if (type instanceof PrimitiveType) {
PrimitiveType assignmentCompatible = ((PrimitiveType) type).getAssignmentCompatible();
if (assignmentCompatible != null) {
ParameterizedTypeRef typeRef = TypeRefsFactory.eINSTANCE.createParameterizedTypeRef();
typeRef.setDeclaredType(assignmentCompatible);
return Collections.singletonList(typeRef);
}
}
if (type instanceof TObjectPrototype) {
// IDE-1221 string based enums: traversing super types for object prototypes as well
TObjectPrototype tObjectPrototype = (TObjectPrototype) type;
if (tObjectPrototype.getSuperType() != null) {
return singletonList(tObjectPrototype.getSuperType());
}
}
return Collections.emptyList();
}
Aggregations