use of org.eclipse.n4js.ts.types.TInterface in project n4js by eclipse.
the class ScriptApiTracker method computeMissingApiFields.
/**
* Computes the list of virtual AccessorTuples for missing static fields on Interfaces
*
* @return List of {@link VirtualApiTField}
*/
private List<AccessorTuple> computeMissingApiFields(TInterface declaration) {
Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(declaration.eResource());
if (optAdapt.isPresent()) {
ProjectComparisonAdapter projectComparisonAdapter = optAdapt.get();
ProjectComparisonEntry compareEntry = projectComparisonAdapter.getEntryFor(EcoreUtil2.getContainerOfType(declaration, TModule.class));
ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(declaration);
if (typeCompare != null) {
ArrayList<AccessorTuple> collectedMissingFields = new ArrayList<>();
Predicate<ProjectComparisonEntry> filter = (pce -> pce.getElementAPI() instanceof TField);
filter = filter.and(pce -> pce.getElementImpl()[0] == null).and(pce -> PROVIDES_INITIALZER.hasAnnotation((TField) pce.getElementAPI()));
Function<TInterface, Consumer<? super ProjectComparisonEntry>> actionProvider = pivot -> pce -> {
TField apiField = ((TField) pce.getElementAPI());
VirtualApiMissingFieldAccessorTuple ret = createVirtFieldAccessorTuple(apiField);
collectedMissingFields.add(ret);
};
if (!checkInterfaceImplementsInterface(declaration, typeCompare.getElementAPI())) {
return emptyList();
}
// Call the supertype iterations scaffolding:
interfaceApiSupertypeWalker(filter, actionProvider, projectComparisonAdapter, (TInterface) typeCompare.getElementAPI(), TInterface.class);
return collectedMissingFields;
}
}
return emptyList();
}
use of org.eclipse.n4js.ts.types.TInterface in project n4js by eclipse.
the class TMemberWithAccessModifierImpl method getMemberAccessModifier.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public MemberAccessModifier getMemberAccessModifier() {
MemberAccessModifier _declaredMemberAccessModifier = this.getDeclaredMemberAccessModifier();
boolean _tripleEquals = (_declaredMemberAccessModifier == MemberAccessModifier.UNDEFINED);
if (_tripleEquals) {
final EObject parent = this.eContainer();
if ((parent instanceof TInterface)) {
final MemberAccessModifier modifierDerivedFromType = AccessModifiers.toMemberModifier(((Type) parent).getTypeAccessModifier());
if ((modifierDerivedFromType != MemberAccessModifier.PRIVATE)) {
return modifierDerivedFromType;
}
}
return MemberAccessModifier.PROJECT;
}
return this.getDeclaredMemberAccessModifier();
}
use of org.eclipse.n4js.ts.types.TInterface in project n4js by eclipse.
the class ConsumptionUtils method findInterfaceDefiningConsumedMember.
/**
* Returns the directly consumed (or otherwise inherited) classifier which indirectly provides the consumed member
* (or null, if interface is found). Usually the returned classifier is a TInterface.
*
* @param consumingClassifier
* the consuming classifier
* @param consumedMember
* the member consumed by the classifier
*/
public static TClassifier findInterfaceDefiningConsumedMember(TClassifier consumingClassifier, TMember consumedMember) {
if (consumedMember == null || !(consumedMember.eContainer() instanceof TInterface)) {
return null;
}
TInterface tinterface = (TInterface) consumedMember.eContainer();
List<TClassifier> path = findPathToInterface(consumingClassifier, tinterface);
if (path.isEmpty()) {
return null;
}
return path.get(0);
}
use of org.eclipse.n4js.ts.types.TInterface 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.TInterface 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