-
Notifications
You must be signed in to change notification settings - Fork 4
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
17 changed files
with
254 additions
and
39 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
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
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
51 changes: 51 additions & 0 deletions
51
generator/src/main/java/fr/inria/diversify/runner/ApplyMultiTransRunner.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,51 @@ | ||
package fr.inria.diversify.runner; | ||
|
||
import fr.inria.diversify.statistic.SinglePointSessionResults; | ||
import fr.inria.diversify.transformation.AddMethodInvocation; | ||
import fr.inria.diversify.transformation.MultiSwapSubType; | ||
import fr.inria.diversify.transformation.SwapSubType; | ||
import fr.inria.diversify.transformation.Transformation; | ||
import fr.inria.diversify.util.Log; | ||
import spoon.reflect.declaration.CtMethod; | ||
import spoon.reflect.declaration.CtParameter; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* Created by nharrand on 09/10/17. | ||
*/ | ||
public class ApplyMultiTransRunner extends SinglePointRunner { | ||
public ApplyMultiTransRunner(InputConfiguration inputConfiguration, String projectDir, String srcDir) { | ||
super(inputConfiguration, projectDir, srcDir); | ||
} | ||
|
||
|
||
@Override | ||
public void run(int n) throws Exception { | ||
int i = new Random().nextInt(n-1); | ||
Set<SwapSubType> transformations = new HashSet<>(); | ||
while (transQuery.hasNextTransformation() && i >= 0) { | ||
transformations.add((SwapSubType) transQuery.query()); | ||
} | ||
Transformation trans = new MultiSwapSubType(transformations); | ||
try { | ||
applyTransformation(trans); | ||
int status; | ||
status = runTest(tmpDir); | ||
} catch (Exception e) { | ||
trans.setStatus(-2); | ||
tryRestore(trans, e); | ||
} | ||
} | ||
|
||
protected void applyTransformation(Transformation trans) throws Exception { | ||
if(withParent) { | ||
if(acceptedErrors) { | ||
builder.setAcceptedErrors(trans.getParent().getFailures()); | ||
} | ||
trans.applyWithParent(tmpDir + "/" + sourceDir); | ||
} else { | ||
trans.apply(tmpDir + "/" + sourceDir); | ||
} | ||
} | ||
} |
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
106 changes: 106 additions & 0 deletions
106
generator/src/main/java/fr/inria/diversify/transformation/MultiSwapSubType.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,106 @@ | ||
package fr.inria.diversify.transformation; | ||
|
||
import fr.inria.diversify.transformation.exception.RestoreTransformationException; | ||
import fr.inria.diversify.util.Log; | ||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import spoon.compiler.Environment; | ||
import spoon.reflect.code.CtStatement; | ||
import spoon.reflect.cu.SourcePosition; | ||
import spoon.reflect.declaration.CtType; | ||
import spoon.reflect.factory.Factory; | ||
import spoon.reflect.visitor.DefaultJavaPrettyPrinter; | ||
import spoon.support.JavaOutputProcessor; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Created by nharrand on 09/10/17. | ||
*/ | ||
public class MultiSwapSubType extends Transformation { | ||
Set<SwapSubType> transformations; | ||
|
||
public MultiSwapSubType(Set<SwapSubType> transformations) { | ||
this.transformations = transformations; | ||
} | ||
|
||
@Override | ||
public String getTransformationString() throws Exception { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void apply(String srcDir) throws Exception { | ||
try { | ||
for(SwapSubType t : transformations) { | ||
if(t.newCall == null) t.newCall = t.newCallSnippet; | ||
t.tp.replace(t.newCall); | ||
} | ||
printJavaFile(srcDir); | ||
} catch (Exception e) { | ||
throw new RestoreTransformationException("", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void applyWithParent(String srcDir) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void restore(String srcDir) throws RestoreTransformationException { | ||
|
||
try { | ||
transformations.stream() | ||
.forEach(t -> t.newCall.replace((CtStatement) t.tp)); | ||
printJavaFile(srcDir); | ||
|
||
} catch (Exception e) { | ||
throw new RestoreTransformationException("", e); | ||
} | ||
} | ||
|
||
@Override | ||
public List<SourcePosition> getPositions() { | ||
return transformations.stream().map(t -> t.getPosition()).collect(Collectors.toList()); | ||
} | ||
|
||
public void printJavaFile(String directory) throws IOException { | ||
if(!transformations.isEmpty()) { | ||
|
||
Factory factory = transformations.iterator().next().getPosition().getCompilationUnit().getMainType().getFactory(); | ||
Environment env = factory.getEnvironment(); | ||
|
||
JavaOutputProcessor processor = new JavaOutputProcessor(new File(directory), new DefaultJavaPrettyPrinter(env)); | ||
processor.setFactory(factory); | ||
transformations.stream() | ||
.map(t -> t.getPosition().getCompilationUnit().getMainType()) | ||
.distinct() | ||
.forEach(t -> processor.createJavaFile(t)); | ||
} | ||
} | ||
|
||
@Override | ||
public JSONObject toJSONObject() throws JSONException { | ||
JSONObject res = super.toJSONObject(); | ||
JSONArray list = new JSONArray(); | ||
for(SwapSubType t : transformations) { | ||
JSONObject object = super.toJSONObject(); | ||
if (t.newCall != null) object.put("newCall", t.newCall.toString()); | ||
else object.put("newCall", t.newCallSnippet.toString()); | ||
JSONObject tpJSON = new JSONObject(); | ||
tpJSON.put("position", t.tp.getParent(CtType.class).getQualifiedName() + ":" + t.tp.getPosition().getLine()); | ||
tpJSON.put("type", t.tp.getClass().getName()); | ||
tpJSON.put("sourcecode", t.tp.toString()); | ||
object.put("transplantationPoint", tpJSON); | ||
} | ||
res.put("type", "MultiSwapSubType"); | ||
res.put("transformations", list); | ||
return res; | ||
} | ||
} |
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
Oops, something went wrong.