You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2020/10/08 04:26:25 UTC

[netbeans] branch master updated: [NETBEANS-4832] Avoid assertion & NPE in fxml code completion (#2399)

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

lkishalmi 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 794e55a  [NETBEANS-4832] Avoid assertion & NPE in fxml code completion (#2399)
794e55a is described below

commit 794e55ab43740e8d8186941635cb728e143d239a
Author: errael <er...@raelity.com>
AuthorDate: Wed Oct 7 21:25:47 2020 -0700

    [NETBEANS-4832] Avoid assertion & NPE in fxml code completion (#2399)
    
    * [NETBEANS-4832] Avoid assertion & NPE in fxml code completion
    
    * Handle ANNOTATION_TYPE and ENUM in getTypeElementByBinaryName().
---
 .../src/org/netbeans/modules/java/source/ElementUtils.java    |  7 ++++++-
 .../org/netbeans/modules/javafx2/editor/FXMLCompletion2.java  | 11 +++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/ElementUtils.java b/java/java.source.base/src/org/netbeans/modules/java/source/ElementUtils.java
index 7aca70d..d411877 100644
--- a/java/java.source.base/src/org/netbeans/modules/java/source/ElementUtils.java
+++ b/java/java.source.base/src/org/netbeans/modules/java/source/ElementUtils.java
@@ -60,6 +60,11 @@ public class ElementUtils {
         for (ModuleElement me : allModules) {
             TypeElement found = getTypeElementByBinaryName(task, me, name);
 
+            if (result == found) {
+                // avoid returning null, partial fix for [NETBEANS-4832]
+                continue;
+            }
+
             if (found != null) {
                 if ((ModuleSymbol) me == syms.unnamedModule) {
                     foundInUnamedModule = true;
@@ -67,7 +72,7 @@ public class ElementUtils {
                 if (result != null) {
                     if (foundInUnamedModule == true) {
                         for (TypeElement elem : new TypeElement[]{result, found}) {
-                            if ((elem.getKind() == ElementKind.CLASS || elem.getKind() == ElementKind.INTERFACE)
+                            if ((elem.getKind().isClass() || elem.getKind().isInterface())
                                     && (((ClassSymbol) elem).packge().modle != syms.unnamedModule)) {
                                 return elem;
                             }
diff --git a/javafx/javafx2.editor/src/org/netbeans/modules/javafx2/editor/FXMLCompletion2.java b/javafx/javafx2.editor/src/org/netbeans/modules/javafx2/editor/FXMLCompletion2.java
index 4931ed8..2e2c5c0 100644
--- a/javafx/javafx2.editor/src/org/netbeans/modules/javafx2/editor/FXMLCompletion2.java
+++ b/javafx/javafx2.editor/src/org/netbeans/modules/javafx2/editor/FXMLCompletion2.java
@@ -30,7 +30,8 @@ import javax.xml.parsers.SAXParserFactory;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.mimelookup.MimeRegistration;
 import org.netbeans.api.java.source.ClasspathInfo;
-import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.api.java.source.CompilationController;
+import org.netbeans.api.java.source.JavaSource.Phase;
 import org.netbeans.api.lexer.TokenHierarchy;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.modules.java.source.parsing.ClasspathInfoProvider;
@@ -131,7 +132,7 @@ public class FXMLCompletion2 implements CompletionProvider {
             private int queryType;
             private boolean fxmlParsing = true;
             private CompletionContext ctx;
-            private CompilationInfo ci;
+            private CompilationController cc;
             private FxmlParserResult fxmlResult;
 
             public Task(ClasspathInfo cpInfo, JTextComponent component, CompletionResultSet resultSet, Document doc, int caretOffset, int queryType) {
@@ -160,7 +161,9 @@ public class FXMLCompletion2 implements CompletionProvider {
                     return;
                 }
                 Parser.Result result = resultIterator.getParserResult();
-                ci = CompilationInfo.get(result);
+                // [NETBEANS-4832] CompController (not CompInfo) for module info (partial fix)
+                cc = CompilationController.get(result);
+                cc.toPhase(Phase.ELEMENTS_RESOLVED);
 
                 ctx = new CompletionContext(doc, caretOffset, queryType);
 
@@ -171,7 +174,7 @@ public class FXMLCompletion2 implements CompletionProvider {
                 // bug in parsing API: snapshot source not modified just after modification to the source file
                 try {
                     TokenHierarchy<?> th = TokenHierarchy.get(doc);
-                    ctx.init(th, ci, fxmlResult); 
+                    ctx.init(th, cc, fxmlResult); 
                 } finally {
                     if (doc instanceof AbstractDocument) {
                         ((AbstractDocument)doc).readUnlock();


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

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