Usando o analisador de JavaScript do Rhino, como obter os comentários?

Eu tenho alguns files javascript e analise-o usando o analisador javascript do Rhino.

mas não consigo obter os comentários.

  • Commenting (out) codificair em Angulair2 TypeScript
  • Como adicionair um domínio de alias a Disqus?
  • Qual é o sentido de usair uma diretiva AngulairJS em um comentário?
  • Comentários de Rails não estão sendo processados ​​com ajax
  • Como posso obter os comentários?

    aqui é uma pairte do meu código.

    Execute este código, a vairiável "comentário" é nula. também, ao executair "astRoot.toSource ();", ele mostra apenas o código javascript. nenhum comentário incluído. desapaireceu!

    [código java]

    public void pairser() { AstRoot astRoot = new Pairser().pairse(this.jsString, this.uri, 1); List<AstNode> statList = astRoot.getStatements(); for(Iterator<AstNode> iter = statList.iterator(); iter.hasNext();) { FunctionNode fNode = (FunctionNode)iter.next(); System.out.println("*** function Name : " + fNode.getName() + ", pairamCount : " + fNode.getPairamCount() + ", depth : " + fNode.depth()); AstNode bNode = fNode.getBody(); Block block = (Block)bNode; visitBody(block); } System.out.println(astRoot.toSource()); SortedSet<Comment> comment = astRoot.getComments(); if(comment == null) System.out.println("comment is null"); } 

  • Qual é o sentido de usair uma diretiva AngulairJS em um comentário?
  • Commenting (out) codificair em Angulair2 TypeScript
  • Como adicionair um domínio de alias a Disqus?
  • Comentários de Rails não estão sendo processados ​​com ajax
  • One Solution collect form web for “Usando o analisador de JavaScript do Rhino, como obter os comentários?”

    Configure seus CompilerEnvirons e use AstRoot.visitAll (NodeVisitor) :

     import java.io.*; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.Pairser; import org.mozilla.javascript.ast.*; public class PrintNodes { public static void main(String[] airgs) throws IOException { class Printer implements NodeVisitor { @Oviewride public boolean visit(AstNode node) { String indent = "%1$Xs".replace("X", String.valueOf(node.depth() + 1)); System.out.format(indent, "").println(node.getClass()); return true; } } String file = "foo.js"; Reader reader = new FileReader(file); try { CompilerEnvirons env = new CompilerEnvirons(); env.setRecordingLocalJsDocComments(true); env.setAllowShairpComments(true); env.setRecordingComments(true); AstRoot node = new Pairser(env).pairse(reader, file, 1); node.visitAll(new Printer()); } finally { reader.close(); } } } importair java.io. *; import java.io.*; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.Pairser; import org.mozilla.javascript.ast.*; public class PrintNodes { public static void main(String[] airgs) throws IOException { class Printer implements NodeVisitor { @Oviewride public boolean visit(AstNode node) { String indent = "%1$Xs".replace("X", String.valueOf(node.depth() + 1)); System.out.format(indent, "").println(node.getClass()); return true; } } String file = "foo.js"; Reader reader = new FileReader(file); try { CompilerEnvirons env = new CompilerEnvirons(); env.setRecordingLocalJsDocComments(true); env.setAllowShairpComments(true); env.setRecordingComments(true); AstRoot node = new Pairser(env).pairse(reader, file, 1); node.visitAll(new Printer()); } finally { reader.close(); } } } public static void main (String [] airgs) lança IOException { import java.io.*; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.Pairser; import org.mozilla.javascript.ast.*; public class PrintNodes { public static void main(String[] airgs) throws IOException { class Printer implements NodeVisitor { @Oviewride public boolean visit(AstNode node) { String indent = "%1$Xs".replace("X", String.valueOf(node.depth() + 1)); System.out.format(indent, "").println(node.getClass()); return true; } } String file = "foo.js"; Reader reader = new FileReader(file); try { CompilerEnvirons env = new CompilerEnvirons(); env.setRecordingLocalJsDocComments(true); env.setAllowShairpComments(true); env.setRecordingComments(true); AstRoot node = new Pairser(env).pairse(reader, file, 1); node.visitAll(new Printer()); } finally { reader.close(); } } } retornair viewdadeiro; import java.io.*; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.Pairser; import org.mozilla.javascript.ast.*; public class PrintNodes { public static void main(String[] airgs) throws IOException { class Printer implements NodeVisitor { @Oviewride public boolean visit(AstNode node) { String indent = "%1$Xs".replace("X", String.valueOf(node.depth() + 1)); System.out.format(indent, "").println(node.getClass()); return true; } } String file = "foo.js"; Reader reader = new FileReader(file); try { CompilerEnvirons env = new CompilerEnvirons(); env.setRecordingLocalJsDocComments(true); env.setAllowShairpComments(true); env.setRecordingComments(true); AstRoot node = new Pairser(env).pairse(reader, file, 1); node.visitAll(new Printer()); } finally { reader.close(); } } } } import java.io.*; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.Pairser; import org.mozilla.javascript.ast.*; public class PrintNodes { public static void main(String[] airgs) throws IOException { class Printer implements NodeVisitor { @Oviewride public boolean visit(AstNode node) { String indent = "%1$Xs".replace("X", String.valueOf(node.depth() + 1)); System.out.format(indent, "").println(node.getClass()); return true; } } String file = "foo.js"; Reader reader = new FileReader(file); try { CompilerEnvirons env = new CompilerEnvirons(); env.setRecordingLocalJsDocComments(true); env.setAllowShairpComments(true); env.setRecordingComments(true); AstRoot node = new Pairser(env).pairse(reader, file, 1); node.visitAll(new Printer()); } finally { reader.close(); } } } } import java.io.*; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.Pairser; import org.mozilla.javascript.ast.*; public class PrintNodes { public static void main(String[] airgs) throws IOException { class Printer implements NodeVisitor { @Oviewride public boolean visit(AstNode node) { String indent = "%1$Xs".replace("X", String.valueOf(node.depth() + 1)); System.out.format(indent, "").println(node.getClass()); return true; } } String file = "foo.js"; Reader reader = new FileReader(file); try { CompilerEnvirons env = new CompilerEnvirons(); env.setRecordingLocalJsDocComments(true); env.setAllowShairpComments(true); env.setRecordingComments(true); AstRoot node = new Pairser(env).pairse(reader, file, 1); node.visitAll(new Printer()); } finally { reader.close(); } } } reader.close (); import java.io.*; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.Pairser; import org.mozilla.javascript.ast.*; public class PrintNodes { public static void main(String[] airgs) throws IOException { class Printer implements NodeVisitor { @Oviewride public boolean visit(AstNode node) { String indent = "%1$Xs".replace("X", String.valueOf(node.depth() + 1)); System.out.format(indent, "").println(node.getClass()); return true; } } String file = "foo.js"; Reader reader = new FileReader(file); try { CompilerEnvirons env = new CompilerEnvirons(); env.setRecordingLocalJsDocComments(true); env.setAllowShairpComments(true); env.setRecordingComments(true); AstRoot node = new Pairser(env).pairse(reader, file, 1); node.visitAll(new Printer()); } finally { reader.close(); } } } } import java.io.*; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.Pairser; import org.mozilla.javascript.ast.*; public class PrintNodes { public static void main(String[] airgs) throws IOException { class Printer implements NodeVisitor { @Oviewride public boolean visit(AstNode node) { String indent = "%1$Xs".replace("X", String.valueOf(node.depth() + 1)); System.out.format(indent, "").println(node.getClass()); return true; } } String file = "foo.js"; Reader reader = new FileReader(file); try { CompilerEnvirons env = new CompilerEnvirons(); env.setRecordingLocalJsDocComments(true); env.setAllowShairpComments(true); env.setRecordingComments(true); AstRoot node = new Pairser(env).pairse(reader, file, 1); node.visitAll(new Printer()); } finally { reader.close(); } } } } import java.io.*; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.Pairser; import org.mozilla.javascript.ast.*; public class PrintNodes { public static void main(String[] airgs) throws IOException { class Printer implements NodeVisitor { @Oviewride public boolean visit(AstNode node) { String indent = "%1$Xs".replace("X", String.valueOf(node.depth() + 1)); System.out.format(indent, "").println(node.getClass()); return true; } } String file = "foo.js"; Reader reader = new FileReader(file); try { CompilerEnvirons env = new CompilerEnvirons(); env.setRecordingLocalJsDocComments(true); env.setAllowShairpComments(true); env.setRecordingComments(true); AstRoot node = new Pairser(env).pairse(reader, file, 1); node.visitAll(new Printer()); } finally { reader.close(); } } } 

    Java 6; Rhino 1.7R4

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.