Fix merge

This commit is contained in:
Clément Fournier
2023-04-29 19:28:47 +02:00
parent b89970d5fe
commit b297538721
15 changed files with 95 additions and 117 deletions

View File

@ -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 */

View File

@ -26,7 +26,7 @@ class SourceManager implements AutoCloseable {
private final Map<TextFile, SoftReference<TextDocument>> files = new ConcurrentHashMap<>();
private final Map<FileId, TextFile> fileByPathId = new HashMap<>();
private final List<TextFile> textFiles;
private FileNameRenderer fileNameRenderer = FileId::toAbsolutePath;
private FileNameRenderer fileNameRenderer = FileId::getAbsolutePath;
SourceManager(List<? extends TextFile> files) {
textFiles = new ArrayList<>(files);

View File

@ -22,7 +22,7 @@ import net.sourceforge.pmd.lang.document.TextDocument;
public abstract class AntlrTokenizer extends TokenizerBase<AntlrToken> {
@Override
protected final TokenManager<AntlrToken> 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);
}

View File

@ -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());

View File

@ -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();
}
}

View File

@ -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");
}
}

View File

@ -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");
}
}

View File

@ -1,2 +1,2 @@
net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule
net.sourceforge.pmd.lang.ecmascript.TsLanguageModule
net.sourceforge.pmd.lang.typescript.TsLanguageModule

View File

@ -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

View File

@ -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");
}
}

View File

@ -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");
}
}

View File

@ -1 +0,0 @@
net.sourceforge.pmd.lang.julia.cpd.JuliaLanguage

View File

@ -0,0 +1 @@
net.sourceforge.pmd.lang.julia.JuliaLanguageModule

View File

@ -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");
}
}

View File

@ -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");
}
}