Reorganise antlr files
Antlr root nodes need to implement RootNode. Also, I didn't like the fact that the swift module didn't use the conventional package structure (lang.swift.ast) but was rolling its own convention (lang.swift.antlr4). I moved base classes for the antlr implementations into nspmd.lang.ast.impl.antlr4. The fact that a module is implemented with antlr is an implementation detail, and it doesn't deserve its own toplevel package in nspmd.lang.
This commit is contained in:
@ -27,7 +27,7 @@
|
||||
<inherited>true</inherited>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>antlr-generation</id>
|
||||
<id>antlr-cleanup</id>
|
||||
<phase>generate-sources</phase>
|
||||
<configuration>
|
||||
<target>
|
||||
|
@ -1,19 +1,16 @@
|
||||
<project name="pmd" default="antlr4" basedir="../../../../">
|
||||
|
||||
<property name="target-package-dir" value="${target}/net/sourceforge/pmd/lang/swift/antlr4" />
|
||||
<property name="target-package-dir" value="${target}/net/sourceforge/pmd/lang/swift/ast" />
|
||||
|
||||
<target name="antlr4" description="Generates all Antlr4 aspects within PMD">
|
||||
<replace file="${target-package-dir}/SwiftParser.java"
|
||||
token="extends ParserRuleContext"
|
||||
value="extends net.sourceforge.pmd.lang.ast.AntlrBaseNode" />
|
||||
token="TopLevelContext extends AntlrBaseNode"
|
||||
value="TopLevelContext extends AntlrBaseRootNode" />
|
||||
<replace file="${target-package-dir}/SwiftBaseVisitor.java"
|
||||
token="extends AbstractParseTreeVisitor"
|
||||
value="extends AbstractAntlrVisitor" />
|
||||
<replace file="${target-package-dir}/SwiftBaseVisitor.java"
|
||||
token="public class SwiftBaseVisitor"
|
||||
value="public abstract class SwiftBaseVisitor" />
|
||||
<replace file="${target-package-dir}/SwiftBaseVisitor.java"
|
||||
token="import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;"
|
||||
value="import net.sourceforge.pmd.lang.antlr.AbstractAntlrVisitor;" />
|
||||
</target>
|
||||
</project>
|
||||
</project>
|
||||
|
@ -33,11 +33,13 @@
|
||||
*/
|
||||
grammar Swift;
|
||||
|
||||
/*
|
||||
@header {
|
||||
package com.sleekbyte.tailor.antlr;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.*;
|
||||
}
|
||||
|
||||
options {
|
||||
contextSuperClass = AntlrBaseNode;
|
||||
}
|
||||
*/
|
||||
|
||||
topLevel : statements? EOF ;
|
||||
|
@ -6,8 +6,9 @@ package net.sourceforge.pmd.cpd;
|
||||
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
|
||||
import net.sourceforge.pmd.lang.antlr.AntlrTokenManager;
|
||||
import net.sourceforge.pmd.lang.swift.antlr4.SwiftLexer;
|
||||
import net.sourceforge.pmd.cpd.internal.AntlrTokenizer;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrTokenManager;
|
||||
import net.sourceforge.pmd.lang.swift.ast.SwiftLexer;
|
||||
|
||||
/**
|
||||
* SwiftTokenizer
|
||||
|
@ -5,7 +5,7 @@
|
||||
package net.sourceforge.pmd.lang.swift;
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.swift.antlr4.SwiftBaseVisitor;
|
||||
import net.sourceforge.pmd.lang.swift.ast.SwiftBaseVisitor;
|
||||
|
||||
public abstract class AbstractSwiftRule<T> extends SwiftBaseVisitor<T> {
|
||||
public AbstractSwiftRule() {
|
||||
|
@ -8,7 +8,7 @@ import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.XPathHandler;
|
||||
import net.sourceforge.pmd.lang.antlr.AntlrRuleViolationFactory;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrRuleViolationFactory;
|
||||
import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler;
|
||||
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
package net.sourceforge.pmd.lang.swift;
|
||||
|
||||
import net.sourceforge.pmd.lang.BaseLanguageModule;
|
||||
import net.sourceforge.pmd.lang.antlr.AntlrRuleChainVisitor;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrRuleChainVisitor;
|
||||
|
||||
/**
|
||||
* Language Module for Swift
|
||||
|
@ -12,10 +12,10 @@ import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.antlr.AntlrBaseParser;
|
||||
import net.sourceforge.pmd.lang.ast.AntlrBaseNode;
|
||||
import net.sourceforge.pmd.lang.swift.antlr4.SwiftLexer;
|
||||
import net.sourceforge.pmd.lang.swift.antlr4.SwiftParser;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrBaseParser;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrBaseNode;
|
||||
import net.sourceforge.pmd.lang.swift.ast.SwiftLexer;
|
||||
import net.sourceforge.pmd.lang.swift.ast.SwiftParser;
|
||||
|
||||
/**
|
||||
* Adapter for the SwiftParser.
|
||||
|
@ -8,9 +8,9 @@ import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.swift.AbstractSwiftRule;
|
||||
import net.sourceforge.pmd.lang.swift.antlr4.SwiftParser;
|
||||
import net.sourceforge.pmd.lang.swift.antlr4.SwiftParser.FunctionHeadContext;
|
||||
import net.sourceforge.pmd.lang.swift.antlr4.SwiftParser.VariableDeclarationHeadContext;
|
||||
import net.sourceforge.pmd.lang.swift.ast.SwiftParser;
|
||||
import net.sourceforge.pmd.lang.swift.ast.SwiftParser.FunctionHeadContext;
|
||||
import net.sourceforge.pmd.lang.swift.ast.SwiftParser.VariableDeclarationHeadContext;
|
||||
|
||||
public class ProhibitedInterfaceBuilderRule extends AbstractSwiftRule<Void> {
|
||||
|
||||
@ -22,7 +22,7 @@ public class ProhibitedInterfaceBuilderRule extends AbstractSwiftRule<Void> {
|
||||
addRuleChainVisit(FunctionHeadContext.class);
|
||||
addRuleChainVisit(VariableDeclarationHeadContext.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Void visitFunctionHead(FunctionHeadContext ctx) {
|
||||
if (ctx == null || ctx.attributes() == null) {
|
||||
|
@ -7,9 +7,9 @@ package net.sourceforge.pmd.lang.swift.rule.bestpractices;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.swift.AbstractSwiftRule;
|
||||
import net.sourceforge.pmd.lang.swift.antlr4.SwiftParser;
|
||||
import net.sourceforge.pmd.lang.swift.antlr4.SwiftParser.FunctionDeclarationContext;
|
||||
import net.sourceforge.pmd.lang.swift.antlr4.SwiftParser.InitializerDeclarationContext;
|
||||
import net.sourceforge.pmd.lang.swift.ast.SwiftParser;
|
||||
import net.sourceforge.pmd.lang.swift.ast.SwiftParser.FunctionDeclarationContext;
|
||||
import net.sourceforge.pmd.lang.swift.ast.SwiftParser.InitializerDeclarationContext;
|
||||
|
||||
public class UnavailableFunctionRule extends AbstractSwiftRule<Void> {
|
||||
|
||||
|
Reference in New Issue
Block a user