Skip to content

Commit a302d1e

Browse files
authored
Prohibit soot.dummy.InvokeDynamic in summaries name and comment text #1869 (#2396)
Prohibit `soot.dummy.InvokeDynamic` in summaries text
1 parent 9475bbd commit a302d1e

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

utbot-summary/src/main/kotlin/org/utbot/summary/comment/SentenceUtil.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,26 @@ val nextSynonyms = arrayOf(
9191
"then"
9292
)
9393

94-
val skipInvokes = arrayOf(
94+
val forbiddenMethodInvokes = arrayOf(
9595
"<init>",
9696
"<clinit>",
9797
"valueOf",
98-
"getClass"
98+
"getClass",
9999
)
100100

101-
// TODO: SAT-1589
102-
fun shouldSkipInvoke(invoke: String) = (invoke in skipInvokes) || (invoke.endsWith('$'))
101+
val forbiddenClassInvokes = arrayOf(
102+
"soot.dummy.InvokeDynamic"
103+
)
104+
105+
/**
106+
* Filters out
107+
* ```soot.dummy.InvokeDynamic#makeConcat```,
108+
* ```soot.dummy.InvokeDynamic#makeConcatWithConstants```,
109+
* constructor calls (```<init>```), ```bootstrap$```
110+
* and other unwanted things from name and comment text.
111+
*/
112+
fun shouldSkipInvoke(className: String, methodName: String) =
113+
className in forbiddenClassInvokes || methodName in forbiddenMethodInvokes || methodName.endsWith("$")
103114

104115
fun squashDocRegularStatements(sentences: List<DocStatement>): List<DocStatement> {
105116
val newStatements = mutableListOf<DocStatement>()

utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleCommentBuilder.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,9 @@ open class SimpleCommentBuilder(
301301
*/
302302
protected fun addTextRecursion(sentenceBlock: SimpleSentenceBlock, stmt: Stmt, frequency: Int) {
303303
if (stmt is JAssignStmt || stmt is JInvokeStmt) {
304+
val className = stmt.invokeExpr.methodRef.declaringClass.name
304305
val methodName = stmt.invokeExpr.method.name
305-
addTextRecursion(sentenceBlock, methodName, frequency)
306+
addTextRecursion(sentenceBlock, className, methodName, frequency)
306307
}
307308
}
308309

@@ -337,7 +338,7 @@ open class SimpleCommentBuilder(
337338
isPrivate: Boolean,
338339
frequency: Int
339340
) {
340-
if (!shouldSkipInvoke(methodName))
341+
if (!shouldSkipInvoke(className, methodName))
341342
sentenceBlock.stmtTexts.add(
342343
StmtDescription(
343344
StmtType.Invoke,
@@ -352,10 +353,11 @@ open class SimpleCommentBuilder(
352353
*/
353354
protected fun addTextRecursion(
354355
sentenceBlock: SimpleSentenceBlock,
356+
className: String,
355357
methodName: String,
356358
frequency: Int
357359
) {
358-
if (!shouldSkipInvoke(methodName))
360+
if (!shouldSkipInvoke(className, methodName))
359361
sentenceBlock.stmtTexts.add(
360362
StmtDescription(
361363
StmtType.RecursionAssignment,

utbot-summary/src/main/kotlin/org/utbot/summary/name/SimpleNameBuilder.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,12 @@ class SimpleNameBuilder(
385385
prefix = "Return"
386386
name = name ?: ""
387387
} else if (statementTag.basicTypeTag == BasicTypeTag.Invoke && statementTag.uniquenessTag == UniquenessTag.Unique) {
388+
val declaringClass = stmt.invokeExpr.methodRef.declaringClass
388389
val methodName = stmt.invokeExpr.method.name.capitalize()
389-
if (!shouldSkipInvoke(methodName)) {
390+
if (!shouldSkipInvoke(declaringClass.name, methodName)) {
390391
if (stmt is JAssignStmt || stmt is JInvokeStmt) {
391392
type = NameType.Invoke
392-
prefix += stmt.invokeExpr.methodRef.declaringClass.javaStyleName.substringBefore('$') //class name
393+
prefix += declaringClass.javaStyleName.substringBefore('$')
393394
prefix += methodName
394395
name =
395396
"" //todo change var name to val name, everything should be mapped through .convertNodeToString

0 commit comments

Comments
 (0)