Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactor to avoid bugs with private methods
  • Loading branch information
amandelpie committed Oct 6, 2022
commit a5ca42bd193040a5147b596d0449dc3efa3a7341
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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.tag.BasicTypeTag
import org.utbot.summary.tag.CallOrderTag
import org.utbot.summary.tag.StatementTag
Expand Down Expand Up @@ -356,45 +357,6 @@ open class SimpleCommentBuilder(
)
}

/**
* Returns a reference to the invoked method. IDE can't resolve references to private methods in comments,
* so we add @link tag only if the invoked method is not private.
*
* It looks like {@link packageName.className#methodName(type1, type2)}.
*
* In case when an enclosing class in nested, we need to replace '$' with '.'
* to render the reference.
*/
fun getMethodReference(
className: String,
methodName: String,
methodParameterTypes: List<Type>,
isPrivate: Boolean
): String {
val prettyClassName: String = className.replace("$", ".")

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(fullClasName: String): String {
return "{@link ${fullClasName.replace("$", ".")}}"
}

protected fun buildIterationsBlock(
iterations: List<StatementTag>,
activatedStep: Step,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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.tag.BasicTypeTag
import org.utbot.summary.tag.CallOrderTag
import org.utbot.summary.tag.StatementTag
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.utbot.summary.comment.customtags

import org.utbot.framework.plugin.api.ClassId
import soot.Type

/**
* Returns a reference to the invoked method. IDE can't resolve references to private methods in comments,
* so we add @link tag only if the invoked method is not private.
*
* It looks like {@link packageName.className#methodName(type1, type2)}.
*
* In case when an enclosing class in nested, we need to replace '$' with '.'
* to render the reference.
*/
fun getMethodReference(
className: String,
methodName: String,
methodParameterTypes: List<Type>,
isPrivate: Boolean
): String {
val prettyClassName: String = className.replace("$", ".")

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("$", ".")}}"
}

/**
* Returns a reference to the invoked method.
*
* It looks like {@link packageName.className#methodName(type1, type2)}.
*
* In case when an enclosing class in nested, we need to replace '$' with '.'
* to render the reference.
*/
fun getMethodReferenceForFuzzingTest(className: String, methodName: String, methodParameterTypes: List<ClassId>, isPrivate: Boolean): String {
Comment thread
amandelpie marked this conversation as resolved.
val prettyClassName: String = className.replace("$", ".")

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

return if (isPrivate) {
text
} else {
"{@link $text}"
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.utbot.summary.comment.customtags.fuzzer

import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.DocCustomTagStatement
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
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
import org.utbot.summary.comment.customtags.getClassReference
import org.utbot.summary.comment.customtags.getMethodReferenceForFuzzingTest
import org.utbot.summary.comment.customtags.symbolic.CustomJavaDocTagProvider

/**
Expand All @@ -29,10 +29,11 @@ class CommentWithCustomTagForTestProducedByFuzzerBuilder(
}

private fun buildCustomJavaDocComment(): CommentWithCustomTagForTestProducedByFuzzer {
val methodReference = getMethodReference(
val methodReference = getMethodReferenceForFuzzingTest(
methodDescription.packageName!! + "." + methodDescription.className!!,
methodDescription.compilableName!!,
methodDescription.parameters
methodDescription.parameters,
false
)
val classReference = getClassReference(methodDescription.packageName!! + "." +methodDescription.className!!)

Expand All @@ -43,31 +44,4 @@ class CommentWithCustomTagForTestProducedByFuzzerBuilder(

return javaDocComment
}

/**
* Returns a reference to the invoked method.
*
* It looks like {@link packageName.className#methodName(type1, type2)}.
*
* In case when an enclosing class in nested, we need to replace '$' with '.'
* to render the reference.
*/
private fun getMethodReference(className: String, methodName: String, methodParameterTypes: List<ClassId>): String {
val prettyClassName: String = className.replace("$", ".")

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

/**
* Returns a reference to the class.
* Replaces '$' with '.' in case a class is nested.
*/
private fun getClassReference(fullClassName: String): String {
return "{@link ${fullClassName.replace("$", ".")}}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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.customtags.getClassReference
import org.utbot.summary.comment.customtags.getMethodReference
import org.utbot.summary.tag.TraceTagWithoutExecution
import soot.SootMethod

Expand Down