Java Code Examples for com.google.gwt.core.ext.typeinfo.JMethod#getParameters()
The following examples show how to use
com.google.gwt.core.ext.typeinfo.JMethod#getParameters() .
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: ServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private void generateServiceImplementationWithCallback(TreeLogger logger, SourceWriter srcWriter) throws UnableToCompleteException { for (JMethod method : this.serviceBinderType.getMethods()) { JParameter[] methodParams = method.getParameters(); JParameter callbackParam = null; if (methodParams != null && methodParams.length > 0) { callbackParam = methodParams[methodParams.length - 1]; } if (callbackParam == null) { break; } this.writeStartMethod(srcWriter, method); this.writeCommandDefinition(logger, srcWriter, method, callbackParam); this.writeCommandParam(srcWriter, method, null, callbackParam); this.writeEndMethod(srcWriter, method); } }
Example 2
Source File: ServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private void writeCommandDefinition(TreeLogger logger, SourceWriter srcWriter, JMethod method, JParameter callbackParameter) throws UnableToCompleteException { srcWriter.print("CommandDefinition commandDefinition = new CommandDefinition("); srcWriter.print("\"%s\", ", this.serviceType.getQualifiedSourceName()); srcWriter.print("\"%s\", ", method.getName()); if (callbackParameter != null) { JParameterizedType parameterizedCallback = callbackParameter.getType().isParameterized(); if (parameterizedCallback != null) { srcWriter.print("\"%s\" ", parameterizedCallback.getTypeArgs()[0].getQualifiedSourceName()); } else { logger.branch(TreeLogger.ERROR, "Callback argument type for method " + method.getName() + " is not parametrized", null); throw new UnableToCompleteException(); } } else { srcWriter.print("\"%s\" ", method.getReturnType().getQualifiedSourceName()); } for (JParameter parameter : method.getParameters()) { if (!parameter.equals(callbackParameter)) { srcWriter.print(", \"%s\"", parameter.getType().getQualifiedSourceName()); } } srcWriter.println(");"); }
Example 3
Source File: ServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private void collectImports() { Collection<JType> toImports = Sets.newHashSet(); for (JMethod method : this.serviceType.getOverridableMethods()) { toImports.add(method.getReturnType()); for (JParameter parameter : method.getParameters()) { toImports.add(parameter.getType()); } } this.imports.addAll(toImports); for (JType importType : this.imports) { if (importType instanceof JParameterizedType) { JParameterizedType parameterizedType = (JParameterizedType) importType; for (JType paramType : parameterizedType.getTypeArgs()) { toImports.add(paramType); } } } this.imports.addAll(toImports); }
Example 4
Source File: InjectPresenterCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void initComposer(ClassSourceFileComposerFactory composerFactory) { composerFactory.addImport(Place.class.getName()); composerFactory.addImport(Presenter.class.getName()); for (JMethod presenterMethod : this.presenterMethods) { if (presenterMethod.getParameters().length > 0) { JType placeType = presenterMethod.getParameters()[0].getType(); composerFactory.addImport(placeType.getQualifiedSourceName()); if (placeType instanceof JParameterizedType) { JParameterizedType parameterizedType = (JParameterizedType) placeType; for (JType paramType : parameterizedType.getTypeArgs()) { composerFactory.addImport(paramType.getQualifiedSourceName()); } } } } composerFactory.addImplementedInterface(Presenter.class.getSimpleName()); composerFactory.addImport(AcceptsOneWidget.class.getName()); }
Example 5
Source File: RestServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private void generateServiceImplementationWithCallback(SourceWriter srcWriter) { for (JMethod method : this.serviceBinderType.getMethods()) { JParameter[] methodParams = method.getParameters(); JParameter callbackParam = null; if (methodParams != null && methodParams.length > 0) { callbackParam = methodParams[methodParams.length - 1]; } if (callbackParam == null) { break; } this.writeStartMethod(srcWriter, method); this.writeMethodCallback(srcWriter, method, null, callbackParam); this.writeMethodCall(srcWriter, method, callbackParam); this.writeEndMethod(srcWriter, method); } }
Example 6
Source File: RestServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private void collectImports() { Collection<JType> toImports = Sets.newHashSet(); for (JMethod method : this.serviceType.getOverridableMethods()) { toImports.add(method.getReturnType()); for (JParameter parameter : method.getParameters()) { toImports.add(parameter.getType()); } } this.imports.addAll(toImports); for (JType importType : this.imports) { if (importType instanceof JParameterizedType) { JParameterizedType parameterizedType = (JParameterizedType) importType; for (JType paramType : parameterizedType.getTypeArgs()) { toImports.add(paramType); } } } this.imports.addAll(toImports); }
Example 7
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void listSetters(JMethod[] methods) { for (JMethod method : methods) { if (method.getName().startsWith("set") && method.getParameters().length == 1 && method.getReturnType().equals(JPrimitiveType.VOID) && method.isPublic()) { this.setters.put(this.extractPropertyNameFromMethod(method), method); this.propertyTypes.put(this.extractPropertyNameFromMethod(method), method.getParameters()[0].getType()); this.addImport(method.getParameters()[0].getType()); } } }
Example 8
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void listGetters(JMethod[] methods) { for (JMethod method : methods) { if (method.getName().startsWith("get") && method.getName().length() > 3 || method.getName().startsWith("is") && method.getName().length() > 2 && method.getParameters().length == 0 && !method.getReturnType().equals(JPrimitiveType.VOID) && method.isPublic()) { this.getters.put(this.extractPropertyNameFromMethod(method), method); this.propertyTypes.put(this.extractPropertyNameFromMethod(method), method.getReturnType()); this.addImport(method.getReturnType()); } } }
Example 9
Source File: ServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void writeStartMethod(SourceWriter srcWriter, JMethod method) { srcWriter.print("public %s %s(", this.typeAsString(method.getReturnType(), false), method.getName()); int i = 0; for (JParameter parameter : method.getParameters()) { if (i++ > 0) { srcWriter.print(", "); } srcWriter.print("%s $%d_%s", this.typeAsString(parameter.getType(), false), i, parameter.getName()); } srcWriter.println("){"); srcWriter.indent(); }
Example 10
Source File: InjectPresenterCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void writePresent(SourceWriter srcWriter) { for (JMethod presenterMethod : this.presenterMethods) { if (presenterMethod.getParameters().length == 0) { srcWriter.println("super.%s();", presenterMethod.getName()); } else if (presenterMethod.getParameters().length > 0) { JType placeType = presenterMethod.getParameters()[0].getType(); srcWriter.println("if(place instanceof %s){", placeType.getSimpleSourceName()); srcWriter.indent(); srcWriter.println("super.%s((%s) place);", presenterMethod.getName(), placeType.getSimpleSourceName()); srcWriter.outdent(); srcWriter.println("}"); } } }
Example 11
Source File: RestServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void writeStartMethod(SourceWriter srcWriter, JMethod method) { srcWriter.print("public %s %s(", this.typeAsString(method.getReturnType(), false), method.getName()); int i = 0; for (JParameter parameter : method.getParameters()) { if (i++ > 0) { srcWriter.print(", "); } srcWriter.print("%s $%d_%s", this.typeAsString(parameter.getType(), false), i, parameter.getName()); } srcWriter.println("){"); srcWriter.indent(); }
Example 12
Source File: RestServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void writeMethodCall(SourceWriter srcWriter, JMethod method, JParameter callbackParam) { srcWriter.print("REST.<%s> withCallback(compositeCallback).call(restService).%s(", this.typeAsString(method .getReturnType(), true), method.getName()); int i = 0; for (JParameter parameter : method.getParameters()) { if (!parameter.equals(callbackParam)) { if (i++ > 0) { srcWriter.print(", "); } srcWriter.print("$%d_%s", i, parameter.getName()); } } srcWriter.println(");"); }
Example 13
Source File: GssResourceGenerator.java From gss.gwt with Apache License 2.0 | 5 votes |
private boolean writeClassMethod(TreeLogger logger, JMethod userMethod, Map<String, String> substitutionMap, SourceWriter sw) throws UnableToCompleteException { if (!isReturnTypeString(userMethod.getReturnType().isClass())) { logger.log(Type.ERROR, "The return type of the method [" + userMethod.getName() + "] must " + "be java.lang.String."); throw new UnableToCompleteException(); } if (userMethod.getParameters().length > 0) { logger.log(Type.ERROR, "The method [" + userMethod.getName() + "] shouldn't contain any " + "parameters"); throw new UnableToCompleteException(); } String name = getClassName(userMethod); String value = substitutionMap.get(name); if (value == null) { logger.log(Type.ERROR, "The following style class [" + name + "] is missing from the source" + " CSS file"); return false; } else { writeSimpleGetter(userMethod, "\"" + value + "\"", sw); } return true; }
Example 14
Source File: ExtendedServiceProxyGenerator.java From appinventor-extensions with Apache License 2.0 | 4 votes |
/** * Generate the implementation of a single method. * * @param out where to print the method to * @param method the method * @param typeName type name of the containing proxy class */ private void printMethod(PrintWriter out, JMethod method, String typeName) { // Build parameter lists int i = 0; StringBuilder actualParamsBuilder = new StringBuilder(); StringBuilder formalParamsBuilder = new StringBuilder(); for (JParameter param : method.getParameters()) { if (i != 0) { actualParamsBuilder.append(", "); formalParamsBuilder.append(", "); } String paramType = param.getType().getParameterizedQualifiedSourceName(); String paramName = "p" + i++; actualParamsBuilder.append(paramName); formalParamsBuilder.append(paramType + " " + paramName); } String actualParams = actualParamsBuilder.toString(); String formalParams = formalParamsBuilder.toString(); // Information about the return type JType returnType = method.getReturnType(); boolean hasReturnValue = !returnType.getSimpleSourceName().equals("void"); JPrimitiveType primitiveReturnType = returnType.isPrimitive(); String resultType = primitiveReturnType != null ? primitiveReturnType.getQualifiedBoxedSourceName() : returnType.getParameterizedQualifiedSourceName(); String callbackType = AsyncCallback.class.getName() + "<" + resultType + ">"; // Print method out.println(" public void " + method.getName() + "(" + formalParams + (formalParams.isEmpty() ? "" : ", ") + "final " + callbackType + " callback" + ") {"); out.println(" fireStart(\"" + method.getName() + "\"" + (actualParams.isEmpty() ? "" : ", ") + actualParams + ");"); out.println(" proxy." + method.getName() + "(" + actualParams + (actualParams.isEmpty() ? "" : ", ") + "new " + callbackType + "() {"); out.println(" public void onSuccess(" + resultType + " result) {"); out.println(" " + outcome(method, "Success", "result")); out.println(" }"); out.println(" public void onFailure(Throwable caught) {"); out.println(" " + outcome(method, "Failure", "caught")); out.println(" }"); out.println(" });"); out.println(" }"); }
Example 15
Source File: ServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void writeCommandParam(SourceWriter srcWriter, JMethod method, Collection<CallbackMethod> callbackSuccess, JParameter callbackParameter) { boolean lazy = method.getAnnotation(LazyCommand.class) != null; boolean quiet = method.getAnnotation(QuietCommand.class) != null; srcWriter.print("CommandParam commandParam = new CommandParam("); srcWriter.print("%s, ", lazy); srcWriter.print("%s, ", quiet); srcWriter.print("this.serializer, "); srcWriter.print("Lists.newArrayList(Arrays.asList("); int i = 0; for (JParameter parameter : method.getParameters()) { if (!parameter.equals(callbackParameter)) { if (i++ > 0) { srcWriter.print(", "); } srcWriter.print("$%d_%s", i, parameter.getName()); } } srcWriter.println(")), "); srcWriter.indent(); srcWriter.println("Lists.newArrayList("); srcWriter.indent(); i = 0; if (callbackParameter != null) { srcWriter.print("$%d_%s", method.getParameters().length, callbackParameter.getName()); i++; } if (callbackSuccess != null) { for (CallbackMethod callbackMethod : callbackSuccess) { if (i++ > 0) { srcWriter.print(", "); } srcWriter.println("new CallbackAdapter<%s>(){", this.typeAsString(method.getReturnType(), true)); srcWriter.indent(); if (callbackMethod.successMethodName != null) { srcWriter.println("public void onSuccess(%s result){", this.typeAsString(method.getReturnType(), true)); srcWriter.indent(); srcWriter.println("getHandler().%s(result);", callbackMethod.successMethodName); srcWriter.outdent(); srcWriter.println("}"); } if (callbackMethod.failureMethodName != null) { srcWriter .println("public void onFailure(Throwable caught){", this.typeAsString(method.getReturnType(), true)); srcWriter.indent(); srcWriter.println("getHandler().%s(caught);", callbackMethod.failureMethodName); srcWriter.outdent(); srcWriter.println("}"); } srcWriter.outdent(); srcWriter.print("}"); } } srcWriter.outdent(); srcWriter.println("));"); srcWriter.outdent(); }