Tiny corrections and cleanups
This commit is contained in:
@@ -217,7 +217,7 @@ public class Classpath {
|
||||
|
||||
public Version getVersion() {
|
||||
if (version == null) {
|
||||
if (isBinary(this) && !isSystem) {
|
||||
if (ENTRY_KIND_BINARY.equals(getKind()) && !isSystem) {
|
||||
version = getDependencyVersion(new File(getPath()).getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,12 @@ import java.util.stream.Collectors;
|
||||
import org.openrewrite.ExecutionContext;
|
||||
import org.openrewrite.Recipe;
|
||||
import org.openrewrite.TreeVisitor;
|
||||
import org.openrewrite.internal.ListUtils;
|
||||
import org.openrewrite.java.JavaIsoVisitor;
|
||||
import org.openrewrite.java.JavaParser;
|
||||
import org.openrewrite.java.JavaTemplate;
|
||||
import org.openrewrite.java.MethodMatcher;
|
||||
import org.openrewrite.java.tree.J;
|
||||
import org.openrewrite.java.tree.JavaType;
|
||||
import org.openrewrite.java.tree.JavaType.FullyQualified;
|
||||
|
||||
public class DefineMethod extends Recipe {
|
||||
|
||||
@@ -83,25 +81,14 @@ public class DefineMethod extends Recipe {
|
||||
JavaType.FullyQualified type = c.getType();
|
||||
if (type != null && targetFqName.equals(type.getFullyQualifiedName())) {
|
||||
JavaTemplate t = JavaTemplate.builder(template)
|
||||
.contextSensitive()
|
||||
.javaParser(JavaParser
|
||||
.fromJavaVersion()
|
||||
.dependsOn(typeStubs.toArray(new String[typeStubs.size()]))
|
||||
.classpath(classpath.stream().map(s -> Paths.get(s)).collect(Collectors.toList())))
|
||||
|
||||
.imports(imports.toArray(new String[imports.size()])).build();
|
||||
// TODO: why did this return ClassDEclaration rather than Block??? Figure this out!!!
|
||||
J.ClassDeclaration templateClass = t.apply(getCursor(), classDecl.getBody().getCoordinates().addMethodDeclaration((m, n) -> 1));
|
||||
FullyQualified classType = c.getType();
|
||||
if (classType != null) {
|
||||
J.Block body = templateClass.getBody().withStatements(ListUtils.map(templateClass.getBody().getStatements(), s -> {
|
||||
if (s instanceof J.MethodDeclaration) {
|
||||
J.MethodDeclaration m = (J.MethodDeclaration) s;
|
||||
return m.withMethodType(m.getMethodType().withDeclaringType(classType));
|
||||
}
|
||||
return s;
|
||||
}));
|
||||
c = c.withBody(body);
|
||||
}
|
||||
c = t.apply(getCursor(), classDecl.getBody().getCoordinates().addMethodDeclaration((m, n) -> 1));
|
||||
for (String fq : imports) {
|
||||
maybeAddImport(fq);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import static org.springframework.ide.vscode.commons.java.SpringProjectUtil.spri
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -31,6 +32,7 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
|
||||
import org.springframework.ide.vscode.boot.java.Annotations;
|
||||
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;
|
||||
@@ -111,8 +113,11 @@ public class NotRegisteredBeansReconciler implements JdtAstReconciler, Applicati
|
||||
paramBuilder.add(typeStr(paramType) + ' ' + paramName);
|
||||
}
|
||||
String paramsStr = String.join(", ", paramBuilder.build().toArray(String[]::new));
|
||||
|
||||
fixListBuilder.add(new FixDescriptor(DefineMethod.class.getName(), List.of(s.getSymbol().getLocation().getLeft().getUri()), "Define bean in config '" + configInfo.getBeanID() + "' with constructor " + contructorParamsLabel)
|
||||
|
||||
final Set<String> allFqTypes = new HashSet<>();
|
||||
allFqTypes.add(Annotations.BEAN);
|
||||
allFqTypes.addAll(allFQTypes(constructor));
|
||||
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(),
|
||||
@@ -121,7 +126,7 @@ public class NotRegisteredBeansReconciler implements JdtAstReconciler, Applicati
|
||||
+ type.getName() + " " + beanMethodName + "(" + paramsStr + ") {\n"
|
||||
+ "return new " + type.getName() + "(" + Arrays.stream(constructor.getParameterNames()).collect(Collectors.joining(", ")) + ");\n"
|
||||
+ "}\n",
|
||||
"imports", allFQTypes(constructor).toArray(String[]::new),
|
||||
"imports", allFqTypes.toArray(String[]::new),
|
||||
"typeStubs", new String[0]/*new String[] { source.printAll() }*/,
|
||||
"classpath", IClasspathUtil.getAllBinaryRoots(project.getClasspath()).stream().map(f -> f.toPath().toString()).toArray(String[]::new)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user