List of usage examples for com.google.gwt.core.ext.typeinfo JMethod isVarArgs
boolean isVarArgs();
From source file:com.google.gwt.testing.easygwtmock.rebind.MocksGenerator.java
License:Apache License
private void printMockMethodBody(SourceWriter sourceWriter, JMethod method, int methodNo, String newClassName) { JParameter[] args = method.getParameters(); String callVar = freeVariableName("call", args); sourceWriter.print("Call %s = new Call(this, %s.methods[%d]", callVar, newClassName, methodNo); int argsCount = method.isVarArgs() ? args.length - 1 : args.length; for (int i = 0; i < argsCount; i++) { sourceWriter.print(", %s", args[i].getName()); }/* w w w. ja va2 s. c o m*/ sourceWriter.println(");"); if (method.isVarArgs()) { sourceWriter.println("%s.addVarArgument(%s);", callVar, args[args.length - 1].getName()); } sourceWriter.println("try {"); sourceWriter.indent(); if (!isVoid(method)) { sourceWriter.print("return ("); JType returnType = method.getReturnType(); JPrimitiveType primitiveType = returnType.isPrimitive(); if (primitiveType != null) { sourceWriter.print(primitiveType.getQualifiedBoxedSourceName()); } else if (returnType.isTypeParameter() != null) { sourceWriter.print(returnType.isTypeParameter().getName()); } else { sourceWriter.print(returnType.getQualifiedSourceName()); } sourceWriter.print(") "); } sourceWriter.println("this.mocksControl.invoke(%s).answer(%s.getArguments().toArray());", callVar, callVar); sourceWriter.outdent(); String exceptionVar = freeVariableName("exception", args); sourceWriter.println("} catch (Throwable %s) {", exceptionVar); sourceWriter.indent(); String assertionError = AssertionErrorWrapper.class.getCanonicalName(); sourceWriter.println( "if (%s instanceof %s) throw (AssertionError) " + "((%s) %s).getAssertionError().fillInStackTrace();", exceptionVar, assertionError, assertionError, exceptionVar); for (JClassType exception : method.getThrows()) { printRethrowException(sourceWriter, exceptionVar, exception.getQualifiedSourceName()); } printRethrowException(sourceWriter, exceptionVar, "RuntimeException"); printRethrowException(sourceWriter, exceptionVar, "Error"); sourceWriter.println("throw new UndeclaredThrowableException(%s);", exceptionVar); sourceWriter.outdent(); sourceWriter.println("}"); }