Cleanup unnecessary constants

This commit is contained in:
aboyko
2023-09-27 11:41:30 -04:00
parent d1e9ed51ea
commit 89c3b2a111
11 changed files with 30 additions and 37 deletions

View File

@@ -47,8 +47,6 @@ import org.springframework.ide.vscode.commons.rewrite.java.FixDescriptor;
public class AddConfigurationIfBeansPresentReconciler implements JdtAstReconciler, ApplicationContextAware {
private static final String ID = AddConfigurationAnnotationIfBeansPresent.class.getName();
private static final String PROBLEM_LABEL = "'@Configuration' is missing on a class defining Spring Beans";
private static final String FIX_LABEL = "Add missing '@Configuration' annotations over classes";
@@ -72,12 +70,14 @@ public class AddConfigurationIfBeansPresentReconciler implements JdtAstReconcile
SimpleName nameAst = classDecl.getName();
ReconcileProblemImpl problem = new ReconcileProblemImpl(getProblemType(), PROBLEM_LABEL,
nameAst.getStartPosition(), nameAst.getLength());
String id = AddConfigurationAnnotationIfBeansPresent.class.getName();
ReconcileUtils.setRewriteFixes(quickfixRegistry, problem,
List.of(new FixDescriptor(ID, List.of(docUri.toASCIIString()),
List.of(new FixDescriptor(id, List.of(docUri.toASCIIString()),
ReconcileUtils.buildLabel(FIX_LABEL, RecipeScope.FILE))
.withRecipeScope(RecipeScope.FILE),
new FixDescriptor(ID, List.of(docUri.toASCIIString()),
new FixDescriptor(id, List.of(docUri.toASCIIString()),
ReconcileUtils.buildLabel(FIX_LABEL, RecipeScope.PROJECT))
.withRecipeScope(RecipeScope.PROJECT)));

View File

@@ -32,8 +32,6 @@ import org.springframework.ide.vscode.commons.rewrite.java.FixDescriptor;
public class AuthorizeHttpRequestsReconciler implements JdtAstReconciler {
private static final String ID = AuthorizeHttpRequests.class.getName();
private static final String FQN_HTTP_SECURITY = "org.springframework.security.config.annotation.web.builders.HttpSecurity";
private static final String AUTHORIZE_REQUESTS = "authorizeRequests";
@@ -71,13 +69,14 @@ public class AuthorizeHttpRequestsReconciler implements JdtAstReconciler {
AUTHORIZE_REQUESTS_PROBLEM_LABEL, node.getName().getStartPosition(),
node.getName().getLength());
String uri = docUri.toASCIIString();
String id = AuthorizeHttpRequests.class.getName();
ReconcileUtils
.setRewriteFixes(registry, problem, List.of(
new FixDescriptor(ID, List.of(uri),
new FixDescriptor(id, List.of(uri),
ReconcileUtils.buildLabel(AUTHORIZE_REQUESTS_FIX_LABEL,
RecipeScope.FILE))
.withRecipeScope(RecipeScope.FILE),
new FixDescriptor(ID, List.of(uri),
new FixDescriptor(id, List.of(uri),
ReconcileUtils.buildLabel(AUTHORIZE_REQUESTS_FIX_LABEL,
RecipeScope.PROJECT))
.withRecipeScope(RecipeScope.PROJECT)));
@@ -103,13 +102,14 @@ public class AuthorizeHttpRequestsReconciler implements JdtAstReconciler {
"Use of type '" + node.getName().getFullyQualifiedName() + "' is outdated",
node.getName().getStartPosition(), node.getName().getLength());
String uri = docUri.toASCIIString();
String id = AuthorizeHttpRequests.class.getName();
ReconcileUtils
.setRewriteFixes(registry, problem, List.of(
new FixDescriptor(ID, List.of(uri),
new FixDescriptor(id, List.of(uri),
ReconcileUtils.buildLabel(String.format(CLASS_FIX_LABEL_TEMPLATE,
replacementClass), RecipeScope.FILE))
.withRecipeScope(RecipeScope.FILE),
new FixDescriptor(ID, List.of(uri),
new FixDescriptor(id, List.of(uri),
ReconcileUtils.buildLabel(
String.format(CLASS_FIX_LABEL_TEMPLATE, replacementClass),
RecipeScope.PROJECT))

View File

@@ -49,7 +49,6 @@ import org.springframework.ide.vscode.commons.rewrite.java.FixDescriptor;
public class AutowiredFieldIntoConstructorParameterReconciler implements JdtAstReconciler {
private static final String LABEL = "Convert @Autowired field into Constructor Parameter";
private static final String ID = ConvertAutowiredFieldIntoConstructorParameter.class.getName();
private QuickfixRegistry registry;
@@ -130,7 +129,7 @@ public class AutowiredFieldIntoConstructorParameterReconciler implements JdtAstR
? cu.getPackage().getName().getFullyQualifiedName() + "."
: "") + typeDecl.getName().getFullyQualifiedName();
ReconcileUtils.setRewriteFixes(registry, problem,
List.of(new FixDescriptor(ID, List.of(docUri.toASCIIString()), LABEL)
List.of(new FixDescriptor(ConvertAutowiredFieldIntoConstructorParameter.class.getName(), List.of(docUri.toASCIIString()), LABEL)
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, typeDecl))
.withParameters(Map.of("classFqName", typeFqName, "fieldName", fieldName))
.withRecipeScope(RecipeScope.NODE)));

View File

@@ -47,7 +47,6 @@ public class BeanMethodNotPublicReconciler implements JdtAstReconciler {
private static final Logger log = LoggerFactory.getLogger(BeanMethodNotPublicReconciler.class);
private static final String ID = BeanMethodsNotPublic.class.getName();
private static final String LABEL = "Remove 'public' from @Bean method";
private final QuickfixRegistry quickfixRegistry;
@@ -102,18 +101,20 @@ public class BeanMethodNotPublicReconciler implements JdtAstReconciler {
private void addQuickFixes(CompilationUnit cu, URI docUri, ReconcileProblemImpl problem, MethodDeclaration method) {
if (quickfixRegistry != null) {
String id = BeanMethodsNotPublic.class.getName();
FixDescriptor fix1 = new FixDescriptor(ID, List.of(docUri.toASCIIString()), LABEL)
FixDescriptor fix1 = new FixDescriptor(id, List.of(docUri.toASCIIString()), LABEL)
.withRecipeScope(RecipeScope.NODE)
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, method));
Range methodRange = ReconcileUtils.createOpenRewriteRange(cu, method);
fix1 = fix1.withRangeScope(methodRange);
FixDescriptor fix2 = new FixDescriptor(ID, List.of(docUri.toASCIIString()), ReconcileUtils.buildLabel(LABEL, RecipeScope.FILE))
FixDescriptor fix2 = new FixDescriptor(id, List.of(docUri.toASCIIString()), ReconcileUtils.buildLabel(LABEL, RecipeScope.FILE))
.withRecipeScope(RecipeScope.FILE);
FixDescriptor fix3 = new FixDescriptor(ID, List.of(docUri.toASCIIString()), ReconcileUtils.buildLabel(LABEL, RecipeScope.PROJECT))
FixDescriptor fix3 = new FixDescriptor(id, List.of(docUri.toASCIIString()), ReconcileUtils.buildLabel(LABEL, RecipeScope.PROJECT))
.withRecipeScope(RecipeScope.PROJECT);

View File

@@ -34,7 +34,6 @@ import org.springframework.ide.vscode.commons.rewrite.java.FixDescriptor;
public class BeanPostProcessingIgnoreInAotReconciler implements JdtAstReconciler {
private static final String RECIPE_ID = BeanPostProcessingIgnoreInAot.class.getName();
private static final String LABEL = "Add method 'isBeanExcludedFromAotProcessing' that returns 'false'";
private static final String RUNTIME_BEAN_POST_PROCESSOR = "org.springframework.beans.factory.config.BeanPostProcessor";
private static final String COMPILE_BEAN_POST_PROCESSOR = "org.springframework.beans.factory.aot.BeanRegistrationAotProcessor";
@@ -87,7 +86,7 @@ public class BeanPostProcessingIgnoreInAotReconciler implements JdtAstReconciler
if (markProblem) {
ReconcileProblemImpl problem = new ReconcileProblemImpl(getProblemType(), LABEL, typeDecl.getName().getStartPosition(), typeDecl.getName().getLength());
ReconcileUtils.setRewriteFixes(registry, problem, List.of(
new FixDescriptor(RECIPE_ID, List.of(docUri.toASCIIString()), ReconcileUtils.buildLabel(LABEL, RecipeScope.NODE))
new FixDescriptor(BeanPostProcessingIgnoreInAot.class.getName(), List.of(docUri.toASCIIString()), ReconcileUtils.buildLabel(LABEL, RecipeScope.NODE))
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, typeDecl))
.withRecipeScope(RecipeScope.NODE)
));

View File

@@ -36,7 +36,6 @@ import org.springframework.ide.vscode.commons.rewrite.java.FixDescriptor;
public class NoAutowiredOnConstructorReconciler implements JdtAstReconciler {
private static final String ID = NoAutowiredOnConstructor.class.getName();
private static final String LABEL = "Remove Unnecessary @Autowired";
private QuickfixRegistry registry;
@@ -76,7 +75,7 @@ public class NoAutowiredOnConstructorReconciler implements JdtAstReconciler {
ReconcileProblemImpl problem = new ReconcileProblemImpl(getProblemType(), LABEL,
autowiredAnnotation.getStartPosition(), autowiredAnnotation.getLength());
ReconcileUtils.setRewriteFixes(registry, problem,
List.of(new FixDescriptor(ID, List.of(docUri.toASCIIString()), LABEL)
List.of(new FixDescriptor(NoAutowiredOnConstructor.class.getName(), List.of(docUri.toASCIIString()), LABEL)
.withRecipeScope(RecipeScope.NODE)
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, typeDecl))));
problemCollector.accept(problem);

View File

@@ -34,7 +34,6 @@ import org.springframework.ide.vscode.commons.rewrite.java.FixDescriptor;
public class NoRepoAnnotationReconciler implements JdtAstReconciler {
private static final String ID = NoRepoAnnotationOnRepoInterface.class.getName();
private static final String LABEL = "Remove Unnecessary @Repository";
private static final String INTERFACE_REPOSITORY = "org.springframework.data.repository.Repository";
@@ -61,14 +60,15 @@ public class NoRepoAnnotationReconciler implements JdtAstReconciler {
if (type != null && isRepo(type)) {
ReconcileProblemImpl problem = new ReconcileProblemImpl(getProblemType(), LABEL, a.getStartPosition(), a.getLength());
String uri = docUri.toASCIIString();
String id = NoRepoAnnotationOnRepoInterface.class.getName();
ReconcileUtils.setRewriteFixes(registry, problem, List.of(
// new FixDescriptor(ID, List.of(uri), LABEL)
// .withRangeScope(RewriteQuickFixUtils.createOpenRewriteRange(cu, typeDecl))
// .withRecipeScope(RecipeScope.NODE),
new FixDescriptor(ID, List.of(uri),
new FixDescriptor(id, List.of(uri),
ReconcileUtils.buildLabel(LABEL, RecipeScope.FILE))
.withRecipeScope(RecipeScope.FILE),
new FixDescriptor(ID, List.of(uri),
new FixDescriptor(id, List.of(uri),
ReconcileUtils.buildLabel(LABEL, RecipeScope.PROJECT))
.withRecipeScope(RecipeScope.PROJECT)
));

View File

@@ -52,8 +52,6 @@ import com.google.common.collect.ImmutableSet;
public class NotRegisteredBeansReconciler implements JdtAstReconciler, ApplicationContextAware {
private static final String DEFINE_METHOD_RECIPE = DefineMethod.class.getName();
private static final List<String> AOT_BEANS = List.of(
"org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor",
"org.springframework.beans.factory.aot.BeanRegistrationAotProcessor"
@@ -114,7 +112,7 @@ public class NotRegisteredBeansReconciler implements JdtAstReconciler, Applicati
}
String paramsStr = String.join(", ", paramBuilder.build().toArray(String[]::new));
fixListBuilder.add(new FixDescriptor(DEFINE_METHOD_RECIPE, List.of(s.getSymbol().getLocation().getLeft().getUri()), "Define bean in config '" + configInfo.getBeanID() + "' with constructor " + contructorParamsLabel)
fixListBuilder.add(new FixDescriptor(DefineMethod.class.getName(), List.of(s.getSymbol().getLocation().getLeft().getUri()), "Define bean in config '" + configInfo.getBeanID() + "' with constructor " + contructorParamsLabel)
.withRecipeScope(RecipeScope.FILE)
.withParameters(Map.of(
"targetFqName", configInfo.getBeanType(),

View File

@@ -39,8 +39,6 @@ import org.springframework.ide.vscode.commons.rewrite.java.FixDescriptor;
public class PreciseBeanTypeReconciler implements JdtAstReconciler {
private static final String RECIPE_ID = PreciseBeanType.class.getName();
private static final String LABEL = "Ensure concrete bean type";
private QuickfixRegistry registry;
@@ -90,13 +88,14 @@ public class PreciseBeanTypeReconciler implements JdtAstReconciler {
} else if (currentReturnTypes.size() == 1 && !method.resolveBinding().getReturnType().isAssignmentCompatible(currentReturnTypes.get(0))) {
String uri = docUri.toASCIIString();
String replacementType = currentReturnTypes.get(0).getName();
String recipeId = PreciseBeanType.class.getName();
ReconcileUtils.setRewriteFixes(registry, problem, List.of(
new FixDescriptor(RECIPE_ID, List.of(uri), ReconcileUtils.buildLabel("Replace return type with '" + replacementType + "'", RecipeScope.NODE))
new FixDescriptor(recipeId, List.of(uri), ReconcileUtils.buildLabel("Replace return type with '" + replacementType + "'", RecipeScope.NODE))
.withRecipeScope(RecipeScope.NODE)
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, method)),
new FixDescriptor(RECIPE_ID, List.of(uri), ReconcileUtils.buildLabel(LABEL, RecipeScope.FILE))
new FixDescriptor(recipeId, List.of(uri), ReconcileUtils.buildLabel(LABEL, RecipeScope.FILE))
.withRecipeScope(RecipeScope.FILE),
new FixDescriptor(RECIPE_ID, List.of(uri), ReconcileUtils.buildLabel(LABEL, RecipeScope.PROJECT))
new FixDescriptor(recipeId, List.of(uri), ReconcileUtils.buildLabel(LABEL, RecipeScope.PROJECT))
.withRecipeScope(RecipeScope.PROJECT)
));
problemCollector.accept(problem);

View File

@@ -35,7 +35,6 @@ import org.springframework.ide.vscode.commons.rewrite.java.FixDescriptor;
public class UnnecessarySpringExtensionReconciler implements JdtAstReconciler {
private static final String LABEL = "Remove unnecessary @SpringExtension";
private static final String ID = UnnecessarySpringExtension.class.getName();
private static final List<String> SPRING_BOOT_TEST_ANNOTATIONS = Arrays.asList(
"org.springframework.boot.test.context.SpringBootTest",
"org.springframework.boot.test.autoconfigure.jdbc.JdbcTest",
@@ -86,7 +85,7 @@ public class UnnecessarySpringExtensionReconciler implements JdtAstReconciler {
if (testAnnotation != null && extendWithAnnotation != null) {
ReconcileProblemImpl problem = new ReconcileProblemImpl(getProblemType(), LABEL, extendWithAnnotation.getStartPosition(), extendWithAnnotation.getLength());
ReconcileUtils.setRewriteFixes(registry, problem, List.of(
new FixDescriptor(ID, List.of(docUri.toASCIIString()), ReconcileUtils.buildLabel(LABEL, RecipeScope.PROJECT))
new FixDescriptor(UnnecessarySpringExtension.class.getName(), List.of(docUri.toASCIIString()), ReconcileUtils.buildLabel(LABEL, RecipeScope.PROJECT))
));
problemCollector.accept(problem);
break;

View File

@@ -35,8 +35,6 @@ import org.springframework.ide.vscode.commons.rewrite.java.FixDescriptor;
public class WebSecurityConfigurerAdapterReconciler implements JdtAstReconciler {
private static final String ID = WebSecurityConfigurerAdapter.class.getName();
private static final String WEB_SECURITY_CONFIGURER_ADAPTER = "WebSecurityConfigurerAdapter";
private static final String FQN_WEB_SECURITY_CONFIGURER_ADAPTER = "org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter";
@@ -92,12 +90,13 @@ public class WebSecurityConfigurerAdapterReconciler implements JdtAstReconciler
ITypeBinding resolveBinding = type.resolveBinding();
String[] typeStubs = resolveBinding == null || resolveBinding.isRecovered() ? new String[] { STUB_WEB_SECURITY_CONFIG_ADAPTER } : new String[0];
String uri = docUri.toASCIIString();
String recipeId = WebSecurityConfigurerAdapter.class.getName();
ReconcileUtils.setRewriteFixes(registry, problem, List.of(
new FixDescriptor(ID, List.of(uri),
new FixDescriptor(recipeId, List.of(uri),
ReconcileUtils.buildLabel(FIX_LABEL, RecipeScope.FILE))
.withRecipeScope(RecipeScope.FILE)
.withTypeStubs(typeStubs),
new FixDescriptor(ID, List.of(uri),
new FixDescriptor(recipeId, List.of(uri),
ReconcileUtils.buildLabel(FIX_LABEL, RecipeScope.PROJECT))
.withRecipeScope(RecipeScope.PROJECT)
.withTypeStubs(typeStubs))