diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java index 7545d7a70a..bd0785639e 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java @@ -101,7 +101,7 @@ public final class CpdAnalysis implements AutoCloseable { } private int doTokenize(TextDocument document, Tokenizer tokenizer, Tokens tokens) throws IOException, TokenMgrError { - LOGGER.trace("Tokenizing {}", document.getFileId().toAbsolutePath()); + LOGGER.trace("Tokenizing {}", document.getFileId().getAbsolutePath()); int lastTokenSize = tokens.size(); Tokenizer.tokenize(tokenizer, document, tokens); return tokens.size() - lastTokenSize - 1; /* EOF */ diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/SourceManager.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/SourceManager.java index 8d520bcb5d..e399d7d422 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/SourceManager.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/SourceManager.java @@ -26,7 +26,7 @@ class SourceManager implements AutoCloseable { private final Map> files = new ConcurrentHashMap<>(); private final Map fileByPathId = new HashMap<>(); private final List textFiles; - private FileNameRenderer fileNameRenderer = FileId::toAbsolutePath; + private FileNameRenderer fileNameRenderer = FileId::getAbsolutePath; SourceManager(List files) { textFiles = new ArrayList<>(files); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/AntlrTokenizer.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/AntlrTokenizer.java index db7a5d6f8d..07e2610d06 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/AntlrTokenizer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/AntlrTokenizer.java @@ -22,7 +22,7 @@ import net.sourceforge.pmd.lang.document.TextDocument; public abstract class AntlrTokenizer extends TokenizerBase { @Override protected final TokenManager makeLexerImpl(TextDocument doc) throws IOException { - CharStream charStream = CharStreams.fromReader(doc.newReader(), doc.getFileId().toAbsolutePath()); + CharStream charStream = CharStreams.fromReader(doc.newReader(), doc.getFileId().getAbsolutePath()); return new AntlrTokenManager(getLexerForSource(charStream), doc); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/XMLRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/XMLRendererTest.java index dacf2196c4..7bbefe3ff7 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/XMLRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/XMLRendererTest.java @@ -77,7 +77,7 @@ class XMLRendererTest { } if (file != null) { assertEquals("1", file.getAttributes().getNamedItem("line").getNodeValue()); - assertEquals(foo1.toAbsolutePath(), file.getAttributes().getNamedItem("path").getNodeValue()); + assertEquals(foo1.getAbsolutePath(), file.getAttributes().getNamedItem("path").getNodeValue()); assertEquals("6", file.getAttributes().getNamedItem("endline").getNodeValue()); assertEquals("1", file.getAttributes().getNamedItem("column").getNodeValue()); assertEquals("1", file.getAttributes().getNamedItem("endcolumn").getNodeValue()); @@ -146,7 +146,7 @@ class XMLRendererTest { } if (file != null) { assertEquals("1", file.getAttributes().getNamedItem("line").getNodeValue()); - assertEquals(fileName.toAbsolutePath(), file.getAttributes().getNamedItem("path").getNodeValue()); + assertEquals(fileName.getAbsolutePath(), file.getAttributes().getNamedItem("path").getNodeValue()); assertEquals("2", file.getAttributes().getNamedItem("endline").getNodeValue()); assertEquals("2", file.getAttributes().getNamedItem("column").getNodeValue()); assertEquals("3", file.getAttributes().getNamedItem("endcolumn").getNodeValue()); diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/TsLanguageModule.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/TsLanguageModule.java deleted file mode 100644 index ff06b2c241..0000000000 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/TsLanguageModule.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.ecmascript; - -import net.sourceforge.pmd.cpd.Tokenizer; -import net.sourceforge.pmd.lang.LanguagePropertyBundle; -import net.sourceforge.pmd.lang.ecmascript.cpd.EcmascriptTokenizer; -import net.sourceforge.pmd.lang.impl.CpdOnlyLanguageModuleBase; - -/** - * CPD only language to recognize TypeScript files. - */ -public class TsLanguageModule extends CpdOnlyLanguageModuleBase { - - public TsLanguageModule() { - super(LanguageMetadata.withId("ts").name("TypeScript").extensions("ts")); - } - - @Override - public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) { - return new EcmascriptTokenizer(); - } -} diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/TsLanguageModule.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/TsLanguageModule.java new file mode 100644 index 0000000000..26e22b4f3d --- /dev/null +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/TsLanguageModule.java @@ -0,0 +1,32 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.typescript; + +import net.sourceforge.pmd.cpd.Tokenizer; +import net.sourceforge.pmd.lang.LanguagePropertyBundle; +import net.sourceforge.pmd.lang.LanguageRegistry; +import net.sourceforge.pmd.lang.impl.CpdOnlyLanguageModuleBase; +import net.sourceforge.pmd.lang.typescript.cpd.TypeScriptTokenizer; + +/** + * @author pguyot@kallisys.net + */ +public class TsLanguageModule extends CpdOnlyLanguageModuleBase { + + public TsLanguageModule() { + super(LanguageMetadata.withId("typescript") + .name("TypeScript") + .extensions("ts")); + } + + @Override + public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) { + return new TypeScriptTokenizer(); + } + + public static TsLanguageModule getInstance() { + return (TsLanguageModule) LanguageRegistry.CPD.getLanguageById("typescript"); + } +} diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptLanguage.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptLanguage.java deleted file mode 100644 index 9191e65cc2..0000000000 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptLanguage.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.typescript.cpd; - -import net.sourceforge.pmd.cpd.AbstractLanguage; - -/** - * @author pguyot@kallisys.net - */ -public class TypeScriptLanguage extends AbstractLanguage { - - public TypeScriptLanguage() { - super("TypeScript", "typescript", new TypeScriptTokenizer(), ".ts"); - } -} diff --git a/pmd-javascript/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language b/pmd-javascript/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language index 6e09a06884..4b7d330499 100644 --- a/pmd-javascript/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language +++ b/pmd-javascript/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language @@ -1,2 +1,2 @@ net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule -net.sourceforge.pmd.lang.ecmascript.TsLanguageModule +net.sourceforge.pmd.lang.typescript.TsLanguageModule diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptTokenizerTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptTokenizerTest.java index 96c7e660ac..27ada122a6 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptTokenizerTest.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptTokenizerTest.java @@ -4,27 +4,15 @@ package net.sourceforge.pmd.lang.typescript.cpd; -import java.util.Properties; - import org.junit.jupiter.api.Test; -import net.sourceforge.pmd.cpd.Tokenizer; import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest; +import net.sourceforge.pmd.lang.typescript.TsLanguageModule; class TypeScriptTokenizerTest extends CpdTextComparisonTest { TypeScriptTokenizerTest() { - super(".ts"); - } - - @Override - public Tokenizer newTokenizer(Properties properties) { - return new TypeScriptTokenizer(); - } - - @Override - protected String getResourcePrefix() { - return "../cpd/testdata"; + super(TsLanguageModule.getInstance(), ".ts"); } @Test diff --git a/pmd-julia/src/main/java/net/sourceforge/pmd/lang/julia/JuliaLanguageModule.java b/pmd-julia/src/main/java/net/sourceforge/pmd/lang/julia/JuliaLanguageModule.java new file mode 100644 index 0000000000..4ffd85e29f --- /dev/null +++ b/pmd-julia/src/main/java/net/sourceforge/pmd/lang/julia/JuliaLanguageModule.java @@ -0,0 +1,33 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.julia; + +import net.sourceforge.pmd.cpd.Tokenizer; +import net.sourceforge.pmd.lang.LanguagePropertyBundle; +import net.sourceforge.pmd.lang.LanguageRegistry; +import net.sourceforge.pmd.lang.impl.CpdOnlyLanguageModuleBase; +import net.sourceforge.pmd.lang.julia.cpd.JuliaTokenizer; + +/** + * Language implementation for Julia. + */ +public class JuliaLanguageModule extends CpdOnlyLanguageModuleBase { + + /** + * Creates a new Julia Language instance. + */ + public JuliaLanguageModule() { + super(LanguageMetadata.withId("julia").name("Julia").extensions("jl")); + } + + @Override + public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) { + return new JuliaTokenizer(); + } + + public static JuliaLanguageModule getInstance() { + return (JuliaLanguageModule) LanguageRegistry.CPD.getLanguageById("julia"); + } +} diff --git a/pmd-julia/src/main/java/net/sourceforge/pmd/lang/julia/cpd/JuliaLanguage.java b/pmd-julia/src/main/java/net/sourceforge/pmd/lang/julia/cpd/JuliaLanguage.java deleted file mode 100644 index d6bd001607..0000000000 --- a/pmd-julia/src/main/java/net/sourceforge/pmd/lang/julia/cpd/JuliaLanguage.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.julia.cpd; - -import net.sourceforge.pmd.cpd.AbstractLanguage; - -/** - * Language implementation for Julia. - */ -public class JuliaLanguage extends AbstractLanguage { - - /** - * Creates a new Julia Language instance. - */ - public JuliaLanguage() { - super("Julia", "julia", new JuliaTokenizer(), ".jl"); - } -} diff --git a/pmd-julia/src/main/resources/META-INF/services/net.sourceforge.pmd.cpd.Language b/pmd-julia/src/main/resources/META-INF/services/net.sourceforge.pmd.cpd.Language deleted file mode 100644 index bd23fbae93..0000000000 --- a/pmd-julia/src/main/resources/META-INF/services/net.sourceforge.pmd.cpd.Language +++ /dev/null @@ -1 +0,0 @@ -net.sourceforge.pmd.lang.julia.cpd.JuliaLanguage diff --git a/pmd-julia/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language b/pmd-julia/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language new file mode 100644 index 0000000000..3d5af03ece --- /dev/null +++ b/pmd-julia/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language @@ -0,0 +1 @@ +net.sourceforge.pmd.lang.julia.JuliaLanguageModule diff --git a/pmd-julia/src/test/java/net/sourceforge/pmd/cpd/JuliaTokenizerTest.java b/pmd-julia/src/test/java/net/sourceforge/pmd/cpd/JuliaTokenizerTest.java deleted file mode 100644 index e09f2f12f3..0000000000 --- a/pmd-julia/src/test/java/net/sourceforge/pmd/cpd/JuliaTokenizerTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.cpd; - -import java.util.Properties; - -import org.junit.jupiter.api.Test; - -import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest; -import net.sourceforge.pmd.lang.julia.cpd.JuliaTokenizer; - -class JuliaTokenizerTest extends CpdTextComparisonTest { - JuliaTokenizerTest() { - super(".jl"); - } - - @Override - protected String getResourcePrefix() { - return "../lang/julia/cpd/testdata"; - } - - @Override - public Tokenizer newTokenizer(Properties properties) { - JuliaTokenizer tok = new JuliaTokenizer(); - return tok; - } - - @Test - void testMathExample() { - doTest("mathExample"); - } -} diff --git a/pmd-julia/src/test/java/net/sourceforge/pmd/lang/julia/cpd/JuliaTokenizerTest.java b/pmd-julia/src/test/java/net/sourceforge/pmd/lang/julia/cpd/JuliaTokenizerTest.java new file mode 100644 index 0000000000..3c493a5544 --- /dev/null +++ b/pmd-julia/src/test/java/net/sourceforge/pmd/lang/julia/cpd/JuliaTokenizerTest.java @@ -0,0 +1,21 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.julia.cpd; + +import org.junit.jupiter.api.Test; + +import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest; +import net.sourceforge.pmd.lang.julia.JuliaLanguageModule; + +class JuliaTokenizerTest extends CpdTextComparisonTest { + JuliaTokenizerTest() { + super(JuliaLanguageModule.getInstance(), ".jl"); + } + + @Test + void testMathExample() { + doTest("mathExample"); + } +}