-
Notifications
You must be signed in to change notification settings - Fork 46
Introduce custom JavaDoc tags #565 #585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e88bd65
Introduce custom plugin's JavaDoc tags #565
onewhl 43c4cf0
Render UtBot custom JavaDoc tags correctly #565
onewhl 760594f
Add an option to generate summaries using custom JavaDoc tags #565
onewhl 050550f
Fill value of utbot.iterates tag #565
onewhl ca86976
Collect info about Invoke, Iterate, and Return sections #565
onewhl d77e739
Review fixes
onewhl 6ae1157
Add unit tests for summaries with custom JavaDoc tags #565
onewhl 100e3df
Fix after rebasing
onewhl 8d4063b
Add summary tests for MinStack #565
onewhl 6d01afe
Fix broken tests
onewhl d03ad76
Add <pre> tag only in case when custom javadoc tags are not used
onewhl 74c5822
Use a full exception name instead of simple name to build inline link…
onewhl 7e4aaf9
Minor refactoring
onewhl 92eb15d
Minor refactoring: avoid code duplication
onewhl cf9b60f
Add DocCustomTagStatement and CgCustomTagStatement
onewhl 9c14eb0
Refactored code to avoid code duplication
onewhl 6dce850
Fix tests: add full name for classes
onewhl 7800d33
Add JUnit extension to control USE_CUSTOM_TAGS setting
onewhl d003962
Move useCustomJavaDocTags to UtSettings, make useFuzzing true
onewhl f8e6764
Remove unused import and fix broken tests
onewhl 321bf0d
Fix broken tests
onewhl a52fb20
Add comments, remove unused method
onewhl 83f4e71
Review fixes: fixed formatting, removed redundant types
onewhl abe7ca6
Review fixes: fixed formatting, removed useless overriding methods
onewhl 475cae5
Review fixes: extracted method, polished code
onewhl 99b06ad
fix after rebasing
onewhl 21a7035
fix after rebasing
onewhl 4951b6f
review fixes
onewhl bd616a9
fix rendering after updating to idea 2022.1. now we don't need to gen…
onewhl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtCustomJavaDocTagProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.utbot.intellij.plugin.javadoc | ||
|
||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiMethod | ||
import com.intellij.psi.PsiReference | ||
import com.intellij.psi.javadoc.CustomJavadocTagProvider | ||
import com.intellij.psi.javadoc.JavadocTagInfo | ||
import com.intellij.psi.javadoc.PsiDocTagValue | ||
import org.utbot.summary.comment.CustomJavaDocTag | ||
import org.utbot.summary.comment.CustomJavaDocTagProvider | ||
|
||
/** | ||
* Provides plugin's custom JavaDoc tags to make test summaries structured. | ||
*/ | ||
class UtCustomJavaDocTagProvider : CustomJavadocTagProvider { | ||
override fun getSupportedTags(): List<UtCustomTagInfo> = | ||
CustomJavaDocTagProvider().getPluginCustomTags().map { UtCustomTagInfo(it) } | ||
|
||
class UtCustomTagInfo(private val tag: CustomJavaDocTag) : JavadocTagInfo { | ||
override fun getName(): String = tag.name | ||
|
||
fun getMessage(): String = tag.message | ||
|
||
override fun isInline() = false | ||
|
||
override fun checkTagValue(value: PsiDocTagValue?): String? = null | ||
|
||
override fun getReference(value: PsiDocTagValue?): PsiReference? = null | ||
|
||
override fun isValidInContext(element: PsiElement?): Boolean = element is PsiMethod | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtDocumentationProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.utbot.intellij.plugin.javadoc | ||
|
||
import com.intellij.codeInsight.javadoc.JavaDocExternalFilter | ||
import com.intellij.codeInsight.javadoc.JavaDocInfoGeneratorFactory | ||
import com.intellij.lang.java.JavaDocumentationProvider | ||
import com.intellij.psi.PsiDocCommentBase | ||
import com.intellij.psi.PsiJavaDocumentedElement | ||
|
||
/** | ||
* To render UtBot custom JavaDoc tags messages, we need to override basic behaviour of [JavaDocumentationProvider]. | ||
* The IJ platform knows only custom tag names, so we need to add their messages in rendered comments to make it look nice. | ||
*/ | ||
class UtDocumentationProvider : JavaDocumentationProvider() { | ||
override fun generateRenderedDoc(comment: PsiDocCommentBase): String? { | ||
val target = comment.owner ?: comment | ||
|
||
if (target !is PsiJavaDocumentedElement) { | ||
return "" | ||
} | ||
|
||
val baseJavaDocInfoGenerator = JavaDocInfoGeneratorFactory.getBuilder(target.getProject()) | ||
.setPsiElement(target) | ||
.setIsGenerationForRenderedDoc(true) | ||
.create() | ||
|
||
val finalDocContent = replaceTagNamesWithMessages(baseJavaDocInfoGenerator.generateRenderedDocInfo()) | ||
|
||
return JavaDocExternalFilter.filterInternalDocInfo(finalDocContent) | ||
} | ||
|
||
/** | ||
* Replaces names of plugin's custom JavaDoc tags with their messages in the comment generated by the IJ platform. | ||
* Example: utbot.MethodUnderTest -> Method under test. | ||
*/ | ||
private fun replaceTagNamesWithMessages(comment: String?) = | ||
comment?.let { | ||
val docTagProvider = UtCustomJavaDocTagProvider() | ||
docTagProvider.supportedTags.fold(it) { result, tag -> | ||
if (result.contains(tag.name)) { | ||
result.replace(tag.name, "${tag.getMessage()}:") | ||
} else { | ||
result | ||
} | ||
} | ||
} ?: "" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
utbot-summary-tests/src/test/kotlin/examples/CustomJavaDocTagsEnabler.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package examples | ||
|
||
import org.junit.jupiter.api.extension.AfterEachCallback | ||
import org.junit.jupiter.api.extension.BeforeEachCallback | ||
import org.junit.jupiter.api.extension.ExtensionContext | ||
import org.utbot.framework.UtSettings | ||
|
||
/** | ||
* Controls the value of useCustomJavaDocTags global variable. | ||
* | ||
* Should be used in summary tests containing custom JavaDoc tags. | ||
* To use it, add an annotation @ExtendWith(CustomJavaDocTagsEnabler::class) under test class. | ||
*/ | ||
class CustomJavaDocTagsEnabler(private val enable: Boolean = true) : BeforeEachCallback, AfterEachCallback { | ||
private var previousValue = false | ||
|
||
override fun beforeEach(context: ExtensionContext?) { | ||
previousValue = UtSettings.useCustomJavaDocTags | ||
UtSettings.useCustomJavaDocTags = enable | ||
} | ||
|
||
override fun afterEach(context: ExtensionContext?) { | ||
UtSettings.useCustomJavaDocTags = previousValue | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package examples.controlflow | ||
|
||
import examples.CustomJavaDocTagsEnabler | ||
import examples.SummaryTestCaseGeneratorTest | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.utbot.examples.DoNotCalculate | ||
import org.utbot.examples.controlflow.Conditions | ||
import org.utbot.framework.plugin.api.MockStrategyApi | ||
|
||
@ExtendWith(CustomJavaDocTagsEnabler::class) | ||
class SummaryConditionsTest : SummaryTestCaseGeneratorTest( | ||
Conditions::class | ||
) { | ||
@Test | ||
fun testSimpleCondition() { | ||
val summary1 = "@utbot.classUnderTest {@link Conditions}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.controlflow.Conditions#simpleCondition(boolean)}\n" + | ||
"@utbot.executesCondition {@code (condition): False}\n" + | ||
"@utbot.returnsFrom {@code return 0;}" | ||
|
||
val summary2 = "@utbot.classUnderTest {@link Conditions}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.controlflow.Conditions#simpleCondition(boolean)}\n" + | ||
"@utbot.executesCondition {@code (condition): True}\n" + | ||
"@utbot.returnsFrom {@code return 1;}" | ||
|
||
val methodName1 = "testSimpleCondition_NotCondition" | ||
val methodName2 = "testSimpleCondition_Condition" | ||
|
||
val displayName1 = "condition : False -> return 0" | ||
val displayName2 = "condition : True -> return 1" | ||
|
||
val summaryKeys = listOf( | ||
summary1, | ||
summary2 | ||
) | ||
|
||
val displayNames = listOf( | ||
displayName1, | ||
displayName2 | ||
) | ||
|
||
val methodNames = listOf( | ||
methodName1, | ||
methodName2 | ||
) | ||
|
||
val method = Conditions::simpleCondition | ||
val mockStrategy = MockStrategyApi.NO_MOCKS | ||
val coverage = DoNotCalculate | ||
|
||
summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames) | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...mmary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package examples.exceptions | ||
|
||
import examples.CustomJavaDocTagsEnabler | ||
import examples.SummaryTestCaseGeneratorTest | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.utbot.examples.DoNotCalculate | ||
import org.utbot.examples.exceptions.ExceptionClusteringExamples | ||
import org.utbot.framework.plugin.api.MockStrategyApi | ||
|
||
@ExtendWith(CustomJavaDocTagsEnabler::class) | ||
class SummaryExceptionClusteringExamplesTest : SummaryTestCaseGeneratorTest( | ||
ExceptionClusteringExamples::class | ||
) { | ||
@Test | ||
fun testDifferentExceptions() { | ||
val summary1 = "@utbot.classUnderTest {@link ExceptionClusteringExamples}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionClusteringExamples#differentExceptions(int)}\n" + | ||
"@utbot.executesCondition {@code (i == 0): True}\n" + | ||
"@utbot.throwsException {@link java.lang.ArithmeticException} in: return 100 / i;" | ||
|
||
val summary2 = "@utbot.classUnderTest {@link ExceptionClusteringExamples}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionClusteringExamples#differentExceptions(int)}\n" + | ||
"@utbot.executesCondition {@code (i == 0): False},\n" + | ||
"{@code (i == 1): True}\n" + | ||
"@utbot.throwsException {@link org.utbot.examples.exceptions.MyCheckedException} after condition: i == 1" | ||
val summary3 = "@utbot.classUnderTest {@link ExceptionClusteringExamples}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionClusteringExamples#differentExceptions(int)}\n" + | ||
"@utbot.executesCondition {@code (i == 0): False},\n" + | ||
"{@code (i == 1): False},\n" + | ||
"{@code (i == 2): True}\n" + | ||
"@utbot.throwsException {@link java.lang.IllegalArgumentException} after condition: i == 2" | ||
val summary4 = "@utbot.classUnderTest {@link ExceptionClusteringExamples}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionClusteringExamples#differentExceptions(int)}\n" + | ||
"@utbot.executesCondition {@code (i == 0): False},\n" + | ||
"{@code (i == 1): False},\n" + | ||
"{@code (i == 2): False}\n" + | ||
"@utbot.returnsFrom {@code return i * 2;}\n" | ||
|
||
val methodName1 = "testDifferentExceptions_IEqualsZero" | ||
val methodName2 = "testDifferentExceptions_IEquals1" | ||
val methodName3 = "testDifferentExceptions_IEquals2" | ||
val methodName4 = "testDifferentExceptions_INotEquals2" | ||
|
||
val displayName1 = "return 100 / i : True -> ThrowArithmeticException" | ||
val displayName2 = "i == 1 -> ThrowMyCheckedException" | ||
val displayName3 = "i == 2 -> ThrowIllegalArgumentException" | ||
val displayName4 = "i == 0 : False -> return i * 2" | ||
|
||
val summaryKeys = listOf( | ||
summary1, | ||
summary2, | ||
summary3, | ||
summary4 | ||
) | ||
|
||
val displayNames = listOf( | ||
displayName1, | ||
displayName2, | ||
displayName3, | ||
displayName4 | ||
) | ||
|
||
val methodNames = listOf( | ||
methodName1, | ||
methodName2, | ||
methodName3, | ||
methodName4 | ||
) | ||
|
||
val method = ExceptionClusteringExamples::differentExceptions | ||
val mockStrategy = MockStrategyApi.NO_MOCKS | ||
val coverage = DoNotCalculate | ||
|
||
summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.