private boolean isNewifyCandidate(MethodCallExpression mce) { return mce.getObjectExpression() == VariableExpression.THIS_EXPRESSION || (auto && isNewMethodStyle(mce)); }
private static boolean usesSuper(MethodCallExpression call) { Expression expression = call.getObjectExpression(); if (expression instanceof VariableExpression) { VariableExpression varExp = (VariableExpression) expression; String variable = varExp.getName(); return variable.equals("super"); } return false; }
private static boolean checkIsBuiltInMethodCall(MethodCallExpression expr) { if (!AstUtil.isThisOrSuperExpression(expr.getObjectExpression())) return false; return Identifiers.BUILT_IN_METHODS.contains(expr.getMethodAsString()); }
private static boolean isNewMethodStyle(MethodCallExpression mce) { final Expression obj = mce.getObjectExpression(); final Expression meth = mce.getMethod(); return (obj instanceof ClassExpression && meth instanceof ConstantExpression && ((ConstantExpression) meth).getValue().equals("new")); }
private Expression unrecord(Expression expr) { if (!(expr instanceof MethodCallExpression)) return expr; MethodCallExpression methodExpr = (MethodCallExpression) expr; Expression targetExpr = methodExpr.getObjectExpression(); if (!(targetExpr instanceof VariableExpression)) return expr; VariableExpression var = (VariableExpression)targetExpr; if (!SpockNames.VALUE_RECORDER.equals(var.getName())) return expr; if(!ValueRecorder.RECORD.equals(methodExpr.getMethodAsString())) return expr; return ((ArgumentListExpression)methodExpr.getArguments()).getExpression(1); }
@Override public void visitMethodCallExpression(MethodCallExpression call) { Expression objectExpression = call.getObjectExpression(); if (objectExpression instanceof VariableExpression) { rewriteMethodObject(call, (VariableExpression)objectExpression); } else if (objectExpression instanceof ClassExpression) { rewriteArgumentList(call, (ClassExpression)objectExpression); } super.visitMethodCallExpression(call); }
private static boolean checkIsConditionBlock(MethodCallExpression methodCallExpr) { ClassNode targetType = methodCallExpr.getObjectExpression().getType(); String methodName = methodCallExpr.getMethodAsString(); List<MethodNode> methods = targetType.getMethods(methodName); for (MethodNode method : methods) { for (AnnotationNode annotation : method.getAnnotations()) { if (annotation.getClassNode().getName().equals(ConditionBlock.class.getName())) return true; } } return false; } }
public void visitMethodCallExpression(final MethodCallExpression call) { assertExpressionAuthorized(call); Expression receiver = call.getObjectExpression(); final String typeName = receiver.getType().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 + "]"); } receiver.visit(this); final Expression method = call.getMethod(); checkConstantTypeIfNotMethodNameOrProperty(method); call.getArguments().visit(this); }
@Override public void visitMethodCallExpression(MethodCallExpression call) { Expression objectExpression = call.getObjectExpression(); if (objectExpression instanceof VariableExpression) { VariableExpression ve = (VariableExpression) objectExpression; if (ve.isThisExpression()) { addError("Can't access instance method '" + call.getMethodAsString() + "' for a constructor parameter default value", param); return; } } super.visitMethodCallExpression(call); }
private int extractVariableNumber(Expression expr){ if (!(expr instanceof MethodCallExpression)) return -1; MethodCallExpression methodExpr = (MethodCallExpression) expr; Expression targetExpr = methodExpr.getObjectExpression(); if (!(targetExpr instanceof VariableExpression)) return -1; VariableExpression var = (VariableExpression)targetExpr; if (!SpockNames.VALUE_RECORDER.equals(var.getName())) return -1; if(!ValueRecorder.RECORD.equals(methodExpr.getMethodAsString())) return -1; Expression startRecordingEpr = ((ArgumentListExpression) methodExpr.getArguments()).getExpression(0); if (!(startRecordingEpr instanceof MethodCallExpression)) return -1; MethodCallExpression startRecording = (MethodCallExpression) startRecordingEpr; if (!ValueRecorder.START_RECORDING_VALUE.equals(startRecording.getMethodAsString())) return -1; final Expression variableNumExpression = ((ArgumentListExpression) startRecording.getArguments()).getExpression(0); if (! (variableNumExpression instanceof ConstantExpression)) return -1; return (Integer)((ConstantExpression)variableNumExpression).getValue(); }
private boolean isStaticInvocation(MethodCallExpression call) { if (!AsmClassGenerator.isThisExpression(call.getObjectExpression())) return false; if (controller.isStaticMethod()) return true; return controller.isStaticContext() && !call.isImplicitThis(); }
private boolean forbidUseOfSuperInFixtureMethod(MethodCallExpression expr) { Method currMethod = resources.getCurrentMethod(); Expression target = expr.getObjectExpression(); if (currMethod instanceof FixtureMethod && target instanceof VariableExpression && ((VariableExpression)target).isSuperExpression() && currMethod.getName().equals(expr.getMethodAsString())) { resources.getErrorReporter().error(expr, "A base class fixture method should not be called explicitly " + "because it is always invoked automatically by the framework"); return true; } return false; }
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; }
@Override public void visitMethodCallExpression(MethodCallExpression expr) { TextPosition anchor = TextPosition.startOf(expr.getMethod()); List<ExpressionInfo> children = new ArrayList<>(); if (!expr.isImplicitThis()) children.add(convert(expr.getObjectExpression())); children.add(convert(expr.getMethod())); children.add(convert(expr.getArguments())); result = new ExpressionInfo( TextRegion.of(expr), anchor, expr.getMethodAsString(), children); }
public void visitMethodCallExpression(MethodCallExpression call) { call.getObjectExpression().visit(this); call.getMethod().visit(this); call.getArguments().visit(this); }
@Override public void visitMethodCallExpression(MethodCallExpression mce) { if (inSpecialConstructorCall && !isInnerClass(currentMethod.getDeclaringClass())) { Expression objectExpression = mce.getObjectExpression(); if (objectExpression instanceof VariableExpression) { VariableExpression ve = (VariableExpression) objectExpression; if (ve.isThisExpression()) { addError("Can't access instance method '" + mce.getMethodAsString() + "' before the class is constructed", mce); return; } } } super.visitMethodCallExpression(mce); }
@Override public void visitMethodCallExpression(MethodCallExpression expression) { if (expression.getNodeMetaData(StatementMeta.class)!=null) return; super.visitMethodCallExpression(expression); Expression object = expression.getObjectExpression(); boolean setTarget = AsmClassGenerator.isThisExpression(object); if (!setTarget) { if (!(object instanceof ClassExpression)) return; setTarget = object.equals(node); } if (!setTarget) return; setMethodTarget(expression, expression.getMethodAsString(), expression.getArguments(), true); }
@Override public void visitMethodCallExpression(MethodCallExpression expr) { expr.setObjectExpression(replaceExpr(expr.getObjectExpression())); expr.setMethod(replaceExpr(expr.getMethod())); expr.setArguments(replaceExpr(expr.getArguments())); }
private boolean isClosureCall(MethodCallExpression call) { // are we a local variable? // it should not be an explicitly "this" qualified method call // and the current class should have a possible method ClassNode classNode = controller.getClassNode(); String methodName = call.getMethodAsString(); if (methodName==null) return false; if (!call.isImplicitThis()) return false; if (!AsmClassGenerator.isThisExpression(call.getObjectExpression())) return false; FieldNode field = classNode.getDeclaredField(methodName); if (field == null) return false; if (isStaticInvocation(call) && !field.isStatic()) return false; Expression arguments = call.getArguments(); return ! classNode.hasPossibleMethod(methodName, arguments); }
protected Expression transformMethodCallExpression(MethodCallExpression mce) { Expression args = transform(mce.getArguments()); Expression method = transform(mce.getMethod()); Expression object = transform(mce.getObjectExpression()); resolveGenericsTypes(mce.getGenericsTypes()); MethodCallExpression result = new MethodCallExpression(object, method, args); result.setSafe(mce.isSafe()); result.setImplicitThis(mce.isImplicitThis()); result.setSpreadSafe(mce.isSpreadSafe()); result.setSourcePosition(mce); result.setGenericsTypes(mce.getGenericsTypes()); result.setMethodTarget(mce.getMethodTarget()); return result; }