tkalkirill commented on a change in pull request #490:
URL: https://github.com/apache/ignite-3/pull/490#discussion_r766663186



##########
File path: 
modules/configuration-annotation-processor/src/main/java/org/apache/ignite/internal/configuration/processor/Processor.java
##########
@@ -955,4 +967,105 @@ private void checkSuperclassContainAnyAnnotation(
             ));
         }
     }
+
+    /**
+     * Validation of class fields with {@link InjectedName} if present.
+     *
+     * @param clazz  Class type.
+     * @param fields Class fields.
+     * @throws ProcessorException If the class validation fails.
+     */
+    private void validateInjectedNameFieldsIfPresents(TypeElement clazz, 
List<VariableElement> fields) {
+        List<VariableElement> injectedNameFields = 
collectAnnotatedFields(fields, InjectedName.class);
+
+        if (injectedNameFields.isEmpty()) {
+            return;
+        }
+
+        if (injectedNameFields.size() > 1) {
+            throw new ProcessorException(String.format(
+                "%s contains more than one field with %s",
+                clazz.getQualifiedName(),
+                simpleName(InjectedName.class)
+            ));
+        }
+
+        VariableElement injectedNameField = injectedNameFields.get(0);
+
+        if (!isStringClass(injectedNameField.asType())) {
+            throw new ProcessorException(String.format(
+                FIELD_MUST_BE_STRING_ERROR_FORMAT,
+                simpleName(InjectedName.class),
+                clazz.getQualifiedName(),
+                injectedNameField.getSimpleName()
+            ));
+        }
+
+        if (injectedNameField.getAnnotationMirrors().size() > 1) {
+            throw new ProcessorException(String.format(
+                "%s.%s must contain only one %s",
+                clazz.getQualifiedName(),
+                injectedNameField.getSimpleName(),
+                simpleName(InjectedName.class)
+            ));
+        }
+
+        if (clazz.getAnnotation(Config.class) == null && 
clazz.getAnnotation(PolymorphicConfig.class) == null) {
+            throw new ProcessorException(String.format(
+                "%s %s.%s can only be in a class with %s",
+                simpleName(InjectedName.class),
+                clazz.getQualifiedName(),
+                injectedNameField.getSimpleName(),
+                joinSimpleName(" or ", Config.class, PolymorphicConfig.class)
+            ));
+        }
+    }
+
+    /**
+     * Validation of class fields with {@link Name} if present.
+     *
+     * @param clazz  Class type.
+     * @param fields Class fields.
+     * @throws ProcessorException If the class validation fails.
+     */
+    private void validateNameFieldsIfPresents(TypeElement clazz, 
List<VariableElement> fields) {
+        List<VariableElement> nameFields = collectAnnotatedFields(fields, 
org.apache.ignite.configuration.annotation.Name.class);
+
+        if (nameFields.isEmpty()) {
+            return;
+        }
+
+        for (VariableElement nameField : nameFields) {
+            if (nameField.getAnnotation(ConfigValue.class) == null) {
+                throw new ProcessorException(String.format(
+                    "%s %s.%s can only be with %s",

Review comment:
       The following format was confirmed:
   `%s annotation can only be used with %s: %s.%s`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to