Skip to content

Commit 542cde4

Browse files
committed
Resolving more deprecations and warnings
1 parent 3c46cc8 commit 542cde4

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/BaseVisitor.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@
3636
import net.sourceforge.pmd.Report.ConfigurationError;
3737
import net.sourceforge.pmd.Report.ProcessingError;
3838
import net.sourceforge.pmd.Rule;
39-
import net.sourceforge.pmd.RuleContext;
4039
import net.sourceforge.pmd.RuleSet;
41-
import net.sourceforge.pmd.RuleSetFactory;
4240
import net.sourceforge.pmd.RuleSets;
4341
import net.sourceforge.pmd.RuleViolation;
4442
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
@@ -51,7 +49,6 @@
5149
import net.sourceforge.pmd.lang.LanguageVersion;
5250
import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
5351
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
54-
import net.sourceforge.pmd.processor.MonoThreadProcessor;
5552
import net.sourceforge.pmd.renderers.AbstractRenderer;
5653
import net.sourceforge.pmd.renderers.Renderer;
5754
import net.sourceforge.pmd.util.datasource.DataSource;
@@ -326,16 +323,12 @@ protected final void reviewResource(IResource resource) {
326323

327324
long start = System.currentTimeMillis();
328325

329-
RuleContext context = PMD.newRuleContext(file.getName(), sourceCodeFile);
330-
context.setLanguageVersion(languageVersion);
331-
332326
input = new InputStreamReader(file.getContents(), file.getCharset());
333327
// getPmdEngine().processFile(input, getRuleSet(), context);
334328
// getPmdEngine().processFile(sourceCodeFile, getRuleSet(),
335329
// context);
336330

337331
DataSource dataSource = new ReaderDataSource(input, file.getRawLocation().toFile().getPath());
338-
RuleSetFactory ruleSetFactory = InternalRuleSetUtil.createFactoryFromRuleSets(ruleSets);
339332
// need to disable multi threading, as the ruleset is
340333
// not recreated and shared between threads...
341334
// but as we anyway have only one file to process, it won't hurt
@@ -383,11 +376,7 @@ public String defaultFileExtension() {
383376
}
384377
};
385378

386-
// PMD.processFiles(configuration(), ruleSetFactory,
387-
// Arrays.asList(dataSource), context,
388-
// Arrays.asList(collectingRenderer));
389-
new MonoThreadProcessor(configuration()).processFiles(ruleSetFactory, Arrays.asList(dataSource),
390-
context, Arrays.asList(collectingRenderer));
379+
PMD.processFiles(configuration(), ruleSets, Arrays.asList(dataSource), Arrays.asList(collectingRenderer));
391380
LOG.debug("PMD run finished.");
392381

393382
pmdDuration += System.currentTimeMillis() - start;

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/actions/PMDGenerateASTAction.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.io.ByteArrayInputStream;
88
import java.io.ByteArrayOutputStream;
99
import java.io.IOException;
10+
import java.io.InputStreamReader;
11+
import java.io.Reader;
1012
import java.lang.reflect.InvocationTargetException;
1113
import java.util.Iterator;
1214

@@ -35,10 +37,13 @@
3537
import net.sourceforge.pmd.eclipse.runtime.writer.WriterException;
3638
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
3739
import net.sourceforge.pmd.eclipse.util.IOUtil;
38-
import net.sourceforge.pmd.lang.ast.JavaCharStream;
40+
import net.sourceforge.pmd.lang.Language;
41+
import net.sourceforge.pmd.lang.LanguageRegistry;
42+
import net.sourceforge.pmd.lang.LanguageVersionHandler;
43+
import net.sourceforge.pmd.lang.Parser;
44+
import net.sourceforge.pmd.lang.ast.ParseException;
45+
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
3946
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
40-
import net.sourceforge.pmd.lang.java.ast.JavaParser;
41-
import net.sourceforge.pmd.lang.java.ast.ParseException;
4247

4348
/**
4449
* Process PMDGenerateAST action menu. Generate a AST from the selected file.
@@ -55,6 +60,7 @@ public class PMDGenerateASTAction extends AbstractUIAction implements IRunnableW
5560
/**
5661
* @see org.eclipse.ui.IActionDelegate#run(IAction)
5762
*/
63+
@Override
5864
public void run(IAction action) {
5965
LOG.info("Generation AST action requested");
6066

@@ -94,6 +100,7 @@ public void run(IAction action) {
94100
/**
95101
* @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
96102
*/
103+
@Override
97104
public void selectionChanged(IAction action, ISelection selection) {
98105
}
99106

@@ -107,10 +114,11 @@ private void generateAST(IFile file) {
107114
LOG.info("Generating AST for file " + file.getName());
108115
ByteArrayOutputStream byteArrayOutputStream = null;
109116
ByteArrayInputStream astInputStream = null;
110-
try {
111-
JavaParser parser = new JavaParser(new JavaCharStream(file.getContents()));
112-
parser.setJdkVersion(Integer.MAX_VALUE);
113-
ASTCompilationUnit compilationUnit = parser.CompilationUnit();
117+
try (Reader reader = new InputStreamReader(file.getContents(), file.getCharset())) {
118+
Language javaLanguage = LanguageRegistry.getLanguage(JavaLanguageModule.NAME);
119+
LanguageVersionHandler languageVersionHandler = javaLanguage.getDefaultVersion().getLanguageVersionHandler();
120+
Parser parser = languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions());
121+
ASTCompilationUnit compilationUnit = (ASTCompilationUnit) parser.parse(file.getName(), reader);
114122
byteArrayOutputStream = new ByteArrayOutputStream();
115123
IAstWriter astWriter = PMDPlugin.getDefault().getAstWriter();
116124
astWriter.write(byteArrayOutputStream, compilationUnit);
@@ -158,13 +166,13 @@ private static String astNameFor(IFile file) {
158166

159167
String name = file.getName();
160168
int dotPosition = name.indexOf('.');
161-
String astName = name.substring(0, dotPosition) + ".ast";
162-
return astName;
169+
return name.substring(0, dotPosition) + ".ast";
163170
}
164171

165172
/**
166173
* @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
167174
*/
175+
@Override
168176
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
169177
monitor.beginTask("", structuredSelection.size());
170178
for (Iterator<?> i = structuredSelection.iterator(); i.hasNext();) {

0 commit comments

Comments
 (0)