javax.annotation.concurrent.Immutable#com.helger.jcodemodel.JMethod源码实例Demo

下面列出了javax.annotation.concurrent.Immutable#com.helger.jcodemodel.JMethod 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。


public JMethod annotate(final Method m) {
  javaxRsAnnotation(m).ifPresent(a -> {
    this.type = a;
    getMethod().annotate(a);
  });
  return getMethod();
}
 

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();
  }
 

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);
}
 

public ApiOperationStep(final JMethod method, final RestOperation restOperation) {
  super(method);
  this.restOperation = restOperation;
}
 

public JaxRsAnnotationStep(final JMethod method) {
  super(method);
}
 
源代码6 项目: camunda-bpm-swagger   文件: MethodStep.java

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;
}
 

public ConsumesAndProducesStep(final JMethod method) {
  super(method);
}
 

public JMethod annotate(final Method method) {
  consumesAndProduces(method).entrySet().forEach(e -> getMethod().annotate(e.getKey()).param("value", e.getValue()));
  return getMethod();
}
 

public ApiResponsesStep(final JMethod method, final RestOperation restOperation) {
  super(method);
  this.restOperation = restOperation;
}