if (!enclosingMethod.isVoidMethod() && !type.equals(void_WRAPPER_TYPE) && !type.equals(VOID_TYPE) addStaticTypeError("Cannot return value of type " + type.toString(false) + " on method returning type " + enclosingMethod.getReturnType().toString(false), expression); } else if (!enclosingMethod.isVoidMethod()) { ClassNode previousType = getInferredReturnType(enclosingMethod); ClassNode inferred = previousType == null ? type : lowestUpperBound(type, previousType);
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); } } }
expression.setImplicitThis(true); if (method.isVoidMethod()) { code.addStatement(new ExpressionStatement(expression)); } else {
return; if (methodNode.isVoidMethod()) { addError("Annotation " + MY_TYPE_NAME + " cannot be used for void methods.", methodNode); return;
if (node.isVoidMethod()) { mv.visitInsn(RETURN); } else {
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(); }
if (m.getName().equals("finalize") && m.isVoidMethod() && !m.isPrivate() && !m.isStatic()) { boolean safe = false;
public void visitMethod(MethodNode node) { this.methodNode = node; Statement statement = node.getCode(); if (!node.isVoidMethod()) { if (statement instanceof ExpressionStatement) { ExpressionStatement expStmt = (ExpressionStatement) statement;
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); } } }
if (!outputReturn || node.isVoidMethod()) { mv.visitInsn(RETURN);
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); } } }
public void call(ArgumentListExpression arguments, Parameter[] newParams, MethodNode method) { MethodCallExpression expression = new MethodCallExpression(VariableExpression.THIS_EXPRESSION, method.getName(), arguments); expression.setImplicitThis(true); Statement code = null; if (method.isVoidMethod()) { code = new ExpressionStatement(expression); } else { code = new ReturnStatement(expression); } MethodNode newMethod = new MethodNode(method.getName(), method.getModifiers(), method.getReturnType(), newParams, method.getExceptions(), code); MethodNode oldMethod = node.getDeclaredMethod(method.getName(), newParams); if (oldMethod!=null) { throw new RuntimeParserException( "The method with default parameters \""+ method.getTypeDescriptor()+ "\" defines a method \""+ newMethod.getTypeDescriptor()+ "\" that is already defined.", method); } node.addMethod(newMethod); } });
public void call(ArgumentListExpression arguments, Parameter[] newParams, MethodNode method) { MethodCallExpression expression = new MethodCallExpression(VariableExpression.THIS_EXPRESSION, method.getName(), arguments); expression.setImplicitThis(true); Statement code = null; if (method.isVoidMethod()) { code = new ExpressionStatement(expression); } else { code = new ReturnStatement(expression); } MethodNode newMethod = new MethodNode(method.getName(), method.getModifiers(), method.getReturnType(), newParams, method.getExceptions(), code); MethodNode oldMethod = node.getDeclaredMethod(method.getName(), newParams); if (oldMethod!=null) { throw new RuntimeParserException( "The method with default parameters \""+ method.getTypeDescriptor()+ "\" defines a method \""+ newMethod.getTypeDescriptor()+ "\" that is already defined.", method); } node.addMethod(newMethod); } });
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); } } }
public void call(ArgumentListExpression arguments, Parameter[] newParams, MethodNode method) { MethodCallExpression expression = new MethodCallExpression(VariableExpression.THIS_EXPRESSION, method.getName(), arguments); expression.setImplicitThis(true); Statement code = null; if (method.isVoidMethod()) { code = new ExpressionStatement(expression); } else { ReturnStatement ret = new ReturnStatement(expression); ret.setSourcePosition(expression); code = ret; } MethodNode newMethod = new MethodNode(method.getName(), method.getModifiers(), method.getReturnType(), newParams, method.getExceptions(), code); MethodNode oldMethod = node.getDeclaredMethod(method.getName(), newParams); if (oldMethod!=null) { throw new RuntimeParserException( "The method with default parameters \""+ method.getTypeDescriptor()+ "\" defines a method \""+ newMethod.getTypeDescriptor()+ "\" that is already defined.", method); } node.addMethod(newMethod); } });
expression.setImplicitThis(true); Statement code = null; if (method.isVoidMethod()) { code = new ExpressionStatement(expression); } else {
if (node.isVoidMethod()) { mv.visitInsn(RETURN); } else {