-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
163 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ry/src/test/java/com/example/staticinitializers/delayedexecution/EnumListOfSuppliers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.staticinitializers.delayedexecution; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
public enum EnumListOfSuppliers { | ||
A(EnumListOfSuppliers::canMutate), B(EnumListOfSuppliers::canMutate); | ||
|
||
private final List<Supplier<String>> supplier; | ||
|
||
EnumListOfSuppliers(Supplier<String> supplier) { | ||
this.supplier = asList(supplier); | ||
} | ||
|
||
private static String canMutate() { | ||
return "mutate me"; // mutate | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
.../src/test/java/com/example/staticinitializers/delayedexecution/StaticListOfFunctions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.staticinitializers.delayedexecution; | ||
|
||
import java.util.function.Function; | ||
import java.util.List; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
public class StaticListOfFunctions { | ||
public static final List<Function<Integer, Integer>> FUNCTIONS = | ||
asList(StaticListOfFunctions::canMutate, StaticListOfFunctions::canAlsoMutate); | ||
|
||
private static Integer canMutate(Integer a) { | ||
return a + 1; | ||
} | ||
|
||
private static Integer canAlsoMutate(Integer a) { | ||
return a + 2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
pitest/src/main/java/org/pitest/bytecode/SignatureParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.pitest.bytecode; | ||
|
||
import org.objectweb.asm.signature.SignatureReader; | ||
import org.objectweb.asm.signature.SignatureVisitor; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class SignatureParser { | ||
|
||
/** | ||
* Extracts all types referenced in a field generic signature | ||
*/ | ||
public static Set<String> extractTypes(String signature) { | ||
if (signature == null) { | ||
return Collections.emptySet(); | ||
} | ||
|
||
Set<String> types = new HashSet<>(); | ||
SignatureReader r = new SignatureReader(signature); | ||
SignatureVisitor visitor = new SignatureVisitor(ASMVersion.asmVersion()) { | ||
@Override | ||
public void visitClassType(String name) { | ||
types.add(name); | ||
} | ||
}; | ||
r.acceptType(visitor); | ||
return types; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
pitest/src/test/java/org/pitest/bytecode/SignatureParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.pitest.bytecode; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SignatureParserTest { | ||
|
||
@Test | ||
public void noTypesForNullSignature() { | ||
assertThat(SignatureParser.extractTypes(null)).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void parsesSupplierOfStrings() { | ||
String signature = "Ljava/util/function/Supplier<Ljava/lang/String;>;"; | ||
assertThat(SignatureParser.extractTypes(signature)).containsExactlyInAnyOrder("java/util/function/Supplier", "java/lang/String"); | ||
} | ||
|
||
@Test | ||
public void parsesListsOfFunctions() { | ||
String signature = "Ljava/util/List<Ljava/util/function/Function<Ljava/lang/Integer;Ljava/lang/Integer;>;>;"; | ||
assertThat(SignatureParser.extractTypes(signature)).containsExactlyInAnyOrder("java/util/List", "java/util/function/Function", "java/lang/Integer"); | ||
} | ||
} |