Skip to content

Commit 295e335

Browse files
authored
bump to Spoon 1.73 (#271)
1 parent efc89bf commit 295e335

File tree

7 files changed

+34
-40
lines changed

7 files changed

+34
-40
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<dependency>
7979
<groupId>fr.inria.gforge.spoon.labs </groupId>
8080
<artifactId>gumtree-spoon-ast-diff</artifactId>
81-
<version>1.70</version>
81+
<version>1.73</version>
8282
</dependency>
8383

8484
<dependency>

src/main/java/fr/inria/coming/changeminer/analyzer/instancedetector/DetectorChangePatternInstanceEngine.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import gumtree.spoon.diff.operations.UpdateOperation;
3232
import spoon.reflect.declaration.CtElement;
3333

34+
import static fr.inria.coming.codefeatures.codeanalyze.BinaryOperatorAnalyzer.getSafeStringRepr;
35+
3436
/**
3537
*
3638
* @author Matias Martinez
@@ -451,7 +453,7 @@ private List<MatchingEntity> matchElements(Operation affectedOperation, PatternE
451453
// Scale the parent hierarchy and check types.
452454
while (currentNodeFromAction != null && i_levels <= parentLevel) {
453455
String typeOfNode = EntityTypesInfoResolver.getNodeLabelFromCtElement(currentNodeFromAction);
454-
String valueOfNode = currentNodeFromAction.toString();
456+
String valueOfNode = getSafeStringRepr(currentNodeFromAction);
455457
String roleInParent = (currentNodeFromAction.getRoleInParent() != null)
456458
? currentNodeFromAction.getRoleInParent().toString().toLowerCase()
457459
: "";

src/main/java/fr/inria/coming/codefeatures/codeanalyze/AbstractCodeAnalyzer.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import spoon.reflect.visitor.filter.LineFilter;
4242
import spoon.reflect.visitor.filter.TypeFilter;
4343

44-
import static fr.inria.coming.codefeatures.codeanalyze.BinaryOperatorAnalyzer.getStringRepr;
44+
import static fr.inria.coming.codefeatures.codeanalyze.BinaryOperatorAnalyzer.getSafeStringRepr;
4545

4646
public abstract class AbstractCodeAnalyzer {
4747

@@ -297,8 +297,8 @@ public boolean checkNormalGuardCondition(CtExpression condition) {
297297
if (binOp != null && binOp.size() > 0) {
298298

299299
for (CtBinaryOperator ctBinaryOperator : binOp) {
300-
if (getStringRepr(ctBinaryOperator.getRightHandOperand()).equals("null")
301-
|| getStringRepr(ctBinaryOperator.getLeftHandOperand()).equals("null")) {
300+
if (getSafeStringRepr(ctBinaryOperator.getRightHandOperand()).equals("null")
301+
|| getSafeStringRepr(ctBinaryOperator.getLeftHandOperand()).equals("null")) {
302302

303303
return false;
304304
}
@@ -351,8 +351,8 @@ public boolean checkNullCheckGuardCondition(CtExpression condition) {
351351
if (binOp != null && binOp.size() > 0) {
352352

353353
for (CtBinaryOperator ctBinaryOperator : binOp) {
354-
if (!getStringRepr(ctBinaryOperator.getRightHandOperand()).equals("null")
355-
&& !getStringRepr(ctBinaryOperator.getLeftHandOperand()).equals("null")) {
354+
if (!getSafeStringRepr(ctBinaryOperator.getRightHandOperand()).equals("null")
355+
&& !getSafeStringRepr(ctBinaryOperator.getLeftHandOperand()).equals("null")) {
356356

357357
return false;
358358
}

src/main/java/fr/inria/coming/codefeatures/codeanalyze/BinaryOperatorAnalyzer.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private void analyzeBinaryWhetehrMathRoot (CtBinaryOperator operatorunderstudy,
8989
whethermathroot =false;
9090
}
9191

92-
writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+getStringRepr(operatorunderstudy), CodeFeatures.O5_IS_MATH_ROOT,
92+
writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+ getSafeStringRepr(operatorunderstudy), CodeFeatures.O5_IS_MATH_ROOT,
9393
whethermathroot, "FEATURES_BINARYOPERATOR");
9494
}
9595

@@ -122,7 +122,7 @@ private void analyzeBinaryLogicalOperator(CtBinaryOperator operatorunderstudy, i
122122
}
123123
}
124124

125-
writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+getStringRepr(operatorunderstudy), CodeFeatures.O2_LOGICAL_CONTAIN_NOT,
125+
writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+ getSafeStringRepr(operatorunderstudy), CodeFeatures.O2_LOGICAL_CONTAIN_NOT,
126126
whethercontainnotoperator, "FEATURES_BINARYOPERATOR");
127127

128128
}
@@ -167,7 +167,7 @@ private void analyzeBinaryOperatorKind(CtBinaryOperator operatorunderstudy, int
167167
for(int index=0; index<binoperatortype.size(); index++) {
168168
CodeFeatures cerainfeature = binoperatortype.get(index);
169169

170-
final String operatorunderstudyStr = getStringRepr(operatorunderstudy);
170+
final String operatorunderstudyStr = getSafeStringRepr(operatorunderstudy);
171171
if(cerainfeature.toString().endsWith(operatorstring.toUpperCase()))
172172
writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+ operatorunderstudyStr, cerainfeature,
173173
true, "FEATURES_BINARYOPERATOR");
@@ -176,7 +176,7 @@ else writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+ operatorund
176176
}
177177
}
178178

179-
public static String getStringRepr(CtElement operatorunderstudy) {
179+
public static String getSafeStringRepr(CtElement element) {
180180
// workaround for
181181
// at spoon.support.reflect.reference.CtTypeReferenceImpl.getAccessType(CtTypeReferenceImpl.java:774)
182182
// at spoon.reflect.visitor.ImportAnalyzer$ScannerListener.enter(ImportAnalyzer.java:135)
@@ -214,7 +214,7 @@ public static String getStringRepr(CtElement operatorunderstudy) {
214214
// at java.base/java.lang.StringConcatHelper.stringOf(StringConcatHelper.java:453)
215215

216216
try {
217-
return operatorunderstudy.toString();
217+
return element.toString();
218218
} catch (Exception e) {
219219
// fake string, please open an issue if this is a problem
220220
return "FIXME_oefa";
@@ -229,12 +229,12 @@ private void analyzeBinaryOperatorInvolveNull(CtBinaryOperator operatorunderstud
229229
CtExpression leftexpression = operatorunderstudy.getLeftHandOperand();
230230
CtExpression rightexpression = operatorunderstudy.getRightHandOperand();
231231

232-
final String leftStr = getStringRepr(leftexpression);
233-
final String rightStr = getStringRepr(rightexpression);
232+
final String leftStr = getSafeStringRepr(leftexpression);
233+
final String rightStr = getSafeStringRepr(rightexpression);
234234
if(leftStr.trim().equals("null") || rightStr.trim().equals("null"))
235235
whethercontainnull = true;
236236

237-
writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+getStringRepr(operatorunderstudy), CodeFeatures.O3_CONTAIN_NULL,
237+
writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+ getSafeStringRepr(operatorunderstudy), CodeFeatures.O3_CONTAIN_NULL,
238238
whethercontainnull, "FEATURES_BINARYOPERATOR");
239239

240240
}
@@ -248,16 +248,16 @@ private void analyzeBinaryOperatorInvolve01 (CtBinaryOperator operatorunderstudy
248248
CtExpression leftexpression = operatorunderstudy.getLeftHandOperand();
249249
CtExpression rightexpression = operatorunderstudy.getRightHandOperand();
250250

251-
final String leftStr = getStringRepr(leftexpression);
252-
final String rightStr = getStringRepr(rightexpression);
251+
final String leftStr = getSafeStringRepr(leftexpression);
252+
final String rightStr = getSafeStringRepr(rightexpression);
253253
if(leftStr.trim().equals("0") || leftStr.trim().equals("0.0") ||
254254
leftStr.trim().equals("1.0") || leftStr.trim().equals("1")
255255
|| rightStr.trim().equals("0") || rightStr.trim().equals("0.0") ||
256256
rightStr.trim().equals("1.0") || rightStr.trim().equals("1")
257257
|| leftStr.trim().endsWith("1") || rightStr.trim().endsWith("1"))
258258
whethercontain01 = true;
259259

260-
writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+getStringRepr(operatorunderstudy), CodeFeatures.O3_CONTAIN_01,
260+
writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+ getSafeStringRepr(operatorunderstudy), CodeFeatures.O3_CONTAIN_01,
261261
whethercontain01, "FEATURES_BINARYOPERATOR");
262262
}
263263

@@ -274,7 +274,7 @@ private void analyzeBinaryOperatorCompareInCondition (CtElement wholeoriginal, C
274274
whethercompareincondition = true;
275275
}
276276

277-
writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+getStringRepr(operatorunderstudy), CodeFeatures.O4_COMPARE_IN_CONDITION,
277+
writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+ getSafeStringRepr(operatorunderstudy), CodeFeatures.O4_COMPARE_IN_CONDITION,
278278
whethercompareincondition, "FEATURES_BINARYOPERATOR");
279279
}
280280
}

src/main/java/fr/inria/coming/core/entities/output/JSonPatternInstanceOutput.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import java.io.File;
44
import java.io.FileWriter;
5-
import java.util.ArrayList;
6-
import java.util.List;
75

86
import com.google.gson.Gson;
97
import com.google.gson.GsonBuilder;
@@ -24,9 +22,8 @@
2422
import fr.inria.coming.main.ComingProperties;
2523
import fr.inria.coming.repairability.models.InstanceStats;
2624
import gumtree.spoon.diff.operations.Operation;
27-
import org.json.simple.JSONObject;
2825

29-
import static fr.inria.coming.codefeatures.codeanalyze.BinaryOperatorAnalyzer.getStringRepr;
26+
import static fr.inria.coming.codefeatures.codeanalyze.BinaryOperatorAnalyzer.getSafeStringRepr;
3027

3128
public class JSonPatternInstanceOutput implements IOutput {
3229

@@ -154,9 +151,9 @@ public static JsonObject getJSONFromOperator(Operation operation) {
154151
: "null");
155152

156153
op.addProperty("src_parent",
157-
(operation.getSrcNode() != null) ? getStringRepr(operation.getSrcNode().getParent()) : "null");
154+
(operation.getSrcNode() != null) ? getSafeStringRepr(operation.getSrcNode().getParent()) : "null");
158155
op.addProperty("dst_parent",
159-
(operation.getDstNode() != null) ? getStringRepr(operation.getDstNode().getParent()) : "null");
156+
(operation.getDstNode() != null) ? getSafeStringRepr(operation.getDstNode().getParent()) : "null");
160157

161158
return op;
162159
}

src/main/java/fr/inria/coming/repairability/repairtools/Arja.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import spoon.reflect.declaration.CtVariable;
3838
import spoon.reflect.reference.CtTypeReference;
3939

40+
import static fr.inria.coming.codefeatures.codeanalyze.BinaryOperatorAnalyzer.getSafeStringRepr;
41+
4042
/**
4143
* Arja tries to correct the code by inserting statements that are in the source
4244
* file either in a direct approach or a type matching approach.
@@ -218,7 +220,7 @@ private boolean checkSrcIncludesDstTemplate(CtElement srcNode, CtElement dstNode
218220
continue;
219221
}
220222

221-
String srcAsString = currentSrcElement.toString();
223+
String srcAsString = getSafeStringRepr(currentSrcElement);
222224
Set<CtElement> elementsInSubtree = new HashSet<>();
223225
elementsInSubtree.add(currentSrcElement);
224226
for (int j = 0; j == 0 || (i + j < allSrcElements.size()

src/test/java/fr/inria/prophet4j/GumtreeDiffTest.java

+7-14
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,10 @@ public void testExplicitConversion() throws Exception {
105105
assertEquals("1", operations.get(0).getDstNode().toString());
106106
}
107107

108-
/**
109-
* This test shows there is bug/limitation in the gumtree diff. Diff exists but
110-
* not found.
111-
*
112-
* @throws Exception
113-
*/
114-
115108
@Test
116-
public void DiffNotFoundTest() throws Exception {
109+
public void diffFoundTest() throws Exception {
110+
// contract: we can find a diff with cast difference
111+
117112
/*
118113
* SRC: x0 = 0.5 * (x0 + x1 - FastMath.max(rtol * FastMath.abs(x1), atol));
119114
* TARGET: x0 = 0.5 * ((int)x0 + x1 - FastMath.max(rtol * FastMath.abs(x1),
@@ -127,12 +122,10 @@ public void DiffNotFoundTest() throws Exception {
127122
List<Operation> operations = diff.getRootOperations();
128123
System.out.println(operations);
129124

130-
// Delete VariableRead at org.apache.commons.math.analysis.solvers.BaseSecantSolver:188
131-
// x0
132-
//, Insert VariableRead at org.apache.commons.math.analysis.solvers.BaseSecantSolver:188
133-
// ((int) (x0))
134-
135-
assertEquals(2, operations.size());
125+
// [Insert TypeReference at org.apache.commons.math.analysis.solvers.BaseSecantSolver:188
126+
// int
127+
//]
128+
assertEquals(1, operations.size());
136129

137130
/*
138131
* SRC: n1n2prod * (n1 + n2 + 1) / 12.0; TARGET: (double) ((double) n1n2prod *

0 commit comments

Comments
 (0)