use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class TaintedValueAnalyser method isUntaintedAssignee.
boolean isUntaintedAssignee(Symbol symbol, ControlFlowElement cfe) {
if (cfe instanceof AssignmentExpression) {
AssignmentExpression ae = (AssignmentExpression) cfe;
Expression lhs = ae.getLhs();
if (symbol.is(lhs)) {
return assignedSymbolIsAnnotatedWith(symbol, "Untainted");
}
}
return false;
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class PrettyPrinterSwitch method caseArrowFunction.
@Override
public Boolean caseArrowFunction(ArrowFunction original) {
if (original.isAsync()) {
write("async");
}
write('(');
process(original.getFpars(), ", ");
write(')');
processReturnTypeRef(original.getReturnTypeRef());
write("=>");
if (original.isHasBracesAroundBody()) {
process(original.getBody());
} else {
if (!original.isSingleExprImplicitReturn()) {
throw new IllegalStateException("arrow function without braces must be a valid single-expression arrow function");
}
final Expression singleExpr = original.getSingleExpression();
process(singleExpr);
}
return DONE;
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class AccessModifierXpectMethod method calculateActual.
private String calculateActual(EObject context) {
String actual = null;
if (context instanceof TMember) {
TMember tMember = (TMember) context;
actual = tMember.getMemberAccessModifier().getName();
} else {
FunctionDeclaration functionDeclaration = EcoreUtil2.getContainerOfType(context, FunctionDeclaration.class);
if (functionDeclaration != null) {
actual = functionDeclaration.getDefinedType().getTypeAccessModifier().getName();
} else {
VariableStatement variableStatement = EcoreUtil2.getContainerOfType(context, VariableStatement.class);
if (variableStatement != null) {
context = variableStatement.getVarDecl().get(0);
if (context instanceof ExportedVariableDeclaration) {
actual = ((ExportedVariableDeclaration) context).getDefinedVariable().getTypeAccessModifier().getName();
} else if (context instanceof VariableDeclaration) {
actual = "private";
}
} else if (context instanceof ExportDeclaration) {
context = ((ExportDeclaration) context).getExportedElement();
actual = calculateActual(context);
} else if (context instanceof ParameterizedPropertyAccessExpression) {
ParameterizedPropertyAccessExpression ppae = (ParameterizedPropertyAccessExpression) context;
IdentifiableElement ie = ppae.getProperty();
actual = calculateActual(ie);
} else if (context instanceof ParameterizedCallExpression) {
ParameterizedCallExpression pce = (ParameterizedCallExpression) context;
Expression targetExpr = pce.getTarget();
actual = calculateActual(targetExpr);
} else {
N4MemberDeclaration member = EcoreUtil2.getContainerOfType(context, N4MemberDeclaration.class);
N4TypeDeclaration type = EcoreUtil2.getContainerOfType(context, N4TypeDeclaration.class);
if (type == null && member == null) {
actual = "no element with access modifier found";
} else if (type != null && (member == null || EcoreUtil.isAncestor(member, type))) {
actual = type.getDefinedType().getTypeAccessModifier().getName();
} else {
actual = member.getDefinedTypeElement().getMemberAccessModifier().getName();
}
}
}
}
return actual;
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class TypeXpectMethod method getTypeString.
private String getTypeString(IEObjectCoveringRegion offset, boolean expectedType) {
final String calculatedString;
EObject eobject = offset.getEObject();
if (eobject instanceof LiteralOrComputedPropertyName) {
eobject = eobject.eContainer();
}
RuleEnvironment G = newRuleEnvironment(eobject);
Result<org.eclipse.n4js.ts.typeRefs.TypeRef> result;
if (expectedType) {
if (!(eobject instanceof Expression && eobject.eContainer() != null))
return "Not an Expression at given region (required to obtain expected type); got instead: " + eobject.eClass().getName();
result = ts.expectedTypeIn(G, eobject.eContainer(), (Expression) eobject);
} else {
if (eobject instanceof BindingProperty) {
/*-
* Small tweak to allow testing the inferred type of variable declarations within binding patterns. For
* example, without this tweak, the following test would fail with a "Not a TypableElement at given
* region" exception:
*
* // Xpect type of 'len' --> number
* var {length:len} = "hello";
*/
if (((BindingProperty) eobject).getValue() != null && ((BindingProperty) eobject).getValue().getVarDecl() != null) {
eobject = ((BindingProperty) eobject).getValue().getVarDecl();
}
}
if (!(eobject instanceof TypableElement))
return "Not a TypableElement at given region; got instead: " + eobject.eClass().getName();
result = ts.type(G, (TypableElement) eobject);
}
if (result.getRuleFailedException() != null) {
calculatedString = result.getRuleFailedException().getMessage();
} else {
calculatedString = result.getValue().getTypeRefAsString();
}
return calculatedString;
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class AssignmentRelationFactory method findInVariableDeclaration.
private void findInVariableDeclaration(Multimap<Symbol, Object> assgns, VariableDeclaration vd) {
EObject parent = vd.eContainer();
if (parent instanceof ForStatement) {
ForStatement fs = (ForStatement) parent;
if (!fs.isForPlain()) {
findInForStatementInOf(assgns, vd, (ForStatement) parent);
return;
}
}
Expression rhs = vd.getExpression();
if (rhs == null) {
Symbol undefinedSymbol = symbolFactory.getUndefined();
createRelation(assgns, vd, undefinedSymbol, null);
} else {
handleSubexpressions(assgns, vd, rhs);
}
}
Aggregations