use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypePropertyNameValuePair.
protected Result<TypeRef> applyRuleTypePropertyNameValuePair(final RuleEnvironment G, final RuleApplicationTrace _trace_, final PropertyNameValuePair property) throws RuleFailedException {
// output parameter
TypeRef T = null;
TypeRef _declaredTypeRef = property.getDeclaredTypeRef();
boolean _tripleNotEquals = (_declaredTypeRef != null);
if (_tripleNotEquals) {
T = property.getDeclaredTypeRef();
} else {
Expression _expression = property.getExpression();
boolean _tripleNotEquals_1 = (_expression != null);
if (_tripleNotEquals_1) {
/* G |- property.expression: var TypeRef E */
Expression _expression_1 = property.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);
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeBinaryLogicalExpression.
protected Result<TypeRef> applyRuleTypeBinaryLogicalExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final BinaryLogicalExpression e) throws RuleFailedException {
// output parameter
TypeRef T = null;
final Expression lhs = e.getLhs();
final Expression rhs = e.getRhs();
boolean _xifexpression = false;
if ((lhs instanceof ArrayLiteral)) {
_xifexpression = ((ArrayLiteral) lhs).getElements().isEmpty();
}
final boolean lhsIsEmptyArrayLiteral = _xifexpression;
boolean _xifexpression_1 = false;
if ((rhs instanceof ArrayLiteral)) {
_xifexpression_1 = ((ArrayLiteral) rhs).getElements().isEmpty();
}
final boolean rhsIsEmptyArrayLiteral = _xifexpression_1;
/* G |- e.lhs : var TypeRef L */
Expression _lhs = e.getLhs();
TypeRef L = null;
Result<TypeRef> result = typeInternal(G, _trace_, _lhs);
checkAssignableTo(result.getFirst(), TypeRef.class);
L = (TypeRef) result.getFirst();
/* G |- e.rhs : var TypeRef R */
Expression _rhs = e.getRhs();
TypeRef R = null;
Result<TypeRef> result_1 = typeInternal(G, _trace_, _rhs);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
R = (TypeRef) result_1.getFirst();
boolean _and = false;
boolean _lhsIsEmptyArrayLiteral = lhsIsEmptyArrayLiteral;
if (!_lhsIsEmptyArrayLiteral) {
_and = false;
} else {
Type _declaredType = null;
if (R != null) {
_declaredType = R.getDeclaredType();
}
TObjectPrototype _arrayType = RuleEnvironmentExtensions.arrayType(G);
boolean _tripleEquals = (_declaredType == _arrayType);
_and = _tripleEquals;
}
if (_and) {
T = R;
} else {
boolean _and_1 = false;
boolean _rhsIsEmptyArrayLiteral = rhsIsEmptyArrayLiteral;
if (!_rhsIsEmptyArrayLiteral) {
_and_1 = false;
} else {
Type _declaredType_1 = null;
if (L != null) {
_declaredType_1 = L.getDeclaredType();
}
TObjectPrototype _arrayType_1 = RuleEnvironmentExtensions.arrayType(G);
boolean _tripleEquals_1 = (_declaredType_1 == _arrayType_1);
_and_1 = _tripleEquals_1;
}
if (_and_1) {
T = L;
} else {
T = this.typeSystemHelper.createUnionType(G, L, R);
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class ExceptionAnalyser method getScriptErrors.
@Override
protected List<Diagnostic> getScriptErrors(Script script) {
EcoreUtil.resolveAll(script.eResource());
List<Diagnostic> diagnostics = super.getScriptErrors(script);
Iterator<Expression> expressions = Iterators.filter(EcoreUtil2.eAll(script), Expression.class);
List<Diagnostic> result = Lists.<Diagnostic>newArrayList(Iterables.filter(diagnostics, ExceptionDiagnostic.class));
while (expressions.hasNext()) {
Expression expression = expressions.next();
RuleEnvironment ruleEnvironment = RuleEnvironmentExtensions.newRuleEnvironment(expression);
Result<TypeRef> type = typeSystem.type(ruleEnvironment, expression);
if (type.getRuleFailedException() != null) {
Throwable cause = Throwables.getRootCause(type.getRuleFailedException());
if (!(cause instanceof RuleFailedException)) {
if (cause instanceof Exception) {
result.add(new ExceptionDiagnostic((Exception) cause));
} else {
throw new RuntimeException(cause);
}
}
}
}
validator.validate(script.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
return result;
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class IndexedAccessExpressionImpl method basicSetIndex.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetIndex(Expression newIndex, NotificationChain msgs) {
Expression oldIndex = index;
index = newIndex;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, N4JSPackage.INDEXED_ACCESS_EXPRESSION__INDEX, oldIndex, newIndex);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class CastExpressionImpl method basicSetExpression.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetExpression(Expression newExpression, NotificationChain msgs) {
Expression oldExpression = expression;
expression = newExpression;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, N4JSPackage.CAST_EXPRESSION__EXPRESSION, oldExpression, newExpression);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
Aggregations