Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cardumen & ground-truth testing added & inheritance relations are considered #182

Merged
merged 22 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
150 changes: 134 additions & 16 deletions coming_results/all_instances_found.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,153 @@
{
"instances": [
{
"revision": "covered",
"revision": "cardumen",
"repairability": [
{
"tool-name": "Elixir",
"pattern-name": "Elixir;update_typre_ref",
"tool-name": "Cardumen",
"pattern-name": "Cardumen;expression_replacement",
"Unified_Diff_of-files:": "Starts Below...",
"INSERT:": "import javarepl.expressions.Type;",
"CHANGE_old:": " minRatioPositions.add(i);\r",
"CHANGE_new:": " Precision.equals(entry, 0.0, maxUlps);\r",
"instance_detail": [
{
"pattern_action": "UPD",
"pattern_entity": {
"entity_type": "TypeReference",
"entity_type": "Expression",
"entity_new value": "*",
"entity_role": "*",
"entity_parent": "null"
},
"concrete_change": {
"operator": "UPD",
"src_type": "TypeReference",
"dst_type": "TypeReference",
"src": "javarepl.Type",
"dst": "javarepl.expressions.Type",
"src_parent_type": "Parameter",
"dst_parent_type": "Parameter",
"src_parent": "javarepl.Type expression",
"dst_parent": "javarepl.expressions.Type expression"
},
"line": 204,
"file": "D:\\Daneshgah\\phd-kth\\projects\\commit summarization\\template-based\\coming\\covered"
"src_type": "Invocation",
"dst_type": "Invocation",
"src": "minRatioPositions.add(i)",
"dst": "org.apache.commons.math3.util.Precision.equals(entry, 0.0, maxUlps)",
"src_parent_type": "Block",
"dst_parent_type": "Block",
"src_parent": "{\r\n minRatioPositions.add(i);\r\n}",
"dst_parent": "{\r\n org.apache.commons.math3.util.Precision.equals(entry, 0.0, maxUlps);\r\n}"
},
"line": 104,
"file": "D:\\Daneshgah\\phd-kth\\projects\\commit summarization\\template-based\\coming\\two",
"stats": {
"number_of_src_entities": 16,
"number_of_dst_entities": 26,
"src_entity_types": "[java.lang.Integer, int, java.util.List\u003cjava.lang.Integer\u003e, java.util.List]",
"dst_entity_types": "[org.apache.commons.math3.util.Precision, double, org.apache.commons.math3.optimization.linear.SimplexSolver]"
}
}
]
},
{
"tool-name": "Cardumen",
"pattern-name": "Cardumen;expression_replacement",
"Unified_Diff_of-files:": "Starts Below...",
"CHANGE_old:": " minRatioPositions.add(i);\r",
"CHANGE_new:": " Precision.equals(entry, 0.0, maxUlps);\r",
"instance_detail": [
{
"pattern_action": "UPD",
"pattern_entity": {
"entity_type": "Expression",
"entity_new value": "*",
"entity_role": "*",
"entity_parent": "null"
},
"concrete_change": {
"operator": "UPD",
"src_type": "VariableRead",
"dst_type": "VariableRead",
"src": "minRatioPositions",
"dst": "entry",
"src_parent_type": "Invocation",
"dst_parent_type": "Invocation",
"src_parent": "minRatioPositions.add(i)",
"dst_parent": "org.apache.commons.math3.util.Precision.equals(entry, 0.0, maxUlps)"
},
"line": 104,
"file": "D:\\Daneshgah\\phd-kth\\projects\\commit summarization\\template-based\\coming\\two",
"stats": {
"number_of_src_entities": 6,
"number_of_dst_entities": 3,
"src_entity_types": "[java.lang.Integer, java.util.List\u003cjava.lang.Integer\u003e]",
"dst_entity_types": "[double]"
}
}
]
},
{
"tool-name": "Cardumen",
"pattern-name": "Cardumen;expression_replacement",
"Unified_Diff_of-files:": "Starts Below...",
"CHANGE_old:": " minRatioPositions.add(i);\r",
"CHANGE_new:": " Precision.equals(entry, 0.0, maxUlps);\r",
"instance_detail": [
{
"pattern_action": "UPD",
"pattern_entity": {
"entity_type": "Expression",
"entity_new value": "*",
"entity_role": "*",
"entity_parent": "null"
},
"concrete_change": {
"operator": "UPD",
"src_type": "Invocation",
"dst_type": "Invocation",
"src": "minRatioPositions.add(i)",
"dst": "org.apache.commons.math3.util.Precision.equals(entry, 0.0, maxUlps)",
"src_parent_type": "Block",
"dst_parent_type": "Block",
"src_parent": "{\r\n minRatio \u003d ratio;\r\n minRatioPositions \u003d new java.util.ArrayList\u003cjava.lang.Integer\u003e();\r\n minRatioPositions.add(i);\r\n}",
"dst_parent": "{\r\n minRatio \u003d ratio;\r\n minRatioPositions \u003d new java.util.ArrayList\u003cjava.lang.Integer\u003e();\r\n org.apache.commons.math3.util.Precision.equals(entry, 0.0, maxUlps);\r\n}"
},
"line": 108,
"file": "D:\\Daneshgah\\phd-kth\\projects\\commit summarization\\template-based\\coming\\two",
"stats": {
"number_of_src_entities": 16,
"number_of_dst_entities": 26,
"src_entity_types": "[java.lang.Integer, int, java.util.List\u003cjava.lang.Integer\u003e, java.util.List]",
"dst_entity_types": "[org.apache.commons.math3.util.Precision, double, org.apache.commons.math3.optimization.linear.SimplexSolver]"
}
}
]
},
{
"tool-name": "Cardumen",
"pattern-name": "Cardumen;expression_replacement",
"Unified_Diff_of-files:": "Starts Below...",
"CHANGE_old:": " minRatioPositions.add(i);\r",
"CHANGE_new:": " Precision.equals(entry, 0.0, maxUlps);\r",
"instance_detail": [
{
"pattern_action": "UPD",
"pattern_entity": {
"entity_type": "Expression",
"entity_new value": "*",
"entity_role": "*",
"entity_parent": "null"
},
"concrete_change": {
"operator": "UPD",
"src_type": "VariableRead",
"dst_type": "VariableRead",
"src": "minRatioPositions",
"dst": "entry",
"src_parent_type": "Invocation",
"dst_parent_type": "Invocation",
"src_parent": "minRatioPositions.add(i)",
"dst_parent": "org.apache.commons.math3.util.Precision.equals(entry, 0.0, maxUlps)"
},
"line": 108,
"file": "D:\\Daneshgah\\phd-kth\\projects\\commit summarization\\template-based\\coming\\two",
"stats": {
"number_of_src_entities": 6,
"number_of_dst_entities": 3,
"src_entity_types": "[java.lang.Integer, java.util.List\u003cjava.lang.Integer\u003e]",
"dst_entity_types": "[double]"
}
}
]
}
Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<dependency>
<groupId>fr.inria.gforge.spoon.labs </groupId>
<artifactId>gumtree-spoon-ast-diff</artifactId>
<version>1.20</version>
<version>1.21</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -154,6 +154,12 @@
<version>4.0</version>
</dependency>

<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
</dependency>

</dependencies>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import fr.inria.coming.utils.EntityTypesInfoResolver;
import org.apache.log4j.Logger;

import com.github.gumtreediff.actions.model.Action;
Expand Down Expand Up @@ -449,7 +450,7 @@ private List<MatchingEntity> matchElements(Operation affectedOperation, PatternE
int i_levels = 1;
// Scale the parent hierarchy and check types.
while (currentNodeFromAction != null && i_levels <= parentLevel) {
String typeOfNode = getNodeLabelFromCtElement(currentNodeFromAction);
String typeOfNode = EntityTypesInfoResolver.getNodeLabelFromCtElement(currentNodeFromAction);
String valueOfNode = currentNodeFromAction.toString();
String roleInParent = (currentNodeFromAction.getRoleInParent() != null)
? currentNodeFromAction.getRoleInParent().toString().toLowerCase()
Expand All @@ -458,7 +459,9 @@ private List<MatchingEntity> matchElements(Operation affectedOperation, PatternE
String patternEntityValue = (matchnewvalue) ? parentEntity.getNewValue() : parentEntity.getOldValue();
if ( // type of element
("*".equals(parentEntity.getEntityType())
|| (typeOfNode != null && typeOfNode.equals(parentEntity.getEntityType())))
// || (typeOfNode != null && typeOfNode.equals(parentEntity.getEntityType())))
|| (typeOfNode != null &&
EntityTypesInfoResolver.getInstance().isAChildOf(typeOfNode, parentEntity.getEntityType())))
///
&&
// value of element
Expand Down Expand Up @@ -508,18 +511,4 @@ public String getTypeLabel(PatternAction patternAction) {
return patternAction.getAffectedEntity().getEntityType();
}

/**
* The label of a CtElement is the simple name of the class without the CT
* prefix.
*
* @param element
* @return
*/
public String getNodeLabelFromCtElement(CtElement element) {
String typeFromCt = element.getClass().getSimpleName();
if (typeFromCt.trim().isEmpty())
return typeFromCt;
return typeFromCt.substring(2, typeFromCt.length() - 4);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import fr.inria.coming.core.entities.RevisionResult;
import fr.inria.coming.core.entities.interfaces.IOutput;
import fr.inria.coming.main.ComingProperties;
import fr.inria.coming.repairability.models.InstanceStats;
import gumtree.spoon.diff.operations.Operation;
import org.json.simple.JSONObject;

public class JSonPatternInstanceOutput implements IOutput {

Expand Down Expand Up @@ -149,6 +151,15 @@ public static JsonObject getJSONFromOperator(Operation operation) {
return op;
}

public static JsonObject getJSONFromInstanceStats(InstanceStats stats){
JsonObject is = new JsonObject();
is.addProperty("number_of_src_entities", stats.getNumberOfSrcEntities());
is.addProperty("number_of_dst_entities", stats.getNumberOfDstEntities());
is.addProperty("src_entity_types", stats.getSrcEntityTypes().toString());
is.addProperty("dst_entity_types", stats.getDstEntityTypes().toString());
return is;
}

private static String clean(String simpleName) {

return simpleName.substring(2, simpleName.length() - 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import fr.inria.coming.core.entities.RevisionResult;
import fr.inria.coming.core.entities.output.JSonPatternInstanceOutput;
import fr.inria.coming.main.ComingProperties;
import fr.inria.coming.repairability.models.InstanceStats;
import gumtree.spoon.diff.Diff;
import gumtree.spoon.diff.operations.Operation;
import org.apache.log4j.Logger;

Expand All @@ -29,52 +31,49 @@ public void getInstancesOfRevision(RevisionResult revisionResult, JsonArray inst
}

PatternInstancesFromRevision result = null;
if(ComingProperties.getPropertyBoolean("print_only_repair_results")) {
if (ComingProperties.getPropertyBoolean("print_only_repair_results")) {
result = (PatternInstancesFromRevision) revisionResult.getResultFromClass(RepairabilityAnalyzer.class);
}
else {
} else {
result = (PatternInstancesFromRevision) revisionResult.getResultFromClass(PatternInstanceAnalyzer.class);
}
for (PatternInstancesFromDiff pi : result.getInfoPerDiff()) {
if (pi.getInstances().size() > 0) {

Diff diff = pi.getDiff();

JsonObject instance = new JsonObject();

instance.addProperty("revision", revisionIdentifier.toString());

log.info("\n--------\ncommit with instance:\n " + revisionIdentifier);
// System.out.println("\n--------\ncommit with instance:\n " + revisionIdentifier);
// log.info(pi.getInstances());
// System.out.println(pi.getInstances());
// System.out.println("\n--------\ncommit with instance:\n " + revisionIdentifier);
// log.info(pi.getInstances());
// System.out.println(pi.getInstances());

JsonArray repair_tools = new JsonArray();
for (ChangePatternInstance instancePattern : pi.getInstances()) {

JsonObject repair = new JsonObject();
repair.addProperty("tool-name", (instancePattern.getPattern().getName().split(File.pathSeparator)[0]));
repair.addProperty("pattern-name", (instancePattern.getPattern().getName()));
repair.addProperty("Unified_Diff_of-files:","Starts Below...");

// System.out.println("result.getRow_list()");
// System.out.println(result.getRow_list());
for (DiffRow row : result.getRow_list()) {
switch (row.getTag()) {
case INSERT:
repair.addProperty("INSERT:",row.getNewLine());
break;
case DELETE:
repair.addProperty("DELETE:",row.getOldLine());
break;
case CHANGE:
repair.addProperty("CHANGE_old:",row.getOldLine());
repair.addProperty("CHANGE_new:",row.getNewLine());
break;
}
}




repair.addProperty("Unified_Diff_of-files:", "Starts Below...");

// System.out.println("result.getRow_list()");
// System.out.println(result.getRow_list());
for (DiffRow row : result.getRow_list()) {
switch (row.getTag()) {
case INSERT:
repair.addProperty("INSERT:", row.getNewLine());
break;
case DELETE:
repair.addProperty("DELETE:", row.getOldLine());
break;
case CHANGE:
repair.addProperty("CHANGE_old:", row.getOldLine());
repair.addProperty("CHANGE_new:", row.getNewLine());
break;
}
}

JsonArray ops = new JsonArray();

Expand All @@ -98,6 +97,11 @@ public void getInstancesOfRevision(RevisionResult revisionResult, JsonArray inst
}
}
}

if(isRootOperation(op, diff)){
InstanceStats instanceStats = getOperationStats(op);
opjson.add("stats", getJSONFromInstanceStats(instanceStats));
}
ops.add(opjson);
}

Expand All @@ -111,4 +115,26 @@ public void getInstancesOfRevision(RevisionResult revisionResult, JsonArray inst
}
}
}

private boolean isRootOperation(Operation op, Diff diff) {
for(Operation diffOp : diff.getRootOperations()){
if(diffOp.getAction().equals(op.getAction())){
return true;
}
}
return false;
}

private InstanceStats getOperationStats(Operation operation) {
InstanceStats stats = new InstanceStats();
if (operation.getSrcNode() != null) {
stats.setSrcEntityTypes(operation.getSrcNode().getReferencedTypes());
stats.setNumberOfSrcEntities(operation.getSrcNode().getElements(null).size());
}
if (operation.getDstNode() != null) {
stats.setDstEntityTypes(operation.getDstNode().getReferencedTypes());
stats.setNumberOfDstEntities(operation.getDstNode().getElements(null).size());
}
return stats;
}
}
Loading