Remove java processing stages
This also removes execution of old symbol table code.
This commit is contained in:
6 files changed
+29
-95
No files matched your search
@@ -48,19 +48,25 @@ public interface Parser {
|
||||
private final String filepath;
|
||||
private final String sourceText;
|
||||
private final SemanticErrorReporter reporter;
|
||||
private final ClassLoader auxclasspathClassLoader;
|
||||
|
||||
private final PropertySource propertySource;
|
||||
|
||||
public ParserTask(LanguageVersion lv, String filepath, String sourceText, SemanticErrorReporter reporter) {
|
||||
public ParserTask(LanguageVersion lv, String filepath, String sourceText, SemanticErrorReporter reporter, ClassLoader auxclasspathClassLoader) {
|
||||
this.lv = Objects.requireNonNull(lv, "lv was null");
|
||||
this.filepath = Objects.requireNonNull(filepath, "filepath was null");
|
||||
this.sourceText = Objects.requireNonNull(sourceText, "sourceText was null");
|
||||
this.reporter = Objects.requireNonNull(reporter, "reporter was null");
|
||||
this.auxclasspathClassLoader = Objects.requireNonNull(auxclasspathClassLoader);
|
||||
|
||||
this.propertySource = new ParserTaskProperties();
|
||||
propertySource.definePropertyDescriptor(COMMENT_MARKER);
|
||||
}
|
||||
|
||||
public ParserTask(LanguageVersion lv, String filepath, String sourceText, SemanticErrorReporter reporter) {
|
||||
this(lv, filepath, sourceText, reporter, Parser.class.getClassLoader());
|
||||
}
|
||||
|
||||
public static final PropertyDescriptor<String> COMMENT_MARKER =
|
||||
PropertyFactory.stringProperty("suppressionCommentMarker")
|
||||
.desc("deprecated! NOPMD")
|
||||
@@ -72,6 +78,10 @@ public interface Parser {
|
||||
return propertySource;
|
||||
}
|
||||
|
||||
@Deprecated // transitional until language properties are implemented
|
||||
public ClassLoader getAuxclasspathClassLoader() {
|
||||
return auxclasspathClassLoader;
|
||||
}
|
||||
|
||||
public LanguageVersion getLanguageVersion() {
|
||||
return lv;
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.sourceforge.pmd.lang.ast.impl.javacc.JavaCharStream;
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument;
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter;
|
||||
import net.sourceforge.pmd.lang.java.ast.internal.LanguageLevelChecker;
|
||||
import net.sourceforge.pmd.lang.java.internal.JavaAstProcessor;
|
||||
|
||||
/**
|
||||
* Adapter for the JavaParser, using the specified grammar version.
|
||||
@@ -44,9 +45,15 @@ public class JavaParser extends JjtreeParserAdapter<ASTCompilationUnit> {
|
||||
parser.setJdkVersion(checker.getJdkVersion());
|
||||
parser.setPreview(checker.isPreviewEnabled());
|
||||
|
||||
ASTCompilationUnit acu = parser.CompilationUnit();
|
||||
acu.setAstInfo(new AstInfo<>(task, acu, parser.getSuppressMap()));
|
||||
checker.check(acu);
|
||||
return acu;
|
||||
ASTCompilationUnit root = parser.CompilationUnit();
|
||||
root.setAstInfo(new AstInfo<>(task, root, parser.getSuppressMap()));
|
||||
checker.check(root);
|
||||
|
||||
JavaAstProcessor processor = JavaAstProcessor.create(task.getAuxclasspathClassLoader(),
|
||||
task.getLanguageVersion(),
|
||||
task.getReporter());
|
||||
processor.process(root);
|
||||
|
||||
return root;
|
||||
}
|
||||
}
|
||||
@@ -186,6 +186,13 @@ public final class JavaAstProcessor {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static JavaAstProcessor create(ClassLoader classLoader,
|
||||
LanguageVersion languageVersion,
|
||||
SemanticErrorReporter logger) {
|
||||
return create(classLoader, languageVersion, logger, defaultTypeInfLogger());
|
||||
}
|
||||
|
||||
public static JavaAstProcessor create(TypeSystem typeSystem,
|
||||
LanguageVersion languageVersion,
|
||||
SemanticErrorReporter semanticLogger,
|
||||
|
||||
@@ -50,7 +50,6 @@ public class JavaLanguageHandler extends AbstractPmdLanguageVersionHandler {
|
||||
}
|
||||
|
||||
public JavaLanguageHandler(int jdkVersion, boolean preview) {
|
||||
super(JavaProcessingStage.class);
|
||||
this.levelChecker = new LanguageLevelChecker<>(jdkVersion, preview, ReportingStrategy.reporterThatThrows());
|
||||
}
|
||||
|
||||
|
||||
-79
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.java.internal;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.annotation.Experimental;
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.ast.AstAnalysisContext;
|
||||
import net.sourceforge.pmd.lang.ast.AstProcessingStage;
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.JavaParser;
|
||||
import net.sourceforge.pmd.lang.java.ast.internal.LanguageLevelChecker;
|
||||
import net.sourceforge.pmd.lang.java.symboltable.SymbolFacade;
|
||||
|
||||
|
||||
/**
|
||||
* Java processing stages.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
* @since 7.0.0
|
||||
*/
|
||||
@Experimental
|
||||
public enum JavaProcessingStage implements AstProcessingStage<JavaProcessingStage> {
|
||||
|
||||
/**
|
||||
* This acts as a merged stage, non-optional. Ideally this would be encapsulated
|
||||
* in the {@link JavaParser}, like the {@link LanguageLevelChecker}.
|
||||
*/
|
||||
JAVA_PROCESSING("Java processing") {
|
||||
@Override
|
||||
public void processAST(RootNode rootNode, AstAnalysisContext configuration) {
|
||||
JavaAstProcessor.create(configuration.getTypeResolutionClassLoader(), configuration.getLanguageVersion(), JavaAstProcessor.defaultLogger(), JavaAstProcessor.defaultTypeInfLogger())
|
||||
.process((ASTCompilationUnit) rootNode);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Symbol table analysis.
|
||||
*/
|
||||
SYMBOL_RESOLUTION("Symbol table") {
|
||||
@Override
|
||||
public void processAST(RootNode rootNode, AstAnalysisContext configuration) {
|
||||
// kept for compatibility with existing tests
|
||||
new SymbolFacade().initializeWith(configuration.getTypeResolutionClassLoader(), (ASTCompilationUnit) rootNode);
|
||||
}
|
||||
};
|
||||
|
||||
private final String displayName;
|
||||
private final List<JavaProcessingStage> dependencies;
|
||||
|
||||
JavaProcessingStage(String displayName, JavaProcessingStage... dependencies) {
|
||||
this.displayName = displayName;
|
||||
this.dependencies = Collections.unmodifiableList(Arrays.asList(dependencies));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JavaProcessingStage> getDependencies() {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final Language getLanguage() {
|
||||
return LanguageRegistry.findLanguageByTerseName("java");
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,11 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.ast.AstProcessingStage;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.JavaParserVisitor;
|
||||
import net.sourceforge.pmd.lang.java.internal.JavaProcessingStage;
|
||||
import net.sourceforge.pmd.lang.rule.AbstractRule;
|
||||
|
||||
|
||||
@@ -52,12 +50,4 @@ public abstract class AbstractJavaRule extends AbstractRule implements JavaParse
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dependsOn(AstProcessingStage<?> stage) {
|
||||
if (!(stage instanceof JavaProcessingStage)) {
|
||||
throw new IllegalArgumentException("Processing stage wasn't a Java one: " + stage);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user