lahodaj commented on code in PR #8423:
URL: https://github.com/apache/netbeans/pull/8423#discussion_r2043888403
##########
java/editor.htmlui/src/org/netbeans/modules/editor/htmlui/JSEmbeddingProvider.java:
##########
@@ -187,6 +190,19 @@ public Void visitLiteral(LiteralTree node, List<? super
LiteralTree> p) {
return super.visitLiteral(node, p);
}
+ private boolean isJsAnnotation(AnnotationTree a) {
+ Tree type = a.getAnnotationType();
+ if (type.getKind() != Tree.Kind.IDENTIFIER) {
Review Comment:
Sorry, but this is not correct. If the name is a (the) FQN, the tree kind
will be `MEMBER_SELECT`.
##########
java/editor.htmlui/src/org/netbeans/modules/editor/htmlui/JSEmbeddingProvider.java:
##########
@@ -158,8 +162,7 @@ public Void visitMethod(
final MethodTree m,
final List<? super LiteralTree> p) {
for (AnnotationTree a : m.getModifiers().getAnnotations()) {
- final TypeElement ae = (TypeElement)
trees.getElement(TreePath.getPath(cu, a.getAnnotationType()));
- if (ae != null &&
JS_ANNOTATION.contentEquals(ae.getQualifiedName())) {
+ if (isJsAnnotation(a)) {
Review Comment:
Unless I am terribly mistaken, the issue here is the call to
`TreePath.getPath` - that is slow, causes `n^2` complexity, and should be
avoided if at all possible.
But the solution here might be (or hopefully is) to construct the `TreePath`
cheaper. I am fairly sure, although I didn't try, that something like:
```
new TreePath(new TreePath(new TreePath(getCurrentPath(), m.getModifiers()),
a), a.getAnnotationType())
```
should work without playing tricks with checking trees.
This is attempting to reconstruct the `TreePath` properly, as it should be.
But, knowing how the implementation looks inside, this should work as well:
```
new TreePath(getCurrentPath(), a.getAnnotationType())
```
(as the `Element` is a property of the leaf tree, and the path is not really
checked normally, surely not in much detail.) I tend to prefer to formal way.
There's also `Trees.getPath(CompilationUnitTree, Tree)`, where there's
theoretically a possibility to do caching (which is virtually impossible for
`TreePath.getPath`). But that wasn't pursued so far.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists