This is an automated email from the ASF dual-hosted git repository.

jlahoda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 1e62ffa  [NETBEANS-3218] Add inline hint support for literals used in 
constructors
1e62ffa is described below

commit 1e62ffaf3a9b8247af9406b742d9e687c59b66c1
Author: Benjamin Graf <benjamin.g...@gmx.net>
AuthorDate: Tue Oct 8 20:13:42 2019 +0200

    [NETBEANS-3218] Add inline hint support for literals used in constructors
---
 .../base/semantic/SemanticHighlighterBase.java     | 13 +++--
 .../java/editor/base/semantic/DetectorTest.java    | 64 ++++++++++++----------
 2 files changed, 45 insertions(+), 32 deletions(-)

diff --git 
a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java
 
b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java
index 224e632..46edf7d 100644
--- 
a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java
+++ 
b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java
@@ -1100,10 +1100,15 @@ public abstract class SemanticHighlighterBase extends 
JavaParserResultTask {
             }
 
             TreePath pp = getCurrentPath().getParentPath();
-            if (pp.getLeaf() != null &&
-                pp.getLeaf().getKind() == Kind.METHOD_INVOCATION) {
-                MethodInvocationTree inv = (MethodInvocationTree) pp.getLeaf();
-                int pos = inv.getArguments().indexOf(node);
+            Tree leaf = pp.getLeaf();
+            if (leaf != null &&
+                (leaf.getKind() == Kind.METHOD_INVOCATION || leaf.getKind() == 
Kind.NEW_CLASS)) {
+                int pos = -1;
+                if (leaf.getKind() == Kind.METHOD_INVOCATION) {
+                    pos = 
MethodInvocationTree.class.cast(leaf).getArguments().indexOf(node);
+                } else if (leaf.getKind() == Kind.NEW_CLASS) {
+                    pos = 
NewClassTree.class.cast(leaf).getArguments().indexOf(node);
+                }
                 if (pos != (-1)) {
                     Element invoked = info.getTrees().getElement(pp);
                     if (invoked != null && (invoked.getKind() == 
ElementKind.METHOD || invoked.getKind() == ElementKind.CONSTRUCTOR)) {
diff --git 
a/java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/DetectorTest.java
 
b/java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/DetectorTest.java
index 31d3937..aa09468 100644
--- 
a/java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/DetectorTest.java
+++ 
b/java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/DetectorTest.java
@@ -258,46 +258,54 @@ public class DetectorTest extends TestBase {
         performTest("Test.java",
                     "package test;" +
                     "public class Test {" +
+                    "    public Test(String param) {" +
+                    "    }" +
                     "    public void api(String param1, int param2, int 
param3, float param4, Object... param5) {" +
                     "    }" +
                     "    private int getValue() {" +
                     "        return -1;" +
                     "    }" +
                     "    private void test() {" +
+                    "        new Test(\"\")" +
                     "        api(\"\", 2, getValue(), 1.0f);" +
                     "        api(\"\", 2, getValue(), 1.0f, null);" +
                     "        api(\"\", 2, getValue(), 1.0f, null, null);" +
                     "    }" +
                     "}",
                     "[PUBLIC, CLASS, DECLARATION], 0:26-0:30\n" +
-                    "[PUBLIC, METHOD, DECLARATION], 0:48-0:51\n" +
-                    "[PUBLIC, CLASS], 0:52-0:58\n" +
-                    "[PARAMETER, DECLARATION], 0:59-0:65\n" +
-                    "[PARAMETER, DECLARATION], 0:71-0:77\n" +
-                    "[PARAMETER, DECLARATION], 0:83-0:89\n" +
-                    "[PARAMETER, DECLARATION], 0:97-0:103\n" +
-                    "[PUBLIC, CLASS], 0:105-0:111\n" +
-                    "[PARAMETER, DECLARATION], 0:115-0:121\n" +
-                    "[PRIVATE, METHOD, DECLARATION], 0:145-0:153\n" +
-                    "[PRIVATE, METHOD, UNUSED, DECLARATION], 0:197-0:201\n" +
-                    "[PUBLIC, METHOD], 0:213-0:216\n" +
-                    "[param1:], 0:217-0:218\n" +
-                    "[param2:], 0:221-0:222\n" +
-                    "[PRIVATE, METHOD], 0:224-0:232\n" +
-                    "[param4:], 0:236-0:237\n" +
-                    "[PUBLIC, METHOD], 0:250-0:253\n" +
-                    "[param1:], 0:254-0:255\n" +
-                    "[param2:], 0:258-0:259\n" +
-                    "[PRIVATE, METHOD], 0:261-0:269\n" +
-                    "[param4:], 0:273-0:274\n" +
-                    "[param5:], 0:279-0:280\n" +
-                    "[PUBLIC, METHOD], 0:293-0:296\n" +
-                    "[param1:], 0:297-0:298\n" +
-                    "[param2:], 0:301-0:302\n" +
-                    "[PRIVATE, METHOD], 0:304-0:312\n" +
-                    "[param4:], 0:316-0:317\n" +
-                    "[param5:], 0:322-0:323\n" +
-                    "[param5:], 0:328-0:329\n");
+                    "[PUBLIC, CONSTRUCTOR, DECLARATION], 0:43-0:47\n" +
+                    "[PUBLIC, CLASS], 0:48-0:54\n" +
+                    "[PARAMETER, DECLARATION], 0:55-0:60\n" +
+                    "[PUBLIC, METHOD, DECLARATION], 0:84-0:87\n" +
+                    "[PUBLIC, CLASS], 0:88-0:94\n" +
+                    "[PARAMETER, DECLARATION], 0:95-0:101\n" +
+                    "[PARAMETER, DECLARATION], 0:107-0:113\n" +
+                    "[PARAMETER, DECLARATION], 0:119-0:125\n" +
+                    "[PARAMETER, DECLARATION], 0:133-0:139\n" +
+                    "[PUBLIC, CLASS], 0:141-0:147\n" +
+                    "[PARAMETER, DECLARATION], 0:151-0:157\n" +
+                    "[PRIVATE, METHOD, DECLARATION], 0:181-0:189\n" +
+                    "[PRIVATE, METHOD, UNUSED, DECLARATION], 0:233-0:237\n" +
+                    "[PUBLIC, CONSTRUCTOR], 0:253-0:257\n" +
+                    "[param:], 0:258-0:259\n" +
+                    "[PUBLIC, METHOD], 0:269-0:272\n" +
+                    "[param1:], 0:273-0:274\n" +
+                    "[param2:], 0:277-0:278\n" +
+                    "[PRIVATE, METHOD], 0:280-0:288\n" +
+                    "[param4:], 0:292-0:293\n" +
+                    "[PUBLIC, METHOD], 0:306-0:309\n" +
+                    "[param1:], 0:310-0:311\n" +
+                    "[param2:], 0:314-0:315\n" +
+                    "[PRIVATE, METHOD], 0:317-0:325\n" +
+                    "[param4:], 0:329-0:330\n" +
+                    "[param5:], 0:335-0:336\n" +
+                    "[PUBLIC, METHOD], 0:349-0:352\n" +
+                    "[param1:], 0:353-0:354\n" +
+                    "[param2:], 0:357-0:358\n" +
+                    "[PRIVATE, METHOD], 0:360-0:368\n" +
+                    "[param4:], 0:372-0:373\n" +
+                    "[param5:], 0:378-0:379\n" +
+                    "[param5:], 0:384-0:385\n");
     }
 
     @RandomlyFails


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to