Java Code Examples for org.codehaus.groovy.ast.expr.MethodCallExpression#isImplicitThis()
The following examples show how to use
org.codehaus.groovy.ast.expr.MethodCallExpression#isImplicitThis() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoNewLineTransformer.java From groovy with Apache License 2.0 | 6 votes |
@Override public void visitMethodCallExpression(final MethodCallExpression call) { boolean old = inBuilderMethod; inBuilderMethod = false; if (call.isImplicitThis() && call.getArguments() instanceof TupleExpression) { List<Expression> expressions = ((TupleExpression) call.getArguments()).getExpressions(); if (!expressions.isEmpty()) { Expression lastArg = expressions.get(expressions.size() - 1); if (lastArg instanceof ClosureExpression) { call.getObjectExpression().visit(this); call.getMethod().visit(this); for (Expression expression : expressions) { inBuilderMethod = (expression == lastArg); expression.visit(this); } } } } else { super.visitMethodCallExpression(call); } inBuilderMethod = old; }
Example 2
Source File: PathFinderVisitor.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void visitMethodCallExpression(MethodCallExpression node) { if (isInside(node, line, column)) { // FIXME http://jira.codehaus.org/browse/GROOVY-3263 if (node.isImplicitThis()) { node.getMethod().visit(this); node.getArguments().visit(this); } else { super.visitMethodCallExpression(node); } } }
Example 3
Source File: MethodCallExpressionTransformer.java From groovy with Apache License 2.0 | 5 votes |
private static boolean isCallOnClosure(final MethodCallExpression expr) { MethodNode target = expr.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); return expr.isImplicitThis() && !"call".equals(expr.getMethodAsString()) && (target == StaticTypeCheckingVisitor.CLOSURE_CALL_VARGS || target == StaticTypeCheckingVisitor.CLOSURE_CALL_NO_ARG || target == StaticTypeCheckingVisitor.CLOSURE_CALL_ONE_ARG); }
Example 4
Source File: VariableScopeVisitor.java From groovy with Apache License 2.0 | 5 votes |
@Override public void visitMethodCallExpression(final MethodCallExpression expression) { if (expression.isImplicitThis() && expression.getMethod() instanceof ConstantExpression) { ConstantExpression methodNameConstant = (ConstantExpression) expression.getMethod(); String methodName = methodNameConstant.getText(); if (methodName == null) { throw new GroovyBugError("method name is null"); } Variable variable = findVariableDeclaration(methodName); if (variable != null && !(variable instanceof DynamicVariable)) { checkVariableContextAccess(variable, expression); } if (variable instanceof VariableExpression || variable instanceof Parameter) { VariableExpression object = new VariableExpression(variable); object.setSourcePosition(methodNameConstant); expression.setObjectExpression(object); ConstantExpression method = new ConstantExpression("call"); method.setSourcePosition(methodNameConstant); // important for GROOVY-4344 expression.setImplicitThis(false); expression.setMethod(method); } } super.visitMethodCallExpression(expression); }
Example 5
Source File: InvocationWriter.java From groovy with Apache License 2.0 | 5 votes |
private boolean isClosureCall(final 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); }
Example 6
Source File: MarkupBuilderCodeTransformer.java From groovy with Apache License 2.0 | 4 votes |
private Expression transformMethodCall(final MethodCallExpression exp) { String name = exp.getMethodAsString(); if (exp.isImplicitThis() && "include".equals(name)) { return tryTransformInclude(exp); } else if (exp.isImplicitThis() && name.startsWith(":")) { List<Expression> args; if (exp.getArguments() instanceof ArgumentListExpression) { args = ((ArgumentListExpression) exp.getArguments()).getExpressions(); } else { args = Collections.singletonList(exp.getArguments()); } Expression newArguments = transform(new ArgumentListExpression(new ConstantExpression(name.substring(1)), new ArrayExpression(ClassHelper.OBJECT_TYPE, args))); MethodCallExpression call = new MethodCallExpression( new VariableExpression("this"), "methodMissing", newArguments ); call.setImplicitThis(true); call.setSafe(exp.isSafe()); call.setSpreadSafe(exp.isSpreadSafe()); call.setSourcePosition(exp); return call; } else if (name!=null && name.startsWith("$")) { MethodCallExpression reformatted = new MethodCallExpression( exp.getObjectExpression(), name.substring(1), exp.getArguments() ); reformatted.setImplicitThis(exp.isImplicitThis()); reformatted.setSafe(exp.isSafe()); reformatted.setSpreadSafe(exp.isSpreadSafe()); reformatted.setSourcePosition(exp); // wrap in a stringOf { ... } closure call ClosureExpression clos = new ClosureExpression(Parameter.EMPTY_ARRAY, new ExpressionStatement(reformatted)); clos.setVariableScope(new VariableScope()); MethodCallExpression stringOf = new MethodCallExpression(new VariableExpression("this"), "stringOf", clos); stringOf.setImplicitThis(true); stringOf.setSourcePosition(reformatted); return stringOf; } return super.transform(exp); }
Example 7
Source File: NewifyASTTransformation.java From groovy with Apache License 2.0 | 4 votes |
private boolean isNewifyCandidate(MethodCallExpression mce) { return (auto && isNewMethodStyle(mce)) || (mce.isImplicitThis() && mce.getObjectExpression() instanceof VariableExpression && ((VariableExpression) mce.getObjectExpression()).isThisExpression()); }
Example 8
Source File: InvocationWriter.java From groovy with Apache License 2.0 | 4 votes |
private boolean isStaticInvocation(final MethodCallExpression call) { if (!AsmClassGenerator.isThisExpression(call.getObjectExpression())) return false; if (controller.isStaticMethod()) return true; return controller.isStaticContext() && !call.isImplicitThis(); }
Example 9
Source File: MethodCallExpressionTest.java From groovy with Apache License 2.0 | 4 votes |
public void visitMethodCallExpression(MethodCallExpression methodCall) { if (defaultScriptMethods.contains(methodCall.getMethodAsString())) { visited = true; isImplicitThis = methodCall.isImplicitThis(); } }