com.helger.jcodemodel.JMod Java Examples
The following examples show how to use
com.helger.jcodemodel.JMod.
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: PermissionDispatcherHolder.java From AndroidAnnotationsPermissionsDispatcherPlugin with Apache License 2.0 | 6 votes |
private void setOnRequestPermissionsResultMethod() { onRequestPermissionsResultMethod = holder().getGeneratedClass().method(JMod.PUBLIC, getCodeModel().VOID, "onRequestPermissionsResult"); onRequestPermissionsResultMethod.annotate(Override.class); onRequestPermissionsResultRequestCodeParam = onRequestPermissionsResultMethod.param(getCodeModel().INT, "requestCode"); JVar permissionsParam = onRequestPermissionsResultMethod.param(getJClass("java.lang.String").array(), "permissions"); onRequestPermissionsResultGrantResultsParam = onRequestPermissionsResultMethod.param(getCodeModel().INT.array(), "grantResults"); JBlock onRequestPermissionsResultMethodBody = onRequestPermissionsResultMethod.body(); onRequestPermissionsResultMethodBody.invoke(JExpr._super(), "onRequestPermissionsResult") .arg(onRequestPermissionsResultRequestCodeParam) .arg(permissionsParam) .arg(onRequestPermissionsResultGrantResultsParam); onRequestPermissionsResultMethodDelegateBlock = onRequestPermissionsResultMethodBody.blockVirtual(); onRequestPermissionsResultMethodBody.assign(getPermissionDispatcherCalledField(), JExpr.FALSE); }
Example #2
Source File: MethodStep.java From camunda-bpm-swagger with Apache License 2.0 | 4 votes |
public JMethod create(final ReturnTypeInfo info, final Pair<String, String> pathPrefix, final Map<Pair<String, String>, RestOperation> docs, final ParentInvocation... parentInvocations) { this.returnType = info.getRawType(); // determine method name and return type Optional<TypeStep> dto = Optional.empty(); if (info.isParametrized()) { this.methodReturnType = this.clazz.owner().ref(info.getRawType()).narrow(info.getParameterTypes()); if (TypeHelper.isList(info.getRawType())) { this.returnTypeStyle = ReturnTypeStyle.DTO_LIST; } else if (TypeHelper.isMap(info.getRawType()) // map && info.getParameterTypes().length == 2 // parametrized && TypeHelper.isString(info.getParameterTypes()[0])) { // with string as key this.returnTypeStyle = ReturnTypeStyle.DTO_MAP_STRING; } else { // doesn't support return parametrized type log.debug("Unsupported return collection type with {} type parameters:", info.getParameterTypes().length, info.getRawType().getName()); this.returnTypeStyle = ReturnTypeStyle.PLAIN; } } else { dto = Optional.of(new TypeStep(modelRepository, info.getRawType(), clazz.owner())); this.returnTypeStyle = dto.get().isDto() ? ReturnTypeStyle.DTO : ReturnTypeStyle.PLAIN; this.methodReturnType = dto.get().getType(); } final String methodName = methodName(parentInvocations, info.getMethod().getName()); method = clazz.method(JMod.PUBLIC, methodReturnType, methodName); // path annotation final PathAnnotationStep pathAnnotationStep = new PathAnnotationStep(this); pathAnnotationStep.annotate(pathPrefix.getRight(), info.getMethod()); this.path = pathAnnotationStep.getPath(); // JAX RS final JaxRsAnnotationStep jaxrsAnnotation = new JaxRsAnnotationStep(method); jaxrsAnnotation.annotate(info.getMethod()); // consume and produce final ConsumesAndProducesStep consumesAndProduces = new ConsumesAndProducesStep(method); consumesAndProduces.annotate(info.getMethod()); final Pair key = Pair.of(DocumentationYaml.normalizePath(pathPrefix.getLeft() + this.path), jaxrsAnnotation.getType().getSimpleName()); final RestOperation doc = docs.get(key); if (doc == null) { log.error("No doc found for {}", key); } // register docs for this DTO. if (dto.isPresent()) { modelRepository.addDoc(dto.get().getFullQualifiedName(), doc, DocStyle.RETURN_TYPE); } // create invocation final JInvocation invoke = new InvocationStep(method).method(modelRepository, info.getMethod(), doc, parentInvocations); // body if (TypeHelper.isVoid(getReturnType())) { method.body().add(invoke); } else { // overriding, only if it is a simple return type (not parametrized, not DTO, not a resource) if (parentInvocations == null) { method.annotate(Override.class); } method.body()._return(invoke); } // ApiOperation final ApiOperationStep apiOperation = new ApiOperationStep(method, doc); apiOperation.annotate(this, info.getMethod()); // add method restService.getOperations().put(info.getMethod().getName(), doc); // ApiResponse final ApiResponsesStep responesStep = new ApiResponsesStep(method, doc); responesStep.annotate(this, info.getMethod()); return method; }
Example #3
Source File: PermissionDispatcherHolder.java From AndroidAnnotationsPermissionsDispatcherPlugin with Apache License 2.0 | 4 votes |
private void setPermissionDispatcherCalledField() { permissionDispatcherCalledField = holder().getGeneratedClass().field(JMod.PRIVATE, getCodeModel().BOOLEAN, "permissionDispatcherCalled_"); }