use of net.sourceforge.pmd.lang.ParserOptions in project pmd by pmd.
the class JavaRuleViolationTest method parse.
private ASTCompilationUnit parse(final String code) {
final LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getDefaultVersion().getLanguageVersionHandler();
final ParserOptions options = languageVersionHandler.getDefaultParserOptions();
final ASTCompilationUnit ast = (ASTCompilationUnit) languageVersionHandler.getParser(options).parse(null, new StringReader(code));
// set scope of AST nodes
ast.jjtAccept(new ScopeAndDeclarationFinder(), null);
return ast;
}
use of net.sourceforge.pmd.lang.ParserOptions in project pmd by pmd.
the class StdCyclomaticComplexityRuleTest method entryStackMustBeEmpty.
/**
* Make sure the entry stack is empty, if show classes complexity is
* disabled.
*
* @see <a href="https://sourceforge.net/p/pmd/bugs/1501/">bug #1501</a>
*/
@Test
public void entryStackMustBeEmpty() {
StdCyclomaticComplexityRule rule = new StdCyclomaticComplexityRule();
rule.setProperty(StdCyclomaticComplexityRule.SHOW_CLASSES_COMPLEXITY_DESCRIPTOR, Boolean.FALSE);
RuleContext ctx = new RuleContext();
LanguageVersion javaLanguageVersion = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion("1.8");
ParserOptions parserOptions = javaLanguageVersion.getLanguageVersionHandler().getDefaultParserOptions();
Parser parser = javaLanguageVersion.getLanguageVersionHandler().getParser(parserOptions);
Node node = parser.parse("test", new StringReader("public class SampleClass {}"));
rule.apply(Arrays.asList(node), ctx);
Assert.assertTrue(rule.entryStack.isEmpty());
}
use of net.sourceforge.pmd.lang.ParserOptions in project pmd by pmd.
the class StdCyclomaticComplexityRuleTest method entryStackMustBeEmpty.
/**
* Make sure the entry stack is empty, if show classes complexity is
* disabled.
*
* @see <a href="https://sourceforge.net/p/pmd/bugs/1501/">bug #1501</a>
*/
@Test
public void entryStackMustBeEmpty() {
StdCyclomaticComplexityRule rule = new StdCyclomaticComplexityRule();
rule.setProperty(StdCyclomaticComplexityRule.SHOW_CLASSES_COMPLEXITY_DESCRIPTOR, Boolean.FALSE);
RuleContext ctx = new RuleContext();
LanguageVersion javaLanguageVersion = LanguageRegistry.getLanguage(ApexLanguageModule.NAME).getDefaultVersion();
ParserOptions parserOptions = javaLanguageVersion.getLanguageVersionHandler().getDefaultParserOptions();
Parser parser = javaLanguageVersion.getLanguageVersionHandler().getParser(parserOptions);
Node node = parser.parse("test", new StringReader("public class SampleClass {}"));
rule.apply(Arrays.asList(node), ctx);
Assert.assertTrue(rule.entryStack.isEmpty());
}
use of net.sourceforge.pmd.lang.ParserOptions in project controller by opendaylight.
the class AbstractGeneratedObjectTest method parse.
protected Node parse(File dstFile) throws IOException {
assertNotNull(dstFile);
LOG.debug(Files.toString(dstFile, StandardCharsets.UTF_8));
Parser parser = new Java17Parser(new ParserOptions());
return parser.parse(dstFile.toString(), new FileReader(dstFile));
}
use of net.sourceforge.pmd.lang.ParserOptions in project pmd by pmd.
the class EcmascriptParserOptionsTest method testEqualsHashcode.
@Test
public void testEqualsHashcode() throws Exception {
BooleanProperty[] properties = { EcmascriptParserOptions.RECORDING_COMMENTS_DESCRIPTOR, EcmascriptParserOptions.RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR };
for (int i = 0; i < properties.length; i++) {
BooleanProperty property = properties[i];
MyRule rule = new MyRule();
rule.setProperty(property, true);
ParserOptions options1 = rule.getParserOptions();
rule.setProperty(property, false);
ParserOptions options2 = rule.getParserOptions();
rule.setProperty(property, true);
ParserOptions options3 = rule.getParserOptions();
rule.setProperty(property, false);
ParserOptions options4 = rule.getParserOptions();
verifyOptionsEqualsHashcode(options1, options2, options3, options4);
}
EcmascriptParserOptions options1 = new EcmascriptParserOptions();
options1.setSuppressMarker("foo");
EcmascriptParserOptions options2 = new EcmascriptParserOptions();
options2.setSuppressMarker("bar");
EcmascriptParserOptions options3 = new EcmascriptParserOptions();
options3.setSuppressMarker("foo");
EcmascriptParserOptions options4 = new EcmascriptParserOptions();
options4.setSuppressMarker("bar");
verifyOptionsEqualsHashcode(options1, options2, options3, options4);
options1 = new EcmascriptParserOptions();
options1.setRhinoLanguageVersion(EcmascriptParserOptions.Version.VERSION_DEFAULT);
options2 = new EcmascriptParserOptions();
options2.setRhinoLanguageVersion(EcmascriptParserOptions.Version.VERSION_1_8);
options3 = new EcmascriptParserOptions();
options3.setRhinoLanguageVersion(EcmascriptParserOptions.Version.VERSION_DEFAULT);
options4 = new EcmascriptParserOptions();
options4.setRhinoLanguageVersion(EcmascriptParserOptions.Version.VERSION_1_8);
verifyOptionsEqualsHashcode(options1, options2, options3, options4);
}
Aggregations