diff --git a/runtime/Java/doxyfile b/runtime/Java/doxyfile index a589fd6c7..c66ff9966 100644 --- a/runtime/Java/doxyfile +++ b/runtime/Java/doxyfile @@ -216,7 +216,7 @@ HAVE_DOT = YES CLASS_GRAPH = YES COLLABORATION_GRAPH = YES GROUP_GRAPHS = YES -UML_LOOK = NO +UML_LOOK = YES TEMPLATE_RELATIONS = NO INCLUDE_GRAPH = YES INCLUDED_BY_GRAPH = YES diff --git a/runtime/Java/src/org/antlr/v4/runtime/TokenStream.java b/runtime/Java/src/org/antlr/v4/runtime/TokenStream.java index 5acfd96f0..e643535bd 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/TokenStream.java +++ b/runtime/Java/src/org/antlr/v4/runtime/TokenStream.java @@ -35,7 +35,7 @@ import org.antlr.v4.runtime.misc.Interval; public interface TokenStream extends IntStream { /** Get Token at current input pointer + i ahead where i=1 is next Token. * i<0 indicates tokens in the past. So -1 is previous token and -2 is - * two tokens ago. LT(0) is undefined. For i>=n, return Token.EOFToken. + * two tokens ago. LT(0) is undefined. For i>=n, return eof token. * Return null for LT(0) and any index that results in an absolute address * that is negative. * TODO (Sam): Throw exception for invalid k? diff --git a/tool/playground/ExtractInheritance.java b/tool/playground/ExtractInheritance.java new file mode 100644 index 000000000..29d97b1c9 --- /dev/null +++ b/tool/playground/ExtractInheritance.java @@ -0,0 +1,54 @@ +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.tree.TerminalNode; + +import java.util.List; + +public class ExtractInheritance extends JavaLRBaseListener { + JavaLRParser parser; + public ExtractInheritance(JavaLRParser parser) { this.parser = parser; } + + /* + normalClassDeclaration + : 'class' Identifier typeParameters? + ('extends' type)? + ('implements' typeList)? + classBody + ; + + */ + @Override + public void enterNormalClassDeclaration(JavaLRParser.NormalClassDeclarationContext ctx) { + TerminalNode id = ctx.Identifier(); + String sup = null; + if ( ctx.type()!=null ) { + sup = ctx.type().getText(); + System.out.println("\""+id+"\" -> \""+sup+"\""); + } + if ( ctx.typeList()!=null ) { + List type = ctx.typeList().type(); + for (JavaLRParser.TypeContext t : type) { + System.out.println("\""+id+"\" -> \""+t.getText()+"\""); + } + } + } + + /* + normalInterfaceDeclaration + : 'interface' Identifier typeParameters? ('extends' typeList)? interfaceBody + ; + + */ + + @Override + public void enterNormalInterfaceDeclaration(JavaLRParser.NormalInterfaceDeclarationContext ctx) { + TerminalNode id = ctx.Identifier(); + System.out.println("###### interface "+id); + String args = null; + if ( ctx.typeList()!=null ) { + List type = ctx.typeList().type(); + for (JavaLRParser.TypeContext t : type) { + System.out.println("\""+id+"\" -> \""+t.getText()+"\""); + } + } + } +} diff --git a/tool/playground/GenHierarchy.java b/tool/playground/GenHierarchy.java new file mode 100644 index 000000000..19222574f --- /dev/null +++ b/tool/playground/GenHierarchy.java @@ -0,0 +1,61 @@ +import org.antlr.v4.runtime.ANTLRInputStream; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.tree.ParseTreeWalker; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +public class GenHierarchy { + public static void main(String[] args) throws Exception { + // START: input + String inputFile = null; + if ( args.length>0 ) inputFile = args[0]; + List files = getFilenames(new File(inputFile)); + for (String file : files) { + InputStream is = new FileInputStream(file); + ANTLRInputStream input = new ANTLRInputStream(is); + // END: input + +// System.out.println(file); + // START: launch + JavaLRLexer lexer = new JavaLRLexer(input); + CommonTokenStream tokens = new CommonTokenStream(lexer); + JavaLRParser parser = new JavaLRParser(tokens); + ParserRuleContext tree = parser.compilationUnit(); // parse + + ParseTreeWalker walker = new ParseTreeWalker(); // create standard walker + ExtractInheritance extractor = new ExtractInheritance(parser); + walker.walk(extractor, tree); // initiate walk of tree with listener + } + // END: launch + } + + public static List getFilenames(File f) throws Exception { + List files = new ArrayList(); + getFilenames_(f, files); + return files; + } + + public static void getFilenames_(File f, List files) throws Exception { + // If this is a directory, walk each file/dir in that directory + if (f.isDirectory()) { + String flist[] = f.list(); + for(int i=0; i < flist.length; i++) { + getFilenames_(new File(f, flist[i]), files); + } + } + + // otherwise, if this is a java file, parse it! + else if ( ((f.getName().length()>5) && + f.getName().substring(f.getName().length()-5).equals(".java")) ) + { + files.add(f.getAbsolutePath()); + } + } + +} diff --git a/tool/src/org/antlr/v4/automata/ATNSerializer.java b/tool/src/org/antlr/v4/automata/ATNSerializer.java index a04fb2018..bc809efe4 100644 --- a/tool/src/org/antlr/v4/automata/ATNSerializer.java +++ b/tool/src/org/antlr/v4/automata/ATNSerializer.java @@ -36,6 +36,7 @@ import org.antlr.v4.runtime.atn.ATNSimulator; import org.antlr.v4.runtime.atn.ATNState; import org.antlr.v4.runtime.atn.ActionTransition; import org.antlr.v4.runtime.atn.AtomTransition; +import org.antlr.v4.runtime.atn.BlockStartState; import org.antlr.v4.runtime.atn.DecisionState; import org.antlr.v4.runtime.atn.LoopEndState; import org.antlr.v4.runtime.atn.PredicateTransition;