com.helger.jcodemodel.JDefinedClass Java Examples

The following examples show how to use com.helger.jcodemodel.JDefinedClass. 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: SwaggerServiceModelGenerator.java    From camunda-bpm-swagger with Apache License 2.0 5 votes vote down vote up
@Override
@SneakyThrows
public JCodeModel generate() {
  final JDefinedClass c = camundaRestService.getDefinedClass();

  // class information
  c._extends(camundaRestService.getServiceImplClass());
  c.annotate(codeModel.ref(Path.class)).param("value", camundaRestService.getPath());

  final String tags = TagRespository.lookup(camundaRestService);
  camundaRestService.getRestService().setPath(camundaRestService.getPath());
  camundaRestService.getRestService().setTags(tags);
  camundaRestService.getRestService().setDescription(camundaRestService.getName());
  c.annotate(codeModel.ref(Api.class)).param("value", camundaRestService.getName()).param("tags", tags);

  // generate constructor
  for (final Constructor<?> constructor : camundaRestService.getServiceImplClass().getConstructors()) {
    new InvocationStep(c.constructor(constructor.getModifiers())).constructor(constructor);
  }

  // construct return type information
  final Map<Method, ReturnTypeInfo> returnTypes = Arrays.stream(camundaRestService.getServiceInterfaceClass().getDeclaredMethods()) // iterate over interface
      // methods
      .map(m -> new ReturnTypeInfo(camundaRestService.getModelRepository(), codeModel, m)
          .applyImplementationMethods(camundaRestService.getServiceImplClass().getDeclaredMethods())) // apply impl methods
      .collect(Collectors.toMap(r -> r.getMethod(), r -> r)); // build the map

  generateMethods(c, camundaRestService.getRestService(), returnTypes, NO_PREFIX);

  return this.codeModel;
}
 
Example #2
Source File: SwaggerServiceModelGenerator.java    From camunda-bpm-swagger with Apache License 2.0 5 votes vote down vote up
private void generateMethods(final JDefinedClass clazz, final RestService restService, final Map<Method, ReturnTypeInfo> methods, final String parentPathPrefix,
    final ParentInvocation... parentInvocations) {

  for (final Method m : methods.keySet()) {
    // create method
    final MethodStep methodStep = new MethodStep(camundaRestService.getModelRepository(), restService, clazz);
    methodStep.create(methods.get(m), Pair.of(camundaRestService.getPath(), parentPathPrefix), camundaRestService.getModelRepository().getDocumentation().get(), parentInvocations);

    // dive into resource processing
    if (TypeHelper.isResource(methodStep.getReturnType())) {

      // add doc reference
      final RestService resourceService = new RestService();
      resourceService.setTags(TagRespository.lookup(camundaRestService));
      // path is not needed for the sub resource
      // resourceService.setPath(camundaRestService.getPath() + methodStep.getPath());
      camundaRestService.getModelRepository().addService(methodStep.getReturnType().getName(), resourceService);

      generateMethods(clazz, // the class
          resourceService,
          ResourceMethodGenerationHelper.resourceReturnTypeInfos(camundaRestService.getModelRepository(), codeModel, methodStep.getReturnType()), // info about return types
          methodStep.getPath(), // path prefix to generate REST paths
          ResourceMethodGenerationHelper.createParentInvocations(parentInvocations, m) // invocation hierarchy
          );
    }

  }
}
 
Example #3
Source File: NeedsPermissionHandler.java    From AndroidAnnotationsPermissionsDispatcherPlugin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private boolean removeRuntimePermissionsAnnotation(JDefinedClass definedClass) {
    try {
        Field annotationsField = definedClass.getClass().getDeclaredField("m_aAnnotations");
        annotationsField.setAccessible(true);
        List<JAnnotationUse> annotations = (List<JAnnotationUse>) annotationsField.get(definedClass);
        if (annotations == null) {
            return true;
        }
        annotations.removeIf(jAnnotationUse -> jAnnotationUse.getAnnotationClass().name().equals("RuntimePermissions"));
        return true;
    } catch (ClassCastException | NoSuchFieldException | IllegalAccessException e) {
        return false;
    }
}
 
Example #4
Source File: MethodStep.java    From camunda-bpm-swagger with Apache License 2.0 4 votes vote down vote up
public MethodStep(final ModelRepository modelRepository, final RestService restService, final JDefinedClass clazz) {
  this.modelRepository = modelRepository;
  this.restService = restService;
  this.clazz = clazz;
}