-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: rename post_dspot package to prettifier * feat: remove redundant casts * pom: rename DSpot to DSpot Core * ci: add now a travis job for dspot-pretiffier * test: remove test resources that are unused * test: add the sample properties
- Loading branch information
Showing
85 changed files
with
214 additions
and
1,826 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
source /opt/jdk_switcher/jdk_switcher.sh | ||
|
||
jdk_switcher use openjdk8 & mvn -Djava.src.version=1.8 test -f dspot-prettifier/pom.xml |
59 changes: 59 additions & 0 deletions
59
dspot-prettifier/src/main/java/eu/stamp_project/prettifier/RedundantCastRemover.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,59 @@ | ||
package eu.stamp_project.prettifier; | ||
|
||
import eu.stamp_project.test_framework.TestFramework; | ||
import spoon.reflect.code.CtExpression; | ||
import spoon.reflect.code.CtInvocation; | ||
import spoon.reflect.declaration.CtMethod; | ||
import spoon.reflect.reference.CtTypeReference; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* created by Benjamin DANGLOT | ||
* [email protected] | ||
* on 04/02/19 | ||
*/ | ||
public class RedundantCastRemover { | ||
|
||
|
||
public CtMethod<?> remove(CtMethod<?> testMethod) { | ||
final List<CtInvocation<?>> assertions = testMethod.getElements(TestFramework.ASSERTIONS_FILTER); | ||
for (CtInvocation<?> assertion : assertions) { | ||
this.remove(assertion); | ||
} | ||
return testMethod; | ||
} | ||
|
||
private void remove(CtInvocation<?> assertion) { | ||
final CtExpression<?> actualValue = assertion.getArguments().get(assertion.getArguments().size() - 1); | ||
final CtExpression<?> expectedValue = assertion.getArguments().get(assertion.getArguments().size() - 2); | ||
// top cast compared to the expected value | ||
if (!actualValue.getTypeCasts().isEmpty() && | ||
actualValue.getTypeCasts().get(0).equals(expectedValue.getType())) { | ||
actualValue.getTypeCasts().remove(0); | ||
} | ||
// inner casts that can be removed | ||
removeCastInvocations(actualValue); | ||
} | ||
|
||
private void removeCastInvocations(CtExpression<?> current) { | ||
while (current instanceof CtInvocation<?>) { | ||
current = ((CtInvocation) current).getTarget(); | ||
if (!current.getTypeCasts().isEmpty() && | ||
matchTypes(current.getTypeCasts().get(0), current.getType())) { | ||
current.getTypeCasts().remove(0); | ||
} | ||
} | ||
} | ||
|
||
private boolean matchTypes(CtTypeReference<?> toBeMatched, CtTypeReference<?> type) { | ||
if (type == null) { | ||
return false; | ||
} else if (toBeMatched.equals(type)) { | ||
return true; | ||
} else { | ||
return matchTypes(toBeMatched, type.getSuperclass()); | ||
} | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...t/post_dspot/code2vec/builder/Cloner.java → ...t/prettifier/code2vec/builder/Cloner.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
2 changes: 1 addition & 1 deletion
2
...ect/post_dspot/code2vec/builder/Main.java → ...ect/prettifier/code2vec/builder/Main.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
2 changes: 1 addition & 1 deletion
2
...e2vec/builder/NumbersOfMethodsPerSet.java → ...e2vec/builder/NumbersOfMethodsPerSet.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
2 changes: 1 addition & 1 deletion
2
...t/post_dspot/code2vec/builder/Output.java → ...t/prettifier/code2vec/builder/Output.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
2 changes: 1 addition & 1 deletion
2
...t/post_dspot/code2vec/builder/Reader.java → ...t/prettifier/code2vec/builder/Reader.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
2 changes: 1 addition & 1 deletion
2
...t/post_dspot/code2vec/builder/Report.java → ...t/prettifier/code2vec/builder/Report.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
2 changes: 1 addition & 1 deletion
2
...ode2vec/builder/TestMethodsExtractor.java → ...ode2vec/builder/TestMethodsExtractor.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
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
2 changes: 1 addition & 1 deletion
2
..._dspot/minimization/GeneralMinimizer.java → ...tifier/minimization/GeneralMinimizer.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
2 changes: 1 addition & 1 deletion
2
...ct/post_dspot/minimization/Minimizer.java → ...ct/prettifier/minimization/Minimizer.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
2 changes: 1 addition & 1 deletion
2
...spot/minimization/PitMutantMinimizer.java → ...fier/minimization/PitMutantMinimizer.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
54 changes: 54 additions & 0 deletions
54
dspot-prettifier/src/test/java/eu/stamp_project/prettifier/RedundantCastRemoverTest.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,54 @@ | ||
package eu.stamp_project.prettifier; | ||
|
||
import org.junit.Test; | ||
import spoon.Launcher; | ||
import spoon.reflect.declaration.CtMethod; | ||
import spoon.reflect.factory.Factory; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* created by Benjamin DANGLOT | ||
* [email protected] | ||
* on 04/02/19 | ||
*/ | ||
public class RedundantCastRemoverTest { | ||
|
||
@Test | ||
public void test() { | ||
|
||
/* | ||
This test that we can remove some redundant cast. | ||
The last statement should keeps its cast | ||
*/ | ||
|
||
Launcher launcher = new Launcher(); | ||
launcher.addInputResource("src/test/java/eu/stamp_project/resources/AmplifiedTest.java"); | ||
launcher.buildModel(); | ||
|
||
final Factory factory = launcher.getFactory(); | ||
final CtMethod<?> redundantCast = factory.Class().get("eu.stamp_project.resources.AmplifiedTest") | ||
.getMethodsByName("redundantCast").get(0); | ||
|
||
final RedundantCastRemover redundantCastRemover = new RedundantCastRemover(); | ||
final CtMethod<?> amplifiedTestWithoutRedundantCast = redundantCastRemover.remove(redundantCast); | ||
assertEquals(expected, | ||
amplifiedTestWithoutRedundantCast.getBody().toString() | ||
); | ||
} | ||
|
||
private static final String expected = "{\n" + | ||
" final eu.stamp_project.resources.AmplifiedTest amplifiedTest = new eu.stamp_project.resources.AmplifiedTest();\n" + | ||
" final eu.stamp_project.resources.AmplifiedTest.MyObject myObject = new eu.stamp_project.resources.AmplifiedTest.MyObject();\n" + | ||
" // should be removed\n" + | ||
" org.junit.Assert.assertEquals(0, amplifiedTest.getInt());\n" + | ||
" org.junit.Assert.assertEquals(0, amplifiedTest.getInt());\n" + | ||
" org.junit.Assert.assertEquals(0, myObject.getInt());\n" + | ||
" org.junit.Assert.assertEquals(0, myObject.getMyInternalObject().getInt());\n" + | ||
" org.junit.Assert.assertEquals(0, myObject.getMyInternalObject().getMySecondIntegernalObject().getInt());\n" + | ||
" org.junit.Assert.assertEquals(0, myObject.getMyInternalObject().getMySecondIntegernalObject().getInt());\n" + | ||
" // should not be removed\n" + | ||
" org.junit.Assert.assertEquals(0, ((eu.stamp_project.resources.AmplifiedTest.MySecondInternalObject) (myObject.getMyInternalObject().getMySecondIntegernalObject().getObject())).getSecondInt());\n" + | ||
"}"; | ||
} |
2 changes: 1 addition & 1 deletion
2
...pot/minimization/ChangeMinimizerTest.java → ...ier/minimization/ChangeMinimizerTest.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
2 changes: 1 addition & 1 deletion
2
...ot/minimization/GeneralMinimizerTest.java → ...er/minimization/GeneralMinimizerTest.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
68 changes: 68 additions & 0 deletions
68
dspot-prettifier/src/test/java/eu/stamp_project/resources/AmplifiedTest.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,68 @@ | ||
package eu.stamp_project.resources; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* created by Benjamin DANGLOT | ||
* [email protected] | ||
* on 04/02/19 | ||
*/ | ||
public class AmplifiedTest { | ||
|
||
public class MyObject { | ||
public MyInternalObject getMyInternalObject() { | ||
return new MyInternalObject(); | ||
} | ||
|
||
public int getInt() { | ||
return 0; | ||
} | ||
} | ||
|
||
public class MyInternalObject { | ||
public int getInt() { | ||
return 0; | ||
} | ||
|
||
public MySecondInternalObject getMySecondIntegernalObject() { | ||
return new MySecondInternalObject(); | ||
} | ||
} | ||
|
||
public class MySecondInternalObject extends MyObject { | ||
public MyObject getObject() { | ||
return this; | ||
} | ||
|
||
public int getSecondInt() { | ||
return 0; | ||
} | ||
} | ||
|
||
public int getInt() { | ||
return 0; | ||
} | ||
|
||
public Integer getInteger() { | ||
return 0; | ||
} | ||
|
||
@Test | ||
public void redundantCast() { | ||
final AmplifiedTest amplifiedTest = new AmplifiedTest(); | ||
final MyObject myObject = new MyObject(); | ||
|
||
// should be removed | ||
assertEquals(0, (int) ((AmplifiedTest) amplifiedTest).getInt()); | ||
assertEquals(0, (int) amplifiedTest.getInt()); | ||
assertEquals(0, (int) ((MyObject) myObject).getInt()); | ||
assertEquals(0, (int) ((MyInternalObject) ((MyObject) myObject).getMyInternalObject()).getInt()); | ||
assertEquals(0, (int) ((MySecondInternalObject) ((MyInternalObject) ((MyObject) myObject).getMyInternalObject()).getMySecondIntegernalObject()).getInt()); | ||
assertEquals(0, (int) ((MyObject) ((MyInternalObject) ((MyObject) myObject).getMyInternalObject()).getMySecondIntegernalObject()).getInt()); | ||
|
||
// should not be removed | ||
assertEquals(0, ((MySecondInternalObject) myObject.getMyInternalObject().getMySecondIntegernalObject().getObject()).getSecondInt()); | ||
} | ||
} |
77 changes: 0 additions & 77 deletions
77
dspot-prettifier/src/test/resources/sample/.dspot__junit5_pom.xml
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
dspot-prettifier/src/test/resources/sample/sample.properties
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,11 @@ | ||
project=src/test/resources/sample/ | ||
src=src/main/java | ||
testSrc=src/test/java | ||
testResources=src/test/resources | ||
outputDirectory=target/trash/ | ||
filter=fr.inria.sample.* | ||
systemProperties=admin=toto,passwd=tata | ||
excludedClasses=fr.inria.filter.failing.* | ||
excludedTestCases=failingTestCase | ||
jvmArgs=-Xmx2048m,-Xms1024m,-Dis.admin.user=admin,-Dis.admin.passwd=$2pRSid# | ||
pitVersion=1.4.0 |
Oops, something went wrong.