Data repository symbols and NPE fixes
This commit is contained in:
@@ -106,7 +106,7 @@
|
||||
<reactor-netty>0.7.5.RELEASE</reactor-netty>
|
||||
<commons-io-version>2.4</commons-io-version>
|
||||
<commons-codec-version>1.13</commons-codec-version>
|
||||
<rewrite-version>7.18.0-SNAPSHOT</rewrite-version>
|
||||
<rewrite-version>7.19.0-SNAPSHOT</rewrite-version>
|
||||
|
||||
<signing.skip>true</signing.skip>
|
||||
<signing.alias>vmware</signing.alias>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package org.springframework.ide.vscode.boot.java.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.SymbolInformation;
|
||||
@@ -97,20 +98,20 @@ public class DataRepositorySymbolProvider extends AbstractSymbolProvider {
|
||||
for (FullyQualified resolvedInterface : resolvedType.getInterfaces()) {
|
||||
if (Constants.REPOSITORY_TYPE.equals(resolvedInterface.getFullyQualifiedName())) {
|
||||
String beanName = getBeanName(typeDeclaration);
|
||||
String beanType = resolvedInterface.toString();
|
||||
String beanType = ORAstUtils.getSimpleNameWithParamTypes(resolvedInterface);
|
||||
|
||||
String domainType = null;
|
||||
if (resolvedType instanceof Parameterized) {
|
||||
List<JavaType> typeParams = ((Parameterized)resolvedType).getTypeParameters();
|
||||
if (resolvedInterface instanceof Parameterized) {
|
||||
List<JavaType> typeParams = ((Parameterized)resolvedInterface).getTypeParameters();
|
||||
if (typeParams != null && !typeParams.isEmpty()) {
|
||||
FullyQualified typeParam = TypeUtils.asFullyQualified(typeParams.get(0));
|
||||
domainType = typeParam == null ? null : typeParam.getFullyQualifiedName();
|
||||
domainType = typeParam == null ? null : ORAstUtils.getSimpleNameWithParamTypes(typeParam);
|
||||
}
|
||||
}
|
||||
|
||||
DocumentRegion region = ORAstUtils.nodeRegion(doc, typeDeclaration.getName());
|
||||
|
||||
return Tuples.of(beanName, beanType, domainType, region);
|
||||
return Tuples.of(beanName, beanType.toString(), domainType, region);
|
||||
} else {
|
||||
Tuple4<String, String, String, DocumentRegion> result = getRepositoryBean(typeDeclaration, doc, resolvedInterface);
|
||||
if (result != null) {
|
||||
|
||||
@@ -12,10 +12,12 @@ package org.springframework.ide.vscode.boot.java.handlers;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.openrewrite.internal.lang.Nullable;
|
||||
import org.openrewrite.java.tree.Expression;
|
||||
import org.openrewrite.java.tree.J.Annotation;
|
||||
import org.openrewrite.java.tree.J.Assignment;
|
||||
import org.openrewrite.java.tree.J.Literal;
|
||||
import org.openrewrite.java.tree.JavaType.FullyQualified;
|
||||
import org.openrewrite.java.tree.TypeUtils;
|
||||
import org.openrewrite.marker.Range;
|
||||
import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchies;
|
||||
@@ -62,8 +64,14 @@ public class AnnotationParamReconciler {
|
||||
if (paramName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
FullyQualified type = TypeUtils.asFullyQualified(annotation.getType());
|
||||
|
||||
Set<String> allAnnotations = AnnotationHierarchies.getTransitiveSuperAnnotations(TypeUtils.asFullyQualified(annotation.getType()));
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> allAnnotations = AnnotationHierarchies.getTransitiveSuperAnnotations(type);
|
||||
if (!allAnnotations.contains(this.annotationType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -118,16 +118,22 @@ public class BootJavaReconcileEngine implements IReconcileEngine {
|
||||
|
||||
new JavaIsoVisitor<IProblemCollector>() {
|
||||
public Annotation visitAnnotation(Annotation annotation, IProblemCollector p) {
|
||||
if (!annotation.getArguments().isEmpty()) {
|
||||
JavaType type = annotation.getType();
|
||||
|
||||
if (type != null) {
|
||||
for (int i = 0; i < reconcilers.length; i++) {
|
||||
reconcilers[i].visit(annotation, problemCollector);
|
||||
try {
|
||||
if (annotation.getArguments() != null && !annotation.getArguments().isEmpty()) {
|
||||
JavaType type = annotation.getType();
|
||||
|
||||
if (type != null) {
|
||||
for (int i = 0; i < reconcilers.length; i++) {
|
||||
reconcilers[i].visit(annotation, problemCollector);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.visitAnnotation(annotation, p);
|
||||
} catch (Exception e) {
|
||||
// TODO: OR AST - uncomment later to fix in OR
|
||||
// log.error("Failed to visit annotation. Fix in OR.", e);
|
||||
return annotation;
|
||||
}
|
||||
return super.visitAnnotation(annotation, p);
|
||||
};
|
||||
}.visitNonNull(cu, problemCollector);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,10 @@ import org.openrewrite.java.tree.J.Literal;
|
||||
import org.openrewrite.java.tree.J.MethodDeclaration;
|
||||
import org.openrewrite.java.tree.J.NewArray;
|
||||
import org.openrewrite.java.tree.J.VariableDeclarations;
|
||||
import org.openrewrite.java.tree.JavaType;
|
||||
import org.openrewrite.java.tree.JavaType.Array;
|
||||
import org.openrewrite.java.tree.JavaType.FullyQualified;
|
||||
import org.openrewrite.java.tree.JavaType.Parameterized;
|
||||
import org.openrewrite.java.tree.TypeUtils;
|
||||
import org.openrewrite.marker.Marker;
|
||||
import org.openrewrite.marker.Range;
|
||||
@@ -312,14 +315,16 @@ public class ORAstUtils {
|
||||
if (annotation != null) {
|
||||
try {
|
||||
List<Expression> args = annotation.getArguments();
|
||||
if (name.equals("value") && args.size() == 1 && !(args.get(0) instanceof Assignment)) {
|
||||
return Optional.ofNullable(args.get(0));
|
||||
} else {
|
||||
for (Expression arg : args) {
|
||||
if (arg instanceof Assignment) {
|
||||
Assignment assignment = (Assignment) arg;
|
||||
if (name.equals(assignment.getVariable().printTrimmed())) {
|
||||
return Optional.ofNullable(assignment.getAssignment());
|
||||
if (args != null) {
|
||||
if (name.equals("value") && args.size() == 1 && !(args.get(0) instanceof Assignment)) {
|
||||
return Optional.ofNullable(args.get(0));
|
||||
} else {
|
||||
for (Expression arg : args) {
|
||||
if (arg instanceof Assignment) {
|
||||
Assignment assignment = (Assignment) arg;
|
||||
if (name.equals(assignment.getVariable().printTrimmed())) {
|
||||
return Optional.ofNullable(assignment.getAssignment());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -468,6 +473,24 @@ public class ORAstUtils {
|
||||
}
|
||||
return nodeRegion;
|
||||
}
|
||||
|
||||
public static String getSimpleNameWithParamTypes(JavaType type) {
|
||||
if (type instanceof FullyQualified) {
|
||||
StringBuilder sb = new StringBuilder(((FullyQualified)type).getClassName());
|
||||
if (type instanceof Parameterized) {
|
||||
List<JavaType> paramTypes = ((Parameterized) type).getTypeParameters();
|
||||
if (paramTypes != null) {
|
||||
sb.append(paramTypes.stream().map(p -> getSimpleNameWithParamTypes(p)).collect(Collectors.joining(",", "<", ">")));
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
} else if (type instanceof Array) {
|
||||
return getSimpleNameWithParamTypes(((Array) type).getElemType()) + "[]";
|
||||
} else {
|
||||
return type.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<CompilationUnit> parse(JavaParser parser, Iterable<Path> sourceFiles) {
|
||||
List<CompilationUnit> cus = parser.parse(sourceFiles, null, new InMemoryExecutionContext());
|
||||
|
||||
@@ -61,7 +61,7 @@ public class DataRepositorySymbolProviderTest {
|
||||
projectFinder.find(new TextDocumentIdentifier(projectDir)).get();
|
||||
|
||||
CompletableFuture<Void> initProject = indexer.waitOperation();
|
||||
initProject.get(5, TimeUnit.SECONDS);
|
||||
initProject.get(25000000L, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user