From cb7813109e1a5b780cb07af39e17ff18fd799b56 Mon Sep 17 00:00:00 2001 From: aboyko Date: Fri, 4 Nov 2022 15:15:00 -0400 Subject: [PATCH] Separate Spring AOT validations into a dedicated category --- .../boot/common/SpringProblemCategories.java | 3 + .../boot/java/Boot3JavaProblemType.java | 7 -- .../boot/java/SpringAotJavaProblemType.java | 64 +++++++++++++ .../BeanPostProcessingIgnoreInAotProblem.java | 4 +- .../reconcile/NotRegisteredBeansProblem.java | 4 +- .../reconcile/PreciseBeanTypeProblem.java | 6 +- .../src/main/resources/problem-types.json | 58 +++++++---- .../boot/test/ProblemTypesMetadataTest.java | 2 + .../vscode/boot/test/ProblemTypesToJson.java | 3 +- .../vscode-spring-boot/package.json | 96 +++++++++++-------- 10 files changed, 171 insertions(+), 76 deletions(-) create mode 100644 headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/SpringAotJavaProblemType.java diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/common/SpringProblemCategories.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/common/SpringProblemCategories.java index 5b8a17997..ab6664dd6 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/common/SpringProblemCategories.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/common/SpringProblemCategories.java @@ -25,6 +25,9 @@ public class SpringProblemCategories { public static final ProblemCategory BOOT_3 = new ProblemCategory("boot3", "Boot 3.x Validation", new Toggle("Enablement", EnumSet.allOf(Toggle.Option.class), AUTO, "boot-java.validation.java.boot3")); + public static final ProblemCategory SPRING_AOT = new ProblemCategory("spring-aot", "Spring AOT Validation", + new Toggle("Enablement", EnumSet.of(OFF, ON), OFF, "boot-java.validation.java.spring-aot")); + public static final ProblemCategory PROPERTIES = new ProblemCategory("application-properties", "Properties Validation", null); public static final ProblemCategory YAML = new ProblemCategory("application-yaml", "YAML Properties Validation", null); diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/Boot3JavaProblemType.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/Boot3JavaProblemType.java index 0726e2233..b84585bb0 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/Boot3JavaProblemType.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/Boot3JavaProblemType.java @@ -11,7 +11,6 @@ package org.springframework.ide.vscode.boot.java; import static org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity.ERROR; -import static org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity.WARNING; import org.springframework.ide.vscode.boot.common.SpringProblemCategories; import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemCategory; @@ -24,12 +23,6 @@ import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemTy */ public enum Boot3JavaProblemType implements ProblemType { - JAVA_CONCRETE_BEAN_TYPE(WARNING, "Bean definition should have precise type for Spring 6 AOT", "Not precise bean defintion type"), - - JAVA_BEAN_POST_PROCESSOR_IGNORED_IN_AOT(WARNING, "'BeanPostProcessor' behaviour is ignored in Spring 6 AOT", "'BeanPostProcessor' behaviour is ignored in AOT"), - - JAVA_BEAN_NOT_REGISTERED_IN_AOT(WARNING, "Not registered as Bean", "Not registered as a Bean"), - JAVA_TYPE_NOT_SUPPORTED(ERROR, "Type no supported as of Spring Boot 3", "Type not supported as of Spring Boot 3"), FACTORIES_KEY_NOT_SUPPORTED(ERROR, "Spring factories key not supported", "Spring factories key not supported"); diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/SpringAotJavaProblemType.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/SpringAotJavaProblemType.java new file mode 100644 index 000000000..752522bcd --- /dev/null +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/SpringAotJavaProblemType.java @@ -0,0 +1,64 @@ +package org.springframework.ide.vscode.boot.java; + +import static org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity.WARNING; + +import org.springframework.ide.vscode.boot.common.SpringProblemCategories; +import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemCategory; +import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity; +import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType; + +public enum SpringAotJavaProblemType implements ProblemType { + + JAVA_CONCRETE_BEAN_TYPE(WARNING, "Bean definition should have precise type", "Not precise bean defintion type"), + + JAVA_BEAN_POST_PROCESSOR_IGNORED_IN_AOT(WARNING, "'BeanPostProcessor' behaviour is ignored", "'BeanPostProcessor' behaviour is ignored in AOT"), + + JAVA_BEAN_NOT_REGISTERED_IN_AOT(WARNING, "Not registered as Bean", "Not registered as a Bean"); + + private final ProblemSeverity defaultSeverity; + private String description; + private String label; + + private SpringAotJavaProblemType(ProblemSeverity defaultSeverity, String description) { + this(defaultSeverity, description, null); + } + + private SpringAotJavaProblemType(ProblemSeverity defaultSeverity, String description, String label) { + this.description = description; + this.defaultSeverity = defaultSeverity; + this.label = label; + } + + @Override + public ProblemSeverity getDefaultSeverity() { + return defaultSeverity; + } + + public String getLabel() { + if (label==null) { + label = createDefaultLabel(); + } + return label; + } + + @Override + public String getDescription() { + return description; + } + + private String createDefaultLabel() { + String label = this.toString().substring(5).toLowerCase().replace('_', ' '); + return Character.toUpperCase(label.charAt(0)) + label.substring(1); + } + + @Override + public String getCode() { + return name(); + } + + @Override + public ProblemCategory getCategory() { + return SpringProblemCategories.SPRING_AOT; + } + +} diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/reconcile/BeanPostProcessingIgnoreInAotProblem.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/reconcile/BeanPostProcessingIgnoreInAotProblem.java index f2e396582..dd2207972 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/reconcile/BeanPostProcessingIgnoreInAotProblem.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/reconcile/BeanPostProcessingIgnoreInAotProblem.java @@ -24,7 +24,7 @@ import org.openrewrite.java.tree.J.ClassDeclaration; import org.openrewrite.java.tree.J.MethodDeclaration; import org.openrewrite.marker.Range; import org.springframework.context.ApplicationContext; -import org.springframework.ide.vscode.boot.java.Boot3JavaProblemType; +import org.springframework.ide.vscode.boot.java.SpringAotJavaProblemType; import org.springframework.ide.vscode.commons.java.IJavaProject; import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType; import org.springframework.ide.vscode.commons.rewrite.config.RecipeCodeActionDescriptor; @@ -81,7 +81,7 @@ public class BeanPostProcessingIgnoreInAotProblem implements RecipeCodeActionDes @Override public ProblemType getProblemType() { - return Boot3JavaProblemType.JAVA_BEAN_POST_PROCESSOR_IGNORED_IN_AOT; + return SpringAotJavaProblemType.JAVA_BEAN_POST_PROCESSOR_IGNORED_IN_AOT; } } diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/reconcile/NotRegisteredBeansProblem.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/reconcile/NotRegisteredBeansProblem.java index d687d75e0..8b2521bd0 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/reconcile/NotRegisteredBeansProblem.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/reconcile/NotRegisteredBeansProblem.java @@ -31,7 +31,7 @@ import org.openrewrite.java.tree.JavaType.FullyQualified; import org.openrewrite.java.tree.TypeUtils; import org.springframework.context.ApplicationContext; import org.springframework.ide.vscode.boot.app.SpringSymbolIndex; -import org.springframework.ide.vscode.boot.java.Boot3JavaProblemType; +import org.springframework.ide.vscode.boot.java.SpringAotJavaProblemType; import org.springframework.ide.vscode.boot.java.beans.BeansSymbolAddOnInformation; import org.springframework.ide.vscode.boot.java.beans.ConfigBeanSymbolAddOnInformation; import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation; @@ -169,7 +169,7 @@ public class NotRegisteredBeansProblem implements RecipeCodeActionDescriptor { @Override public ProblemType getProblemType() { - return Boot3JavaProblemType.JAVA_BEAN_NOT_REGISTERED_IN_AOT; + return SpringAotJavaProblemType.JAVA_BEAN_NOT_REGISTERED_IN_AOT; } private static String typePattern(JavaType type) { diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/reconcile/PreciseBeanTypeProblem.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/reconcile/PreciseBeanTypeProblem.java index 0c22aab86..eba340f8e 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/reconcile/PreciseBeanTypeProblem.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/reconcile/PreciseBeanTypeProblem.java @@ -26,7 +26,7 @@ import org.openrewrite.java.tree.JavaType; import org.openrewrite.java.tree.TypeUtils; import org.openrewrite.marker.Range; import org.springframework.context.ApplicationContext; -import org.springframework.ide.vscode.boot.java.Boot3JavaProblemType; +import org.springframework.ide.vscode.boot.java.SpringAotJavaProblemType; import org.springframework.ide.vscode.commons.java.IJavaProject; import org.springframework.ide.vscode.commons.rewrite.config.RecipeCodeActionDescriptor; import org.springframework.ide.vscode.commons.rewrite.config.RecipeScope; @@ -95,8 +95,8 @@ public class PreciseBeanTypeProblem implements RecipeCodeActionDescriptor { } @Override - public Boot3JavaProblemType getProblemType() { - return Boot3JavaProblemType.JAVA_CONCRETE_BEAN_TYPE; + public SpringAotJavaProblemType getProblemType() { + return SpringAotJavaProblemType.JAVA_CONCRETE_BEAN_TYPE; } } diff --git a/headless-services/spring-boot-language-server/src/main/resources/problem-types.json b/headless-services/spring-boot-language-server/src/main/resources/problem-types.json index 2ff2e26a8..8a95f1c89 100644 --- a/headless-services/spring-boot-language-server/src/main/resources/problem-types.json +++ b/headless-services/spring-boot-language-server/src/main/resources/problem-types.json @@ -61,24 +61,6 @@ }, "order": 2, "problemTypes": [ - { - "code": "JAVA_CONCRETE_BEAN_TYPE", - "label": "Not precise bean defintion type", - "description": "Bean definition should have precise type for Spring 6 AOT", - "defaultSeverity": "WARNING" - }, - { - "code": "JAVA_BEAN_POST_PROCESSOR_IGNORED_IN_AOT", - "label": "'BeanPostProcessor' behaviour is ignored in AOT", - "description": "'BeanPostProcessor' behaviour is ignored in Spring 6 AOT", - "defaultSeverity": "WARNING" - }, - { - "code": "JAVA_BEAN_NOT_REGISTERED_IN_AOT", - "label": "Not registered as a Bean", - "description": "Not registered as Bean", - "defaultSeverity": "WARNING" - }, { "code": "JAVA_TYPE_NOT_SUPPORTED", "label": "Type not supported as of Spring Boot 3", @@ -93,10 +75,44 @@ } ] }, + { + "id": "spring-aot", + "label": "Spring AOT Validation", + "toggle": { + "label": "Enablement", + "values": [ + "OFF", + "ON" + ], + "preferenceKey": "boot-java.validation.java.spring-aot", + "defaultValue": "OFF" + }, + "order": 3, + "problemTypes": [ + { + "code": "JAVA_CONCRETE_BEAN_TYPE", + "label": "Not precise bean defintion type", + "description": "Bean definition should have precise type", + "defaultSeverity": "WARNING" + }, + { + "code": "JAVA_BEAN_POST_PROCESSOR_IGNORED_IN_AOT", + "label": "'BeanPostProcessor' behaviour is ignored in AOT", + "description": "'BeanPostProcessor' behaviour is ignored", + "defaultSeverity": "WARNING" + }, + { + "code": "JAVA_BEAN_NOT_REGISTERED_IN_AOT", + "label": "Not registered as a Bean", + "description": "Not registered as Bean", + "defaultSeverity": "WARNING" + } + ] + }, { "id": "application-properties", "label": "Properties Validation", - "order": 3, + "order": 4, "problemTypes": [ { "code": "PROP_INVALID_BEAN_NAVIGATION", @@ -169,7 +185,7 @@ { "id": "application-yaml", "label": "YAML Properties Validation", - "order": 4, + "order": 5, "problemTypes": [ { "code": "YAML_SYNTAX_ERROR", @@ -263,7 +279,7 @@ "preferenceKey": "boot-java.validation.spel.on", "defaultValue": "ON" }, - "order": 5, + "order": 6, "problemTypes": [ { "code": "JAVA_SPEL_EXPRESSION_SYNTAX", diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ProblemTypesMetadataTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ProblemTypesMetadataTest.java index c08e62568..9afa2fb76 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ProblemTypesMetadataTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ProblemTypesMetadataTest.java @@ -12,6 +12,7 @@ package org.springframework.ide.vscode.boot.test; import org.junit.jupiter.api.Test; import org.springframework.ide.vscode.boot.java.Boot2JavaProblemType; +import org.springframework.ide.vscode.boot.java.SpringAotJavaProblemType; import org.springframework.ide.vscode.boot.java.Boot3JavaProblemType; import org.springframework.ide.vscode.boot.java.SpelProblemType; import org.springframework.ide.vscode.boot.properties.reconcile.ApplicationPropertiesProblemType; @@ -29,6 +30,7 @@ public class ProblemTypesMetadataTest { reader.validate("application-yaml", ApplicationYamlProblemType.values()); reader.validate("boot2", Boot2JavaProblemType.values()); reader.validate("boot3", Boot3JavaProblemType.values()); + reader.validate("spring-aot", SpringAotJavaProblemType.values()); reader.validate("spel", SpelProblemType.values()); } diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ProblemTypesToJson.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ProblemTypesToJson.java index c9c0ac98b..012638594 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ProblemTypesToJson.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ProblemTypesToJson.java @@ -20,7 +20,6 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -28,6 +27,7 @@ import java.util.stream.Stream; import org.apache.commons.io.FileUtils; import org.springframework.ide.vscode.boot.java.Boot2JavaProblemType; +import org.springframework.ide.vscode.boot.java.SpringAotJavaProblemType; import org.springframework.ide.vscode.boot.java.Boot3JavaProblemType; import org.springframework.ide.vscode.boot.java.SpelProblemType; import org.springframework.ide.vscode.boot.properties.reconcile.ApplicationPropertiesProblemType; @@ -174,6 +174,7 @@ public class ProblemTypesToJson { writer.collectProblemTypeData(Boot2JavaProblemType.values()); writer.collectProblemTypeData(ApplicationPropertiesProblemType.values()); writer.collectProblemTypeData(Boot3JavaProblemType.values()); + writer.collectProblemTypeData(SpringAotJavaProblemType.values()); Collections.sort(writer.problemCategories); diff --git a/vscode-extensions/vscode-spring-boot/package.json b/vscode-extensions/vscode-spring-boot/package.json index 80e6efe34..1c2a5b143 100644 --- a/vscode-extensions/vscode-spring-boot/package.json +++ b/vscode-extensions/vscode-spring-boot/package.json @@ -378,42 +378,6 @@ "ON" ] }, - "spring-boot.ls.problem.boot3.JAVA_CONCRETE_BEAN_TYPE": { - "type": "string", - "default": "WARNING", - "description": "Bean definition should have precise type for Spring 6 AOT", - "enum": [ - "IGNORE", - "INFO", - "WARNING", - "HINT", - "ERROR" - ] - }, - "spring-boot.ls.problem.boot3.JAVA_BEAN_POST_PROCESSOR_IGNORED_IN_AOT": { - "type": "string", - "default": "WARNING", - "description": "'BeanPostProcessor' behaviour is ignored in Spring 6 AOT", - "enum": [ - "IGNORE", - "INFO", - "WARNING", - "HINT", - "ERROR" - ] - }, - "spring-boot.ls.problem.boot3.JAVA_BEAN_NOT_REGISTERED_IN_AOT": { - "type": "string", - "default": "WARNING", - "description": "Not registered as Bean", - "enum": [ - "IGNORE", - "INFO", - "WARNING", - "HINT", - "ERROR" - ] - }, "spring-boot.ls.problem.boot3.JAVA_TYPE_NOT_SUPPORTED": { "type": "string", "default": "ERROR", @@ -440,10 +404,62 @@ } } }, + { + "id": "spring-aot", + "title": "Spring AOT Validation", + "order": 403, + "properties": { + "boot-java.validation.java.spring-aot": { + "type": "string", + "default": "OFF", + "description": "Enablement", + "enum": [ + "OFF", + "ON" + ] + }, + "spring-boot.ls.problem.spring-aot.JAVA_CONCRETE_BEAN_TYPE": { + "type": "string", + "default": "WARNING", + "description": "Bean definition should have precise type", + "enum": [ + "IGNORE", + "INFO", + "WARNING", + "HINT", + "ERROR" + ] + }, + "spring-boot.ls.problem.spring-aot.JAVA_BEAN_POST_PROCESSOR_IGNORED_IN_AOT": { + "type": "string", + "default": "WARNING", + "description": "'BeanPostProcessor' behaviour is ignored", + "enum": [ + "IGNORE", + "INFO", + "WARNING", + "HINT", + "ERROR" + ] + }, + "spring-boot.ls.problem.spring-aot.JAVA_BEAN_NOT_REGISTERED_IN_AOT": { + "type": "string", + "default": "WARNING", + "description": "Not registered as Bean", + "enum": [ + "IGNORE", + "INFO", + "WARNING", + "HINT", + "ERROR" + ] + } + } + }, { "id": "application-properties", "title": "Properties Validation", - "order": 403, + "order": 404, "properties": { "spring-boot.ls.problem.application-properties.PROP_INVALID_BEAN_NAVIGATION": { "type": "string", @@ -582,7 +598,7 @@ { "id": "application-yaml", "title": "YAML Properties Validation", - "order": 404, + "order": 405, "properties": { "spring-boot.ls.problem.application-yaml.YAML_SYNTAX_ERROR": { "type": "string", @@ -745,7 +761,7 @@ { "id": "spel", "title": "SPEL Validation", - "order": 405, + "order": 406, "properties": { "boot-java.validation.spel.on": { "type": "string", @@ -811,4 +827,4 @@ "extensionDependencies": [ "redhat.java" ] -} +} \ No newline at end of file