tkalkirill commented on code in PR #1541: URL: https://github.com/apache/ignite-3/pull/1541#discussion_r1073298474
########## modules/configuration-api/src/main/java/org/apache/ignite/configuration/validation/ValidatorChecker.java: ########## @@ -0,0 +1,202 @@ +/* + * 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.configuration.validation; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.WildcardType; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; +import org.apache.ignite.configuration.NamedListView; +import org.apache.ignite.configuration.annotation.Value; + +/** + * Helper class for the default {@link Validator#canValidate(Class, Class, boolean)} implementation. + */ +class ValidatorChecker { + /** + * Pattern for configuration schema class names. Used to replace the suffix with something else. + * + * @see #canValidateConfigValue(Class, Class) + */ + private static final Pattern CONFIGURATION_SCHEMA_PATTERN = Pattern.compile("ConfigurationSchema$"); + + /** + * Please refer to {@link Validator#canValidate(Class, Class, boolean)} for parameters descriptions. + */ + static boolean canValidate( + Validator<?, ?> validator, + Class<? extends Annotation> annotationType, + Class<?> schemaFieldType, + boolean namedList + ) { + Type[] genericTypeParameters = genericTypeParameters(validator); + + if (genericTypeParameters[0] != annotationType) { Review Comment: Add some description with examples. ########## modules/configuration-api/src/main/java/org/apache/ignite/configuration/validation/ValidatorChecker.java: ########## @@ -0,0 +1,202 @@ +/* + * 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.configuration.validation; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.WildcardType; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; +import org.apache.ignite.configuration.NamedListView; +import org.apache.ignite.configuration.annotation.Value; + +/** + * Helper class for the default {@link Validator#canValidate(Class, Class, boolean)} implementation. + */ +class ValidatorChecker { + /** + * Pattern for configuration schema class names. Used to replace the suffix with something else. + * + * @see #canValidateConfigValue(Class, Class) + */ + private static final Pattern CONFIGURATION_SCHEMA_PATTERN = Pattern.compile("ConfigurationSchema$"); + + /** + * Please refer to {@link Validator#canValidate(Class, Class, boolean)} for parameters descriptions. + */ + static boolean canValidate( + Validator<?, ?> validator, + Class<? extends Annotation> annotationType, + Class<?> schemaFieldType, + boolean namedList + ) { + Type[] genericTypeParameters = genericTypeParameters(validator); + + if (genericTypeParameters[0] != annotationType) { + return false; + } + + Type viewType = genericTypeParameters(validator)[1]; + + if (viewType instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) viewType; + + assert parameterizedType.getRawType() == NamedListView.class; Review Comment: Missed printout what's wrong. ########## modules/configuration-api/src/main/java/org/apache/ignite/configuration/validation/ValidatorChecker.java: ########## @@ -0,0 +1,202 @@ +/* + * 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.configuration.validation; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.WildcardType; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; +import org.apache.ignite.configuration.NamedListView; +import org.apache.ignite.configuration.annotation.Value; + +/** + * Helper class for the default {@link Validator#canValidate(Class, Class, boolean)} implementation. + */ +class ValidatorChecker { + /** + * Pattern for configuration schema class names. Used to replace the suffix with something else. + * + * @see #canValidateConfigValue(Class, Class) + */ + private static final Pattern CONFIGURATION_SCHEMA_PATTERN = Pattern.compile("ConfigurationSchema$"); + + /** + * Please refer to {@link Validator#canValidate(Class, Class, boolean)} for parameters descriptions. + */ + static boolean canValidate( + Validator<?, ?> validator, + Class<? extends Annotation> annotationType, + Class<?> schemaFieldType, + boolean namedList + ) { + Type[] genericTypeParameters = genericTypeParameters(validator); + + if (genericTypeParameters[0] != annotationType) { + return false; + } + + Type viewType = genericTypeParameters(validator)[1]; + + if (viewType instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) viewType; + + assert parameterizedType.getRawType() == NamedListView.class; + + if (!namedList) { + return false; + } + + Type namedListElementType = parameterizedType.getActualTypeArguments()[0]; + + if (namedListElementType instanceof WildcardType) { + return true; + } + + assert namedListElementType instanceof Class; + + Class<?> namedListElementClass = (Class<?>) namedListElementType; + + return canValidateConfigValue(schemaFieldType, namedListElementClass); + } + + if (namedList) { + return false; + } + + assert viewType instanceof Class; Review Comment: Missed printout what's wrong. ########## modules/configuration-api/src/main/java/org/apache/ignite/configuration/validation/ValidatorChecker.java: ########## @@ -0,0 +1,202 @@ +/* + * 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.configuration.validation; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.WildcardType; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; +import org.apache.ignite.configuration.NamedListView; +import org.apache.ignite.configuration.annotation.Value; + +/** + * Helper class for the default {@link Validator#canValidate(Class, Class, boolean)} implementation. + */ +class ValidatorChecker { + /** + * Pattern for configuration schema class names. Used to replace the suffix with something else. + * + * @see #canValidateConfigValue(Class, Class) + */ + private static final Pattern CONFIGURATION_SCHEMA_PATTERN = Pattern.compile("ConfigurationSchema$"); + + /** + * Please refer to {@link Validator#canValidate(Class, Class, boolean)} for parameters descriptions. + */ + static boolean canValidate( + Validator<?, ?> validator, + Class<? extends Annotation> annotationType, + Class<?> schemaFieldType, + boolean namedList + ) { + Type[] genericTypeParameters = genericTypeParameters(validator); + + if (genericTypeParameters[0] != annotationType) { + return false; + } + + Type viewType = genericTypeParameters(validator)[1]; Review Comment: Why call `genericTypeParameters` again? ########## modules/configuration-api/src/main/java/org/apache/ignite/configuration/validation/ValidatorChecker.java: ########## @@ -0,0 +1,202 @@ +/* + * 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.configuration.validation; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.WildcardType; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; +import org.apache.ignite.configuration.NamedListView; +import org.apache.ignite.configuration.annotation.Value; + +/** + * Helper class for the default {@link Validator#canValidate(Class, Class, boolean)} implementation. + */ +class ValidatorChecker { + /** + * Pattern for configuration schema class names. Used to replace the suffix with something else. + * + * @see #canValidateConfigValue(Class, Class) + */ + private static final Pattern CONFIGURATION_SCHEMA_PATTERN = Pattern.compile("ConfigurationSchema$"); + + /** + * Please refer to {@link Validator#canValidate(Class, Class, boolean)} for parameters descriptions. + */ + static boolean canValidate( + Validator<?, ?> validator, + Class<? extends Annotation> annotationType, + Class<?> schemaFieldType, + boolean namedList + ) { + Type[] genericTypeParameters = genericTypeParameters(validator); + + if (genericTypeParameters[0] != annotationType) { + return false; + } + + Type viewType = genericTypeParameters(validator)[1]; + + if (viewType instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) viewType; + + assert parameterizedType.getRawType() == NamedListView.class; + + if (!namedList) { + return false; + } + + Type namedListElementType = parameterizedType.getActualTypeArguments()[0]; + + if (namedListElementType instanceof WildcardType) { + return true; + } + + assert namedListElementType instanceof Class; Review Comment: Missed printout what's wrong. ########## modules/configuration/src/main/java/org/apache/ignite/internal/configuration/ConfigurationChanger.java: ########## @@ -157,13 +158,13 @@ private StorageRoots(SuperRoot roots, long version) { public ConfigurationChanger( Notificator notificator, Collection<RootKey<?, ?>> rootKeys, - Map<Class<? extends Annotation>, Set<Validator<?, ?>>> validators, + Collection<Validator<?, ?>> validators, ConfigurationStorage storage ) { checkConfigurationType(rootKeys, storage); this.notificator = notificator; - this.validators = validators; + this.validators = new ArrayList<>(validators); Review Comment: Maybe: `List.copyOf(validators)` ? -- 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]
