Merge branch 'master' into pr-2377

This commit is contained in:
Andreas Dangel
2020-04-16 17:52:03 +02:00
81 changed files with 3873 additions and 246 deletions

View File

@ -11,9 +11,7 @@ import net.sourceforge.pmd.lang.DataFlowHandler;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.VisitorStarter;
import net.sourceforge.pmd.lang.XPathHandler;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler;
import net.sourceforge.pmd.lang.dfa.DFAGraphRule;
import net.sourceforge.pmd.lang.plsql.ast.ASTInput;
import net.sourceforge.pmd.lang.plsql.ast.DumpFacade;
@ -83,11 +81,4 @@ public class PLSQLHandler extends AbstractLanguageVersionHandler {
};
}
/**
* Return minimal XPathHandler to cope with Jaxen XPath Rules.
*/
@Override
public XPathHandler getXPathHandler() {
return new DefaultASTXPathHandler();
}
}

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.plsql;
import java.util.Arrays;
import static java.util.Collections.singletonList;
import org.junit.Assert;
import org.junit.Test;
@ -13,21 +13,19 @@ import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.plsql.ast.ASTInput;
import net.sourceforge.pmd.lang.rule.XPathRule;
import net.sourceforge.pmd.lang.rule.xpath.XPathVersion;
/**
* Tests to use XPath rules with PLSQL.
*/
public class PLSQLXPathRuleTest extends AbstractPLSQLParserTst {
private ASTInput node = plsql.parse(
private final ASTInput node = plsql.parse(
"create or replace\n" + "package pkg_xpath_problem\n" + "AS\n" + " PROCEDURE pkg_minimal\n" + " IS\n"
+ " a_variable VARCHAR2(1);\n" + " BEGIN \n" + " --PRAGMA INLINE(output,'YES');\n"
+ " a_variable := 'Y' ;\n" + " END ;\n" + "end pkg_xpath_problem;\n" + "/\n" + "");
private RuleContext ctx = new RuleContext();
public PLSQLXPathRuleTest() {
ctx.setLanguageVersion(plsql.getDefaultVersion());
}
/**
@ -35,10 +33,7 @@ public class PLSQLXPathRuleTest extends AbstractPLSQLParserTst {
*/
@Test
public void testXPathRule1() {
XPathRule rule = createRule("1.0");
rule.apply(Arrays.asList(node), ctx);
Assert.assertEquals(2, ctx.getReport().treeSize());
testOnVersion(XPathVersion.XPATH_1_0);
}
/**
@ -46,10 +41,7 @@ public class PLSQLXPathRuleTest extends AbstractPLSQLParserTst {
*/
@Test
public void testXPathRule1Compatibility() {
XPathRule rule = createRule("1.0 compatibility");
rule.apply(Arrays.asList(node), ctx);
Assert.assertEquals(2, ctx.getReport().treeSize());
testOnVersion(XPathVersion.XPATH_1_0_COMPATIBILITY);
}
/**
@ -57,18 +49,21 @@ public class PLSQLXPathRuleTest extends AbstractPLSQLParserTst {
*/
@Test
public void testXPathRule2() {
XPathRule rule = createRule("2.0");
rule.apply(Arrays.asList(node), ctx);
Assert.assertEquals(2, ctx.getReport().treeSize());
testOnVersion(XPathVersion.XPATH_2_0);
}
private XPathRule createRule(String version) {
XPathRule rule = new XPathRule("//PrimaryPrefix");
private void testOnVersion(XPathVersion xpath10) {
XPathRule rule = new XPathRule(xpath10, "//PrimaryPrefix");
rule.setLanguage(LanguageRegistry.getLanguage(PLSQLLanguageModule.NAME));
rule.setVersion(version);
rule.setMessage("Test Violation");
return rule;
RuleContext ctx = new RuleContext();
ctx.setLanguageVersion(plsql.getDefaultVersion());
rule.apply(singletonList(node), ctx);
Assert.assertEquals(2, ctx.getReport().size());
}
}