This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new fa9bf5b9eb Code clean-up - formatting. No functional change. fa9bf5b9eb is described below commit fa9bf5b9ebde586d59e7a36b0c478d0125679adb Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri Aug 29 11:30:29 2025 +0100 Code clean-up - formatting. No functional change. --- .../ObjectReflectionPropertyInspector.java | 184 ++++++++------------- .../xreflection/ReflectionLessCodeGenerator.java | 54 +++--- .../util/xreflection/ReflectionProperty.java | 4 +- .../tomcat/util/xreflection/SetPropertyClass.java | 36 ++-- 4 files changed, 110 insertions(+), 168 deletions(-) diff --git a/java/org/apache/tomcat/util/xreflection/ObjectReflectionPropertyInspector.java b/java/org/apache/tomcat/util/xreflection/ObjectReflectionPropertyInspector.java index 8929e53628..82f5487120 100644 --- a/java/org/apache/tomcat/util/xreflection/ObjectReflectionPropertyInspector.java +++ b/java/org/apache/tomcat/util/xreflection/ObjectReflectionPropertyInspector.java @@ -36,94 +36,75 @@ public final class ObjectReflectionPropertyInspector { public static void main(String... args) throws Exception { if (args.length == 0) { - System.err.println("Usage:\n\t"+ - "org.apache.tomcat.util.xreflection.ObjectReflectionPropertyInspector" + - " <destination directory>" - ); + System.err.println("Usage:\n\t" + "org.apache.tomcat.util.xreflection.ObjectReflectionPropertyInspector" + + " <destination directory>"); System.exit(1); } File outputDir = new File(args[0]); if (!outputDir.exists() || !outputDir.isDirectory()) { - System.err.println("Invalid output directory: "+ outputDir.getAbsolutePath()); + System.err.println("Invalid output directory: " + outputDir.getAbsolutePath()); System.exit(1); } - Set<SetPropertyClass> baseClasses = getKnownClasses() - .stream() - .map(ObjectReflectionPropertyInspector::processClass) - .collect(Collectors.toCollection(LinkedHashSet::new)); - generateCode( - baseClasses, - "org.apache.tomcat.util", - outputDir, - "XReflectionIntrospectionUtils" - ); + Set<SetPropertyClass> baseClasses = + getKnownClasses().stream().map(ObjectReflectionPropertyInspector::processClass) + .collect(Collectors.toCollection(LinkedHashSet::new)); + generateCode(baseClasses, "org.apache.tomcat.util", outputDir, "XReflectionIntrospectionUtils"); } private static Set<Class<?>> getKnownClasses() throws ClassNotFoundException { - return - Collections.unmodifiableSet(new LinkedHashSet<>( - Arrays.asList( - Class.forName("org.apache.catalina.authenticator.jaspic.SimpleAuthConfigProvider"), - Class.forName("org.apache.catalina.authenticator.jaspic.PersistentProviderRegistrations$Property"), - Class.forName("org.apache.catalina.authenticator.jaspic.PersistentProviderRegistrations$Provider"), - Class.forName("org.apache.catalina.connector.Connector"), - Class.forName("org.apache.catalina.core.AprLifecycleListener"), - Class.forName("org.apache.catalina.core.ContainerBase"), - Class.forName("org.apache.catalina.core.StandardContext"), - Class.forName("org.apache.catalina.core.StandardEngine"), - Class.forName("org.apache.catalina.core.StandardHost"), - Class.forName("org.apache.catalina.core.StandardServer"), - Class.forName("org.apache.catalina.core.StandardService"), - Class.forName("org.apache.catalina.filters.AddDefaultCharsetFilter"), - Class.forName("org.apache.catalina.filters.RestCsrfPreventionFilter"), - Class.forName("org.apache.catalina.loader.ParallelWebappClassLoader"), - Class.forName("org.apache.catalina.loader.WebappClassLoaderBase"), - Class.forName("org.apache.catalina.realm.UserDatabaseRealm"), - Class.forName("org.apache.catalina.valves.AccessLogValve"), - Class.forName("org.apache.coyote.AbstractProtocol"), - Class.forName("org.apache.coyote.ajp.AbstractAjpProtocol"), - Class.forName("org.apache.coyote.ajp.AjpAprProtocol"), - Class.forName("org.apache.coyote.ajp.AjpNio2Protocol"), - Class.forName("org.apache.coyote.ajp.AjpNioProtocol"), - Class.forName("org.apache.coyote.http11.AbstractHttp11JsseProtocol"), - Class.forName("org.apache.coyote.http11.AbstractHttp11Protocol"), - Class.forName("org.apache.coyote.http11.Http11AprProtocol"), - Class.forName("org.apache.coyote.http11.Http11Nio2Protocol"), - Class.forName("org.apache.coyote.http11.Http11NioProtocol"), - Class.forName("org.apache.tomcat.util.descriptor.web.ContextResource"), - Class.forName("org.apache.tomcat.util.descriptor.web.ResourceBase"), - Class.forName("org.apache.tomcat.util.modeler.AttributeInfo"), - Class.forName("org.apache.tomcat.util.modeler.FeatureInfo"), - Class.forName("org.apache.tomcat.util.modeler.ManagedBean"), - Class.forName("org.apache.tomcat.util.modeler.OperationInfo"), - Class.forName("org.apache.tomcat.util.modeler.ParameterInfo"), - Class.forName("org.apache.tomcat.util.net.AbstractEndpoint"), - Class.forName("org.apache.tomcat.util.net.AprEndpoint"), - Class.forName("org.apache.tomcat.util.net.Nio2Endpoint"), - Class.forName("org.apache.tomcat.util.net.NioEndpoint"), - Class.forName("org.apache.tomcat.util.net.SocketProperties") - ) - ) - ); + return Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList( + Class.forName("org.apache.catalina.authenticator.jaspic.SimpleAuthConfigProvider"), + Class.forName("org.apache.catalina.authenticator.jaspic.PersistentProviderRegistrations$Property"), + Class.forName("org.apache.catalina.authenticator.jaspic.PersistentProviderRegistrations$Provider"), + Class.forName("org.apache.catalina.connector.Connector"), + Class.forName("org.apache.catalina.core.AprLifecycleListener"), + Class.forName("org.apache.catalina.core.ContainerBase"), + Class.forName("org.apache.catalina.core.StandardContext"), + Class.forName("org.apache.catalina.core.StandardEngine"), + Class.forName("org.apache.catalina.core.StandardHost"), + Class.forName("org.apache.catalina.core.StandardServer"), + Class.forName("org.apache.catalina.core.StandardService"), + Class.forName("org.apache.catalina.filters.AddDefaultCharsetFilter"), + Class.forName("org.apache.catalina.filters.RestCsrfPreventionFilter"), + Class.forName("org.apache.catalina.loader.ParallelWebappClassLoader"), + Class.forName("org.apache.catalina.loader.WebappClassLoaderBase"), + Class.forName("org.apache.catalina.realm.UserDatabaseRealm"), + Class.forName("org.apache.catalina.valves.AccessLogValve"), + Class.forName("org.apache.coyote.AbstractProtocol"), + Class.forName("org.apache.coyote.ajp.AbstractAjpProtocol"), + Class.forName("org.apache.coyote.ajp.AjpAprProtocol"), + Class.forName("org.apache.coyote.ajp.AjpNio2Protocol"), + Class.forName("org.apache.coyote.ajp.AjpNioProtocol"), + Class.forName("org.apache.coyote.http11.AbstractHttp11JsseProtocol"), + Class.forName("org.apache.coyote.http11.AbstractHttp11Protocol"), + Class.forName("org.apache.coyote.http11.Http11AprProtocol"), + Class.forName("org.apache.coyote.http11.Http11Nio2Protocol"), + Class.forName("org.apache.coyote.http11.Http11NioProtocol"), + Class.forName("org.apache.tomcat.util.descriptor.web.ContextResource"), + Class.forName("org.apache.tomcat.util.descriptor.web.ResourceBase"), + Class.forName("org.apache.tomcat.util.modeler.AttributeInfo"), + Class.forName("org.apache.tomcat.util.modeler.FeatureInfo"), + Class.forName("org.apache.tomcat.util.modeler.ManagedBean"), + Class.forName("org.apache.tomcat.util.modeler.OperationInfo"), + Class.forName("org.apache.tomcat.util.modeler.ParameterInfo"), + Class.forName("org.apache.tomcat.util.net.AbstractEndpoint"), + Class.forName("org.apache.tomcat.util.net.AprEndpoint"), + Class.forName("org.apache.tomcat.util.net.Nio2Endpoint"), + Class.forName("org.apache.tomcat.util.net.NioEndpoint"), + Class.forName("org.apache.tomcat.util.net.SocketProperties")))); } - //types of properties that IntrospectionUtils.setProperty supports - private static final Set<Class<?>> ALLOWED_TYPES = Collections.unmodifiableSet(new LinkedHashSet<>( - Arrays.asList( - Boolean.TYPE, - Integer.TYPE, - Long.TYPE, - String.class, - InetAddress.class - ) - )); - private static final Map<Class<?>, SetPropertyClass> classes = new LinkedHashMap<>(); + // types of properties that IntrospectionUtils.setProperty supports + private static final Set<Class<?>> ALLOWED_TYPES = Collections.unmodifiableSet( + new LinkedHashSet<>(Arrays.asList(Boolean.TYPE, Integer.TYPE, Long.TYPE, String.class, InetAddress.class))); + private static final Map<Class<?>,SetPropertyClass> classes = new LinkedHashMap<>(); - public static void generateCode(Set<SetPropertyClass> baseClasses, String packageName, File location, String className) throws Exception { - String packageDirectory = packageName.replace('.','/'); + public static void generateCode(Set<SetPropertyClass> baseClasses, String packageName, File location, + String className) throws Exception { + String packageDirectory = packageName.replace('.', '/'); File sourceFileLocation = new File(location, packageDirectory); ReflectionLessCodeGenerator.generateCode(sourceFileLocation, className, packageName, baseClasses); } @@ -134,18 +115,14 @@ public final class ObjectReflectionPropertyInspector { } private static boolean isAllowedSetMethod(Method method) { - return method.getName().startsWith("set") && - method.getParameterTypes().length == 1 && - ALLOWED_TYPES.contains(method.getParameterTypes()[0]) && - !Modifier.isPrivate(method.getModifiers()); + return method.getName().startsWith("set") && method.getParameterTypes().length == 1 && + ALLOWED_TYPES.contains(method.getParameterTypes()[0]) && !Modifier.isPrivate(method.getModifiers()); } private static boolean isAllowedGetMethod(Method method) { return (method.getName().startsWith("get") || method.getName().startsWith("is")) && - method.getParameterTypes().length == 0 && - ALLOWED_TYPES.contains(method.getReturnType()) && - !Modifier.isPrivate(method.getModifiers()) && - isPresentInJava8Api(method); + method.getParameterTypes().length == 0 && ALLOWED_TYPES.contains(method.getReturnType()) && + !Modifier.isPrivate(method.getModifiers()) && isPresentInJava8Api(method); } private static boolean isPresentInJava8Api(Method method) { @@ -171,7 +148,8 @@ public final class ObjectReflectionPropertyInspector { } static Method findGetter(Class<?> declaringClass, String propertyName) { - for (String getterName : Arrays.asList("get" + IntrospectionUtils.capitalize(propertyName), "is" + propertyName)) { + for (String getterName : Arrays.asList("get" + IntrospectionUtils.capitalize(propertyName), + "is" + propertyName)) { try { Method method = declaringClass.getMethod(getterName); if (!Modifier.isPrivate(method.getModifiers())) { @@ -217,8 +195,7 @@ public final class ObjectReflectionPropertyInspector { if (name == null || name.isEmpty()) { return name; } - if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) && - Character.isUpperCase(name.charAt(0))) { + if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) && Character.isUpperCase(name.charAt(0))) { return name; } char[] chars = name.toCharArray(); @@ -236,13 +213,8 @@ public final class ObjectReflectionPropertyInspector { Class<?> propertyType = method.getParameterTypes()[0]; Method getter = findGetter(clazz, propertyName); Method setter = findSetter(clazz, propertyName, propertyType); - ReflectionProperty property = new ReflectionProperty( - spc.getClazz().getName(), - propertyName, - propertyType, - setter, - getter - ); + ReflectionProperty property = + new ReflectionProperty(spc.getClazz().getName(), propertyName, propertyType, setter, getter); spc.addProperty(property); } else if (isAllowedGetMethod(method)) { boolean startsWithIs = method.getName().startsWith("is"); @@ -250,13 +222,8 @@ public final class ObjectReflectionPropertyInspector { Class<?> propertyType = method.getReturnType(); Method getter = findGetter(clazz, propertyName); Method setter = findSetter(clazz, propertyName, propertyType); - ReflectionProperty property = new ReflectionProperty( - spc.getClazz().getName(), - propertyName, - propertyType, - setter, - getter - ); + ReflectionProperty property = + new ReflectionProperty(spc.getClazz().getName(), propertyName, propertyType, setter, getter); spc.addProperty(property); } } @@ -264,22 +231,11 @@ public final class ObjectReflectionPropertyInspector { final Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (isAllowedField(field)) { - Method getter = findGetter( - field.getDeclaringClass(), - IntrospectionUtils.capitalize(field.getName()) - ); - Method setter = findSetter( - field.getDeclaringClass(), - IntrospectionUtils.capitalize(field.getName()), - field.getType() - ); - ReflectionProperty property = new ReflectionProperty( - spc.getClazz().getName(), - field.getName(), - field.getType(), - setter, - getter - ); + Method getter = findGetter(field.getDeclaringClass(), IntrospectionUtils.capitalize(field.getName())); + Method setter = findSetter(field.getDeclaringClass(), IntrospectionUtils.capitalize(field.getName()), + field.getType()); + ReflectionProperty property = new ReflectionProperty(spc.getClazz().getName(), field.getName(), + field.getType(), setter, getter); spc.addProperty(property); } } diff --git a/java/org/apache/tomcat/util/xreflection/ReflectionLessCodeGenerator.java b/java/org/apache/tomcat/util/xreflection/ReflectionLessCodeGenerator.java index f859fb77ba..512da37846 100644 --- a/java/org/apache/tomcat/util/xreflection/ReflectionLessCodeGenerator.java +++ b/java/org/apache/tomcat/util/xreflection/ReflectionLessCodeGenerator.java @@ -33,12 +33,8 @@ final class ReflectionLessCodeGenerator { return indent; } - static void generateCode( - File directory, - String className, - String packageName, - Set<SetPropertyClass> baseClasses - ) throws IOException { + static void generateCode(File directory, String className, String packageName, Set<SetPropertyClass> baseClasses) + throws IOException { //@formatter:off // begin - class StringBuilder code = new StringBuilder(AL20_HEADER) @@ -186,7 +182,7 @@ final class ReflectionLessCodeGenerator { .append(System.lineSeparator()); // end - class //@formatter:on - File destination = new File(directory, className+".java"); + File destination = new File(directory, className + ".java"); try (BufferedWriter writer = new BufferedWriter(new FileWriter(destination, false))) { writer.write(code.toString()); writer.flush(); @@ -203,7 +199,8 @@ final class ReflectionLessCodeGenerator { } } - private static void generateCaseStatementsForSetPropertyInternal(Set<SetPropertyClass> baseClasses, StringBuilder code) { + private static void generateCaseStatementsForSetPropertyInternal(Set<SetPropertyClass> baseClasses, + StringBuilder code) { for (SetPropertyClass clazz : baseClasses) { generateCaseStatementForSetPropertyInternal(clazz, code); } @@ -213,9 +210,7 @@ final class ReflectionLessCodeGenerator { for (SetPropertyClass child : clazz.getChildren()) { generateSetPropertyForMethod(child, code); } - code.append(clazz.generateSetPropertyForMethod()) - .append(System.lineSeparator()) - .append(System.lineSeparator()); + code.append(clazz.generateSetPropertyForMethod()).append(System.lineSeparator()).append(System.lineSeparator()); } private static void generateSetPropertyForMethods(Set<SetPropertyClass> baseClasses, StringBuilder code) { @@ -225,7 +220,6 @@ final class ReflectionLessCodeGenerator { } - private static void generateCaseStatementForGetPropertyInternal(SetPropertyClass clazz, StringBuilder code) { for (SetPropertyClass child : clazz.getChildren()) { generateCaseStatementForGetPropertyInternal(child, code); @@ -235,7 +229,8 @@ final class ReflectionLessCodeGenerator { } } - private static void generateCaseStatementsForGetPropertyInternal(Set<SetPropertyClass> baseClasses, StringBuilder code) { + private static void generateCaseStatementsForGetPropertyInternal(Set<SetPropertyClass> baseClasses, + StringBuilder code) { for (SetPropertyClass clazz : baseClasses) { generateCaseStatementForGetPropertyInternal(clazz, code); } @@ -245,9 +240,7 @@ final class ReflectionLessCodeGenerator { for (SetPropertyClass child : clazz.getChildren()) { generateGetPropertyForMethod(child, code); } - code.append(clazz.generateGetPropertyForMethod()) - .append(System.lineSeparator()) - .append(System.lineSeparator()); + code.append(clazz.generateGetPropertyForMethod()).append(System.lineSeparator()).append(System.lineSeparator()); } private static void generateGetPropertyForMethods(Set<SetPropertyClass> baseClasses, StringBuilder code) { @@ -256,20 +249,17 @@ final class ReflectionLessCodeGenerator { } } - private static final String AL20_HEADER = "/*\n" + - " * Licensed to the Apache Software Foundation (ASF) under one or more\n" + - " * contributor license agreements. See the NOTICE file distributed with\n" + - " * this work for additional information regarding copyright ownership.\n" + - " * The ASF licenses this file to You under the Apache License, Version 2.0\n" + - " * (the \"License\"); you may not use this file except in compliance with\n" + - " * the License. You may obtain a copy of the License at\n" + - " *\n" + - " * http://www.apache.org/licenses/LICENSE-2.0\n" + - " *\n" + - " * Unless required by applicable law or agreed to in writing, software\n" + - " * distributed under the License is distributed on an \"AS IS\" BASIS,\n" + - " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + - " * See the License for the specific language governing permissions and\n" + - " * limitations under the License.\n" + - " */\n"; + private static final String AL20_HEADER = + "/*\n" + " * Licensed to the Apache Software Foundation (ASF) under one or more\n" + + " * contributor license agreements. See the NOTICE file distributed with\n" + + " * this work for additional information regarding copyright ownership.\n" + + " * The ASF licenses this file to You under the Apache License, Version 2.0\n" + + " * (the \"License\"); you may not use this file except in compliance with\n" + + " * the License. You may obtain a copy of the License at\n" + " *\n" + + " * http://www.apache.org/licenses/LICENSE-2.0\n" + " *\n" + + " * Unless required by applicable law or agreed to in writing, software\n" + + " * distributed under the License is distributed on an \"AS IS\" BASIS,\n" + + " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + + " * See the License for the specific language governing permissions and\n" + + " * limitations under the License.\n" + " */\n"; } diff --git a/java/org/apache/tomcat/util/xreflection/ReflectionProperty.java b/java/org/apache/tomcat/util/xreflection/ReflectionProperty.java index 2036af9f2a..852206f3b2 100644 --- a/java/org/apache/tomcat/util/xreflection/ReflectionProperty.java +++ b/java/org/apache/tomcat/util/xreflection/ReflectionProperty.java @@ -116,9 +116,7 @@ final class ReflectionProperty implements Comparable<ReflectionProperty> { @Override public String toString() { - return "ReflectionProperty{" + "name='" + propertyName + '\'' + - ", type=" + propertyType + - '}'; + return "ReflectionProperty{" + "name='" + propertyName + '\'' + ", type=" + propertyType + '}'; } @Override diff --git a/java/org/apache/tomcat/util/xreflection/SetPropertyClass.java b/java/org/apache/tomcat/util/xreflection/SetPropertyClass.java index 6180946d6f..d39b3f26ff 100644 --- a/java/org/apache/tomcat/util/xreflection/SetPropertyClass.java +++ b/java/org/apache/tomcat/util/xreflection/SetPropertyClass.java @@ -118,8 +118,7 @@ public final class SetPropertyClass implements Comparable<SetPropertyClass> { @Override public String toString() { - return "SetPropertyClass{" + "clazz=" + clazz.getName() + - '}'; + return "SetPropertyClass{" + "clazz=" + clazz.getName() + '}'; } public void addProperty(ReflectionProperty property) { @@ -127,33 +126,32 @@ public final class SetPropertyClass implements Comparable<SetPropertyClass> { } - public String generateSetPropertyMethod(ReflectionProperty property) { - //this property has a setProperty method + // this property has a setProperty method if (property.hasSetPropertySetter()) { - return "((" + this.getClazz().getName().replace('$','.') + ")" + OBJECT_VAR_NAME + ")." + - property.getSetMethod().getName() + "(" + NAME_VAR_NAME + ", " + VALUE_VAR_NAME + ");"; + return "((" + this.getClazz().getName().replace('$', '.') + ")" + OBJECT_VAR_NAME + ")." + + property.getSetMethod().getName() + "(" + NAME_VAR_NAME + ", " + VALUE_VAR_NAME + ");"; } - //direct setter + // direct setter if (property.hasSetter()) { - return "((" + this.getClazz().getName().replace('$','.') + ")" + OBJECT_VAR_NAME + ")." + - property.getSetMethod().getName() + "(" + property.getConversion(VALUE_VAR_NAME) + ");"; + return "((" + this.getClazz().getName().replace('$', '.') + ")" + OBJECT_VAR_NAME + ")." + + property.getSetMethod().getName() + "(" + property.getConversion(VALUE_VAR_NAME) + ");"; } return null; } public String generateGetPropertyMethod(ReflectionProperty property) { - //this property has a getProperty method + // this property has a getProperty method if (property.hasGetPropertyGetter()) { - return "result = ((" + this.getClazz().getName().replace('$','.') + ")" + OBJECT_VAR_NAME + ")." + - property.getGetMethod().getName() + "(" + NAME_VAR_NAME + ");"; + return "result = ((" + this.getClazz().getName().replace('$', '.') + ")" + OBJECT_VAR_NAME + ")." + + property.getGetMethod().getName() + "(" + NAME_VAR_NAME + ");"; } - //direct getter + // direct getter if (property.hasGetter()) { - return "result = ((" + this.getClazz().getName().replace('$','.') + ")" + OBJECT_VAR_NAME + ")." + - property.getGetMethod().getName() + "();"; + return "result = ((" + this.getClazz().getName().replace('$', '.') + ")" + OBJECT_VAR_NAME + ")." + + property.getGetMethod().getName() + "();"; } return null; } @@ -239,10 +237,10 @@ public final class SetPropertyClass implements Comparable<SetPropertyClass> { private String getSetPropertyForExitStatement() { return (getParent() != null) ? - //invoke the parent if we have one - getParent().generateParentSetPropertyForMethodInvocation() : - //if we invoke setProperty, return true, return false otherwise - getGenericSetPropertyMethod() != null ? "true;" : "false;"; + // invoke the parent if we have one + getParent().generateParentSetPropertyForMethodInvocation() : + // if we invoke setProperty, return true, return false otherwise + getGenericSetPropertyMethod() != null ? "true;" : "false;"; } public String generateInvocationSetForPropertyCaseStatement(int level) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org