Skip to content

Commit a5ca42b

Browse files
committed
Refactor to avoid bugs with private methods
1 parent 408e87e commit a5ca42b

5 files changed

Lines changed: 77 additions & 70 deletions

File tree

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

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.utbot.framework.plugin.api.exceptionOrNull
1616
import org.utbot.summary.AbstractTextBuilder
1717
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
1818
import org.utbot.summary.ast.JimpleToASTMap
19+
import org.utbot.summary.comment.customtags.getMethodReference
1920
import org.utbot.summary.tag.BasicTypeTag
2021
import org.utbot.summary.tag.CallOrderTag
2122
import org.utbot.summary.tag.StatementTag
@@ -356,45 +357,6 @@ open class SimpleCommentBuilder(
356357
)
357358
}
358359

359-
/**
360-
* Returns a reference to the invoked method. IDE can't resolve references to private methods in comments,
361-
* so we add @link tag only if the invoked method is not private.
362-
*
363-
* It looks like {@link packageName.className#methodName(type1, type2)}.
364-
*
365-
* In case when an enclosing class in nested, we need to replace '$' with '.'
366-
* to render the reference.
367-
*/
368-
fun getMethodReference(
369-
className: String,
370-
methodName: String,
371-
methodParameterTypes: List<Type>,
372-
isPrivate: Boolean
373-
): String {
374-
val prettyClassName: String = className.replace("$", ".")
375-
376-
val text = if (methodParameterTypes.isEmpty()) {
377-
"$prettyClassName#$methodName()"
378-
} else {
379-
val methodParametersAsString = methodParameterTypes.joinToString(",")
380-
"$prettyClassName#$methodName($methodParametersAsString)"
381-
}
382-
383-
return if (isPrivate) {
384-
text
385-
} else {
386-
"{@link $text}"
387-
}
388-
}
389-
390-
/**
391-
* Returns a reference to the class.
392-
* Replaces '$' with '.' in case a class is nested.
393-
*/
394-
fun getClassReference(fullClasName: String): String {
395-
return "{@link ${fullClasName.replace("$", ".")}}"
396-
}
397-
398360
protected fun buildIterationsBlock(
399361
iterations: List<StatementTag>,
400362
activatedStep: Step,

utbot-summary/src/main/kotlin/org/utbot/summary/comment/cluster/SymbolicExecutionClusterCommentBuilder.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.utbot.framework.plugin.api.DocStatement
77
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
88
import org.utbot.summary.ast.JimpleToASTMap
99
import org.utbot.summary.comment.*
10+
import org.utbot.summary.comment.customtags.getMethodReference
1011
import org.utbot.summary.tag.BasicTypeTag
1112
import org.utbot.summary.tag.CallOrderTag
1213
import org.utbot.summary.tag.StatementTag
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.utbot.summary.comment.customtags
2+
3+
import org.utbot.framework.plugin.api.ClassId
4+
import soot.Type
5+
6+
/**
7+
* Returns a reference to the invoked method. IDE can't resolve references to private methods in comments,
8+
* so we add @link tag only if the invoked method is not private.
9+
*
10+
* It looks like {@link packageName.className#methodName(type1, type2)}.
11+
*
12+
* In case when an enclosing class in nested, we need to replace '$' with '.'
13+
* to render the reference.
14+
*/
15+
fun getMethodReference(
16+
className: String,
17+
methodName: String,
18+
methodParameterTypes: List<Type>,
19+
isPrivate: Boolean
20+
): String {
21+
val prettyClassName: String = className.replace("$", ".")
22+
23+
val text = if (methodParameterTypes.isEmpty()) {
24+
"$prettyClassName#$methodName()"
25+
} else {
26+
val methodParametersAsString = methodParameterTypes.joinToString(",")
27+
"$prettyClassName#$methodName($methodParametersAsString)"
28+
}
29+
30+
return if (isPrivate) {
31+
text
32+
} else {
33+
"{@link $text}"
34+
}
35+
}
36+
37+
/**
38+
* Returns a reference to the class.
39+
* Replaces '$' with '.' in case a class is nested.
40+
*/
41+
fun getClassReference(fullClassName: String): String {
42+
return "{@link ${fullClassName.replace("$", ".")}}"
43+
}
44+
45+
/**
46+
* Returns a reference to the invoked method.
47+
*
48+
* It looks like {@link packageName.className#methodName(type1, type2)}.
49+
*
50+
* In case when an enclosing class in nested, we need to replace '$' with '.'
51+
* to render the reference.
52+
*/
53+
fun getMethodReferenceForFuzzingTest(className: String, methodName: String, methodParameterTypes: List<ClassId>, isPrivate: Boolean): String {
54+
val prettyClassName: String = className.replace("$", ".")
55+
56+
val text = if (methodParameterTypes.isEmpty()) {
57+
"$prettyClassName#$methodName()"
58+
} else {
59+
val methodParametersAsString = methodParameterTypes.joinToString(",") { it.canonicalName }
60+
"$prettyClassName#$methodName($methodParametersAsString)"
61+
}
62+
63+
return if (isPrivate) {
64+
text
65+
} else {
66+
"{@link $text}"
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.utbot.summary.comment.customtags.fuzzer
22

3-
import org.utbot.framework.plugin.api.ClassId
43
import org.utbot.framework.plugin.api.DocCustomTagStatement
54
import org.utbot.framework.plugin.api.DocStatement
65
import org.utbot.framework.plugin.api.UtExecutionResult
76
import org.utbot.fuzzer.FuzzedMethodDescription
87
import org.utbot.fuzzer.FuzzedValue
9-
import org.utbot.summary.SummarySentenceConstants
108
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
9+
import org.utbot.summary.comment.customtags.getClassReference
10+
import org.utbot.summary.comment.customtags.getMethodReferenceForFuzzingTest
1111
import org.utbot.summary.comment.customtags.symbolic.CustomJavaDocTagProvider
1212

1313
/**
@@ -29,10 +29,11 @@ class CommentWithCustomTagForTestProducedByFuzzerBuilder(
2929
}
3030

3131
private fun buildCustomJavaDocComment(): CommentWithCustomTagForTestProducedByFuzzer {
32-
val methodReference = getMethodReference(
32+
val methodReference = getMethodReferenceForFuzzingTest(
3333
methodDescription.packageName!! + "." + methodDescription.className!!,
3434
methodDescription.compilableName!!,
35-
methodDescription.parameters
35+
methodDescription.parameters,
36+
false
3637
)
3738
val classReference = getClassReference(methodDescription.packageName!! + "." +methodDescription.className!!)
3839

@@ -43,31 +44,4 @@ class CommentWithCustomTagForTestProducedByFuzzerBuilder(
4344

4445
return javaDocComment
4546
}
46-
47-
/**
48-
* Returns a reference to the invoked method.
49-
*
50-
* It looks like {@link packageName.className#methodName(type1, type2)}.
51-
*
52-
* In case when an enclosing class in nested, we need to replace '$' with '.'
53-
* to render the reference.
54-
*/
55-
private fun getMethodReference(className: String, methodName: String, methodParameterTypes: List<ClassId>): String {
56-
val prettyClassName: String = className.replace("$", ".")
57-
58-
return if (methodParameterTypes.isEmpty()) {
59-
"{@link $prettyClassName#$methodName()}"
60-
} else {
61-
val methodParametersAsString = methodParameterTypes.joinToString(",") { it.canonicalName }
62-
"{@link $prettyClassName#$methodName($methodParametersAsString)}"
63-
}
64-
}
65-
66-
/**
67-
* Returns a reference to the class.
68-
* Replaces '$' with '.' in case a class is nested.
69-
*/
70-
private fun getClassReference(fullClassName: String): String {
71-
return "{@link ${fullClassName.replace("$", ".")}}"
72-
}
7347
}

utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/symbolic/CustomJavaDocCommentBuilder.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import org.utbot.framework.plugin.api.exceptionOrNull
66
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
77
import org.utbot.summary.ast.JimpleToASTMap
88
import org.utbot.summary.comment.*
9+
import org.utbot.summary.comment.customtags.getClassReference
10+
import org.utbot.summary.comment.customtags.getMethodReference
911
import org.utbot.summary.tag.TraceTagWithoutExecution
1012
import soot.SootMethod
1113

0 commit comments

Comments
 (0)