mbien commented on code in PR #5173:
URL: https://github.com/apache/netbeans/pull/5173#discussion_r1223859565
##########
java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/UnusedDetector.java:
##########
@@ -597,5 +619,49 @@ private void handleDeclaration(TreePath path) {
}
}
}
+
+ @Override
+ public Void visitLiteral(LiteralTree node, Void p) {
+ if (node.getKind() == Kind.STRING_LITERAL) {
+ allStringLiterals.add((String) ((LiteralTree)
node).getValue());
+ }
+ return super.visitLiteral(node, p);
+ }
+
+ @Override
+ public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
+ Element invoked = info.getTrees().getElement(new
TreePath(getCurrentPath(), node.getMethodSelect()));
+ if (invoked != null && invoked.getEnclosingElement() ==
methodHandlesLookup && node.getArguments().size() > 0) {
+ ExpressionTree clazz = node.getArguments().get(0);
+ Element lookupType = null;
+ if (clazz.getKind() == Kind.MEMBER_SELECT) {
+ MemberSelectTree mst = (MemberSelectTree) clazz;
+ if (mst.getIdentifier().contentEquals("class")) {
+ lookupType = info.getTrees().getElement(new
TreePath(new TreePath(getCurrentPath(), clazz), mst.getExpression()));
+ }
+ }
+ String lookupName = null;
+ if (node.getArguments().size() > 1) {
+ ExpressionTree name = node.getArguments().get(1);
+ if (name.getKind() == Kind.STRING_LITERAL) {
+ lookupName = (String) ((LiteralTree) name).getValue();
+ }
+ }
+ switch (invoked.getSimpleName().toString()) {
+ case "findStatic": case "findVirtual": case "findSpecial":
+ type2LookedUpMethods.computeIfAbsent(lookupType, t ->
new HashSet<>()).add(lookupName);
Review Comment:
nitpick:
`type2LookedUpMethods.computeIfAbsent(lookupType, t -> new
HashSet<>()).add(lookupName);`
->
`type2LookedUpMethods.putIfAbsent(lookupType, new
HashSet<>()).add(lookupName);`
potentially clearer?
(multiple occurrences in file)
--
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