Merge branch 'master' into 7.0.x

This commit is contained in:
Clément Fournier
2020-06-19 01:32:32 +02:00
233 changed files with 21584 additions and 1726 deletions

View File

@ -75,10 +75,20 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-lang-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,28 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
public class Issue628Test {
@Test
public void tokenize() throws IOException {
SwiftTokenizer tokenizer = new SwiftTokenizer();
String code = IOUtils.toString(Issue628Test.class.getResourceAsStream("Issue628.swift"), StandardCharsets.UTF_8);
SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader(code));
final Tokens tokenEntries = new Tokens();
// must not throw an exception
tokenizer.tokenize(sourceCode, tokenEntries);
Assert.assertEquals(6, tokenEntries.size());
Assert.assertEquals(4394, tokenEntries.getTokens().get(3).toString().length());
}
}

View File

@ -4,56 +4,51 @@
package net.sourceforge.pmd.cpd;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.Properties;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
@RunWith(Parameterized.class)
public class SwiftTokenizerTest extends AbstractTokenizerTest {
public class SwiftTokenizerTest extends CpdTextComparisonTest {
private final String filename;
private final int nExpectedTokens;
public SwiftTokenizerTest(String filename, int nExpectedTokens) {
this.filename = filename;
this.nExpectedTokens = nExpectedTokens;
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[] { "Swift5.2.swift", 90 },
new Object[] { "Swift5.1.swift", 242 },
new Object[] { "Swift5.0.swift", 172 },
new Object[] { "Swift4.2.swift", 91 },
new Object[] { "BTree.swift", 4239 }
);
}
@Before
@Override
public void buildTokenizer() throws IOException {
this.tokenizer = new SwiftTokenizer();
this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), this.filename));
public SwiftTokenizerTest() {
super(".swift");
}
@Override
public String getSampleCode() throws IOException {
return IOUtils.toString(SwiftTokenizer.class.getResourceAsStream(this.filename), StandardCharsets.UTF_8);
protected String getResourcePrefix() {
return "../lang/swift/cpd/testdata";
}
@Override
public Tokenizer newTokenizer(Properties properties) {
return new SwiftTokenizer();
}
@Test
public void testSwift42() {
doTest("Swift4.2");
}
@Test
public void tokenizeTest() throws IOException {
this.expectedTokenCount = nExpectedTokens;
super.tokenizeTest();
public void testSwift50() {
doTest("Swift5.0");
}
@Test
public void testSwift51() {
doTest("Swift5.1");
}
@Test
public void testSwift52() {
doTest("Swift5.2");
}
@Test
public void testStackoverflowOnLongLiteral() {
doTest("Issue628");
}
}

View File

@ -0,0 +1,8 @@
[Image] or [Truncated image[ Bcol Ecol
L4
[var] 1 3
[str] 5 7
[=] 9 9
["Hello Hello Hello Hello Hello Hel[ 11 4404
[;] 4405 4405
EOF

View File

@ -0,0 +1,108 @@
[Image] or [Truncated image[ Bcol Ecol
L4
[let] 1 3
[diceRoll] 5 12
[=] 14 14
[Int] 16 18
[.] 19 19
[random] 20 25
[(] 26 26
[in] 27 28
[:] 29 29
[1] 31 31
[...] 33 35
[6] 37 37
[)] 38 38
L5
[let] 1 3
[randomUnit] 5 14
[=] 16 16
[Double] 18 23
[.] 24 24
[random] 25 30
[(] 31 31
[in] 32 33
[:] 34 34
[0] 36 36
[..] 38 39
[<] 40 40
[1] 42 42
[)] 43 43
L6
[let] 1 3
[randomBool] 5 14
[=] 16 16
[Bool] 18 21
[.] 22 22
[random] 23 28
[(] 29 29
[)] 30 30
L9
[public] 1 6
[class] 8 12
[C] 14 14
[{] 16 16
L10
[public] 3 8
[func] 10 13
[f] 15 15
[(] 16 16
[)] 17 17
[{] 19 19
[}] 20 20
L11
[}] 1 1
L13
[public] 1 6
[class] 8 12
[Cbis] 14 17
[{] 19 19
L14
[@] 3 3
[usableFromInline] 4 19
[internal] 21 28
[class] 30 34
[D] 36 36
[{] 38 38
L15
[@] 5 5
[usableFromInline] 6 21
[internal] 23 30
[func] 32 35
[f] 37 37
[(] 38 38
[)] 39 39
[{] 41 41
[}] 42 42
L17
[@] 5 5
[inlinable] 6 14
[internal] 16 23
[func] 25 28
[g] 30 30
[(] 31 31
[)] 32 32
[{] 34 34
[}] 35 35
L18
[}] 3 3
L19
[}] 1 1
L22
[#warning] 1 8
[(] 9 9
["this is incomplete"] 10 29
[)] 30 30
L24
[#if] 1 3
[MY_BUILD_CONFIG] 5 19
[&&] 21 22
[MY_OTHER_BUILD_CONFIG] 24 44
L25
[#error] 3 8
[(] 9 9
["MY_BUILD_CONFIG and MY_OTHER_BUIL[ 10 71
[)] 72 72
L26
[#endif] 1 6
EOF

View File

@ -0,0 +1,200 @@
[Image] or [Truncated image[ Bcol Ecol
L4
[enum] 1 4
[Result] 6 11
[<] 12 12
[Success] 13 19
[,] 20 20
[Failure] 22 28
[:] 29 29
[Error] 31 35
[>] 36 36
[{] 38 38
L5
[case] 5 8
[success] 10 16
[(] 17 17
[Success] 18 24
[)] 25 25
L6
[case] 5 8
[failure] 10 16
[(] 17 17
[Failure] 18 24
[)] 25 25
L7
[}] 1 1
L10
[struct] 1 6
[MyType] 8 13
[{] 15 15
[}] 16 16
L11
[#if] 1 3
[compiler] 5 12
[(] 13 13
[<] 14 14
[5.0] 15 17
[)] 18 18
L12
[extension] 1 9
[MyType] 11 16
[:] 18 18
[_ExpressibleByStringInterpolation] 20 52
[{] 54 54
[}] 56 56
L13
[#else] 1 5
L14
[extension] 1 9
[MyType] 11 16
[:] 18 18
[ExpressibleByStringInterpolation] 20 51
[{] 53 53
[}] 55 55
L15
[#endif] 1 6
L18
[func] 1 4
[foo] 6 8
[(] 9 9
[_] 10 10
[fn] 12 13
[:] 14 14
[@] 16 16
[autoclosure] 17 27
[(] 29 29
[)] 30 30
[->] 32 33
[Int] 35 37
[)] 38 38
[{] 40 40
[}] 41 41
L19
[func] 1 4
[bar] 6 8
[(] 9 9
[_] 10 10
[fn] 12 13
[:] 14 14
[@] 16 16
[autoclosure] 17 27
[(] 29 29
[)] 30 30
[->] 32 33
[Int] 35 37
[)] 38 38
[{] 40 40
L21
[foo] 3 5
[(] 6 6
[fn] 7 8
[(] 9 9
[)] 10 10
[)] 11 11
L22
[}] 1 1
L25
[@] 1 1
[dynamicCallable] 2 16
L26
[struct] 1 6
[ToyCallable] 8 18
[{] 20 20
L27
[func] 3 6
[dynamicallyCall] 8 22
[(] 23 23
[withArguments] 24 36
[:] 37 37
[\[] 39 39
[Int] 40 42
[\]] 43 43
[)] 44 44
[{] 46 46
[}] 47 47
L28
[func] 3 6
[dynamicallyCall] 8 22
[(] 23 23
[withKeywordArguments] 24 43
[:] 44 44
[KeyValuePairs] 46 58
[<] 59 59
[String] 60 65
[,] 66 66
[Int] 68 70
[>] 71 71
[)] 72 72
[{] 74 74
[}] 75 75
L29
[}] 1 1
L30
[let] 1 3
[toy] 5 7
[=] 9 9
[ToyCallable] 11 21
[(] 22 22
[)] 23 23
L31
[toy] 1 3
[(] 4 4
[1] 5 5
[,] 6 6
[2] 8 8
[,] 9 9
[3] 11 11
[)] 12 12
L32
[toy] 1 3
[(] 4 4
[label] 5 9
[:] 10 10
[1] 12 12
[,] 13 13
[2] 15 15
[)] 16 16
L35
[let] 1 3
[id] 5 6
[=] 8 8
[\\] 10 10
[Int] 11 13
[.] 14 14
[self] 15 18
L37
[var] 1 3
[x] 5 5
[=] 7 7
[2] 9 9
L38
[print] 1 5
[(] 6 6
[x] 7 7
[\[] 8 8
[keyPath] 9 15
[:] 16 16
[id] 18 19
[\]] 20 20
[)] 21 21
L39
[x] 1 1
[\[] 2 2
[keyPath] 3 9
[:] 10 10
[id] 12 13
[\]] 14 14
[=] 16 16
[3] 18 18
L40
[print] 1 5
[(] 6 6
[x] 7 7
[\[] 8 8
[keyPath] 9 15
[:] 16 16
[id] 18 19
[\]] 20 20
[)] 21 21
EOF

View File

@ -0,0 +1,290 @@
[Image] or [Truncated image[ Bcol Ecol
L6
[import] 1 6
[Combine] 8 14
L7
[class] 1 5
[Weather] 7 13
[{] 15 15
L8
[@] 5 5
[Published] 6 14
[var] 16 18
[temperature] 20 30
[:] 31 31
[Double] 33 38
L9
[init] 5 8
[(] 9 9
[temperature] 10 20
[:] 21 21
[Double] 23 28
[)] 29 29
[{] 31 31
L10
[self] 9 12
[.] 13 13
[temperature] 14 24
[=] 26 26
[temperature] 28 38
L11
[}] 5 5
L12
[}] 1 1
L14
[let] 1 3
[weather] 5 11
[=] 13 13
[Weather] 15 21
[(] 22 22
[temperature] 23 33
[:] 34 34
[20] 36 37
[)] 38 38
L15
[let] 1 3
[cancellable] 5 15
[=] 17 17
[weather] 19 25
[.] 26 26
[$] 27 27
[temperature] 28 38
L16
[.] 5 5
[sink] 6 9
[(] 10 10
[)] 11 11
[{] 13 13
L17
[print] 9 13
[(] 15 15
["Temperature now: \\($0)"] 16 39
[)] 40 40
L18
[}] 1 1
L19
[weather] 1 7
[.] 8 8
[temperature] 9 19
[=] 21 21
[25] 23 24
L26
[func] 1 4
[makeMeACollection] 6 22
[(] 23 23
[)] 24 24
[->] 26 27
[some] 29 32
[Collection] 34 43
[{] 45 45
L27
[return] 3 8
[\[] 10 10
[1] 11 11
[,] 12 12
[2] 14 14
[,] 15 15
[3] 17 17
[\]] 18 18
L28
[}] 1 1
L31
[@] 1 1
[dynamicMemberLookup] 2 20
L32
[struct] 1 6
[Lens] 8 11
[<] 12 12
[T] 13 13
[>] 14 14
[{] 16 16
L33
[let] 3 5
[getter:] 7 13
[(] 15 15
[)] 16 16
[->] 18 19
[T] 21 21
L34
[let] 3 5
[setter:] 7 13
[(] 15 15
[T] 16 16
[)] 17 17
[->] 19 20
[Void] 22 25
L36
[var] 3 5
[value] 7 11
[:] 12 12
[T] 14 14
[{] 16 16
L37
[get] 5 7
[{] 9 9
L38
[return] 7 12
[getter] 14 19
[(] 20 20
[)] 21 21
L39
[}] 5 5
L40
[set] 5 7
[{] 9 9
L41
[setter] 7 12
[(] 13 13
[newValue] 14 21
[)] 22 22
L42
[}] 5 5
L43
[}] 3 3
L45
[subscript] 3 11
[<] 12 12
[U] 13 13
[>] 14 14
[(] 15 15
[dynamicMember] 16 28
[keyPath] 30 36
[:] 37 37
[WritableKeyPath] 39 53
[<] 54 54
[T] 55 55
[,] 56 56
[U] 58 58
[>] 59 59
[)] 60 60
[->] 62 63
[Lens] 65 68
[<] 69 69
[U] 70 70
[>] 71 71
[{] 73 73
L46
[return] 5 10
[Lens] 12 15
[<] 16 16
[U] 17 17
[>] 18 18
[(] 19 19
L47
[getter:] 9 15
[{] 17 17
[self] 19 22
[.] 23 23
[value] 24 28
[\[] 29 29
[keyPath] 30 36
[:] 37 37
[keyPath] 39 45
[\]] 46 46
[}] 48 48
[,] 49 49
L48
[setter:] 9 15
[{] 17 17
[self] 19 22
[.] 23 23
[value] 24 28
[\[] 29 29
[keyPath] 30 36
[:] 37 37
[keyPath] 39 45
[\]] 46 46
[=] 48 48
[$0] 50 51
[}] 53 53
[)] 54 54
L49
[}] 3 3
L50
[}] 1 1
L53
[struct] 1 6
[Dog] 8 10
[{] 12 12
L54
[var] 3 5
[name] 7 10
[=] 12 12
["Generic dog name"] 14 31
L55
[var] 3 5
[age] 7 9
[=] 11 11
[0] 13 13
L58
[init] 3 6
[(] 7 7
[name] 8 11
[:] 12 12
[String] 14 19
[=] 21 21
["Generic dog name"] 23 40
[,] 41 41
[age] 43 45
[:] 46 46
[Int] 48 50
[=] 52 52
[0] 54 54
[)] 55 55
[{] 57 57
[}] 58 58
L59
[}] 1 1
L61
[let] 1 3
[sparky] 5 10
[=] 12 12
[Dog] 14 16
[(] 17 17
[name] 18 21
[:] 22 22
["Sparky"] 24 31
[)] 32 32
L65
[enum] 1 4
[Foo] 6 8
[{] 10 10
[case] 12 15
[zero] 17 20
[,] 21 21
[one] 23 25
[}] 27 27
L67
[let] 1 3
[foo] 5 7
[:] 8 8
[Foo] 10 12
[?] 13 13
[=] 15 15
[.] 17 17
[zero] 18 21
L69
[switch] 1 6
[foo] 8 10
[{] 12 12
L70
[case] 3 6
[.] 8 8
[zero] 9 12
[:] 13 13
[break] 15 19
L71
[case] 3 6
[.] 8 8
[one] 9 11
[:] 12 12
[break] 14 18
L72
[case] 3 6
[.] 8 8
[none] 9 12
[:] 13 13
[break] 15 19
L73
[}] 1 1
EOF

View File

@ -0,0 +1,111 @@
[Image] or [Truncated image[ Bcol Ecol
L4
[struct] 1 6
[Adder] 8 12
[{] 14 14
L5
[var] 3 5
[base] 7 10
[:] 11 11
[Int] 13 15
L6
[func] 3 6
[callAsFunction] 8 21
[(] 22 22
[_] 23 23
[x] 25 25
[:] 26 26
[Int] 28 30
[)] 31 31
[->] 33 34
[Int] 36 38
[{] 40 40
L7
[return] 5 10
[x] 12 12
[+] 14 14
[base] 16 19
L8
[}] 3 3
L9
[}] 1 1
L10
[var] 1 3
[adder] 5 9
[=] 11 11
[Adder] 13 17
[(] 18 18
[base] 19 22
[:] 23 23
[3] 25 25
[)] 26 26
L11
[adder] 1 5
[(] 6 6
[10] 7 8
[)] 9 9
L14
[struct] 1 6
[User] 8 11
[{] 13 13
L15
[let] 3 5
[email] 7 11
[:] 12 12
[String] 14 19
L16
[let] 3 5
[isAdmin] 7 13
[:] 14 14
[Bool] 16 19
L17
[}] 1 1
L19
[users] 1 5
[.] 6 6
[map] 7 9
[(] 10 10
[\\] 11 11
[.] 12 12
[email] 13 17
[)] 18 18
L22
[struct] 1 6
[Subscriptable] 8 20
[{] 22 22
L23
[subscript] 3 11
[(] 12 12
[x] 13 13
[:] 14 14
[Int] 16 18
[,] 19 19
[y] 21 21
[:] 22 22
[Int] 24 26
[=] 28 28
[0] 30 30
[)] 31 31
[{] 33 33
L24
[...] 5 7
L25
[}] 3 3
L26
[}] 1 1
L28
[let] 1 3
[s] 5 5
[=] 7 7
[Subscriptable] 9 21
[(] 22 22
[)] 23 23
L29
[print] 1 5
[(] 6 6
[s] 7 7
[\[] 8 8
[0] 9 9
[\]] 10 10
[)] 11 11
EOF