Skip to content

Commit

Permalink
Updates ANTLR Java parser
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanue1 committed Jul 1, 2015
1 parent 78d1636 commit 7e56f6d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion services/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ task antlr4GenerateGrammarSource(dependsOn: antlr4OutputDir, type: JavaExec) {

main = 'org.antlr.v4.Tool'
classpath = configurations.antlr4
args = ['-o', "${antlr4.destinationDir}/${pkg}", '-atn', '-package', antlr4.grammarPackage, grammars.files].flatten()
args = ['-o', "${antlr4.destinationDir}/${pkg}", '-package', antlr4.grammarPackage, grammars.files].flatten()
}

compileJava {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package jd.gui.view.component
import groovy.transform.CompileStatic
import jd.gui.api.API
import jd.gui.api.model.Container
import jd.gui.util.parser.antlr.ANTLRParser
import jd.gui.util.parser.antlr.ANTLRJavaParser
import jd.gui.util.parser.antlr.AbstractJavaListener
import jd.gui.util.parser.antlr.JavaParser
import org.antlr.v4.runtime.ANTLRInputStream
Expand All @@ -27,9 +27,9 @@ class JavaFilePage extends TypePage {
def declarationListener = new DeclarationListener(entry)
def referenceListener = new ReferenceListener(entry)

ANTLRParser.parse(new ANTLRInputStream(text), declarationListener)
ANTLRJavaParser.parse(new ANTLRInputStream(text), declarationListener)
referenceListener.init(declarationListener)
ANTLRParser.parse(new ANTLRInputStream(text), referenceListener)
ANTLRJavaParser.parse(new ANTLRInputStream(text), referenceListener)
// Display
setText(text)
// Show hyperlinks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import jd.gui.api.API;
import jd.gui.api.model.Container;
import jd.gui.api.model.Indexes;
import jd.gui.util.parser.antlr.ANTLRParser;
import jd.gui.util.parser.antlr.ANTLRJavaParser;
import jd.gui.util.parser.antlr.AbstractJavaListener;
import jd.gui.util.parser.antlr.JavaParser;
import org.antlr.v4.runtime.ANTLRInputStream;
Expand All @@ -27,7 +27,7 @@ public class JavaFileIndexerProvider extends AbstractIndexerProvider {

static {
// Early class loading
ANTLRParser.parse(new ANTLRInputStream("class EarlyLoading{}"), new Listener(null));
ANTLRJavaParser.parse(new ANTLRInputStream("class EarlyLoading{}"), new Listener(null));
}

/**
Expand All @@ -54,7 +54,7 @@ public String[] getSelectors() {
public void index(API api, Container.Entry entry, Indexes indexes) {
try (InputStream inputStream = entry.getInputStream()) {
Listener listener = new Listener(entry);
ANTLRParser.parse(new ANTLRInputStream(inputStream), listener);
ANTLRJavaParser.parse(new ANTLRInputStream(inputStream), listener);

// Append sets to indexes
addToIndex(indexes, "typeDeclarations", listener.getTypeDeclarationSet(), entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class JavaFileTypeFactoryProvider extends AbstractTypeFactoryProvider {

static {
// Early class loading
ANTLRParser.parse(new ANTLRInputStream("class EarlyLoading{}"), new Listener(null));
ANTLRJavaParser.parse(new ANTLRInputStream("class EarlyLoading{}"), new Listener(null));
}

// Create cache
Expand Down Expand Up @@ -88,7 +88,7 @@ protected Listener getListener(Container.Entry entry) {
Listener listener;

try (InputStream inputStream = entry.getInputStream()) {
ANTLRParser.parse(new ANTLRInputStream(inputStream), listener = new Listener(entry));
ANTLRJavaParser.parse(new ANTLRInputStream(inputStream), listener = new Listener(entry));
} catch (IOException ignore) {
listener = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

public class ANTLRParser {
public class ANTLRJavaParser {

public static void parse(CharStream input, JavaListener listener) {
try {
JavaLexer lexer = new JavaLexer(input);

lexer.removeErrorListeners();

CommonTokenStream tokens = new CommonTokenStream(lexer);
JavaParser parser = new JavaParser(tokens);

parser.removeErrorListeners();

ParseTree tree = parser.compilationUnit();

ParseTreeWalker.DEFAULT.walk(listener, tree);
Expand Down

0 comments on commit 7e56f6d

Please sign in to comment.