com.helger.jcodemodel.AbstractJClass Java Examples

The following examples show how to use com.helger.jcodemodel.AbstractJClass. 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 5 votes vote down vote up
public void setOnRequestPermissionsResultDelegateCall(AbstractJClass delegateClass) {
    if (onRequestPermissionsResultMethod != null) {
        return;
    }

    setOnRequestPermissionsResultMethod();

    onRequestPermissionsResultMethodDelegateBlock.add(delegateClass.staticInvoke("onRequestPermissionsResult")
            .arg(JExpr._this())
            .arg(onRequestPermissionsResultRequestCodeParam)
            .arg(onRequestPermissionsResultGrantResultsParam));
}
 
Example #2
Source File: PermissionDispatcherHolder.java    From AndroidAnnotationsPermissionsDispatcherPlugin with Apache License 2.0 5 votes vote down vote up
public void setOnActivityResultDelegateCall(AbstractJClass delegateClass) {
    if (onActivityResultMethod != null) {
        return;
    }

    setOnActivityResultMethod();

    onActivityResultMethodDelegateBlock.add(delegateClass.staticInvoke("onActivityResult")
            .arg(JExpr._this())
            .arg(onActivityResultRequestCodeParam));
}
 
Example #3
Source File: NeedsPermissionHandler.java    From AndroidAnnotationsPermissionsDispatcherPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void process(Element element, EComponentHolder holder) throws Exception {
    TypeElement annotatedElement = holder.getAnnotatedElement();
    if (annotatedElementHasRuntimePermissions(annotatedElement)) {
        String delegateClassName = annotatedElement.getQualifiedName().toString() + "PermissionsDispatcher";
        AbstractJClass delegateClass = getJClass(delegateClassName);
        PermissionDispatcherHolder permissionDispatcherHolder = holder.getPluginHolder(new PermissionDispatcherHolder(holder));

        setDispatcherCallbacks(element, delegateClass, permissionDispatcherHolder);
        JFieldVar dispatcherCalledField = permissionDispatcherHolder.getPermissionDispatcherCalledField();
        setPermissionMethods(element, holder, delegateClass, dispatcherCalledField);
    }
}
 
Example #4
Source File: NeedsPermissionHandler.java    From AndroidAnnotationsPermissionsDispatcherPlugin with Apache License 2.0 5 votes vote down vote up
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 #5
Source File: NeedsPermissionHandler.java    From AndroidAnnotationsPermissionsDispatcherPlugin with Apache License 2.0 5 votes vote down vote up
private void setDispatcherCallbacks(Element element, AbstractJClass delegateClass, PermissionDispatcherHolder permissionDispatcherHolder) {
    if (hasSpecialPermissions(element)) {
        permissionDispatcherHolder.setOnActivityResultDelegateCall(delegateClass);
    }
    if (hasNormalPermissions(element)) {
        permissionDispatcherHolder.setOnRequestPermissionsResultDelegateCall(delegateClass);
    }
}
 
Example #6
Source File: ReturnTypeInfo.java    From camunda-bpm-swagger with Apache License 2.0 4 votes vote down vote up
void extractReturnType(final Method method) {
  final Type returnType = method.getGenericReturnType();
  Class<?> result;

  if (returnType instanceof ParameterizedType) {
    final ParameterizedType type = (ParameterizedType) returnType;
    result = (Class<?>) type.getRawType();

    AbstractJClass[] parameterClasses = new AbstractJClass[type.getActualTypeArguments().length];
    for (int i = 0; i < type.getActualTypeArguments().length; i++) {
      final Type typeArg = type.getActualTypeArguments()[i];
      if (typeArg instanceof Class<?>) {
        // plain class X -> List<X>
        final Class<?> candidateParameterClass = (Class<?>) typeArg;
        if (TypeHelper.isDto(candidateParameterClass)) {
          final TypeStep dto = new TypeStep(modelRepository, candidateParameterClass, codeModel);
          // collect DTO
          dtos.add(dto);
          // an DTO is always a class
          parameterClasses[i] = (AbstractJClass) dto.getType();
        } else {
          // non DTO
          parameterClasses[i] = codeModel.ref(candidateParameterClass);
        }

      } else if (typeArg instanceof ParameterizedType) {
        // parametrized type Map<?,?> -> List<Map<X,Y>>
        log.debug(
            "The return type was a class parametrized by a parametrized class. The generator doesn't support it yet. Falling back to the basic type for {}",
            method);
        parameterClasses = new AbstractJClass[0];
        break;
      }
    }

    this.parameterTypes = parameterClasses;

  } else {
    result = method.getReturnType();
  }
  this.rawType = result;
}