Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import com.github.javaparser.ast.stmt.SwitchStmt
import com.github.javaparser.ast.stmt.WhileStmt
import org.utbot.framework.plugin.api.Step
import org.utbot.summary.ast.JimpleToASTMap
import org.utbot.summary.comment.IterationDescription
import org.utbot.summary.comment.SimpleSentenceBlock
import org.utbot.summary.comment.StmtDescription
import org.utbot.summary.comment.StmtType
import org.utbot.summary.comment.classic.symbolic.IterationDescription
import org.utbot.summary.comment.classic.symbolic.SimpleSentenceBlock
import org.utbot.summary.comment.classic.symbolic.StmtDescription
import org.utbot.summary.comment.classic.symbolic.StmtType
import org.utbot.summary.comment.getTextIterationDescription
import org.utbot.summary.comment.getTextTypeIterationDescription
import org.utbot.summary.comment.numberWithSuffix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.utbot.summary.analysis.ExecutionStructureAnalysis
import org.utbot.summary.ast.JimpleToASTMap
import org.utbot.summary.ast.SourceCodeParser
import org.utbot.summary.comment.cluster.SymbolicExecutionClusterCommentBuilder
import org.utbot.summary.comment.SimpleCommentBuilder
import org.utbot.summary.comment.classic.symbolic.SimpleCommentBuilder
import org.utbot.summary.name.SimpleNameBuilder
import java.io.File
import java.nio.file.Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ object SummarySentenceConstants {
const val AT_CODE = "@code"
const val OPEN_BRACKET = "{"
const val CLOSE_BRACKET = "}"

const val JAVA_CLASS_DELIMITER = "$"
const val JAVA_DOC_CLASS_DELIMITER = "."
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import org.utbot.summary.SummarySentenceConstants.COMMA_SYMBOL
import org.utbot.summary.SummarySentenceConstants.DOT_SYMBOL
import org.utbot.summary.SummarySentenceConstants.NEW_LINE
import org.utbot.summary.SummarySentenceConstants.TAB
import org.utbot.summary.comment.classic.symbolic.SquashedStmtTexts
import org.utbot.summary.comment.classic.symbolic.StmtType

fun numberWithSuffix(number: Int) = when (number % 10) {
1 -> "${number}st"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
package org.utbot.summary.comment.classic.fuzzer

import org.utbot.framework.plugin.api.DocPreTagStatement
import org.utbot.framework.plugin.api.DocRegularStmt
import org.utbot.framework.plugin.api.DocStatement
import org.utbot.framework.plugin.api.UtExecutionResult
import org.utbot.fuzzer.FuzzedMethodDescription
import org.utbot.fuzzer.FuzzedValue
import org.utbot.summary.SummarySentenceConstants.NEW_LINE
import org.utbot.summary.comment.customtags.getClassReference
import org.utbot.summary.comment.customtags.getMethodReferenceForFuzzingTest

// TODO: https://github.com/UnitTestBot/UTBotJava/issues/1127
class SimpleCommentForTestProducedByFuzzerBuilder(
description: FuzzedMethodDescription,
values: List<FuzzedValue>,
result: UtExecutionResult?
val methodDescription: FuzzedMethodDescription,
val values: List<FuzzedValue>,
val result: UtExecutionResult?
) {
fun buildDocStatements(): List<DocStatement> {
return listOf<DocStatement>(DocPreTagStatement(emptyList()))
val packageName = methodDescription.packageName
val className = methodDescription.className
val methodName = methodDescription.compilableName

val result = if (packageName != null && className != null && methodName != null) {
val fullClassName = "$packageName.$className"

val methodReference = getMethodReferenceForFuzzingTest(
fullClassName,
methodName,
methodDescription.parameters,
false
)

val classReference = getClassReference(fullClassName)

val docStatements = mutableListOf<DocStatement>()
docStatements.add(DocRegularStmt("Class under test: $classReference$NEW_LINE"))
docStatements.add(DocRegularStmt("Method under test: $methodReference$NEW_LINE"))
docStatements
} else {
emptyList()
}

return listOf<DocStatement>(DocPreTagStatement(result))
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.summary.comment
package org.utbot.summary.comment.classic.symbolic

import com.github.javaparser.ast.body.MethodDeclaration
import com.github.javaparser.ast.stmt.CatchClause
Expand All @@ -16,7 +16,8 @@ import org.utbot.framework.plugin.api.exceptionOrNull
import org.utbot.summary.AbstractTextBuilder
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
import org.utbot.summary.ast.JimpleToASTMap
import org.utbot.summary.comment.customtags.getMethodReference
import org.utbot.summary.comment.*
import org.utbot.summary.comment.customtags.getMethodReferenceForSymbolicTest
import org.utbot.summary.tag.BasicTypeTag
import org.utbot.summary.tag.CallOrderTag
import org.utbot.summary.tag.StatementTag
Expand Down Expand Up @@ -196,7 +197,7 @@ open class SimpleCommentBuilder(
if (!sentenceInvoke.isEmpty()) {
sentenceBlock.invokeSentenceBlock =
Pair(
getMethodReference(className, methodName, methodParameterTypes, invokeSootMethod.isPrivate),
getMethodReferenceForSymbolicTest(className, methodName, methodParameterTypes, invokeSootMethod.isPrivate),
sentenceInvoke
)
createNextBlock = true
Expand Down Expand Up @@ -333,7 +334,7 @@ open class SimpleCommentBuilder(
sentenceBlock.stmtTexts.add(
StmtDescription(
StmtType.Invoke,
getMethodReference(className, methodName, methodParameterTypes, isPrivate),
getMethodReferenceForSymbolicTest(className, methodName, methodParameterTypes, isPrivate),
frequency
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.summary.comment
package org.utbot.summary.comment.classic.symbolic

import org.utbot.framework.plugin.api.DocCodeStmt
import org.utbot.framework.plugin.api.DocRegularStmt
Expand All @@ -12,6 +12,7 @@ import org.utbot.summary.SummarySentenceConstants.NEW_LINE
import org.utbot.summary.SummarySentenceConstants.OPEN_BRACKET
import org.utbot.summary.SummarySentenceConstants.SENTENCE_SEPARATION
import org.utbot.summary.SummarySentenceConstants.TAB
import org.utbot.summary.comment.*

class SimpleSentenceBlock(val stringTemplates: StringsTemplatesInterface) {
val iterationSentenceBlocks = mutableListOf<Pair<String, List<SimpleSentenceBlock>>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import org.utbot.framework.plugin.api.DocStatement
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
import org.utbot.summary.ast.JimpleToASTMap
import org.utbot.summary.comment.*
import org.utbot.summary.comment.customtags.getMethodReference
import org.utbot.summary.comment.classic.symbolic.*
import org.utbot.summary.comment.customtags.getMethodReferenceForSymbolicTest
import org.utbot.summary.tag.BasicTypeTag
import org.utbot.summary.tag.CallOrderTag
import org.utbot.summary.tag.StatementTag
Expand Down Expand Up @@ -42,7 +43,7 @@ class SymbolicExecutionClusterCommentBuilder(
sentence = splitLongSentence(sentence)
sentence = lastCommaToDot(sentence)

return "<pre>\n$sentence</pre>".replace(CARRIAGE_RETURN, "")
return "<pre>\n$sentence</pre>".replace(CARRIAGE_RETURN, EMPTY_STRING)
}

override fun buildDocStmts(currentMethod: SootMethod): List<DocStatement> {
Expand Down Expand Up @@ -98,7 +99,7 @@ class SymbolicExecutionClusterCommentBuilder(
if (!sentenceInvoke.isEmpty()) {
sentenceBlock.invokeSentenceBlock =
Pair(
getMethodReference(className, methodName, methodParameterTypes, isPrivate),
getMethodReferenceForSymbolicTest(className, methodName, methodParameterTypes, isPrivate),
sentenceInvoke
)
createNextBlock = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.utbot.summary.comment.customtags

import org.utbot.framework.plugin.api.ClassId
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
import org.utbot.summary.SummarySentenceConstants.JAVA_CLASS_DELIMITER
import org.utbot.summary.SummarySentenceConstants.JAVA_DOC_CLASS_DELIMITER
import org.utbot.summary.comment.classic.symbolic.EMPTY_STRING
import soot.Type

/**
Expand All @@ -12,34 +16,15 @@ import soot.Type
* In case when an enclosing class in nested, we need to replace '$' with '.'
* to render the reference.
*/
fun getMethodReference(
fun getMethodReferenceForSymbolicTest(
className: String,
methodName: String,
methodParameterTypes: List<Type>,
isPrivate: Boolean
): String {
val prettyClassName: String = className.replace("$", ".")
val methodParametersAsString = if (methodParameterTypes.isNotEmpty()) methodParameterTypes.joinToString(",") else EMPTY_STRING

val text = if (methodParameterTypes.isEmpty()) {
"$prettyClassName#$methodName()"
} else {
val methodParametersAsString = methodParameterTypes.joinToString(",")
"$prettyClassName#$methodName($methodParametersAsString)"
}

return if (isPrivate) {
text
} else {
"{@link $text}"
}
}

/**
* Returns a reference to the class.
* Replaces '$' with '.' in case a class is nested.
*/
fun getClassReference(fullClassName: String): String {
return "{@link ${fullClassName.replace("$", ".")}}"
return formMethodReferenceForJavaDoc(className, methodName, methodParametersAsString, isPrivate)
}

/**
Expand All @@ -51,12 +36,24 @@ fun getClassReference(fullClassName: String): String {
* to render the reference.
*/
fun getMethodReferenceForFuzzingTest(className: String, methodName: String, methodParameterTypes: List<ClassId>, isPrivate: Boolean): String {
val prettyClassName: String = className.replace("$", ".")
val methodParametersAsString = if (methodParameterTypes.isNotEmpty()) methodParameterTypes.joinToString(",") { it.canonicalName } else EMPTY_STRING

return formMethodReferenceForJavaDoc(className, methodName, methodParametersAsString, isPrivate).replace(
CARRIAGE_RETURN, EMPTY_STRING
)
}

private fun formMethodReferenceForJavaDoc(
className: String,
methodName: String,
methodParametersAsString: String,
isPrivate: Boolean
): String {
val prettyClassName: String = className.replace(JAVA_CLASS_DELIMITER, JAVA_DOC_CLASS_DELIMITER)

val text = if (methodParameterTypes.isEmpty()) {
val text = if (methodParametersAsString == EMPTY_STRING) {
"$prettyClassName#$methodName()"
} else {
val methodParametersAsString = methodParameterTypes.joinToString(",") { it.canonicalName }
"$prettyClassName#$methodName($methodParametersAsString)"
}

Expand All @@ -65,4 +62,12 @@ fun getMethodReferenceForFuzzingTest(className: String, methodName: String, meth
} else {
"{@link $text}"
}
}

/**
* Returns a reference to the class.
* Replaces '$' with '.' in case a class is nested.
*/
fun getClassReference(fullClassName: String): String {
return "{@link ${fullClassName.replace(JAVA_CLASS_DELIMITER, JAVA_DOC_CLASS_DELIMITER)}}".replace(CARRIAGE_RETURN, EMPTY_STRING)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.summary.comment.customtags.fuzzer

import org.utbot.summary.comment.EMPTY_STRING
import org.utbot.summary.comment.classic.symbolic.EMPTY_STRING

/**
* Represents a set of plugin's custom JavaDoc tags.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class CommentWithCustomTagForTestProducedByFuzzerBuilder(
methodName,
methodDescription.parameters,
false
).replace(CARRIAGE_RETURN, "")
)

val classReference = getClassReference(fullClassName).replace(CARRIAGE_RETURN, "")
val classReference = getClassReference(fullClassName)

CommentWithCustomTagForTestProducedByFuzzer(
classUnderTest = classReference,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.summary.comment.customtags.symbolic

import org.utbot.summary.comment.EMPTY_STRING
import org.utbot.summary.comment.classic.symbolic.EMPTY_STRING

/**
* Represents a set of plugin's custom JavaDoc tags.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import org.utbot.framework.plugin.api.exceptionOrNull
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
import org.utbot.summary.ast.JimpleToASTMap
import org.utbot.summary.comment.*
import org.utbot.summary.comment.classic.symbolic.*
import org.utbot.summary.comment.customtags.getClassReference
import org.utbot.summary.comment.customtags.getMethodReference
import org.utbot.summary.comment.customtags.getMethodReferenceForSymbolicTest
import org.utbot.summary.tag.TraceTagWithoutExecution
import soot.SootMethod

Expand All @@ -30,7 +31,7 @@ class CustomJavaDocCommentBuilder(
}

private fun buildCustomJavaDocComment(currentMethod: SootMethod): CustomJavaDocComment {
val methodReference = getMethodReference(
val methodReference = getMethodReferenceForSymbolicTest(
currentMethod.declaringClass.name,
currentMethod.name,
currentMethod.parameterTypes,
Expand All @@ -39,8 +40,8 @@ class CustomJavaDocCommentBuilder(
val classReference = getClassReference(currentMethod.declaringClass.javaStyleName)

val comment = CustomJavaDocComment(
classUnderTest = classReference.replace(CARRIAGE_RETURN, ""),
methodUnderTest = methodReference.replace(CARRIAGE_RETURN, ""),
classUnderTest = classReference,
methodUnderTest = methodReference,
)

val rootSentenceBlock = SimpleSentenceBlock(stringTemplates = stringTemplates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.utbot.framework.plugin.api.*
import org.utbot.framework.plugin.api.util.voidClassId
import org.utbot.fuzzer.FuzzedMethodDescription
import org.utbot.fuzzer.FuzzedValue
import org.utbot.summary.UtSummarySettings
import org.utbot.summary.comment.classic.fuzzer.SimpleCommentForTestProducedByFuzzerBuilder
import org.utbot.summary.comment.customtags.fuzzer.CommentWithCustomTagForTestProducedByFuzzerBuilder
import java.util.*
Expand Down Expand Up @@ -32,9 +33,9 @@ class ModelBasedNameSuggester(

return sequenceOf(
TestSuggestedInfo(
testName = createTestName(description, values, result),
testName = createTestName(description, values, result),
displayName = createDisplayName(description, values, result),
javaDoc = createJavaDoc(description, values, result)
javaDoc = if (UtSummarySettings.GENERATE_COMMENTS) createJavaDoc(description, values, result) else null
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import org.mockito.Mockito.`when`
import org.utbot.framework.plugin.api.Step
import org.utbot.framework.plugin.api.UtOverflowFailure
import org.utbot.summary.ast.JimpleToASTMap
import org.utbot.summary.comment.customtags.getMethodReference
import org.utbot.summary.comment.classic.symbolic.SimpleCommentBuilder
import org.utbot.summary.comment.customtags.getMethodReferenceForSymbolicTest
import org.utbot.summary.tag.StatementTag
import org.utbot.summary.tag.TraceTag
import soot.SootMethod
Expand Down Expand Up @@ -67,17 +68,16 @@ class SimpleCommentBuilderTest {

@Test
fun `builds inline link for method`() {
val methodReference = getMethodReference("org.utbot.ClassName", "methodName", listOf(), false)
val methodReference = getMethodReferenceForSymbolicTest("org.utbot.ClassName", "methodName", listOf(), false)
val expectedMethodReference = "{@link org.utbot.ClassName#methodName()}"
assertEquals(methodReference, expectedMethodReference)
}

@Test
fun `builds inline link for method in nested class`() {
val methodReference =
getMethodReference("org.utbot.ClassName\$NestedClassName", "methodName", listOf(), false)
getMethodReferenceForSymbolicTest("org.utbot.ClassName\$NestedClassName", "methodName", listOf(), false)
val expectedMethodReference = "{@link org.utbot.ClassName.NestedClassName#methodName()}"
assertEquals(methodReference, expectedMethodReference)
}

}