Fix a potential endless parsing loop processing imports
diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrParserResult.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrParserResult.java
index 29411dd..bced56f 100644
--- a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrParserResult.java
+++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrParserResult.java
@@ -20,9 +20,11 @@
 
 import java.util.ArrayList;
 import java.util.Deque;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.TreeMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 import org.antlr.v4.runtime.ANTLRErrorListener;
@@ -53,6 +55,7 @@
     public final List<OffsetRange> folds = new ArrayList<>();
     public final List<AntlrStructureItem> structure = new ArrayList<>();
 
+    final Set<FileObject> queued = new HashSet<>();
     final Deque<T> parsingQueue = new LinkedList<>();
 
     final AtomicBoolean finished = new AtomicBoolean();
@@ -63,7 +66,6 @@
     }
     
 
-
     public AntlrParserResult get() {
         while (!parsingQueue.isEmpty()) {
             evaluateParser(parsingQueue.removeFirst());
@@ -83,18 +85,24 @@
 
 
     protected final void addParseTask(Snapshot snapshot, boolean imported) {
+        // TODO: In a more decent implementation we should not try to parse
+        //       other files. Parser results in other files should be put
+        //       and retrieved by the Indexer infrastructure, which is yet to be
+        //       implemented.
         FileObject fo = snapshot.getSource().getFileObject();
-        T parser = createParser(snapshot);
+        if (queued.add(fo)) {
+            T parser = createParser(snapshot);
 
 
-        if (!imported) {
-            parser.addErrorListener(createErrorListener(fo));
-            parser.addParseListener(createFoldListener());
+            if (!imported) {
+                parser.addErrorListener(createErrorListener(fo));
+                parser.addParseListener(createFoldListener());
+            }
+            parser.addParseListener(createReferenceListener(fo));
+            parser.addParseListener(createImportListener(fo));
+            parser.addParseListener(createStructureListener(fo));
+            parsingQueue.add(parser);
         }
-        parser.addParseListener(createReferenceListener(fo));
-        parser.addParseListener(createImportListener(fo));
-        parser.addParseListener(createStructureListener(fo));
-        parsingQueue.add(parser);
     }
 
     @Override