sashapolo commented on code in PR #5039: URL: https://github.com/apache/ignite-3/pull/5039#discussion_r1916549503
########## modules/configuration-annotation-processor/src/main/java/org/apache/ignite/internal/configuration/processor/validation/Validator.java: ########## @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.configuration.processor.validation; + +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toSet; +import static org.apache.ignite.internal.configuration.processor.ConfigurationProcessor.TOP_LEVEL_ANNOTATIONS; +import static org.apache.ignite.internal.configuration.processor.ConfigurationProcessorUtils.containsAnyAnnotation; +import static org.apache.ignite.internal.configuration.processor.ConfigurationProcessorUtils.isValidValueAnnotationFieldType; +import static org.apache.ignite.internal.configuration.processor.ConfigurationProcessorUtils.joinSimpleName; +import static org.apache.ignite.internal.configuration.processor.ConfigurationProcessorUtils.sameType; +import static org.apache.ignite.internal.configuration.processor.ConfigurationProcessorUtils.simpleName; + +import java.lang.annotation.Annotation; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.Name; +import javax.lang.model.element.VariableElement; +import org.apache.ignite.internal.configuration.processor.ClassWrapper; +import org.apache.ignite.internal.configuration.processor.ConfigurationValidationException; + +/** + * Base class for configuration validators. + */ +public abstract class Validator { + final ProcessingEnvironment processingEnvironment; + + Validator(ProcessingEnvironment processingEnvironment) { + this.processingEnvironment = processingEnvironment; + } + + public abstract void validate(ClassWrapper classWrapper) throws ConfigurationValidationException; + + @SafeVarargs + static void assertNotContainsFieldAnnotatedWith(ClassWrapper classWrapper, Class<? extends Annotation>... annotations) { + if (containsAnyAnnotation(classWrapper.fields(), annotations)) { + throw new ConfigurationValidationException(classWrapper, String.format( + "Must not have fields annotated with %s.", joinSimpleName(" or ", annotations) + )); + } + } + + @SafeVarargs + static void assertSuperClassNotContainsFieldAnnotatedWith(ClassWrapper classWrapper, Class<? extends Annotation>... annotations) { + if (containsAnyAnnotation(classWrapper.requiredSuperClass().fields(), annotations)) { + throw new ConfigurationValidationException(classWrapper, String.format( + "Superclass %s must not have fields annotated with %s.", + classWrapper.requiredSuperClass(), joinSimpleName(" or ", annotations) + )); + } + } + + static void assertHasNoSuperClass(ClassWrapper classWrapper) { Review Comment: In `ClassWrapper` we have a `getRequiredSuperclass` method, which does the opposite, do you think we should move it there? -- 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]
