-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Add annotation inspection support (#104)
* Add annotation inspection support Signed-off-by: Juan Manuel Leflet Estrada <jleflete@redhat.com> * Remove unneeded pom changes Signed-off-by: Juan Manuel Leflet Estrada <jleflete@redhat.com> * Remove gradle stuff Signed-off-by: Juan Manuel Leflet Estrada <jleflete@redhat.com> * Add guard against null pointer Signed-off-by: Juan Manuel Leflet Estrada <jleflete@redhat.com> --------- Signed-off-by: Juan Manuel Leflet Estrada <jleflete@redhat.com>
- Loading branch information
Showing
10 changed files
with
445 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...zer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/query/AnnotationQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.konveyor.tackle.core.internal.query; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Represents additional query information to inspect annotations in annotated symbols. | ||
*/ | ||
public class AnnotationQuery { | ||
|
||
/** | ||
* The annotation type, ie: <code>@org.business.BeanAnnotation</code> | ||
*/ | ||
private String type; | ||
|
||
/** | ||
* The elements within the annotation, ie, "value" in <code>@BeanAnnotation(value = "value")</code> | ||
*/ | ||
private Map<String, String> elements; | ||
|
||
public AnnotationQuery(String type, Map<String, String> elements) { | ||
this.type = type; | ||
this.elements = elements; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public Map<String, String> getElements() { | ||
return elements; | ||
} | ||
|
||
public static AnnotationQuery fromMap(Map<String, Object> query) { | ||
if (query == null) { | ||
return null; | ||
} | ||
|
||
String typePattern = (String) query.get("pattern"); | ||
final Map<String, String> elements = new HashMap<>(); | ||
List<Map<String, String>> mapElements = (List<Map<String, String>>) query.get("elements"); | ||
for (int i = 0; mapElements != null && i < mapElements.size(); i++) { | ||
String key = mapElements.get(i).get("name"); | ||
String value = mapElements.get(i).get("value"); | ||
elements.put(key, value); | ||
} | ||
|
||
return new AnnotationQuery(typePattern, elements); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...undle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/FieldSymbolProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.konveyor.tackle.core.internal.symbol; | ||
|
||
import static org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logInfo; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
|
||
import io.konveyor.tackle.core.internal.query.AnnotationQuery; | ||
import org.eclipse.core.runtime.URIUtil; | ||
import org.eclipse.jdt.core.IAnnotation; | ||
import org.eclipse.jdt.core.IClassFile; | ||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.IImportDeclaration; | ||
import org.eclipse.jdt.core.IJavaElement; | ||
import org.eclipse.jdt.core.IMemberValuePair; | ||
import org.eclipse.jdt.core.IMethod; | ||
import org.eclipse.jdt.core.IPackageDeclaration; | ||
import org.eclipse.jdt.core.JavaModelException; | ||
import org.eclipse.jdt.core.search.FieldDeclarationMatch; | ||
import org.eclipse.jdt.core.search.SearchMatch; | ||
import org.eclipse.jdt.core.search.MethodDeclarationMatch; | ||
import org.eclipse.jdt.core.search.TypeReferenceMatch; | ||
import org.eclipse.jdt.internal.core.Annotation; | ||
import org.eclipse.jdt.internal.core.ResolvedSourceField; | ||
import org.eclipse.jdt.internal.core.ResolvedSourceMethod; | ||
import org.eclipse.jdt.internal.core.ResolvedSourceType; | ||
import org.eclipse.jdt.internal.core.SourceMethod; | ||
import org.eclipse.jdt.internal.core.SourceRefElement; | ||
import org.eclipse.lsp4j.Location; | ||
import org.eclipse.lsp4j.SymbolInformation; | ||
import org.eclipse.lsp4j.SymbolKind; | ||
|
||
public class FieldSymbolProvider implements SymbolProvider, WithQuery, WithAnnotationQuery { | ||
private String query; | ||
private AnnotationQuery annotationQuery; | ||
|
||
public List<SymbolInformation> get(SearchMatch match) { | ||
SymbolKind k = convertSymbolKind((IJavaElement) match.getElement()); | ||
List<SymbolInformation> symbols = new ArrayList<>(); | ||
try { | ||
TypeReferenceMatch m = (TypeReferenceMatch) match; | ||
ResolvedSourceField e = (ResolvedSourceField) m.getElement(); | ||
SymbolInformation symbol = new SymbolInformation(); | ||
symbol.setName(e.getElementName()); | ||
symbol.setKind(convertSymbolKind(e)); | ||
symbol.setContainerName(e.getParent().getElementName()); | ||
symbol.setLocation(getLocation(e, match)); | ||
|
||
List<Class<? extends SourceRefElement>> classes = new ArrayList<>(); | ||
classes.add(ResolvedSourceField.class); | ||
if (matchesAnnotationQuery(match, classes)) { | ||
symbols.add(symbol); | ||
} | ||
} catch (Exception e) { | ||
logInfo("unable to convert for variable: " + e); | ||
} | ||
|
||
return symbols; | ||
} | ||
|
||
public void setQuery(String query) { | ||
this.query = query; | ||
} | ||
|
||
@Override | ||
public AnnotationQuery getAnnotationQuery() { | ||
return this.annotationQuery; | ||
} | ||
|
||
public void setAnnotationQuery(AnnotationQuery annotationQuery) { | ||
this.annotationQuery = annotationQuery; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.