-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Add annotation inspection support #104
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much!