use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeSuperLiteral.
protected Result<TypeRef> applyRuleTypeSuperLiteral(final RuleEnvironment G, final RuleApplicationTrace _trace_, final SuperLiteral superLiteral) throws RuleFailedException {
// output parameter
TypeRef T = null;
final N4MemberDeclaration containingMemberDecl = EcoreUtil2.<N4MemberDeclaration>getContainerOfType(superLiteral.eContainer(), N4MemberDeclaration.class);
/* if (containingMemberDecl === null) { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } else { val containingClass = (containingMemberDecl.eContainer as N4ClassDeclaration).definedType as TClass; val superClass = G.getDeclaredOrImplicitSuperType(containingClass) var effectiveSuperClass = superClass if( containingClass.isStaticPolyfill ) { effectiveSuperClass = G.getDeclaredOrImplicitSuperType( superClass as TClass ) } { superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression if(containingMemberDecl.static) T = effectiveSuperClass?.createConstructorTypeRef else T = effectiveSuperClass?.createTypeRef if (T !== null) T = TypeUtils.enforceNominalTyping(T) } or { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } } or { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } */
{
RuleFailedException previousFailure = null;
try {
if ((containingMemberDecl == null)) {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
} else {
EObject _eContainer = containingMemberDecl.eContainer();
Type _definedType = ((N4ClassDeclaration) _eContainer).getDefinedType();
final TClass containingClass = ((TClass) _definedType);
final TClassifier superClass = RuleEnvironmentExtensions.getDeclaredOrImplicitSuperType(G, containingClass);
TClassifier effectiveSuperClass = superClass;
boolean _isStaticPolyfill = containingClass.isStaticPolyfill();
if (_isStaticPolyfill) {
effectiveSuperClass = RuleEnvironmentExtensions.getDeclaredOrImplicitSuperType(G, ((TClass) superClass));
}
/* { superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression if(containingMemberDecl.static) T = effectiveSuperClass?.createConstructorTypeRef else T = effectiveSuperClass?.createTypeRef if (T !== null) T = TypeUtils.enforceNominalTyping(T) } or { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } */
{
try {
/* superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression */
if (!((superLiteral.eContainer() instanceof ParameterizedPropertyAccessExpression) || (superLiteral.eContainer() instanceof IndexedAccessExpression))) {
sneakyThrowRuleFailedException("superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression");
}
boolean _isStatic = containingMemberDecl.isStatic();
if (_isStatic) {
TypeRef _createConstructorTypeRef = null;
if (effectiveSuperClass != null) {
_createConstructorTypeRef = TypeUtils.createConstructorTypeRef(effectiveSuperClass);
}
T = _createConstructorTypeRef;
} else {
ParameterizedTypeRef _createTypeRef = null;
if (effectiveSuperClass != null) {
_createTypeRef = TypeUtils.createTypeRef(effectiveSuperClass);
}
T = _createTypeRef;
}
if ((T != null)) {
T = TypeUtils.enforceNominalTyping(T);
}
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
/* { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } */
{
try {
EObject _eContainer_1 = superLiteral.eContainer();
/* superLiteral.eContainer instanceof ParameterizedCallExpression */
if (!(_eContainer_1 instanceof ParameterizedCallExpression)) {
sneakyThrowRuleFailedException("superLiteral.eContainer instanceof ParameterizedCallExpression");
}
if (((containingMemberDecl instanceof N4MethodDeclaration) && Objects.equal(containingMemberDecl.getName(), "constructor"))) {
final TMethod ctor = this.containerTypesHelper.fromContext(superLiteral.eResource()).findConstructor(effectiveSuperClass);
ParameterizedTypeRef _createTypeRef_1 = null;
if (ctor != null) {
_createTypeRef_1 = TypeUtils.createTypeRef(ctor);
}
T = _createTypeRef_1;
} else {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
}
} catch (Exception e_1) {
previousFailure = extractRuleFailedException(e_1);
EObject _eContainer_2 = superLiteral.eContainer();
/* superLiteral.eContainer instanceof NewExpression */
if (!(_eContainer_2 instanceof NewExpression)) {
sneakyThrowRuleFailedException("superLiteral.eContainer instanceof NewExpression");
}
}
}
}
}
}
} catch (Exception e_2) {
previousFailure = extractRuleFailedException(e_2);
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleSubstTypeVariablesWildcard.
protected Result<TypeArgument> applyRuleSubstTypeVariablesWildcard(final RuleEnvironment G, final RuleApplicationTrace _trace_, final Wildcard wildcard) throws RuleFailedException {
// output parameter
Wildcard T = null;
TypeRef ub = wildcard.getDeclaredUpperBound();
if ((ub != null)) {
/* G |- ub ~> ub */
Result<TypeArgument> result = substTypeVariablesInternal(G, _trace_, ub);
checkAssignableTo(result.getFirst(), TypeRef.class);
ub = (TypeRef) result.getFirst();
}
TypeRef lb = wildcard.getDeclaredLowerBound();
if ((lb != null)) {
/* G |- lb ~> lb */
Result<TypeArgument> result_1 = substTypeVariablesInternal(G, _trace_, lb);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
lb = (TypeRef) result_1.getFirst();
}
if (((ub != wildcard.getDeclaredUpperBound()) || (lb != wildcard.getDeclaredLowerBound()))) {
T = TypeUtils.<Wildcard>copy(wildcard);
T.setDeclaredUpperBound(TypeUtils.<TypeRef>copyIfContained(ub));
T.setDeclaredLowerBound(TypeUtils.<TypeRef>copyIfContained(lb));
} else {
T = wildcard;
}
return new Result<TypeArgument>(T);
}
use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.
the class InternalTypeSystem method typeImpl.
protected Result<TypeRef> typeImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final PromisifyExpression e) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<TypeRef> _result_ = applyRuleTypePromisifyExpression(G, _subtrace_, e);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("typePromisifyExpression") + stringRepForEnv(G) + " |- " + stringRep(e) + " : " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleTypePromisifyExpression) {
typeThrowException(ruleName("typePromisifyExpression") + stringRepForEnv(G) + " |- " + stringRep(e) + " : " + "TypeRef", TYPEPROMISIFYEXPRESSION, e_applyRuleTypePromisifyExpression, e, new ErrorInformation[] { new ErrorInformation(e) });
return null;
}
}
use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.
the class InternalTypeSystem method expectedTypeInImpl.
protected Result<TypeRef> expectedTypeInImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final Argument argument, final Expression argumentExpression) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<TypeRef> _result_ = applyRuleExpectedTypeOfArgument(G, _subtrace_, argument, argumentExpression);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("expectedTypeOfArgument") + stringRepForEnv(G) + " |- " + stringRep(argument) + " |> " + stringRep(argumentExpression) + " : " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleExpectedTypeOfArgument) {
expectedTypeInThrowException(ruleName("expectedTypeOfArgument") + stringRepForEnv(G) + " |- " + stringRep(argument) + " |> " + stringRep(argumentExpression) + " : " + "TypeRef", EXPECTEDTYPEOFARGUMENT, e_applyRuleExpectedTypeOfArgument, argument, argumentExpression, new ErrorInformation[] { new ErrorInformation(argument), new ErrorInformation(argumentExpression) });
return null;
}
}
use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeN4FieldDeclaration.
protected Result<TypeRef> applyRuleTypeN4FieldDeclaration(final RuleEnvironment G, final RuleApplicationTrace _trace_, final N4FieldDeclaration fieldDecl) throws RuleFailedException {
// output parameter
TypeRef T = null;
TypeRef _declaredTypeRef = fieldDecl.getDeclaredTypeRef();
boolean _tripleNotEquals = (_declaredTypeRef != null);
if (_tripleNotEquals) {
T = fieldDecl.getDeclaredTypeRef();
} else {
Expression _expression = fieldDecl.getExpression();
boolean _tripleNotEquals_1 = (_expression != null);
if (_tripleNotEquals_1) {
/* G |- fieldDecl.expression : var TypeRef E */
Expression _expression_1 = fieldDecl.getExpression();
TypeRef E = null;
Result<TypeRef> result = typeInternal(G, _trace_, _expression_1);
checkAssignableTo(result.getFirst(), TypeRef.class);
E = (TypeRef) result.getFirst();
/* G |~ E /\ E */
Result<TypeRef> result_1 = upperBoundInternal(G, _trace_, E);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
E = (TypeRef) result_1.getFirst();
if ((((E.getDeclaredType() == RuleEnvironmentExtensions.undefinedType(G)) || (E.getDeclaredType() == RuleEnvironmentExtensions.nullType(G))) || (E.getDeclaredType() == RuleEnvironmentExtensions.voidType(G)))) {
T = RuleEnvironmentExtensions.anyTypeRef(G);
} else {
T = E;
}
} else {
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
}
return new Result<TypeRef>(T);
}
Aggregations