/** * Throws an exception indicating the returned type is not compatible with the return type of the given method * @throws StructuralCodeConstraintException always * @since 6.0 */ public void invalidReturnTypeError(final Type returnedType, final MethodGen m) { throw new StructuralCodeConstraintException( "Returned type "+returnedType+" does not match Method's return type "+m.getReturnType()); }
@Override public void visitMethod( final Method method ) { final MethodGen mg = new MethodGen(method, _clazz.getClassName(), _cp); _out.println(" InstructionList il = new InstructionList();"); _out.println(" MethodGen method = new MethodGen(" + printFlags(method.getAccessFlags(), FLAGS.METHOD) + ", " + printType(mg.getReturnType()) + ", " + printArgumentTypes(mg.getArgumentTypes()) + ", " + "new String[] { " + Utility.printArray(mg.getArgumentNames(), false, true) + " }, \"" + method.getName() + "\", \"" + _clazz.getClassName() + "\", il, _cp);"); _out.println(); final BCELFactory factory = new BCELFactory(mg, _out); factory.start(); _out.println(" method.setMaxStack();"); _out.println(" method.setMaxLocals();"); _out.println(" _cg.addMethod(method.getMethod());"); _out.println(" il.dispose();"); }
public void visitMethod(Method method) { MethodGen mg = new MethodGen(method, _clazz.getClassName(), _cp); Type result_type = mg.getReturnType(); Type[] arg_types = mg.getArgumentTypes(); _out.println(" InstructionList il = new InstructionList();"); _out.println(" MethodGen method = new MethodGen(" + printFlags(method.getAccessFlags()) + ", " + printType(result_type) + ", " + printArgumentTypes(arg_types) + ", " + "new String[] { " + Utility.printArray(mg.getArgumentNames(), false, true) + " }, \"" + method.getName() + "\", \"" + _clazz.getClassName() + "\", il, _cp);\n"); BCELFactory factory = new BCELFactory(mg, _out); factory.start(); _out.println(" method.setMaxStack();"); _out.println(" method.setMaxLocals();"); _out.println(" _cg.addMethod(method.getMethod());"); _out.println(" il.dispose();"); }
if (returnedType instanceof ReferenceType) { try { if (!((ReferenceType) returnedType).isCastableTo(m.getReturnType())) { invalidReturnTypeError(returnedType, m); } else if (!returnedType.equals(m.getReturnType().normalizeForStackOrLocal())) { invalidReturnTypeError(returnedType, m);