diff --git a/antlr4-wrapper.xml b/antlr4-wrapper.xml index 410ef976e4..2e4b617e27 100644 --- a/antlr4-wrapper.xml +++ b/antlr4-wrapper.xml @@ -50,7 +50,7 @@ + value="${root-node-name}Context extends ${lang-name}RootNode"/> diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrBaseParser.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrBaseParser.java index 402facbd72..983efd6b74 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrBaseParser.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrBaseParser.java @@ -8,8 +8,8 @@ import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.Lexer; +import net.sourceforge.pmd.lang.ast.AstInfo; import net.sourceforge.pmd.lang.ast.Parser; -import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.RootNode; @@ -25,19 +25,13 @@ public abstract class AntlrBaseParser< R extends BaseAntlrInnerNode & RootNode > implements Parser { - protected final ParserOptions parserOptions; - - public AntlrBaseParser(final ParserOptions parserOptions) { - this.parserOptions = parserOptions; - } - @Override - public R parse(ParserTask task) throws ParseException { + public AstInfo parse(ParserTask task) throws ParseException { CharStream cs = CharStreams.fromString(task.getSourceText(), task.getFileDisplayName()); return parse(getLexer(cs), task); } - protected abstract R parse(Lexer parser, ParserTask task); + protected abstract AstInfo parse(Lexer parser, ParserTask task); protected abstract Lexer getLexer(CharStream source); } diff --git a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftHandler.java b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftHandler.java index 1a4cb075f5..b5aec2c447 100644 --- a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftHandler.java +++ b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftHandler.java @@ -5,14 +5,14 @@ package net.sourceforge.pmd.lang.swift; import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler; -import net.sourceforge.pmd.lang.ast.Parser; import net.sourceforge.pmd.lang.ParserOptions; +import net.sourceforge.pmd.lang.ast.Parser; import net.sourceforge.pmd.lang.swift.ast.PmdSwiftParser; public class SwiftHandler extends AbstractPmdLanguageVersionHandler { @Override public Parser getParser(final ParserOptions parserOptions) { - return new PmdSwiftParser(parserOptions); + return new PmdSwiftParser(); } } diff --git a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/ast/PmdSwiftParser.java b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/ast/PmdSwiftParser.java index 2cba64edc8..265da4391f 100644 --- a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/ast/PmdSwiftParser.java +++ b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/ast/PmdSwiftParser.java @@ -8,7 +8,7 @@ import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.Lexer; -import net.sourceforge.pmd.lang.ParserOptions; +import net.sourceforge.pmd.lang.ast.AstInfo; import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrBaseParser; import net.sourceforge.pmd.lang.swift.ast.SwiftParser.SwTopLevel; @@ -17,14 +17,10 @@ import net.sourceforge.pmd.lang.swift.ast.SwiftParser.SwTopLevel; */ public final class PmdSwiftParser extends AntlrBaseParser { - public PmdSwiftParser(final ParserOptions parserOptions) { - super(parserOptions); - } - @Override - protected SwTopLevel parse(final Lexer lexer) { + protected AstInfo parse(final Lexer lexer, ParserTask task) { SwiftParser parser = new SwiftParser(new CommonTokenStream(lexer)); - return parser.topLevel(); + return parser.topLevel().makeAstInfo(task); } @Override diff --git a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/ast/SwiftRootNode.java b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/ast/SwiftRootNode.java new file mode 100644 index 0000000000..7ca0bba741 --- /dev/null +++ b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/ast/SwiftRootNode.java @@ -0,0 +1,37 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.swift.ast; + +import org.antlr.v4.runtime.ParserRuleContext; + +import net.sourceforge.pmd.lang.ast.AstInfo; +import net.sourceforge.pmd.lang.ast.Parser.ParserTask; +import net.sourceforge.pmd.lang.ast.RootNode; +import net.sourceforge.pmd.lang.swift.ast.SwiftParser.SwTopLevel; + +// package private base class +abstract class SwiftRootNode extends SwiftInnerNode implements RootNode { + + private AstInfo astInfo; + + SwiftRootNode() { + super(); + } + + SwiftRootNode(ParserRuleContext parent, int invokingStateNumber) { + super(parent, invokingStateNumber); + } + + @Override + public AstInfo getAstInfo() { + return astInfo; + } + + AstInfo makeAstInfo(ParserTask task) { + this.astInfo = new AstInfo<>(task, (SwTopLevel) this); + return astInfo; + } + +}