forked from phoedos/pmd
Fix some details
This commit is contained in:
@ -32,7 +32,7 @@ public final class ASTApexFile extends AbstractApexNode<AstNode> implements Root
|
|||||||
Map<Integer, String> suppressMap,
|
Map<Integer, String> suppressMap,
|
||||||
@NonNull ApexLanguageProcessor apexLang) {
|
@NonNull ApexLanguageProcessor apexLang) {
|
||||||
super(jorjeNode);
|
super(jorjeNode);
|
||||||
this.astInfo = new AstInfo<>(task, this, suppressMap);
|
this.astInfo = new AstInfo<>(task, this).withSuppressMap(suppressMap);
|
||||||
this.multifileAnalysis = apexLang.getMultiFileState();
|
this.multifileAnalysis = apexLang.getMultiFileState();
|
||||||
this.setRegion(TextRegion.fromOffsetLength(0, task.getTextDocument().getLength()));
|
this.setRegion(TextRegion.fromOffsetLength(0, task.getTextDocument().getLength()));
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import java.util.List;
|
|||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import net.sourceforge.pmd.RuleSets;
|
import net.sourceforge.pmd.RuleSets;
|
||||||
|
import net.sourceforge.pmd.annotation.InternalApi;
|
||||||
import net.sourceforge.pmd.cache.AnalysisCache;
|
import net.sourceforge.pmd.cache.AnalysisCache;
|
||||||
import net.sourceforge.pmd.lang.document.TextFile;
|
import net.sourceforge.pmd.lang.document.TextFile;
|
||||||
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
|
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
|
||||||
@ -68,6 +69,11 @@ public interface LanguageProcessor extends AutoCloseable {
|
|||||||
private final LanguageProcessorRegistry lpRegistry;
|
private final LanguageProcessorRegistry lpRegistry;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new task. This constructor is internal and will be
|
||||||
|
* called by PMD.
|
||||||
|
*/
|
||||||
|
@InternalApi
|
||||||
public AnalysisTask(RuleSets rulesets,
|
public AnalysisTask(RuleSets rulesets,
|
||||||
List<TextFile> files,
|
List<TextFile> files,
|
||||||
GlobalAnalysisListener listener,
|
GlobalAnalysisListener listener,
|
||||||
|
@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -68,18 +69,29 @@ public final class LanguageRegistry implements Iterable<Language> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a language registry containing the given languages and
|
* Creates a language registry containing the given language and
|
||||||
* their dependencies, fetched from this language registry or the
|
* its dependencies, fetched from this language registry or the
|
||||||
* parameter.
|
* parameter.
|
||||||
|
*
|
||||||
|
* @throws IllegalStateException If dependencies cannot be fulfilled.
|
||||||
*/
|
*/
|
||||||
public LanguageRegistry getDependenciesOf(Language lang) {
|
public LanguageRegistry getDependenciesOf(Language lang) {
|
||||||
Set<Language> dependencies =
|
Set<Language> result = new HashSet<>();
|
||||||
lang.getDependencies().stream()
|
addDepsOrThrow(lang, result);
|
||||||
.map(this::getLanguageById)
|
return new LanguageRegistry(result);
|
||||||
.collect(CollectionUtil.toMutableSet());
|
}
|
||||||
dependencies.add(lang);
|
|
||||||
|
|
||||||
return new LanguageRegistry(dependencies);
|
private void addDepsOrThrow(Language l, Set<Language> languages) {
|
||||||
|
for (String depId : l.getDependencies()) {
|
||||||
|
Language dep = getLanguageById(depId);
|
||||||
|
if (dep == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Cannot find language " + depId + " in " + this);
|
||||||
|
}
|
||||||
|
if (languages.add(dep)) {
|
||||||
|
addDepsOrThrow(dep, languages);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,11 +30,7 @@ public final class AstInfo<T extends RootNode> {
|
|||||||
|
|
||||||
|
|
||||||
public AstInfo(ParserTask task, T rootNode) {
|
public AstInfo(ParserTask task, T rootNode) {
|
||||||
this(task, rootNode, Collections.emptyMap());
|
this(task.getTextDocument(), rootNode, task.getLpRegistry(), Collections.emptyMap());
|
||||||
}
|
|
||||||
|
|
||||||
public AstInfo(ParserTask task, T rootNode, Map<Integer, String> suppressionComments) {
|
|
||||||
this(task.getTextDocument(), rootNode, task.getLpRegistry(), suppressionComments);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AstInfo(TextDocument textDocument,
|
private AstInfo(TextDocument textDocument,
|
||||||
|
@ -21,7 +21,7 @@ public final class ASTHtmlDocument extends ASTHtmlElement implements RootNode {
|
|||||||
Parser.ParserTask task,
|
Parser.ParserTask task,
|
||||||
Map<Integer, String> suppressMap) {
|
Map<Integer, String> suppressMap) {
|
||||||
super(document);
|
super(document);
|
||||||
this.astInfo = new AstInfo<>(task, this, suppressMap);
|
this.astInfo = new AstInfo<>(task, this).withSuppressMap(suppressMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,7 +55,7 @@ public class JavaParser extends JjtreeParserAdapter<ASTCompilationUnit> {
|
|||||||
parser.setPreview(preview);
|
parser.setPreview(preview);
|
||||||
|
|
||||||
ASTCompilationUnit root = parser.CompilationUnit();
|
ASTCompilationUnit root = parser.CompilationUnit();
|
||||||
root.setAstInfo(new AstInfo<>(task, root, parser.getSuppressMap()));
|
root.setAstInfo(new AstInfo<>(task, root).withSuppressMap(parser.getSuppressMap()));
|
||||||
|
|
||||||
LanguageLevelChecker<?> levelChecker =
|
LanguageLevelChecker<?> levelChecker =
|
||||||
new LanguageLevelChecker<>(jdkVersion,
|
new LanguageLevelChecker<>(jdkVersion,
|
||||||
|
@ -70,7 +70,7 @@ public final class EcmascriptParser implements net.sourceforge.pmd.lang.ast.Pars
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tree.setAstInfo(new AstInfo<>(task, tree, suppressMap));
|
tree.setAstInfo(new AstInfo<>(task, tree).withSuppressMap(suppressMap));
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user