use of net.sourceforge.pmd.lang.LanguageVersion in project pmd by pmd.
the class SourceCodeProcessor method processSource.
private void processSource(Reader sourceCode, RuleSets ruleSets, RuleContext ctx) {
LanguageVersion languageVersion = ctx.getLanguageVersion();
LanguageVersionHandler languageVersionHandler = languageVersion.getLanguageVersionHandler();
Parser parser = PMD.parserFor(languageVersion, configuration);
Node rootNode = parse(ctx, sourceCode, parser);
resolveQualifiedNames(rootNode, languageVersionHandler);
symbolFacade(rootNode, languageVersionHandler);
Language language = languageVersion.getLanguage();
usesDFA(languageVersion, rootNode, ruleSets, language);
usesTypeResolution(languageVersion, rootNode, ruleSets, language);
usesMultifile(rootNode, languageVersionHandler, ruleSets, language);
List<Node> acus = Collections.singletonList(rootNode);
ruleSets.apply(acus, ctx, language);
}
use of net.sourceforge.pmd.lang.LanguageVersion in project pmd by pmd.
the class PMDParameters method toConfiguration.
/**
* Converts these parameters into a configuration.
*
* @return A new PMDConfiguration corresponding to these parameters
*
* @throws IllegalArgumentException if the parameters are inconsistent or incomplete
*/
public PMDConfiguration toConfiguration() {
if (null == this.getSourceDir() && null == this.getUri() && null == this.getFileListPath()) {
throw new IllegalArgumentException("Please provide a parameter for source root directory (-dir or -d), database URI (-uri or -u), or file list path (-filelist).");
}
PMDConfiguration configuration = new PMDConfiguration();
configuration.setInputPaths(this.getSourceDir());
configuration.setInputFilePath(this.getFileListPath());
configuration.setInputUri(this.getUri());
configuration.setReportFormat(this.getFormat());
configuration.setBenchmark(this.isBenchmark());
configuration.setDebug(this.isDebug());
configuration.setMinimumPriority(this.getMinimumPriority());
configuration.setReportFile(this.getReportfile());
configuration.setReportProperties(this.getProperties());
configuration.setReportShortNames(this.isShortnames());
configuration.setRuleSets(this.getRulesets());
configuration.setRuleSetFactoryCompatibilityEnabled(!this.noRuleSetCompatibility);
configuration.setShowSuppressedViolations(this.isShowsuppressed());
configuration.setSourceEncoding(this.getEncoding());
configuration.setStressTest(this.isStress());
configuration.setSuppressMarker(this.getSuppressmarker());
configuration.setThreads(this.getThreads());
configuration.setFailOnViolation(this.isFailOnViolation());
configuration.setAnalysisCacheLocation(this.cacheLocation);
configuration.setIgnoreIncrementalAnalysis(this.isIgnoreIncrementalAnalysis());
LanguageVersion languageVersion = LanguageRegistry.findLanguageVersionByTerseName(this.getLanguage() + ' ' + this.getVersion());
if (languageVersion != null) {
configuration.getLanguageVersionDiscoverer().setDefaultLanguageVersion(languageVersion);
}
try {
configuration.prependClasspath(this.getAuxclasspath());
} catch (IOException e) {
throw new IllegalArgumentException("Invalid auxiliary classpath: " + e.getMessage(), e);
}
return configuration;
}
use of net.sourceforge.pmd.lang.LanguageVersion in project pmd by pmd.
the class Benchmarker method main.
/**
* @param args
* String[]
* @throws RuleSetNotFoundException
* @throws IOException
* @throws PMDException
*/
public static void main(String[] args) throws RuleSetNotFoundException, IOException, PMDException {
String targetjdk = findOptionalStringValue(args, "--targetjdk", "1.4");
Language language = LanguageRegistry.getLanguage("Java");
LanguageVersion languageVersion = language.getVersion(targetjdk);
if (languageVersion == null) {
languageVersion = language.getDefaultVersion();
}
String srcDir = findOptionalStringValue(args, "--source-directory", "/usr/local/java/src/java/lang/");
List<DataSource> dataSources = FileUtil.collectFiles(srcDir, new LanguageFilenameFilter(language));
boolean debug = findBooleanSwitch(args, "--debug");
boolean parseOnly = findBooleanSwitch(args, "--parse-only");
if (debug) {
System.out.println("Using " + language.getName() + " " + languageVersion.getVersion());
}
if (parseOnly) {
Parser parser = PMD.parserFor(languageVersion, null);
parseStress(parser, dataSources, debug);
} else {
String ruleset = findOptionalStringValue(args, "--ruleset", "");
if (debug) {
System.out.println("Checking directory " + srcDir);
}
Set<RuleDuration> results = new TreeSet<>();
RuleSetFactory factory = new RuleSetFactory();
if (StringUtils.isNotBlank(ruleset)) {
stress(languageVersion, factory.createRuleSet(ruleset), dataSources, results, debug);
} else {
Iterator<RuleSet> i = factory.getRegisteredRuleSets();
while (i.hasNext()) {
stress(languageVersion, i.next(), dataSources, results, debug);
}
}
TextReport report = new TextReport();
report.generate(results, System.err);
}
}
use of net.sourceforge.pmd.lang.LanguageVersion in project pmd by pmd.
the class LanguageVersionDiscovererTest method testPlsql.
/**
* Test on PLSQL file with default version
*/
@Test
public void testPlsql() {
LanguageVersionDiscoverer discoverer = new LanguageVersionDiscoverer();
File plsqlFile = new File("/path/to/MY_PACKAGE.sql");
LanguageVersion languageVersion = discoverer.getDefaultLanguageVersionForFile(plsqlFile);
assertEquals("LanguageVersion must be PLSQL!", LanguageRegistry.getLanguage(PLSQLLanguageModule.NAME).getDefaultVersion(), languageVersion);
}
use of net.sourceforge.pmd.lang.LanguageVersion in project pmd by pmd.
the class LanguageVersionDiscovererTest method testJavaFileUsingDefaults.
/**
* Test on Java file with default options.
*/
@Test
public void testJavaFileUsingDefaults() {
LanguageVersionDiscoverer discoverer = new LanguageVersionDiscoverer();
File javaFile = new File("/path/to/MyClass.java");
LanguageVersion languageVersion = discoverer.getDefaultLanguageVersionForFile(javaFile);
assertEquals("LanguageVersion must be Java 9 !", LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion("9"), languageVersion);
}
Aggregations