public String toString() { return super.toString() + "[" + getOwnerType().getName() + "#" + method + " arguments: " + arguments + "]"; }
public void visitStaticMethodCallExpression(final StaticMethodCallExpression call) { assertExpressionAuthorized(call); final String typeName = call.getOwnerType().getName(); if (receiversWhiteList != null && !receiversWhiteList.contains(typeName)) { throw new SecurityException("Method calls not allowed on [" + typeName + "]"); } else if (receiversBlackList != null && receiversBlackList.contains(typeName)) { throw new SecurityException("Method calls not allowed on [" + typeName + "]"); } call.getArguments().visit(this); }
public String getText() { return getOwnerType().getName() + "." + method + arguments.getText(); }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new StaticMethodCallExpression(getOwnerType(), method, transformer.transform(arguments)); ret.setSourcePosition(this); ret.copyNodeMetaData(this); return ret; }
public static Expression getInvocationTarget(Expression expr) { if (expr instanceof PropertyExpression) return ((PropertyExpression) expr).getObjectExpression(); if (expr instanceof MethodCallExpression) return ((MethodCallExpression) expr).getObjectExpression(); if (expr instanceof StaticMethodCallExpression) return new ClassExpression(((StaticMethodCallExpression) expr).getOwnerType()); if (expr instanceof ConstructorCallExpression) return new ClassExpression(((ConstructorCallExpression) expr).getType()); return null; }
public void writeInvokeStaticMethod(StaticMethodCallExpression call) { makeCall(call, new ClassExpression(call.getOwnerType()), new ConstantExpression(call.getMethod()), call.getArguments(), InvocationWriter.invokeStaticMethod, false, false, false); }
private Statement rewriteStaticMethodCondition(StaticMethodCallExpression condition, Expression message, boolean explicit) { StaticMethodCallExpression rewritten; int lastVariableNum; final Expression converted = convert(condition); rewritten = (StaticMethodCallExpression) unrecord(converted); lastVariableNum = extractVariableNumber(converted); List<Expression> args = new ArrayList<>(); args.add(new ClassExpression(rewritten.getOwnerType())); args.add(new ConstantExpression(rewritten.getMethod())); args.add(AstUtil.toArgumentArray(AstUtil.getArgumentList(rewritten), resources)); // rewriting has produced N/A's that haven't been realized yet, so do that now args.add(realizeNas(ConstantExpression.FALSE)); args.add(new ConstantExpression(explicit)); args.add(new ConstantExpression(lastVariableNum)); return surroundWithTryCatch( condition, message, rewriteToSpockRuntimeCall( resources.getAstNodeCache().SpockRuntime_VerifyMethodCondition, condition, message, args)); }
} else if (expression instanceof StaticMethodCallExpression) { StaticMethodCallExpression expr = (StaticMethodCallExpression) expression; final String typename = expr.getOwnerType().getName(); assertImportIsAllowed(typename); assertStaticImportIsAllowed(expr.getMethod(), typename);
@Override public void visitStaticMethodCallExpression(StaticMethodCallExpression expr) { StaticMethodCallExpression result = new StaticMethodCallExpression( expr.getOwnerType(), expr.getMethod(), replaceExpr(expr.getArguments())); result.setType(expr.getType()); result.setSourcePosition(expr); replaceVisitedExpressionWith(result); }
@Override public void visitStaticMethodCallExpression(StaticMethodCallExpression expr) { StaticMethodCallExpression conversion = new StaticMethodCallExpression( expr.getOwnerType(), recordNa(expr.getMethod()), convert(expr.getArguments())); conversion.setSourcePosition(expr); conversion.setMetaMethod(expr.getMetaMethod()); result = record(conversion); }
/** * Given a method call, first checks that it's a static method call, and if it is, returns the * class node for the receiver. For example, with the following code: * <code></code>Person.findAll { ... }</code>, it would return the class node for <i>Person</i>. * If it's not a static method call, returns null. * @param call a method call * @return null if it's not a static method call, or the class node for the receiver instead. */ public ClassNode extractStaticReceiver(MethodCall call) { if (call instanceof StaticMethodCallExpression) { return ((StaticMethodCallExpression) call).getOwnerType(); } else if (call instanceof MethodCallExpression) { Expression objectExpr = ((MethodCallExpression) call).getObjectExpression(); if (objectExpr instanceof ClassExpression && ClassHelper.CLASS_Type.equals(objectExpr.getType())) { GenericsType[] genericsTypes = objectExpr.getType().getGenericsTypes(); if (genericsTypes!=null && genericsTypes.length==1) { return genericsTypes[0].getType(); } } if (objectExpr instanceof ClassExpression) { return objectExpr.getType(); } } return null; }
Expression transformStaticMethodCallExpression(final StaticMethodCallExpression orig) { MethodNode target = (MethodNode) orig.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); if (target != null) { MethodCallExpression call = new MethodCallExpression( new ClassExpression(orig.getOwnerType()), orig.getMethod(), orig.getArguments() ); call.setMethodTarget(target); call.setSourcePosition(orig); call.copyNodeMetaData(orig); return transformer.transform(call); } return transformer.superTransform(orig); }
final ClassNode receiver = call.getOwnerType(); visitMethodCallArguments(receiver, argumentList, false, null);
protected Expression transformBinaryExpression(BinaryExpression be) { int type = be.getOperation().getType(); boolean oldInLeftExpression; Expression right = transform(be.getRightExpression()); be.setRightExpression(right); Expression left; if (type == Types.EQUAL && be.getLeftExpression() instanceof VariableExpression) { oldInLeftExpression = inLeftExpression; inLeftExpression = true; left = transform(be.getLeftExpression()); inLeftExpression = oldInLeftExpression; if (left instanceof StaticMethodCallExpression) { StaticMethodCallExpression smce = (StaticMethodCallExpression) left; StaticMethodCallExpression result = new StaticMethodCallExpression(smce.getOwnerType(), smce.getMethod(), right); setSourcePosition(result, be); return result; } } else { left = transform(be.getLeftExpression()); } be.setLeftExpression(left); return be; }
} else if (exp instanceof StaticMethodCallExpression) { StaticMethodCallExpression call = (StaticMethodCallExpression) exp; ClassNode ownerType = call.getOwnerType(); if (traitClass.equals(ownerType)) { MethodCallExpression result = new MethodCallExpression(
public void visitStaticMethodCallExpression(StaticMethodCallExpression call) { onLineNumber(call, "visitStaticMethodCallExpression: \"" + call.getMethod() + "\":"); makeCall( new ClassExpression(call.getOwnerType()), new ConstantExpression(call.getMethod()), call.getArguments(), invokeStaticMethod, false, false, false); }
@Override public void run() { loc(exp); literal(exp.getOwnerType()); literal(exp.getMethod()); visit(((TupleExpression) exp.getArguments()).getExpressions()); } });
public void visitStaticMethodCallExpression(StaticMethodCallExpression call) { onLineNumber(call, "visitStaticMethodCallExpression: \"" + call.getMethod() + "\":"); makeCall( new ClassExpression(call.getOwnerType()), new ConstantExpression(call.getMethod()), call.getArguments(), invokeStaticMethod, false, false, false); }
public void visitStaticMethodCallExpression(StaticMethodCallExpression call) { onLineNumber(call, "visitStaticMethodCallExpression: \"" + call.getMethod() + "\":"); makeCall( new ClassExpression(call.getOwnerType()), new ConstantExpression(call.getMethod()), call.getArguments(), invokeStaticMethod, false, false, false); }
@Override public void visitStaticMethodCallExpression(StaticMethodCallExpression expr) { StaticMethodCallExpression result = new StaticMethodCallExpression( expr.getOwnerType(), expr.getMethod(), replaceExpr(expr.getArguments())); result.setType(expr.getType()); result.setSourcePosition(expr); replaceVisitedExpressionWith(result); }