Example #1
0
 public static JavaType getInlineType(BuilderContext context, Inline inline) {
   try {
     return ClassToJavaType.FUNCTION.apply(inline.type());
   } catch (MirroredTypeException e) {
     return context.getStringJavaTypeFunction().apply(e.getTypeMirror().toString());
   }
 }
Example #2
0
 private String getDecoratorClass(FixedField fixedField) {
   try {
     fixedField.decorator();
   } catch (MirroredTypeException mte) {
     return mte.getTypeMirror().toString();
   }
   return null;
 }
Example #3
0
 public static Set<TypeElement> getBuildableReferences(
     BuilderContext context, ExternalBuildables buildable) {
   Set<TypeElement> result = new LinkedHashSet<TypeElement>();
   for (BuildableReference ref : buildable.refs()) {
     try {
       result.add(context.getElements().getTypeElement(ref.value().getCanonicalName()));
     } catch (MirroredTypeException e) {
       result.add(context.getElements().getTypeElement(e.getTypeMirror().toString()));
     }
   }
   return result;
 }
  private void processElement(TypeElement serviceProvider) {
    if (processed.contains(serviceProvider)) {
      return;
    }

    processed.add(serviceProvider);
    ServiceProvider annotation = serviceProvider.getAnnotation(ServiceProvider.class);
    if (annotation != null) {
      try {
        annotation.value();
      } catch (MirroredTypeException ex) {
        TypeMirror serviceInterface = ex.getTypeMirror();
        if (verifyAnnotation(serviceInterface, serviceProvider)) {
          String interfaceName = ex.getTypeMirror().toString();
          createProviderFile(serviceProvider, interfaceName);
        }
      }
    }
  }
  public ContentProviderDefinition(Element typeElement, ProcessorManager processorManager) {
    super(typeElement, processorManager);

    ContentProvider provider = element.getAnnotation(ContentProvider.class);
    if (provider != null) {
      try {
        provider.database();
      } catch (MirroredTypeException mte) {
        databaseName = TypeName.get(mte.getTypeMirror());
      }
      useSafeQueryChecking = provider.useSafeQueryChecking();
      DatabaseDefinition databaseDefinition = manager.getDatabaseWriter(databaseName);
      databaseNameString = databaseDefinition.databaseName;
      setOutputClassName(databaseDefinition.classSeparator + DEFINITION_NAME);

      authority = provider.authority();

      TableEndpointValidator validator = new TableEndpointValidator();
      List<? extends Element> elements =
          manager.getElements().getAllMembers((TypeElement) typeElement);
      for (Element innerElement : elements) {
        if (innerElement.getAnnotation(TableEndpoint.class) != null) {
          TableEndpointDefinition endpointDefinition =
              new TableEndpointDefinition(innerElement, manager);
          if (validator.validate(processorManager, endpointDefinition)) {
            endpointDefinitions.add(endpointDefinition);
          }
        }
      }
    }

    methods =
        new MethodDefinition[] {
          new QueryMethod(this, manager),
          new InsertMethod(this, false),
          new InsertMethod(this, true),
          new DeleteMethod(this, manager),
          new UpdateMethod(this, manager)
        };
  }
  @Override
  public boolean doProcess(Set<? extends TypeElement> set, RoundEnvironment re) {
    GenerationInfo generationInfo = getGenerationInfo();
    for (Element element : re.getElementsAnnotatedWith(UaithneConfiguration.class)) {
      if (element.getKind() == ElementKind.CLASS) {
        UaithneConfiguration configuration = element.getAnnotation(UaithneConfiguration.class);
        if (configuration != null) {
          generationInfo.setConfigurationElement(element);
          generationInfo.setUseIsInBooleanObjectGetter(configuration.booleanObjectGetterWithIs());
          generationInfo.setIncludeExecuteOtherMethodInExecutors(
              configuration.includeExecuteOtherMethodInExecutors());
          generationInfo.setIncludeExecutePostOperationInOperations(
              configuration.includeExecutePostOperationInOperations());
          generationInfo.setSetResultingIdInOperationEnabled(
              configuration.setResultingIdInOperation());
          generationInfo.setExecutorExtendsExecutorGroup(
              configuration.executorExtendsExecutorGroup());

          if (generationInfo.isIncludeExecuteOtherMethodInExecutors()
              && generationInfo.isExecutorExtendsExecutorGroup()) {
            processingEnv
                .getMessager()
                .printMessage(
                    Diagnostic.Kind.ERROR,
                    "For set includeExecutePostOperationInOperations to true you also must set executorExtendsExecutorGroup to false (continue assuming the first one as false)",
                    element);
            generationInfo.setIncludeExecutePostOperationInOperations(false);
          }

          generationInfo.setGenerateDefaultEntityOperations(
              configuration.enableDefaultEntityOperations());
          generationInfo.setGenerateJustOperationsEnabled(configuration.enableJustOperations());
          generationInfo.setGenerateSaveOperationsEnabled(configuration.enableSaveOperations());
          generationInfo.setGenerateMergeOperationsEnabled(configuration.enableMergeOperations());
          generationInfo.setGenerateModuleAbstractExecutorsEnabled(
              configuration.enableModuleAbstractExecutors());
          generationInfo.setGenerateModuleChainedExecutorsEnabled(
              configuration.enableModuleChainedExecutors());
          generationInfo.setGenerateModuleChainedGroupingExecutorsEnabled(
              configuration.enableModuleChainedGroupingExecutors());

          if (generationInfo.isGenerateModuleChainedGroupingExecutorsEnabled()
              && generationInfo.isExecutorExtendsExecutorGroup()) {
            processingEnv
                .getMessager()
                .printMessage(
                    Diagnostic.Kind.ERROR,
                    "For set enableModuleChainedGroupingExecutors to true you also must set executorExtendsExecutorGroup to false (continue assuming the first one as false)",
                    element);
            generationInfo.setGenerateModuleChainedGroupingExecutorsEnabled(false);
          }

          generationInfo.setMyBatisBackends(configuration.myBatisBackendConfigurations());

          generationInfo.setEnableBeanValidations(configuration.enableBeanValidations());

          HashMap<AnnotationConfigurationKeys, ArrayList<DataTypeInfo>> validationConfigurations =
              generationInfo.getValidationConfigurations();
          for (AnnotationConfiguration annotationConfiguration :
              configuration.annotationConfigurations()) {
            AnnotationConfigurationKeys key = annotationConfiguration.key();
            DataTypeInfo dataType;
            try {
              dataType = NamesGenerator.createResultDataType(annotationConfiguration.value());
            } catch (MirroredTypeException ex) {
              // See:
              // http://blog.retep.org/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor/
              dataType = NamesGenerator.createDataTypeFor(ex.getTypeMirror());
            }
            validationConfigurations.get(key).add(dataType);
          }

          ArrayList<DataTypeInfo> validationDataTypes =
              validationConfigurations.get(AnnotationConfigurationKeys.ID_STRING);
          if (validationDataTypes.isEmpty()) {
            validationDataTypes.addAll(
                validationConfigurations.get(AnnotationConfigurationKeys.ID));
          }

          validationDataTypes =
              validationConfigurations.get(AnnotationConfigurationKeys.MANDATORY_STRING);
          if (validationDataTypes.isEmpty()) {
            validationDataTypes.addAll(
                validationConfigurations.get(AnnotationConfigurationKeys.MANDATORY));
          }

          validationDataTypes =
              validationConfigurations.get(
                  AnnotationConfigurationKeys.MANDATORY_WITH_DEFAULT_VALUE_WHEN_INSERT_STRING);
          if (validationDataTypes.isEmpty()) {
            validationDataTypes.addAll(
                validationConfigurations.get(
                    AnnotationConfigurationKeys.MANDATORY_WITH_DEFAULT_VALUE_WHEN_INSERT));
          }

          validationDataTypes =
              validationConfigurations.get(AnnotationConfigurationKeys.OPTIONAL_STRING);
          if (validationDataTypes.isEmpty()) {
            validationDataTypes.addAll(
                validationConfigurations.get(AnnotationConfigurationKeys.OPTIONAL));
          }

          validationDataTypes =
              validationConfigurations.get(AnnotationConfigurationKeys.INSERT_ENTITY_VALUE);
          if (validationDataTypes.isEmpty()) {
            validationDataTypes.addAll(
                validationConfigurations.get(AnnotationConfigurationKeys.MANDATORY));
          }

          validationDataTypes =
              validationConfigurations.get(AnnotationConfigurationKeys.UPDATE_ENTITY_VALUE);
          if (validationDataTypes.isEmpty()) {
            validationDataTypes.addAll(
                validationConfigurations.get(AnnotationConfigurationKeys.MANDATORY));
          }

          validationDataTypes =
              validationConfigurations.get(AnnotationConfigurationKeys.MERGE_ENTITY_VALUE);
          if (validationDataTypes.isEmpty()) {
            validationDataTypes.addAll(
                validationConfigurations.get(AnnotationConfigurationKeys.MANDATORY));
          }

          validationDataTypes =
              validationConfigurations.get(AnnotationConfigurationKeys.SAVE_ENTITY_VALUE);
          if (validationDataTypes.isEmpty()) {
            validationDataTypes.addAll(
                validationConfigurations.get(AnnotationConfigurationKeys.MANDATORY));
          }

          validationDataTypes =
              validationConfigurations.get(AnnotationConfigurationKeys.INSERT_GROUP);
          if (validationDataTypes.size() > 1) {
            processingEnv
                .getMessager()
                .printMessage(Diagnostic.Kind.ERROR, "Only one INSERT_GROUP can exist", element);
          }

          validationDataTypes =
              validationConfigurations.get(AnnotationConfigurationKeys.UPDATE_GROUP);
          if (validationDataTypes.size() > 1) {
            processingEnv
                .getMessager()
                .printMessage(Diagnostic.Kind.ERROR, "Only one UPDATE_GROUP can exist", element);
          }

          validationDataTypes =
              validationConfigurations.get(AnnotationConfigurationKeys.MERGE_GROUP);
          if (validationDataTypes.size() > 1) {
            processingEnv
                .getMessager()
                .printMessage(Diagnostic.Kind.ERROR, "Only one MERGE_GROUP can exist", element);
          }

          validationDataTypes =
              validationConfigurations.get(AnnotationConfigurationKeys.SAVE_GROUP);
          if (validationDataTypes.size() > 1) {
            processingEnv
                .getMessager()
                .printMessage(Diagnostic.Kind.ERROR, "Only one SAVE_GROUP can exist", element);
          }

          for (ArrayList<DataTypeInfo> types : validationConfigurations.values()) {
            while (types.remove(DataTypeInfo.VOID_DATA_TYPE)) {}
          }

          HashMap<AnnotationConfigurationKeys, HashMap<DataTypeInfo, DataTypeInfo>>
              validationSubstitutions = generationInfo.getValidationSubstitutions();
          for (AnnotationSubstitution annotationSubstitution :
              configuration.annotationSubstitutions()) {
            AnnotationConfigurationKeys key = annotationSubstitution.when();

            DataTypeInfo from;
            try {
              from = NamesGenerator.createResultDataType(annotationSubstitution.from());
            } catch (MirroredTypeException ex) {
              // See:
              // http://blog.retep.org/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor/
              from = NamesGenerator.createDataTypeFor(ex.getTypeMirror());
            }

            DataTypeInfo to;
            try {
              to = NamesGenerator.createResultDataType(annotationSubstitution.to());
            } catch (MirroredTypeException ex) {
              // See:
              // http://blog.retep.org/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor/
              to = NamesGenerator.createDataTypeFor(ex.getTypeMirror());
            }

            validationSubstitutions.get(key).put(from, to);
          }

          DataTypeInfo entitiesImplementsDataType;
          try {
            entitiesImplementsDataType =
                NamesGenerator.createResultDataType(configuration.entitiesImplements());
          } catch (MirroredTypeException ex) {
            // See:
            // http://blog.retep.org/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor/
            entitiesImplementsDataType = NamesGenerator.createDataTypeFor(ex.getTypeMirror());
          }

          if (entitiesImplementsDataType == null) {
            processingEnv
                .getMessager()
                .printMessage(
                    Diagnostic.Kind.ERROR,
                    "Unable to find the interface that the entities implements",
                    element);
            return true;
          }

          if (!entitiesImplementsDataType.isVoid()) {
            generationInfo.setEntitiesImplements(entitiesImplementsDataType);
          }

          DataTypeInfo applicationParameterType;
          try {
            applicationParameterType =
                NamesGenerator.createResultDataType(configuration.applicationParameterType());
          } catch (MirroredTypeException ex) {
            // See:
            // http://blog.retep.org/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor/
            applicationParameterType = NamesGenerator.createDataTypeFor(ex.getTypeMirror());
          }
          if (!applicationParameterType.isVoid()) {
            generationInfo.setApplicationParameterType(applicationParameterType);
          }
        }
      }
    }
    return true; // no further processing of this annotation type
  }