use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class InternalTypeSystem method applyRuleUpperBoundParameterizedTypeRef.
protected Result<TypeRef> applyRuleUpperBoundParameterizedTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ParameterizedTypeRef ptr) throws RuleFailedException {
// output parameter
TypeRef T = null;
Type _declaredType = ptr.getDeclaredType();
if ((_declaredType instanceof TypeVariable)) {
T = ptr;
} else {
T = ptr;
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class MemberRedefinitionUtils method findThisContextForConstructor.
/**
* Returns the context type to be used as this binding (see
* {@link N4JSTypeSystem#createRuleEnvironmentForContext(TypeRef, TypeRef, Resource) here} and
* {@link RuleEnvironmentExtensions#addThisType(RuleEnvironment, TypeRef)} here) for checking constructor
* compatibility.
*
* For example, given the following code
*
* <pre>
* class C1 {
* constructor(@Spec spec: ~i~this) {}
* }
*
* class C2 extends C1 {
* public field2;
* }
*
* @CovariantConstructor
* class C3 extends C2 {
* public field3;
* }
*
* class C4 extends C3 {
* // XPECT noerrors -->
* constructor(@Spec spec: ~i~this) { super(spec); }
* }
* </pre>
*
* When checking constructor compatibility in C4, we have to use class C3 as the 'this' context on right-hand side,
* not class C1, because the addition of fields <code>field2</code> and <code>field3</code> does not break the
* contract of the @CovariantConstructor annotation. Therefore, we cannot simply use the containing type of the
* right-hand side constructor as 'this' context. In the above example, we would call this method with C4 as
* <code>baseContext</code> and C1's constructor as <code>ctor</code> and it would return C3 as the 'this' context
* to use.
*/
public static final Type findThisContextForConstructor(Type baseContext, TMethod ctor) {
final Type ctorContainer = ctor.getContainingType();
if (!(baseContext instanceof TClass) || !(ctorContainer instanceof TClass)) {
return ctorContainer;
}
final TClass ctorContainerCasted = (TClass) ctorContainer;
final TClass baseContextCasted = (TClass) baseContext;
if (N4JSLanguageUtils.hasCovariantConstructor(ctorContainerCasted)) {
return ctorContainerCasted;
}
final List<TClass> superClassesUpToCtorContainer = new ArrayList<>();
for (TClass superClass : new ExtendedClassesIterable(baseContextCasted)) {
if (superClass != ctorContainerCasted) {
superClassesUpToCtorContainer.add(superClass);
} else {
break;
}
}
for (int i = superClassesUpToCtorContainer.size() - 1; i >= 0; i--) {
final TClass superClass = superClassesUpToCtorContainer.get(i);
if (N4JSLanguageUtils.hasCovariantConstructor(superClass)) {
return superClass;
}
}
return baseContext;
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class FunctionDefinitionImpl method setDefinedType.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setDefinedType(Type newDefinedType) {
Type oldDefinedType = definedType;
definedType = newDefinedType;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.FUNCTION_DEFINITION__DEFINED_TYPE, oldDefinedType, definedType));
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class FunctionDefinitionImpl method getDefinedFunction.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TFunction getDefinedFunction() {
final Type defType = this.getDefinedType();
TFunction _xifexpression = null;
if ((defType instanceof TFunction)) {
_xifexpression = ((TFunction) defType);
}
return _xifexpression;
}
use of org.eclipse.n4js.ts.types.Type 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, Map<String, SpecSection> specsByKey, TreeMap<String, SpecFile> specChangeSet) {
IdentifiableElement element = specInfo.specElementRef.identifiableElement;
if (element instanceof TN4Classifier) {
addMembers(specInfo, (TN4Classifier) element, specsByKey, specChangeSet);
Type pfaElement = specInfo.specElementRef.polyfillAware;
if (pfaElement instanceof TN4Classifier) {
addMembers(specInfo, (TN4Classifier) pfaElement, specsByKey, specChangeSet);
}
}
}
Aggregations