com.helger.jcodemodel.JMethod Java Examples
The following examples show how to use
com.helger.jcodemodel.JMethod.
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: JaxRsAnnotationStep.java From camunda-bpm-swagger with Apache License 2.0 | 5 votes |
public JMethod annotate(final Method m) { javaxRsAnnotation(m).ifPresent(a -> { this.type = a; getMethod().annotate(a); }); return getMethod(); }
Example #2
Source File: PathAnnotationStep.java From camunda-bpm-swagger with Apache License 2.0 | 5 votes |
public JMethod annotate(final String parentPathPrefix, final Method method) { this.path = path(parentPathPrefix, method); if (!TypeHelper.isResource(methodStep.getReturnType())) { getMethod().annotate(Path.class).param("value", this.path); } return getMethod(); }
Example #3
Source File: NeedsPermissionHandler.java From AndroidAnnotationsPermissionsDispatcherPlugin with Apache License 2.0 | 5 votes |
private void setPermissionMethods(Element element, EComponentHolder holder, AbstractJClass delegateClass, JFieldVar dispatcherCalledField) { ExecutableElement executableElement = (ExecutableElement) element; JMethod overrideMethod = codeModelHelper.overrideAnnotatedMethod(executableElement, holder); JBlock previousMethodBody = codeModelHelper.removeBody(overrideMethod); JBlock overrideMethodBody = overrideMethod.body(); JConditional conditional = overrideMethodBody._if(dispatcherCalledField.not()); JBlock thenBlock = conditional._then(); thenBlock.assign(dispatcherCalledField, JExpr.TRUE); String delegateMethodName = element.getSimpleName().toString() + "WithPermissionCheck"; JInvocation delegateCall = delegateClass.staticInvoke(delegateMethodName) .arg(JExpr._this()); overrideMethod.params().forEach(delegateCall::arg); if (overrideMethod.hasVarArgs()) { JVar jVar = overrideMethod.varParam(); if (jVar != null) { delegateCall.arg(jVar); } } if (!removeRuntimePermissionsAnnotation(holder.getGeneratedClass())) { codeModelHelper.copyAnnotation(overrideMethod, findAnnotation(element)); } thenBlock.add(delegateCall); JBlock elseBlock = conditional._else(); elseBlock.assign(dispatcherCalledField, JExpr.FALSE); elseBlock.add(previousMethodBody); }
Example #4
Source File: ApiOperationStep.java From camunda-bpm-swagger with Apache License 2.0 | 4 votes |
public ApiOperationStep(final JMethod method, final RestOperation restOperation) { super(method); this.restOperation = restOperation; }
Example #5
Source File: JaxRsAnnotationStep.java From camunda-bpm-swagger with Apache License 2.0 | 4 votes |
public JaxRsAnnotationStep(final JMethod method) { super(method); }
Example #6
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 #7
Source File: ConsumesAndProducesStep.java From camunda-bpm-swagger with Apache License 2.0 | 4 votes |
public ConsumesAndProducesStep(final JMethod method) { super(method); }
Example #8
Source File: ConsumesAndProducesStep.java From camunda-bpm-swagger with Apache License 2.0 | 4 votes |
public JMethod annotate(final Method method) { consumesAndProduces(method).entrySet().forEach(e -> getMethod().annotate(e.getKey()).param("value", e.getValue())); return getMethod(); }
Example #9
Source File: ApiResponsesStep.java From camunda-bpm-swagger with Apache License 2.0 | 4 votes |
public ApiResponsesStep(final JMethod method, final RestOperation restOperation) { super(method); this.restOperation = restOperation; }