Mark types not supported as of Boot 3
This commit is contained in:
@@ -24,7 +24,9 @@ public class FixAssistMarker implements Marker {
|
||||
|
||||
private String descriptorId;
|
||||
|
||||
private List<FixDescriptor> fixes = new ArrayList<>();;
|
||||
private List<FixDescriptor> fixes = new ArrayList<>();
|
||||
|
||||
private String label;
|
||||
|
||||
public FixAssistMarker(UUID id, String descriptorId) {
|
||||
super();
|
||||
@@ -61,6 +63,15 @@ public class FixAssistMarker implements Marker {
|
||||
public List<FixDescriptor> getFixes() {
|
||||
return fixes;
|
||||
}
|
||||
|
||||
public FixAssistMarker withLabel(String label) {
|
||||
this.label = label;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*******************************************************************************/
|
||||
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;
|
||||
@@ -27,7 +28,9 @@ public enum Boot3JavaProblemType implements ProblemType {
|
||||
|
||||
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_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");
|
||||
|
||||
private final ProblemSeverity defaultSeverity;
|
||||
private String description;
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.springframework.ide.vscode.boot.java.rewrite.codeaction.AutowiredFiel
|
||||
import org.springframework.ide.vscode.boot.java.rewrite.codeaction.NoRequestMappingAnnotationCodeAction;
|
||||
import org.springframework.ide.vscode.boot.java.rewrite.reconcile.BeanMethodNotPublicProblem;
|
||||
import org.springframework.ide.vscode.boot.java.rewrite.reconcile.BeanPostProcessingIgnoreInAotProblem;
|
||||
import org.springframework.ide.vscode.boot.java.rewrite.reconcile.Boot3NotSupportedTypeProblem;
|
||||
import org.springframework.ide.vscode.boot.java.rewrite.reconcile.NoAutowiredOnConstructorProblem;
|
||||
import org.springframework.ide.vscode.boot.java.rewrite.reconcile.NotRegisteredBeansProblem;
|
||||
import org.springframework.ide.vscode.boot.java.rewrite.reconcile.PreciseBeanTypeProblem;
|
||||
@@ -42,7 +43,8 @@ public class BootCodeActionRepository extends CodeActionRepository {
|
||||
new UnnecessarySpringExtensionProblem(),
|
||||
new PreciseBeanTypeProblem(),
|
||||
new BeanPostProcessingIgnoreInAotProblem(),
|
||||
new NotRegisteredBeansProblem()
|
||||
new NotRegisteredBeansProblem(),
|
||||
new Boot3NotSupportedTypeProblem()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ public class RewriteReconciler implements JavaReconciler {
|
||||
private ReconcileProblemImpl createProblem(IDocument doc, RecipeSpringJavaProblemDescriptor recipeFixDescriptor,
|
||||
FixAssistMarker m, Range range) {
|
||||
ProblemType problemType = recipeFixDescriptor.getProblemType();
|
||||
ReconcileProblemImpl problem = new ReconcileProblemImpl(problemType, problemType.getLabel(), range.getStart().getOffset(), range.getEnd().getOffset() - range.getStart().getOffset());
|
||||
ReconcileProblemImpl problem = new ReconcileProblemImpl(problemType, m.getLabel() == null ? problemType.getLabel() : m.getLabel(), range.getStart().getOffset(), range.getEnd().getOffset() - range.getStart().getOffset());
|
||||
QuickfixType quickfixType = quickfixRegistry.getQuickfixType(RewriteRefactorings.REWRITE_RECIPE_QUICKFIX);
|
||||
if (quickfixType != null) {
|
||||
for (FixDescriptor f : m.getFixes()) {
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2022 VMware, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* VMware, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.rewrite.reconcile;
|
||||
|
||||
import static org.springframework.ide.vscode.commons.java.SpringProjectUtil.springBootVersionGreaterOrEqual;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.openrewrite.ExecutionContext;
|
||||
import org.openrewrite.Tree;
|
||||
import org.openrewrite.java.JavaIsoVisitor;
|
||||
import org.openrewrite.java.JavaVisitor;
|
||||
import org.openrewrite.java.tree.J;
|
||||
import org.openrewrite.java.tree.J.MethodInvocation;
|
||||
import org.openrewrite.java.tree.JavaType;
|
||||
import org.openrewrite.java.tree.JavaType.FullyQualified;
|
||||
import org.openrewrite.java.tree.JavaType.Method;
|
||||
import org.openrewrite.java.tree.NameTree;
|
||||
import org.openrewrite.java.tree.TypeUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.ide.vscode.boot.java.Boot3JavaProblemType;
|
||||
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.RecipeSpringJavaProblemDescriptor;
|
||||
import org.springframework.ide.vscode.commons.rewrite.java.FixAssistMarker;
|
||||
|
||||
public class Boot3NotSupportedTypeProblem implements RecipeSpringJavaProblemDescriptor {
|
||||
|
||||
private static final List<String> TYPE_FQNAMES = List.of(
|
||||
"org.springframework.web.multipart.commons.CommonsMultipartResolver",
|
||||
"java.lang.SecurityManager",
|
||||
"java.security.AccessControlException"
|
||||
);
|
||||
|
||||
@Override
|
||||
public JavaVisitor<ExecutionContext> getMarkerVisitor(ApplicationContext applicationContext) {
|
||||
return new JavaIsoVisitor<>() {
|
||||
@Override
|
||||
public J.Identifier visitIdentifier(J.Identifier ident, ExecutionContext executionContext) {
|
||||
if (ident.getType() != null &&
|
||||
getCursor().firstEnclosing(J.Import.class) == null &&
|
||||
getCursor().firstEnclosing(J.FieldAccess.class) == null &&
|
||||
!(getCursor().getParentOrThrow().getValue() instanceof J.ParameterizedType)) {
|
||||
JavaType.FullyQualified type = TypeUtils.asFullyQualified(ident.getType());
|
||||
for (String fqName : TYPE_FQNAMES) {
|
||||
if (typeMatches(true, fqName, type) &&
|
||||
ident.getSimpleName().equals(type.getClassName())) {
|
||||
return ident.withMarkers(ident.getMarkers().add(new FixAssistMarker(Tree.randomId(), getId()).withLabel(createLabel(fqName))));
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.visitIdentifier(ident, executionContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends NameTree> N visitTypeName(N name, ExecutionContext ctx) {
|
||||
N n = super.visitTypeName(name, ctx);
|
||||
JavaType.FullyQualified type = TypeUtils.asFullyQualified(n.getType());
|
||||
for (String fqName : TYPE_FQNAMES) {
|
||||
if (typeMatches(true, fqName, type) &&
|
||||
getCursor().firstEnclosing(J.Import.class) == null) {
|
||||
return n.withMarkers(n.getMarkers().add(new FixAssistMarker(Tree.randomId(), getId()).withLabel(createLabel(fqName))));
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public J.FieldAccess visitFieldAccess(J.FieldAccess fieldAccess, ExecutionContext ctx) {
|
||||
J.FieldAccess fa = (J.FieldAccess) super.visitFieldAccess(fieldAccess, ctx);
|
||||
JavaType.FullyQualified type = TypeUtils.asFullyQualified(fa.getTarget().getType());
|
||||
for (String fqName : TYPE_FQNAMES) {
|
||||
if (typeMatches(true, fqName, type) &&
|
||||
fa.getName().getSimpleName().equals("class")) {
|
||||
return fa.withMarkers(fa.getMarkers().add(new FixAssistMarker(Tree.randomId(), getId()).withLabel(createLabel(fqName))));
|
||||
}
|
||||
}
|
||||
return fa;
|
||||
}
|
||||
|
||||
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
|
||||
MethodInvocation m = super.visitMethodInvocation(method, ctx);
|
||||
Method methodType = m.getMethodType();
|
||||
if (methodType != null) {
|
||||
FullyQualified fqType = TypeUtils.asFullyQualified(methodType.getReturnType());
|
||||
if (fqType != null) {
|
||||
for (String fqName : TYPE_FQNAMES) {
|
||||
if (typeMatches(true, fqName, fqType)) {
|
||||
return m.withMarkers(m.getMarkers().add(new FixAssistMarker(Tree.randomId(), getId()).withLabel(createLabel(fqName))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static String createLabel(String type) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("'");
|
||||
sb.append(type);
|
||||
sb.append("' not supported as of Spring Boot 3");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static boolean typeMatches(boolean checkAssignability, String fqName, JavaType.FullyQualified test) {
|
||||
return test != null && (checkAssignability ? test.isAssignableTo(fqName) : fqName.equals(test.getFullyQualifiedName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(IJavaProject project) {
|
||||
return springBootVersionGreaterOrEqual(3, 0, 0).test(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProblemType getProblemType() {
|
||||
return Boot3JavaProblemType.JAVA_TYPE_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -66,6 +66,12 @@
|
||||
"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",
|
||||
"description": "Type no supported as of Spring Boot 3",
|
||||
"defaultSeverity": "ERROR"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -359,6 +359,18 @@
|
||||
"HINT",
|
||||
"ERROR"
|
||||
]
|
||||
},
|
||||
"spring-boot.ls.problem.boot3.JAVA_TYPE_NOT_SUPPORTED": {
|
||||
"type": "string",
|
||||
"default": "ERROR",
|
||||
"description": "Type no supported as of Spring Boot 3",
|
||||
"enum": [
|
||||
"IGNORE",
|
||||
"INFO",
|
||||
"WARNING",
|
||||
"HINT",
|
||||
"ERROR"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user