@Override public void visitMethod(MethodNode node) { scope = node.getVariableScope(); super.visitMethod(node); opt.reset(); }
private TryCatchStatement tryCatchAssertionFailedError(AnnotationNode annotationNode, MethodNode methodNode, ArrayList<Statement> statements) { TryCatchStatement tryCatchStatement = new TryCatchStatement(new BlockStatement(statements, methodNode.getVariableScope()), EmptyStatement.INSTANCE); tryCatchStatement.addCatch(new CatchStatement(new Parameter(CATCHED_THROWABLE_TYPE, "ex"), ReturnStatement.RETURN_NULL_OR_VOID)); return tryCatchStatement; }
private void passThisReference(ConstructorCallExpression call) { ClassNode cn = call.getType().redirect(); if (!shouldHandleImplicitThisForInnerClass(cn)) return; boolean isInStaticContext = true; if (currentMethod != null) isInStaticContext = currentMethod.getVariableScope().isInStaticContext(); else if (currentField != null) isInStaticContext = currentField.isStatic(); else if (processingObjInitStatements) isInStaticContext = false; // if constructor call is not in static context, return if (isInStaticContext) { // constructor call is in static context and the inner class is non-static - 1st arg is supposed to be // passed as enclosing "this" instance // Expression args = call.getArguments(); if (args instanceof TupleExpression && ((TupleExpression) args).getExpressions().isEmpty()) { addError("No enclosing instance passed in constructor call of a non-static inner class", call); } return; } insertThis0ToSuperCall(call, cn); }
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { VariableScope oldScope = currentScope; currentScope = node.getVariableScope(); Map<GenericsTypeName, GenericsType> oldPNames = genericParameterNames; genericParameterNames = node.isStatic() && !Traits.isTrait(node.getDeclaringClass()) ? new HashMap<GenericsTypeName, GenericsType>() : new HashMap<GenericsTypeName, GenericsType>(genericParameterNames); resolveGenericsHeader(node.getGenericsTypes()); Parameter[] paras = node.getParameters(); for (Parameter p : paras) { p.setInitialExpression(transform(p.getInitialExpression())); resolveOrFail(p.getType(), p.getType()); visitAnnotations(p); } ClassNode[] exceptions = node.getExceptions(); for (ClassNode t : exceptions) { resolveOrFail(t, node); } resolveOrFail(node.getReturnType(), node); MethodNode oldCurrentMethod = currentMethod; currentMethod = node; super.visitConstructorOrMethod(node, isConstructor); currentMethod = oldCurrentMethod; genericParameterNames = oldPNames; currentScope = oldScope; }
private MethodNode copyMethod(MethodNode method, String newName) { // can't hurt to set return type to void MethodNode newMethod = new MethodNode(newName, method.getModifiers(), ClassHelper.VOID_TYPE, method.getParameters(), method.getExceptions(), method.getCode()); newMethod.addAnnotations(method.getAnnotations()); newMethod.setSynthetic(method.isSynthetic()); newMethod.setDeclaringClass(method.getDeclaringClass()); newMethod.setSourcePosition(method); newMethod.setVariableScope(method.getVariableScope()); newMethod.setGenericsTypes(method.getGenericsTypes()); newMethod.setAnnotationDefault(method.hasAnnotationDefault()); return newMethod; }
public void visitMethod(MethodNode node) { Statement statement = node.getCode(); if (!node.isVoidMethod()) { if (statement != null) // it happens with @interface methods { final Statement code = addReturnsIfNeeded(statement, node.getVariableScope()); if (doAdd) node.setCode(code); } } else if (!node.isAbstract() && node.getReturnType().redirect()!=ClassHelper.VOID_TYPE) { if (!(statement instanceof BytecodeSequence)) { BlockStatement newBlock = new BlockStatement(); Statement code = node.getCode(); if (code instanceof BlockStatement) { newBlock.setVariableScope(((BlockStatement) code).getVariableScope()); } if (statement instanceof BlockStatement) { newBlock.addStatements(((BlockStatement)statement).getStatements()); } else { newBlock.addStatement(statement); } final ReturnStatement returnStatement = ReturnStatement.RETURN_NULL_OR_VOID; listener.returnStatementAdded(returnStatement); newBlock.addStatement(returnStatement); newBlock.setSourcePosition(statement); if (doAdd) node.setCode(newBlock); } } }
private void visitStdMethod(MethodNode node, boolean isConstructor, Parameter[] parameters, Statement code) { controller.getCompileStack().init(node.getVariableScope(), parameters); controller.getCallSiteWriter().makeSiteEntry();
@Override public void visitMethod(MethodNode node) { scope = node.getVariableScope(); super.visitMethod(node); opt.reset(); }
private void visitStdMethod(MethodNode node, boolean isConstructor, Parameter[] parameters, Statement code) { if (isConstructor && (code == null || !((ConstructorNode) node).firstStatementIsSpecialConstructorCall())) { // invokes the super class constructor mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, BytecodeHelper.getClassInternalName(classNode.getSuperClass()), "<init>", "()V"); } compileStack.init(node.getVariableScope(), parameters, mv, classNode); if (isNotClinit()) { mv.visitMethodInsn(INVOKESTATIC,internalClassName,"$getCallSiteArray","()[Lorg/codehaus/groovy/runtime/callsite/CallSite;"); callSiteArrayVarIndex = compileStack.defineTemporaryVariable("$local$callSiteArray", ClassHelper.make(CallSite[].class), true); } // handle body super.visitConstructorOrMethod(node, isConstructor); if (!outputReturn || node.isVoidMethod()) { mv.visitInsn(RETURN); } compileStack.clear(); final Label finallyStart = new Label(); mv.visitJumpInsn(GOTO, finallyStart); // let's do all the exception blocks for (Iterator iter = exceptionBlocks.iterator(); iter.hasNext();) { Runnable runnable = (Runnable) iter.next(); runnable.run(); } exceptionBlocks.clear(); }
private void visitStdMethod(MethodNode node, boolean isConstructor, Parameter[] parameters, Statement code) { if (isConstructor && (code == null || !((ConstructorNode) node).firstStatementIsSpecialConstructorCall())) { // invokes the super class constructor mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, BytecodeHelper.getClassInternalName(classNode.getSuperClass()), "<init>", "()V"); } compileStack.init(node.getVariableScope(), parameters, mv, classNode); if (isNotClinit()) { mv.visitMethodInsn(INVOKESTATIC,internalClassName,"$getCallSiteArray","()[Lorg/codehaus/groovy/runtime/callsite/CallSite;"); callSiteArrayVarIndex = compileStack.defineTemporaryVariable("$local$callSiteArray", ClassHelper.make(CallSite[].class), true); } // handle body super.visitConstructorOrMethod(node, isConstructor); if (!outputReturn || node.isVoidMethod()) { mv.visitInsn(RETURN); } compileStack.clear(); final Label finallyStart = new Label(); mv.visitJumpInsn(GOTO, finallyStart); // let's do all the exception blocks for (Iterator iter = exceptionBlocks.iterator(); iter.hasNext();) { Runnable runnable = (Runnable) iter.next(); runnable.run(); } exceptionBlocks.clear(); }
private TryCatchStatement tryCatchAssertionFailedError(AnnotationNode annotationNode, MethodNode methodNode, ArrayList<Statement> statements) { TryCatchStatement tryCatchStatement = new TryCatchStatement( block(methodNode.getVariableScope(), statements), EmptyStatement.INSTANCE); tryCatchStatement.addCatch(catchS(param(CATCHED_THROWABLE_TYPE, "ex"), ReturnStatement.RETURN_NULL_OR_VOID)); return tryCatchStatement; }
private TryCatchStatement tryCatchAssertionFailedError(AnnotationNode annotationNode, MethodNode methodNode, ArrayList<Statement> statements) { TryCatchStatement tryCatchStatement = new TryCatchStatement(new BlockStatement(statements, methodNode.getVariableScope()), EmptyStatement.INSTANCE); tryCatchStatement.addCatch(new CatchStatement(new Parameter(CATCHED_THROWABLE_TYPE, "ex"), ReturnStatement.RETURN_NULL_OR_VOID)); return tryCatchStatement; }
protected void addReturnIfNeeded(MethodNode node) { Statement statement = node.getCode(); if (!node.isVoidMethod()) { if (statement != null) // it happens with @interface methods node.setCode(addReturnsIfNeeded(statement, node.getVariableScope())); } else if (!node.isAbstract()) { if (!(statement instanceof BytecodeSequence)) { BlockStatement newBlock = new BlockStatement(); newBlock.setVariableScope(node.getVariableScope()); if (statement instanceof BlockStatement) { newBlock.addStatements(((BlockStatement)statement).getStatements()); } else { newBlock.addStatement(statement); } newBlock.addStatement(ReturnStatement.RETURN_NULL_OR_VOID); newBlock.setSourcePosition(statement); node.setCode(newBlock); } } }
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { VariableScope oldScope = currentScope; currentScope = node.getVariableScope(); Map<String, GenericsType> oldPNames = genericParameterNames; genericParameterNames = new HashMap<String, GenericsType>(genericParameterNames); resolveGenericsHeader(node.getGenericsTypes()); Parameter[] paras = node.getParameters(); for (Parameter p : paras) { p.setInitialExpression(transform(p.getInitialExpression())); resolveOrFail(p.getType(), p.getType()); visitAnnotations(p); } ClassNode[] exceptions = node.getExceptions(); for (ClassNode t : exceptions) { resolveOrFail(t, node); } resolveOrFail(node.getReturnType(), node); MethodNode oldCurrentMethod = currentMethod; currentMethod = node; super.visitConstructorOrMethod(node, isConstructor); currentMethod = oldCurrentMethod; genericParameterNames = oldPNames; currentScope = oldScope; }
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { VariableScope oldScope = currentScope; currentScope = node.getVariableScope(); Map oldPNames = genericParameterNames; genericParameterNames = new HashMap(genericParameterNames); resolveGenericsHeader(node.getGenericsTypes()); Parameter[] paras = node.getParameters(); for (int i = 0; i < paras.length; i++) { Parameter p = paras[i]; p.setInitialExpression(transform(p.getInitialExpression())); resolveOrFail(p.getType(), p.getType()); visitAnnotations(p); } ClassNode[] exceptions = node.getExceptions(); for (int i = 0; i < exceptions.length; i++) { ClassNode t = exceptions[i]; resolveOrFail(t, node); } resolveOrFail(node.getReturnType(), node); super.visitConstructorOrMethod(node, isConstructor); genericParameterNames = oldPNames; currentScope = oldScope; }
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { VariableScope oldScope = currentScope; currentScope = node.getVariableScope(); Map oldPNames = genericParameterNames; genericParameterNames = new HashMap(genericParameterNames); resolveGenericsHeader(node.getGenericsTypes()); Parameter[] paras = node.getParameters(); for (int i = 0; i < paras.length; i++) { Parameter p = paras[i]; p.setInitialExpression(transform(p.getInitialExpression())); resolveOrFail(p.getType(), p.getType()); visitAnnotations(p); } ClassNode[] exceptions = node.getExceptions(); for (int i = 0; i < exceptions.length; i++) { ClassNode t = exceptions[i]; resolveOrFail(t, node); } resolveOrFail(node.getReturnType(), node); super.visitConstructorOrMethod(node, isConstructor); genericParameterNames = oldPNames; currentScope = oldScope; }
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { VariableScope oldScope = currentScope; currentScope = node.getVariableScope(); Map oldPNames = genericParameterNames; genericParameterNames = new HashMap(genericParameterNames); resolveGenericsHeader(node.getGenericsTypes()); Parameter[] paras = node.getParameters(); for (int i = 0; i < paras.length; i++) { Parameter p = paras[i]; p.setInitialExpression(transform(p.getInitialExpression())); resolveOrFail(p.getType(), p.getType()); visitAnnotations(p); } ClassNode[] exceptions = node.getExceptions(); for (int i = 0; i < exceptions.length; i++) { ClassNode t = exceptions[i]; resolveOrFail(t, node); } resolveOrFail(node.getReturnType(), node); super.visitConstructorOrMethod(node, isConstructor); genericParameterNames = oldPNames; currentScope = oldScope; }
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { VariableScope oldScope = currentScope; currentScope = node.getVariableScope(); Map<String, GenericsType> oldPNames = genericParameterNames; genericParameterNames = new HashMap<String, GenericsType>(genericParameterNames); resolveGenericsHeader(node.getGenericsTypes()); Parameter[] paras = node.getParameters(); for (Parameter p : paras) { p.setInitialExpression(transform(p.getInitialExpression())); resolveOrFail(p.getType(), p.getType()); visitAnnotations(p); } ClassNode[] exceptions = node.getExceptions(); for (ClassNode t : exceptions) { resolveOrFail(t, node); } resolveOrFail(node.getReturnType(), node); MethodNode oldCurrentMethod = currentMethod; currentMethod = node; super.visitConstructorOrMethod(node, isConstructor); currentMethod = oldCurrentMethod; genericParameterNames = oldPNames; currentScope = oldScope; }
private void addReturnIfNeeded(MethodNode node) { Statement statement = node.getCode(); if (!node.isVoidMethod()) { if (statement != null) // it happens with @interface methods node.setCode(addReturnsIfNeeded(statement, node.getVariableScope())); } else if (!node.isAbstract()) { if (!(statement instanceof BytecodeSequence)) { BlockStatement newBlock = new BlockStatement(); if (statement instanceof BlockStatement) { newBlock.addStatements(((BlockStatement)statement).getStatements()); } else { newBlock.addStatement(statement); } newBlock.addStatement(ReturnStatement.RETURN_NULL_OR_VOID); newBlock.setSourcePosition(statement); node.setCode(newBlock); } } }
public static void addReturnIfNeeded(MethodNode node) { Statement statement = node.getCode(); if (!node.isVoidMethod()) { if (statement != null) // it happens with @interface methods node.setCode(addReturnsIfNeeded(statement, node.getVariableScope())); } else if (!node.isAbstract() && node.getReturnType().redirect()!=ClassHelper.VOID_TYPE) { if (!(statement instanceof BytecodeSequence)) { BlockStatement newBlock = new BlockStatement(); Statement code = node.getCode(); if (code instanceof BlockStatement) { newBlock.setVariableScope(((BlockStatement) code).getVariableScope()); } if (statement instanceof BlockStatement) { newBlock.addStatements(((BlockStatement)statement).getStatements()); } else { newBlock.addStatement(statement); } newBlock.addStatement(ReturnStatement.RETURN_NULL_OR_VOID); newBlock.setSourcePosition(statement); node.setCode(newBlock); } } }