forked from phoedos/pmd
Rename PathId -> FileId
This commit is contained in:
@ -13,7 +13,7 @@ import org.antlr.runtime.Token;
|
||||
|
||||
import net.sourceforge.pmd.lang.apex.ApexJorjeLogging;
|
||||
import net.sourceforge.pmd.lang.ast.TokenMgrError;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
|
||||
import apex.jorje.parser.impl.ApexLexer;
|
||||
|
||||
@ -43,7 +43,7 @@ public class ApexTokenizer implements Tokenizer {
|
||||
ApexLexer lexer = new ApexLexer(ass) {
|
||||
@Override
|
||||
public void emitErrorMessage(String msg) {
|
||||
throw new TokenMgrError(getLine(), getCharPositionInLine(), PathId.fromPathLikeString(getSourceName()), msg, null);
|
||||
throw new TokenMgrError(getLine(), getCharPositionInLine(), FileId.fromPathLikeString(getSourceName()), msg, null);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -18,7 +18,7 @@ import java.util.function.Predicate;
|
||||
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
|
||||
import net.sourceforge.pmd.annotation.Experimental;
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
import net.sourceforge.pmd.renderers.AbstractAccumulatingRenderer;
|
||||
import net.sourceforge.pmd.reporting.FileAnalysisListener;
|
||||
@ -103,7 +103,7 @@ public final class Report {
|
||||
public static class ProcessingError {
|
||||
|
||||
private final Throwable error;
|
||||
private final PathId file;
|
||||
private final FileId file;
|
||||
|
||||
/**
|
||||
* Creates a new processing error
|
||||
@ -113,7 +113,7 @@ public final class Report {
|
||||
* @param file
|
||||
* the file during which the error occurred
|
||||
*/
|
||||
public ProcessingError(Throwable error, PathId file) {
|
||||
public ProcessingError(Throwable error, FileId file) {
|
||||
this.error = error;
|
||||
this.file = file;
|
||||
}
|
||||
@ -133,7 +133,7 @@ public final class Report {
|
||||
}
|
||||
}
|
||||
|
||||
public PathId getFileId() {
|
||||
public FileId getFileId() {
|
||||
return file;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.cache.ChecksumAware;
|
||||
import net.sourceforge.pmd.internal.util.PredicateUtil;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
import net.sourceforge.pmd.lang.rule.RuleReference;
|
||||
import net.sourceforge.pmd.lang.rule.XPathRule;
|
||||
@ -610,7 +610,7 @@ public class RuleSet implements ChecksumAware {
|
||||
*/
|
||||
// TODO get rid of this overload
|
||||
@InternalApi
|
||||
public boolean applies(PathId qualFileName) {
|
||||
public boolean applies(FileId qualFileName) {
|
||||
return filter.test(qualFileName.toAbsolutePath());
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
|
||||
import net.sourceforge.pmd.lang.document.FileLocation;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
|
||||
/**
|
||||
* A RuleViolation is created by a Rule when it identifies a violation of the
|
||||
@ -83,7 +83,7 @@ public interface RuleViolation {
|
||||
/**
|
||||
* Return the ID of the file where the violation was found.
|
||||
*/
|
||||
default PathId getFileId() {
|
||||
default FileId getFileId() {
|
||||
return getLocation().getFileId();
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ import net.sourceforge.pmd.benchmark.TimedOperation;
|
||||
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
|
||||
import net.sourceforge.pmd.cache.internal.ClasspathFingerprinter;
|
||||
import net.sourceforge.pmd.internal.util.IOUtil;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.TextDocument;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
import net.sourceforge.pmd.reporting.FileAnalysisListener;
|
||||
@ -52,8 +52,8 @@ public abstract class AbstractAnalysisCache implements AnalysisCache {
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(AbstractAnalysisCache.class);
|
||||
protected static final ClasspathFingerprinter FINGERPRINTER = new ClasspathFingerprinter();
|
||||
protected final String pmdVersion;
|
||||
protected final ConcurrentMap<PathId, AnalysisResult> fileResultsCache = new ConcurrentHashMap<>();
|
||||
protected final ConcurrentMap<PathId, AnalysisResult> updatedResultsCache = new ConcurrentHashMap<>();
|
||||
protected final ConcurrentMap<FileId, AnalysisResult> fileResultsCache = new ConcurrentHashMap<>();
|
||||
protected final ConcurrentMap<FileId, AnalysisResult> updatedResultsCache = new ConcurrentHashMap<>();
|
||||
protected final CachedRuleMapper ruleMapper = new CachedRuleMapper();
|
||||
protected long rulesetChecksum;
|
||||
protected long auxClassPathChecksum;
|
||||
@ -218,7 +218,7 @@ public abstract class AbstractAnalysisCache implements AnalysisCache {
|
||||
|
||||
@Override
|
||||
public FileAnalysisListener startFileAnalysis(TextDocument file) {
|
||||
final PathId fileName = file.getPathId();
|
||||
final FileId fileName = file.getPathId();
|
||||
|
||||
return new FileAnalysisListener() {
|
||||
@Override
|
||||
|
@ -17,8 +17,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.FileLocation;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.TextRange2d;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
@ -42,13 +42,13 @@ public final class CachedRuleViolation implements RuleViolation {
|
||||
private final FileLocation location;
|
||||
|
||||
private CachedRuleViolation(final CachedRuleMapper mapper, final String description,
|
||||
final PathId filePathId, final String ruleClassName, final String ruleName,
|
||||
final FileId fileFileId, final String ruleClassName, final String ruleName,
|
||||
final String ruleTargetLanguage, final int beginLine, final int beginColumn,
|
||||
final int endLine, final int endColumn,
|
||||
final Map<String, String> additionalInfo) {
|
||||
this.mapper = mapper;
|
||||
this.description = description;
|
||||
this.location = FileLocation.range(filePathId, TextRange2d.range2d(beginLine, beginColumn, endLine, endColumn));
|
||||
this.location = FileLocation.range(fileFileId, TextRange2d.range2d(beginLine, beginColumn, endLine, endColumn));
|
||||
this.ruleClassName = ruleClassName;
|
||||
this.ruleName = ruleName;
|
||||
this.ruleTargetLanguage = ruleTargetLanguage;
|
||||
@ -80,7 +80,7 @@ public final class CachedRuleViolation implements RuleViolation {
|
||||
* Helper method to load a {@link CachedRuleViolation} from an input stream.
|
||||
*
|
||||
* @param stream The stream from which to load the violation.
|
||||
* @param filePathId The name of the file on which this rule was reported.
|
||||
* @param fileFileId The name of the file on which this rule was reported.
|
||||
* @param mapper The mapper to be used to obtain rule instances from the active rulesets.
|
||||
*
|
||||
* @return The loaded rule violation.
|
||||
@ -88,7 +88,7 @@ public final class CachedRuleViolation implements RuleViolation {
|
||||
/* package */
|
||||
static CachedRuleViolation loadFromStream(
|
||||
DataInputStream stream,
|
||||
PathId filePathId, CachedRuleMapper mapper) throws IOException {
|
||||
FileId fileFileId, CachedRuleMapper mapper) throws IOException {
|
||||
|
||||
String description = stream.readUTF();
|
||||
String ruleClassName = stream.readUTF();
|
||||
@ -99,7 +99,7 @@ public final class CachedRuleViolation implements RuleViolation {
|
||||
int endLine = stream.readInt();
|
||||
int endColumn = stream.readInt();
|
||||
Map<String, String> additionalInfo = readAdditionalInfo(stream);
|
||||
return new CachedRuleViolation(mapper, description, filePathId, ruleClassName, ruleName, ruleTargetLanguage,
|
||||
return new CachedRuleViolation(mapper, description, fileFileId, ruleClassName, ruleName, ruleTargetLanguage,
|
||||
beginLine, beginColumn, endLine, endColumn, additionalInfo);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.benchmark.TimeTracker;
|
||||
import net.sourceforge.pmd.benchmark.TimedOperation;
|
||||
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
|
||||
/**
|
||||
@ -61,9 +61,9 @@ public class FileAnalysisCache extends AbstractAnalysisCache {
|
||||
* @param cacheFile The file which backs the file analysis cache.
|
||||
*/
|
||||
private void loadFromFile(final File cacheFile, Set<TextFile> files) {
|
||||
Map<String, PathId> idMap =
|
||||
Map<String, FileId> idMap =
|
||||
files.stream().map(TextFile::getPathId)
|
||||
.collect(Collectors.toMap(PathId::toUriString, id -> id));
|
||||
.collect(Collectors.toMap(FileId::toUriString, id -> id));
|
||||
|
||||
try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.ANALYSIS_CACHE, "load")) {
|
||||
if (cacheExists()) {
|
||||
@ -84,21 +84,21 @@ public class FileAnalysisCache extends AbstractAnalysisCache {
|
||||
// Cached results
|
||||
while (inputStream.available() > 0) {
|
||||
final String filePathId = inputStream.readUTF();
|
||||
PathId pathId = idMap.get(filePathId);
|
||||
if (pathId == null) {
|
||||
FileId fileId = idMap.get(filePathId);
|
||||
if (fileId == null) {
|
||||
LOG.debug("File {} is in the cache but is not part of the analysis",
|
||||
filePathId);
|
||||
pathId = PathId.fromPathLikeString(filePathId);
|
||||
fileId = FileId.fromPathLikeString(filePathId);
|
||||
}
|
||||
final long checksum = inputStream.readLong();
|
||||
|
||||
final int countViolations = inputStream.readInt();
|
||||
final List<RuleViolation> violations = new ArrayList<>(countViolations);
|
||||
for (int i = 0; i < countViolations; i++) {
|
||||
violations.add(CachedRuleViolation.loadFromStream(inputStream, pathId, ruleMapper));
|
||||
violations.add(CachedRuleViolation.loadFromStream(inputStream, fileId, ruleMapper));
|
||||
}
|
||||
|
||||
fileResultsCache.put(pathId, new AnalysisResult(checksum, violations));
|
||||
fileResultsCache.put(fileId, new AnalysisResult(checksum, violations));
|
||||
}
|
||||
|
||||
LOG.debug("Analysis cache loaded from {}", cacheFile);
|
||||
@ -144,7 +144,7 @@ public class FileAnalysisCache extends AbstractAnalysisCache {
|
||||
outputStream.writeLong(auxClassPathChecksum);
|
||||
outputStream.writeLong(executionClassPathChecksum);
|
||||
|
||||
for (final Map.Entry<PathId, AnalysisResult> resultEntry : updatedResultsCache.entrySet()) {
|
||||
for (final Map.Entry<FileId, AnalysisResult> resultEntry : updatedResultsCache.entrySet()) {
|
||||
final List<RuleViolation> violations = resultEntry.getValue().getViolations();
|
||||
|
||||
outputStream.writeUTF(resultEntry.getKey().toUriString()); // the path id
|
||||
|
@ -17,7 +17,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.sourceforge.pmd.PMDConfiguration;
|
||||
import net.sourceforge.pmd.lang.document.FileCollector;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.util.database.DBMSMetadata;
|
||||
import net.sourceforge.pmd.util.database.DBURI;
|
||||
import net.sourceforge.pmd.util.database.SourceObject;
|
||||
@ -127,7 +127,7 @@ public final class FileCollectionUtil {
|
||||
|
||||
try (Reader sourceCode = dbmsMetadata.getSourceCode(sourceObject)) {
|
||||
String source = IOUtil.readToString(sourceCode);
|
||||
collector.addSourceFile(PathId.fromPathLikeString(falseFilePath), source);
|
||||
collector.addSourceFile(FileId.fromPathLikeString(falseFilePath), source);
|
||||
} catch (SQLException ex) {
|
||||
collector.getReporter().warnEx("Cannot get SourceCode for {} - skipping ...",
|
||||
new Object[] { falseFilePath },
|
||||
|
@ -10,8 +10,8 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.FileLocation;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
|
||||
/**
|
||||
* An exception that occurs while processing a file. Subtypes include
|
||||
@ -24,7 +24,7 @@ import net.sourceforge.pmd.lang.document.PathId;
|
||||
*/
|
||||
public class FileAnalysisException extends RuntimeException {
|
||||
|
||||
private PathId fileId = PathId.UNKNOWN;
|
||||
private FileId fileId = FileId.UNKNOWN;
|
||||
|
||||
public FileAnalysisException() {
|
||||
super();
|
||||
@ -42,19 +42,19 @@ public class FileAnalysisException extends RuntimeException {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public FileAnalysisException setFileId(PathId fileId) {
|
||||
public FileAnalysisException setFileId(FileId fileId) {
|
||||
this.fileId = Objects.requireNonNull(fileId);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected boolean hasFileName() {
|
||||
return !PathId.UNKNOWN.equals(fileId);
|
||||
return !FileId.UNKNOWN.equals(fileId);
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the file in which the error occurred.
|
||||
*/
|
||||
public @NonNull PathId getFileId() {
|
||||
public @NonNull FileId getFileId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ public class FileAnalysisException extends RuntimeException {
|
||||
*
|
||||
* @return An exception
|
||||
*/
|
||||
public static FileAnalysisException wrap(@NonNull PathId filename, @NonNull String message, @NonNull Throwable cause) {
|
||||
public static FileAnalysisException wrap(@NonNull FileId filename, @NonNull String message, @NonNull Throwable cause) {
|
||||
if (cause instanceof FileAnalysisException) {
|
||||
return ((FileAnalysisException) cause).setFileId(filename);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.document.FileLocation;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
/**
|
||||
@ -29,7 +29,7 @@ public final class TokenMgrError extends FileAnalysisException {
|
||||
* @param message Message of the error
|
||||
* @param cause Cause of the error, if any
|
||||
*/
|
||||
public TokenMgrError(int line, int column, @Nullable PathId filename, String message, @Nullable Throwable cause) {
|
||||
public TokenMgrError(int line, int column, @Nullable FileId filename, String message, @Nullable Throwable cause) {
|
||||
super(message, cause);
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
@ -74,7 +74,7 @@ public final class TokenMgrError extends FileAnalysisException {
|
||||
* @return A new exception
|
||||
*/
|
||||
@Override
|
||||
public TokenMgrError setFileId(PathId fileId) {
|
||||
public TokenMgrError setFileId(FileId fileId) {
|
||||
super.setFileId(fileId);
|
||||
return this;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ abstract class BaseMappedDocument implements TextDocument {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathId getPathId() {
|
||||
public FileId getPathId() {
|
||||
return base.getPathId();
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public final class CpdCompat {
|
||||
public static TextFile cpdCompat(SourceCode sourceCode) {
|
||||
return TextFile.forCharSeq(
|
||||
sourceCode.getCodeBuffer(),
|
||||
PathId.fromPathLikeString(sourceCode.getFileName()),
|
||||
FileId.fromPathLikeString(sourceCode.getFileName()),
|
||||
dummyVersion()
|
||||
);
|
||||
}
|
||||
|
@ -64,13 +64,13 @@ public final class FileCollector implements AutoCloseable {
|
||||
private Charset charset = StandardCharsets.UTF_8;
|
||||
private final LanguageVersionDiscoverer discoverer;
|
||||
private final MessageReporter reporter;
|
||||
private final PathId outerFsPath;
|
||||
private final FileId outerFsPath;
|
||||
private final List<Path> relativizeRootPaths = new ArrayList<>();
|
||||
private boolean closed;
|
||||
|
||||
// construction
|
||||
|
||||
private FileCollector(LanguageVersionDiscoverer discoverer, MessageReporter reporter, PathId outerFsPath) {
|
||||
private FileCollector(LanguageVersionDiscoverer discoverer, MessageReporter reporter, FileId outerFsPath) {
|
||||
this.discoverer = discoverer;
|
||||
this.reporter = reporter;
|
||||
this.outerFsPath = outerFsPath;
|
||||
@ -201,13 +201,13 @@ public final class FileCollector implements AutoCloseable {
|
||||
*
|
||||
* @return True if the file has been added
|
||||
*/
|
||||
public boolean addSourceFile(PathId pathId, String sourceContents) {
|
||||
public boolean addSourceFile(FileId fileId, String sourceContents) {
|
||||
AssertionUtil.requireParamNotNull("sourceContents", sourceContents);
|
||||
AssertionUtil.requireParamNotNull("pathId", pathId);
|
||||
AssertionUtil.requireParamNotNull("pathId", fileId);
|
||||
|
||||
LanguageVersion version = discoverLanguage(pathId.getFileName());
|
||||
LanguageVersion version = discoverLanguage(fileId.getFileName());
|
||||
return version != null
|
||||
&& addFileImpl(TextFile.builderForCharSeq(sourceContents, pathId, version)
|
||||
&& addFileImpl(TextFile.builderForCharSeq(sourceContents, fileId, version)
|
||||
.setParentFsPath(outerFsPath)
|
||||
.build());
|
||||
}
|
||||
@ -265,7 +265,7 @@ public final class FileCollector implements AutoCloseable {
|
||||
*
|
||||
* <p>package private for test only</p>
|
||||
*/
|
||||
static String getDisplayName(PathId file, List<Path> relativizeRoots) {
|
||||
static String getDisplayName(FileId file, List<Path> relativizeRoots) {
|
||||
String best = file.toAbsolutePath();
|
||||
for (Path root : relativizeRoots) {
|
||||
if (isFileSystemRoot(root)) {
|
||||
@ -432,7 +432,7 @@ public final class FileCollector implements AutoCloseable {
|
||||
/** A collector that prefixes the display name of the files it will contain with the path of the zip. */
|
||||
@Experimental
|
||||
private FileCollector newZipCollector(Path zipFilePath) {
|
||||
return new FileCollector(discoverer, reporter, PathId.forPath(zipFilePath));
|
||||
return new FileCollector(discoverer, reporter, FileId.forPath(zipFilePath));
|
||||
}
|
||||
|
||||
// configuration
|
||||
@ -469,15 +469,15 @@ public final class FileCollector implements AutoCloseable {
|
||||
private final List<Path> relativizeRootPaths = new ArrayList<>(FileCollector.this.relativizeRootPaths);
|
||||
|
||||
@Override
|
||||
public String getDisplayName(PathId pathId) {
|
||||
String localDisplayName = getLocalDisplayName(pathId);
|
||||
if (pathId.getParentFsPath() != null) {
|
||||
return getDisplayName(pathId.getParentFsPath()) + "!" + localDisplayName;
|
||||
public String getDisplayName(FileId fileId) {
|
||||
String localDisplayName = getLocalDisplayName(fileId);
|
||||
if (fileId.getParentFsPath() != null) {
|
||||
return getDisplayName(fileId.getParentFsPath()) + "!" + localDisplayName;
|
||||
}
|
||||
return localDisplayName;
|
||||
}
|
||||
|
||||
private String getLocalDisplayName(PathId file) {
|
||||
private String getLocalDisplayName(FileId file) {
|
||||
if (!relativizeRootPaths.isEmpty()) {
|
||||
return FileCollector.getDisplayName(file, relativizeRootPaths);
|
||||
}
|
||||
|
@ -14,15 +14,15 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public interface PathId extends Comparable<PathId> {
|
||||
public interface FileId extends Comparable<FileId> {
|
||||
|
||||
/**
|
||||
* The name used for a file that has no name. This is mostly only
|
||||
* relevant for unit tests.
|
||||
*/
|
||||
PathId UNKNOWN = fromPathLikeString("(unknown file)");
|
||||
FileId UNKNOWN = fromPathLikeString("(unknown file)");
|
||||
|
||||
@Nullable PathId getParentFsPath();
|
||||
@Nullable FileId getParentFsPath();
|
||||
|
||||
String toUriString();
|
||||
|
||||
@ -38,11 +38,11 @@ public interface PathId extends Comparable<PathId> {
|
||||
|
||||
|
||||
@Override
|
||||
default int compareTo(PathId o) {
|
||||
default int compareTo(FileId o) {
|
||||
return this.toUriString().compareTo(o.toUriString());
|
||||
}
|
||||
|
||||
PathId STDIN = new PathId() {
|
||||
FileId STDIN = new FileId() {
|
||||
@Override
|
||||
public String toAbsolutePath() {
|
||||
return "stdin";
|
||||
@ -64,18 +64,18 @@ public interface PathId extends Comparable<PathId> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PathId getParentFsPath() {
|
||||
public @Nullable FileId getParentFsPath() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
static PathId fromPathLikeString(String str) {
|
||||
static FileId fromPathLikeString(String str) {
|
||||
String[] segments = str.split("[/\\\\]");
|
||||
if (segments.length == 0) {
|
||||
throw new IllegalArgumentException("Invalid path id: '" + str + "'");
|
||||
}
|
||||
String fname = segments[segments.length - 1];
|
||||
return new PathId() {
|
||||
return new FileId() {
|
||||
@Override
|
||||
public String toAbsolutePath() {
|
||||
return Paths.get(str).toAbsolutePath().toString();
|
||||
@ -100,8 +100,8 @@ public interface PathId extends Comparable<PathId> {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof PathId
|
||||
&& ((PathId) obj).toUriString().equals(this.toUriString());
|
||||
return obj instanceof FileId
|
||||
&& ((FileId) obj).toUriString().equals(this.toUriString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,14 +110,14 @@ public interface PathId extends Comparable<PathId> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PathId getParentFsPath() {
|
||||
public @Nullable FileId getParentFsPath() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static PathId forPath(Path path, @Nullable PathId fsPath) {
|
||||
return new PathId() {
|
||||
static FileId forPath(Path path, @Nullable FileId fsPath) {
|
||||
return new FileId() {
|
||||
@Override
|
||||
public String toAbsolutePath() {
|
||||
return path.normalize().toAbsolutePath().toString();
|
||||
@ -139,14 +139,14 @@ public interface PathId extends Comparable<PathId> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PathId getParentFsPath() {
|
||||
public @Nullable FileId getParentFsPath() {
|
||||
return fsPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof PathId
|
||||
&& ((PathId) obj).toUriString().equals(this.toUriString());
|
||||
return obj instanceof FileId
|
||||
&& ((FileId) obj).toUriString().equals(this.toUriString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -161,14 +161,14 @@ public interface PathId extends Comparable<PathId> {
|
||||
};
|
||||
}
|
||||
|
||||
static PathId forPath(Path path) {
|
||||
static FileId forPath(Path path) {
|
||||
return forPath(path, null);
|
||||
}
|
||||
|
||||
static PathId asChildOf(PathId self, PathId parentFsPath) {
|
||||
return new PathId() {
|
||||
static FileId asChildOf(FileId self, FileId parentFsPath) {
|
||||
return new FileId() {
|
||||
@Override
|
||||
public @Nullable PathId getParentFsPath() {
|
||||
public @Nullable FileId getParentFsPath() {
|
||||
return parentFsPath;
|
||||
}
|
||||
|
@ -41,14 +41,14 @@ public final class FileLocation {
|
||||
private final int endLine;
|
||||
private final int beginColumn;
|
||||
private final int endColumn;
|
||||
private final PathId fileName;
|
||||
private final FileId fileName;
|
||||
private final @Nullable TextRegion region;
|
||||
|
||||
FileLocation(PathId fileName, int beginLine, int beginColumn, int endLine, int endColumn) {
|
||||
FileLocation(FileId fileName, int beginLine, int beginColumn, int endLine, int endColumn) {
|
||||
this(fileName, beginLine, beginColumn, endLine, endColumn, null);
|
||||
}
|
||||
|
||||
FileLocation(PathId fileName, int beginLine, int beginColumn, int endLine, int endColumn, @Nullable TextRegion region) {
|
||||
FileLocation(FileId fileName, int beginLine, int beginColumn, int endLine, int endColumn, @Nullable TextRegion region) {
|
||||
this.fileName = Objects.requireNonNull(fileName);
|
||||
this.beginLine = AssertionUtil.requireOver1("Begin line", beginLine);
|
||||
this.endLine = AssertionUtil.requireOver1("End line", endLine);
|
||||
@ -70,7 +70,7 @@ public final class FileLocation {
|
||||
/**
|
||||
* File name of this position.
|
||||
*/
|
||||
public PathId getFileId() {
|
||||
public FileId getFileId() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ public final class FileLocation {
|
||||
* @throws IllegalArgumentException If the line and column are not correctly ordered
|
||||
* @throws IllegalArgumentException If the start offset or length are negative
|
||||
*/
|
||||
public static FileLocation range(PathId fileName, TextRange2d range2d) {
|
||||
public static FileLocation range(FileId fileName, TextRange2d range2d) {
|
||||
TextPos2d start = range2d.getStartPos();
|
||||
TextPos2d end = range2d.getEndPos();
|
||||
return new FileLocation(fileName,
|
||||
@ -163,9 +163,9 @@ public final class FileLocation {
|
||||
*
|
||||
* @return A new location
|
||||
*
|
||||
* @throws IllegalArgumentException See {@link #range(PathId, TextRange2d)}
|
||||
* @throws IllegalArgumentException See {@link #range(FileId, TextRange2d)}
|
||||
*/
|
||||
public static FileLocation caret(PathId fileName, int line, int column) {
|
||||
public static FileLocation caret(FileId fileName, int line, int column) {
|
||||
return new FileLocation(fileName, line, column, line, column);
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,11 @@ class NioTextFile extends BaseCloseable implements TextFile {
|
||||
private final Path path;
|
||||
private final Charset charset;
|
||||
private final LanguageVersion languageVersion;
|
||||
private final PathId pathId;
|
||||
private final FileId fileId;
|
||||
private boolean readOnly;
|
||||
|
||||
NioTextFile(Path path,
|
||||
@Nullable PathId parentFsPath,
|
||||
@Nullable FileId parentFsPath,
|
||||
Charset charset,
|
||||
LanguageVersion languageVersion,
|
||||
boolean readOnly) {
|
||||
@ -44,7 +44,7 @@ class NioTextFile extends BaseCloseable implements TextFile {
|
||||
this.languageVersion = languageVersion;
|
||||
// using the URI here, that handles files inside zip archives automatically (schema "jar:file:...!/path/inside/zip")
|
||||
// normalization ensures cannonical paths
|
||||
this.pathId = PathId.forPath(path, parentFsPath);
|
||||
this.fileId = FileId.forPath(path, parentFsPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,8 +53,8 @@ class NioTextFile extends BaseCloseable implements TextFile {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathId getPathId() {
|
||||
return pathId;
|
||||
public FileId getPathId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,23 +17,23 @@ import net.sourceforge.pmd.util.AssertionUtil;
|
||||
*/
|
||||
class ReaderTextFile implements TextFile {
|
||||
|
||||
private final PathId pathId;
|
||||
private final FileId fileId;
|
||||
private final LanguageVersion languageVersion;
|
||||
private final Reader reader;
|
||||
|
||||
ReaderTextFile(Reader reader, @NonNull PathId pathId, LanguageVersion languageVersion) {
|
||||
ReaderTextFile(Reader reader, @NonNull FileId fileId, LanguageVersion languageVersion) {
|
||||
AssertionUtil.requireParamNotNull("reader", reader);
|
||||
AssertionUtil.requireParamNotNull("path id", pathId);
|
||||
AssertionUtil.requireParamNotNull("path id", fileId);
|
||||
AssertionUtil.requireParamNotNull("language version", languageVersion);
|
||||
|
||||
this.reader = reader;
|
||||
this.languageVersion = languageVersion;
|
||||
this.pathId = pathId;
|
||||
this.fileId = fileId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathId getPathId() {
|
||||
return pathId;
|
||||
public FileId getPathId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,7 +53,7 @@ class ReaderTextFile implements TextFile {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ReaderTextFile[" + pathId + "]";
|
||||
return "ReaderTextFile[" + fileId + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,16 +27,16 @@ final class RootTextDocument extends BaseCloseable implements TextDocument {
|
||||
|
||||
private final LanguageVersion langVersion;
|
||||
|
||||
private final PathId pathId;
|
||||
private final FileId fileId;
|
||||
|
||||
RootTextDocument(TextFile backend) throws IOException {
|
||||
this.backend = backend;
|
||||
this.content = backend.readContents();
|
||||
this.langVersion = backend.getLanguageVersion();
|
||||
this.pathId = backend.getPathId();
|
||||
this.fileId = backend.getPathId();
|
||||
|
||||
Objects.requireNonNull(langVersion, "Null language version for file " + backend);
|
||||
Objects.requireNonNull(pathId, "Null path id for file " + backend);
|
||||
Objects.requireNonNull(fileId, "Null path id for file " + backend);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,8 +45,8 @@ final class RootTextDocument extends BaseCloseable implements TextDocument {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathId getPathId() {
|
||||
return pathId;
|
||||
public FileId getPathId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,7 +71,7 @@ final class RootTextDocument extends BaseCloseable implements TextDocument {
|
||||
: positioner.lineColFromOffset(region.getEndOffset(), false);
|
||||
|
||||
return new FileLocation(
|
||||
pathId,
|
||||
fileId,
|
||||
bpos.getLine(),
|
||||
bpos.getColumn(),
|
||||
epos.getLine(),
|
||||
|
@ -16,17 +16,17 @@ import net.sourceforge.pmd.util.StringUtil;
|
||||
class StringTextFile implements TextFile {
|
||||
|
||||
private final TextFileContent content;
|
||||
private final PathId pathId;
|
||||
private final FileId fileId;
|
||||
private final LanguageVersion languageVersion;
|
||||
|
||||
StringTextFile(CharSequence source, PathId pathId, LanguageVersion languageVersion) {
|
||||
StringTextFile(CharSequence source, FileId fileId, LanguageVersion languageVersion) {
|
||||
AssertionUtil.requireParamNotNull("source text", source);
|
||||
AssertionUtil.requireParamNotNull("file name", pathId);
|
||||
AssertionUtil.requireParamNotNull("file name", fileId);
|
||||
AssertionUtil.requireParamNotNull("language version", languageVersion);
|
||||
|
||||
this.languageVersion = languageVersion;
|
||||
this.content = TextFileContent.fromCharSeq(source);
|
||||
this.pathId = pathId;
|
||||
this.fileId = fileId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,12 +36,12 @@ class StringTextFile implements TextFile {
|
||||
|
||||
@Override
|
||||
public @NonNull String getDisplayName() {
|
||||
return pathId.toUriString();
|
||||
return fileId.toUriString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathId getPathId() {
|
||||
return pathId;
|
||||
public FileId getPathId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -88,7 +88,7 @@ public interface TextDocument extends Closeable {
|
||||
/**
|
||||
* Returns {@link TextFile#getPathId()} for the text file backing this document.
|
||||
*/
|
||||
PathId getPathId();
|
||||
FileId getPathId();
|
||||
|
||||
/**
|
||||
* Returns {@link TextFile#getDisplayName()} for the text file backing this document.
|
||||
@ -263,10 +263,10 @@ public interface TextDocument extends Closeable {
|
||||
/**
|
||||
* Returns a read-only document for the given text.
|
||||
*
|
||||
* @see TextFile#forCharSeq(CharSequence, PathId, LanguageVersion)
|
||||
* @see TextFile#forCharSeq(CharSequence, FileId, LanguageVersion)
|
||||
*/
|
||||
static TextDocument readOnlyString(final CharSequence source, LanguageVersion lv) {
|
||||
return readOnlyString(source, PathId.UNKNOWN, lv);
|
||||
return readOnlyString(source, FileId.UNKNOWN, lv);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,10 +276,10 @@ public interface TextDocument extends Closeable {
|
||||
* but doesn't throw {@link IOException}, as such text files will
|
||||
* not throw.
|
||||
*
|
||||
* @see TextFile#forCharSeq(CharSequence, PathId, LanguageVersion)
|
||||
* @see TextFile#forCharSeq(CharSequence, FileId, LanguageVersion)
|
||||
*/
|
||||
@SuppressWarnings("PMD.CloseResource")
|
||||
static TextDocument readOnlyString(@NonNull CharSequence source, @NonNull PathId filename, @NonNull LanguageVersion lv) {
|
||||
static TextDocument readOnlyString(@NonNull CharSequence source, @NonNull FileId filename, @NonNull LanguageVersion lv) {
|
||||
TextFile textFile = TextFile.forCharSeq(source, filename, lv);
|
||||
try {
|
||||
return create(textFile);
|
||||
|
@ -70,7 +70,7 @@ public interface TextFile extends Closeable {
|
||||
* <p>Basically this may be implemented as a URL, or a file path. It
|
||||
* is used to index violation caches.
|
||||
*/
|
||||
PathId getPathId();
|
||||
FileId getPathId();
|
||||
|
||||
|
||||
/**
|
||||
@ -185,13 +185,13 @@ public interface TextFile extends Closeable {
|
||||
* may not produce exactly the same char sequence.
|
||||
*
|
||||
* @param charseq Text of the file
|
||||
* @param pathId File name to use as path id
|
||||
* @param fileId File name to use as path id
|
||||
* @param languageVersion Language version
|
||||
*
|
||||
* @throws NullPointerException If any parameter is null
|
||||
*/
|
||||
static TextFile forCharSeq(CharSequence charseq, PathId pathId, LanguageVersion languageVersion) {
|
||||
return builderForCharSeq(charseq, pathId, languageVersion)
|
||||
static TextFile forCharSeq(CharSequence charseq, FileId fileId, LanguageVersion languageVersion) {
|
||||
return builderForCharSeq(charseq, fileId, languageVersion)
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -201,13 +201,13 @@ public interface TextFile extends Closeable {
|
||||
* may not produce exactly the same char sequence.
|
||||
*
|
||||
* @param charseq Text of the file
|
||||
* @param pathId File name to use as path id
|
||||
* @param fileId File name to use as path id
|
||||
* @param languageVersion Language version
|
||||
*
|
||||
* @throws NullPointerException If any parameter is null
|
||||
*/
|
||||
static TextFileBuilder builderForCharSeq(CharSequence charseq, PathId pathId, LanguageVersion languageVersion) {
|
||||
return new ForCharSeq(charseq, pathId, languageVersion);
|
||||
static TextFileBuilder builderForCharSeq(CharSequence charseq, FileId fileId, LanguageVersion languageVersion) {
|
||||
return new ForCharSeq(charseq, fileId, languageVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,13 +218,13 @@ public interface TextFile extends Closeable {
|
||||
* throw an {@link IOException}.
|
||||
*
|
||||
* @param reader Text of the file
|
||||
* @param pathId File name to use as path id
|
||||
* @param fileId File name to use as path id
|
||||
* @param languageVersion Language version
|
||||
*
|
||||
* @throws NullPointerException If any parameter is null
|
||||
*/
|
||||
static TextFile forReader(Reader reader, PathId pathId, LanguageVersion languageVersion) {
|
||||
return builderForReader(reader, pathId, languageVersion)
|
||||
static TextFile forReader(Reader reader, FileId fileId, LanguageVersion languageVersion) {
|
||||
return builderForReader(reader, fileId, languageVersion)
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -236,13 +236,13 @@ public interface TextFile extends Closeable {
|
||||
* throw an {@link IOException}.
|
||||
*
|
||||
* @param reader Text of the file
|
||||
* @param pathId File name to use as path id
|
||||
* @param fileId File name to use as path id
|
||||
* @param languageVersion Language version
|
||||
*
|
||||
* @throws NullPointerException If any parameter is null
|
||||
*/
|
||||
static TextFileBuilder builderForReader(Reader reader, PathId pathId, LanguageVersion languageVersion) {
|
||||
return new ForReader(languageVersion, reader, pathId);
|
||||
static TextFileBuilder builderForReader(Reader reader, FileId fileId, LanguageVersion languageVersion) {
|
||||
return new ForReader(languageVersion, reader, fileId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -257,7 +257,7 @@ public interface TextFile extends Closeable {
|
||||
@DeprecatedUntil700
|
||||
static TextFile dataSourceCompat(DataSource ds, PMDConfiguration config) {
|
||||
String pathId = ds.getNiceFileName(false, null);
|
||||
PathId pathId2 = PathId.fromPathLikeString(pathId);
|
||||
FileId fileId2 = FileId.fromPathLikeString(pathId);
|
||||
LanguageVersion languageVersion = config.getLanguageVersionOfFile(pathId);
|
||||
if (languageVersion == null) {
|
||||
throw new NullPointerException("no language version detected for " + pathId);
|
||||
@ -271,8 +271,8 @@ public interface TextFile extends Closeable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathId getPathId() {
|
||||
return pathId2;
|
||||
public FileId getPathId() {
|
||||
return fileId2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,7 @@ import net.sourceforge.pmd.util.AssertionUtil;
|
||||
public abstract class TextFileBuilder {
|
||||
|
||||
protected final LanguageVersion languageVersion;
|
||||
protected PathId parentFsId;
|
||||
protected FileId parentFsId;
|
||||
|
||||
TextFileBuilder(LanguageVersion languageVersion) {
|
||||
this.languageVersion = AssertionUtil.requireParamNotNull("language version", languageVersion);
|
||||
@ -38,8 +38,8 @@ public abstract class TextFileBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextFileBuilder setParentFsPath(@Nullable PathId pathId) {
|
||||
parentFsId = pathId;
|
||||
public TextFileBuilder setParentFsPath(@Nullable FileId fileId) {
|
||||
parentFsId = fileId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -76,47 +76,47 @@ public abstract class TextFileBuilder {
|
||||
static class ForCharSeq extends TextFileBuilder {
|
||||
|
||||
private final CharSequence charSequence;
|
||||
private PathId pathId;
|
||||
private FileId fileId;
|
||||
|
||||
ForCharSeq(CharSequence charSequence, PathId pathId, LanguageVersion languageVersion) {
|
||||
ForCharSeq(CharSequence charSequence, FileId fileId, LanguageVersion languageVersion) {
|
||||
super(languageVersion);
|
||||
this.charSequence = AssertionUtil.requireParamNotNull("charseq", charSequence);
|
||||
this.pathId = AssertionUtil.requireParamNotNull("path ID", pathId);
|
||||
this.fileId = AssertionUtil.requireParamNotNull("path ID", fileId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextFileBuilder setParentFsPath(@Nullable PathId pathId) {
|
||||
this.pathId = PathId.asChildOf(this.pathId, pathId);
|
||||
return super.setParentFsPath(pathId);
|
||||
public TextFileBuilder setParentFsPath(@Nullable FileId fileId) {
|
||||
this.fileId = FileId.asChildOf(this.fileId, fileId);
|
||||
return super.setParentFsPath(fileId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextFile build() {
|
||||
return new StringTextFile(charSequence, pathId, languageVersion);
|
||||
return new StringTextFile(charSequence, fileId, languageVersion);
|
||||
}
|
||||
}
|
||||
|
||||
static class ForReader extends TextFileBuilder {
|
||||
|
||||
private final Reader reader;
|
||||
private PathId pathId;
|
||||
private FileId fileId;
|
||||
|
||||
ForReader(LanguageVersion languageVersion, Reader reader, PathId pathId) {
|
||||
ForReader(LanguageVersion languageVersion, Reader reader, FileId fileId) {
|
||||
super(languageVersion);
|
||||
this.reader = AssertionUtil.requireParamNotNull("reader", reader);
|
||||
this.pathId = AssertionUtil.requireParamNotNull("path ID", pathId);
|
||||
this.fileId = AssertionUtil.requireParamNotNull("path ID", fileId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextFileBuilder setParentFsPath(@Nullable PathId pathId) {
|
||||
this.pathId = PathId.asChildOf(this.pathId, pathId);
|
||||
return super.setParentFsPath(pathId);
|
||||
public TextFileBuilder setParentFsPath(@Nullable FileId fileId) {
|
||||
this.fileId = FileId.asChildOf(this.fileId, fileId);
|
||||
return super.setParentFsPath(fileId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TextFile build() {
|
||||
return new ReaderTextFile(reader, pathId, languageVersion);
|
||||
return new ReaderTextFile(reader, fileId, languageVersion);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import java.io.Writer;
|
||||
|
||||
import net.sourceforge.pmd.annotation.Experimental;
|
||||
import net.sourceforge.pmd.internal.util.IOUtil;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.properties.AbstractPropertySource;
|
||||
|
||||
/**
|
||||
@ -21,7 +21,7 @@ public abstract class AbstractRenderer extends AbstractPropertySource implements
|
||||
|
||||
protected boolean showSuppressedViolations = true;
|
||||
protected PrintWriter writer;
|
||||
private FileNameRenderer fileNameRenderer = PathId::getOriginalPath;
|
||||
private FileNameRenderer fileNameRenderer = FileId::getOriginalPath;
|
||||
|
||||
public AbstractRenderer(String name, String description) {
|
||||
this.name = name;
|
||||
@ -74,7 +74,7 @@ public abstract class AbstractRenderer extends AbstractPropertySource implements
|
||||
* is without the directory prefix of the directories, that have been analyzed.
|
||||
* If the option "shortnames" is not enabled, then the fileId is returned as-is.
|
||||
*/
|
||||
protected String determineFileName(PathId fileId) {
|
||||
protected String determineFileName(FileId fileId) {
|
||||
return fileNameRenderer.getDisplayName(fileId);
|
||||
}
|
||||
|
||||
|
@ -4,18 +4,18 @@
|
||||
|
||||
package net.sourceforge.pmd.renderers;
|
||||
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
|
||||
/**
|
||||
* Renders a {@link PathId} into a display name.
|
||||
* Renders a {@link FileId} into a display name.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public interface FileNameRenderer {
|
||||
|
||||
|
||||
String getDisplayName(PathId pathId);
|
||||
String getDisplayName(FileId fileId);
|
||||
|
||||
default String getDisplayName(TextFile textFile) {
|
||||
return getDisplayName(textFile.getPathId());
|
||||
|
@ -17,7 +17,7 @@ import net.sourceforge.pmd.Report;
|
||||
import net.sourceforge.pmd.Report.ConfigurationError;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.properties.PropertyFactory;
|
||||
import net.sourceforge.pmd.properties.StringProperty;
|
||||
@ -154,7 +154,7 @@ public class HTMLRenderer extends AbstractIncrementingRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
private String renderFileName(PathId fileId, int beginLine) {
|
||||
private String renderFileName(FileId fileId, int beginLine) {
|
||||
return maybeWrap(StringEscapeUtils.escapeHtml4(determineFileName(fileId)),
|
||||
linePrefix == null || beginLine < 0 ? "" : linePrefix + beginLine);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import net.sourceforge.pmd.Report.ProcessingError;
|
||||
import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.internal.util.IOUtil;
|
||||
import net.sourceforge.pmd.lang.ast.FileAnalysisException;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
import net.sourceforge.pmd.renderers.Renderer;
|
||||
import net.sourceforge.pmd.util.AssertionUtil;
|
||||
@ -198,7 +198,7 @@ public interface GlobalAnalysisListener extends AutoCloseable {
|
||||
|
||||
@Override
|
||||
public FileAnalysisListener startFileAnalysis(TextFile file) {
|
||||
PathId filename = file.getPathId(); // capture the filename instead of the file
|
||||
FileId filename = file.getPathId(); // capture the filename instead of the file
|
||||
return new FileAnalysisListener() {
|
||||
@Override
|
||||
public void onRuleViolation(RuleViolation violation) {
|
||||
|
@ -23,7 +23,7 @@ import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
import net.sourceforge.pmd.lang.ast.SemanticErrorReporter;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.TextDocument;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
import net.sourceforge.pmd.lang.rule.xpath.Attribute;
|
||||
@ -74,7 +74,7 @@ public class TreeExporter {
|
||||
TextFile textFile;
|
||||
if (configuration.isReadStdin()) {
|
||||
io.stderr.println("Reading from stdin...");
|
||||
textFile = TextFile.forReader(readFromSystemIn(), PathId.STDIN, langVersion);
|
||||
textFile = TextFile.forReader(readFromSystemIn(), FileId.STDIN, langVersion);
|
||||
} else {
|
||||
textFile = TextFile.forPath(configuration.getFile(), configuration.getSourceEncoding(), langVersion);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.DummyNode.DummyRootNode;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.rule.AbstractRule;
|
||||
import net.sourceforge.pmd.lang.rule.ParametricRuleViolation;
|
||||
import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
@ -78,7 +78,7 @@ class AbstractRuleTest {
|
||||
void testCreateRV() {
|
||||
MyRule r = new MyRule();
|
||||
r.setRuleSetName("foo");
|
||||
DummyRootNode s = helper.parse("abc()", PathId.fromPathLikeString("abc"));
|
||||
DummyRootNode s = helper.parse("abc()", FileId.fromPathLikeString("abc"));
|
||||
|
||||
RuleViolation rv = new ParametricRuleViolation(r, s, r.getMessage());
|
||||
assertEquals(1, rv.getBeginLine(), "Line number mismatch!");
|
||||
@ -91,7 +91,7 @@ class AbstractRuleTest {
|
||||
@Test
|
||||
void testCreateRV2() {
|
||||
MyRule r = new MyRule();
|
||||
DummyRootNode s = helper.parse("abc()", PathId.fromPathLikeString("filename"));
|
||||
DummyRootNode s = helper.parse("abc()", FileId.fromPathLikeString("filename"));
|
||||
RuleViolation rv = new ParametricRuleViolation(r, s, "specificdescription");
|
||||
assertEquals(1, rv.getBeginLine(), "Line number mismatch!");
|
||||
assertEquals("filename", rv.getFileId().getOriginalPath(), "Filename mismatch!");
|
||||
@ -110,7 +110,7 @@ class AbstractRuleTest {
|
||||
r.definePropertyDescriptor(PropertyFactory.intProperty("testInt").desc("description").require(inRange(0, 100)).defaultValue(10).build());
|
||||
r.setMessage("Message ${packageName} ${className} ${methodName} ${variableName} ${testInt} ${noSuchProperty}");
|
||||
|
||||
DummyRootNode s = helper.parse("abc()", PathId.UNKNOWN);
|
||||
DummyRootNode s = helper.parse("abc()", FileId.UNKNOWN);
|
||||
|
||||
RuleViolation rv = getReportForRuleApply(r, s).getViolations().get(0);
|
||||
assertEquals("Message foo ${className} ${methodName} ${variableName} 10 ${noSuchProperty}", rv.getDescription());
|
||||
@ -118,7 +118,7 @@ class AbstractRuleTest {
|
||||
|
||||
@Test
|
||||
void testRuleSuppress() {
|
||||
DummyRootNode n = helper.parse("abc()", PathId.UNKNOWN)
|
||||
DummyRootNode n = helper.parse("abc()", FileId.UNKNOWN)
|
||||
.withNoPmdComments(Collections.singletonMap(1, "ohio"));
|
||||
|
||||
FileAnalysisListener listener = mock(FileAnalysisListener.class);
|
||||
|
@ -19,7 +19,7 @@ import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.ast.DummyNode.DummyRootNode;
|
||||
import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
|
||||
import net.sourceforge.pmd.lang.ast.SemanticErrorReporter;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.TextDocument;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
|
||||
@ -35,14 +35,14 @@ public class DummyParsingHelper implements Extension, BeforeEachCallback, AfterE
|
||||
}
|
||||
|
||||
public DummyRootNode parse(String code) {
|
||||
return parse(code, PathId.UNKNOWN);
|
||||
return parse(code, FileId.UNKNOWN);
|
||||
}
|
||||
|
||||
public DummyRootNode parse(String code, String filename) {
|
||||
return parse(code, PathId.fromPathLikeString(filename));
|
||||
return parse(code, FileId.fromPathLikeString(filename));
|
||||
}
|
||||
|
||||
public DummyRootNode parse(String code, PathId filename) {
|
||||
public DummyRootNode parse(String code, FileId filename) {
|
||||
LanguageVersion version = DummyLanguageModule.getInstance().getDefaultVersion();
|
||||
ParserTask task = new ParserTask(
|
||||
TextDocument.readOnlyString(code, filename, version),
|
||||
|
@ -28,7 +28,7 @@ import net.sourceforge.pmd.lang.DummyLanguageModule;
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageProcessor;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.document.PathId;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.SimpleTestTextFile;
|
||||
import net.sourceforge.pmd.lang.rule.AbstractRule;
|
||||
import net.sourceforge.pmd.renderers.Renderer;
|
||||
@ -94,7 +94,7 @@ class PmdAnalysisTest {
|
||||
config.setForceLanguageVersion(DummyLanguageModule.getInstance().getVersionWhereParserThrows());
|
||||
try (PmdAnalysis pmd = PmdAnalysis.create(config)) {
|
||||
pmd.addRuleSet(RuleSet.forSingleRule(new MockRule()));
|
||||
pmd.files().addSourceFile(PathId.fromPathLikeString("file"), "some source");
|
||||
pmd.files().addSourceFile(FileId.fromPathLikeString("file"), "some source");
|
||||
|
||||
ReportStats stats = pmd.runAndReturnStats();
|
||||
assertEquals(1, stats.getNumErrors(), "Errors");
|
||||
@ -117,7 +117,7 @@ class PmdAnalysisTest {
|
||||
}
|
||||
}));
|
||||
|
||||
pmd.files().addSourceFile(PathId.fromPathLikeString("fname1.dummy"), "some source");
|
||||
pmd.files().addSourceFile(FileId.fromPathLikeString("fname1.dummy"), "some source");
|
||||
|
||||
ReportStats stats = pmd.runAndReturnStats();
|
||||
// the error number here is only for FileAnalysisException, so
|
||||
@ -157,7 +157,7 @@ class PmdAnalysisTest {
|
||||
|
||||
try (PmdAnalysis pmd = PmdAnalysis.create(config)) {
|
||||
pmd.addRuleSet(ruleset);
|
||||
pmd.files().addFile(new SimpleTestTextFile("test content foo", PathId.fromPathLikeString("foo.txt"), language.getDefaultVersion()));
|
||||
pmd.files().addFile(new SimpleTestTextFile("test content foo", FileId.fromPathLikeString("foo.txt"), language.getDefaultVersion()));
|
||||
Report report = pmd.performAnalysisAndCollectReport();
|
||||
for (Report.ProcessingError error : report.getProcessingErrors()) {
|
||||
System.out.println("error = " + error.getMsg() + ": " + error.getDetail());
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user