This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: process description annotations in backend * feat: update validation in backend * feat(backend): actually trigger processing * style: apply automatic fixes of linters * feat: Adding description annotation (WIP) * revert: changes to Kotlin files * feat: Added description annotation, a filter for it and adjusted the heatmap to also count description annotations. * style: apply automatic fixes of linters * feat: don't show new description in annotation view (long) * fix: build error * feat: consistent label for new description text area * refactor: sort stuff * fix: description annotations not sent to server * fix: remove log * refactor: sort stuff * refactor: sort stuff * style: apply automatic fixes of linters * fix: build error Co-authored-by: lars-reimann <lars-reimann@users.noreply.github.com> Co-authored-by: Arsam Islami <arsamislami@yahoo.de> Co-authored-by: Masara <Masara@users.noreply.github.com>
- Loading branch information
1 parent
cca834d
commit 9f3ff94
Showing
25 changed files
with
361 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
34 changes: 34 additions & 0 deletions
34
...c/main/kotlin/com/larsreimann/api_editor/transformation/DescriptionAnnotationProcessor.kt
This file contains 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,34 @@ | ||
package com.larsreimann.api_editor.transformation | ||
|
||
import com.larsreimann.api_editor.model.DescriptionAnnotation | ||
import com.larsreimann.api_editor.mutable_model.PythonClass | ||
import com.larsreimann.api_editor.mutable_model.PythonDeclaration | ||
import com.larsreimann.api_editor.mutable_model.PythonFunction | ||
import com.larsreimann.api_editor.mutable_model.PythonPackage | ||
import com.larsreimann.api_editor.mutable_model.PythonParameter | ||
import com.larsreimann.modeling.descendants | ||
|
||
/** | ||
* Processes and removes `@description` annotations. | ||
*/ | ||
fun PythonPackage.processDescriptionAnnotations() { | ||
this.descendants() | ||
.filterIsInstance<PythonDeclaration>() | ||
.forEach { it.processDescriptionAnnotations() } | ||
} | ||
|
||
private fun PythonDeclaration.processDescriptionAnnotations() { | ||
this.annotations | ||
.filterIsInstance<DescriptionAnnotation>() | ||
.forEach { | ||
when (this) { | ||
is PythonClass -> this.description = it.newDescription | ||
is PythonFunction -> this.description = it.newDescription | ||
is PythonParameter -> this.description = it.newDescription | ||
else -> { | ||
// Do nothing | ||
} | ||
} | ||
this.annotations.remove(it) | ||
} | ||
} |
This file contains 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 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
99 changes: 99 additions & 0 deletions
99
...st/kotlin/com/larsreimann/api_editor/transformation/DescriptionAnnotationProcessorTest.kt
This file contains 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,99 @@ | ||
package com.larsreimann.api_editor.transformation | ||
|
||
import com.larsreimann.api_editor.model.DescriptionAnnotation | ||
import com.larsreimann.api_editor.mutable_model.PythonClass | ||
import com.larsreimann.api_editor.mutable_model.PythonFunction | ||
import com.larsreimann.api_editor.mutable_model.PythonModule | ||
import com.larsreimann.api_editor.mutable_model.PythonPackage | ||
import com.larsreimann.api_editor.mutable_model.PythonParameter | ||
import io.kotest.matchers.collections.shouldBeEmpty | ||
import io.kotest.matchers.shouldBe | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
class DescriptionAnnotationProcessorTest { | ||
private lateinit var testClass: PythonClass | ||
private lateinit var testFunction: PythonFunction | ||
private lateinit var testParameter: PythonParameter | ||
private lateinit var testPackage: PythonPackage | ||
|
||
@BeforeEach | ||
fun reset() { | ||
testClass = PythonClass( | ||
name = "TestClass", | ||
description = "Lorem ipsum", | ||
annotations = mutableListOf(DescriptionAnnotation("Important class")) | ||
) | ||
testParameter = PythonParameter( | ||
name = "testParameter", | ||
description = "Lorem ipsum", | ||
annotations = mutableListOf(DescriptionAnnotation("Important parameter")) | ||
) | ||
testFunction = PythonFunction( | ||
name = "testFunction", | ||
description = "Lorem ipsum", | ||
annotations = mutableListOf(DescriptionAnnotation("Important function")), | ||
parameters = mutableListOf(testParameter) | ||
) | ||
testPackage = PythonPackage( | ||
distribution = "testPackage", | ||
name = "testPackage", | ||
version = "1.0.0", | ||
modules = listOf( | ||
PythonModule( | ||
name = "testModule", | ||
classes = listOf(testClass), | ||
functions = listOf(testFunction) | ||
) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `should process DescriptionAnnotation of classes`() { | ||
testPackage.processDescriptionAnnotations() | ||
|
||
testClass.description shouldBe "Important class" | ||
} | ||
|
||
@Test | ||
fun `should remove DescriptionAnnotation of classes`() { | ||
testPackage.processDescriptionAnnotations() | ||
|
||
testClass.annotations | ||
.filterIsInstance<DescriptionAnnotation>() | ||
.shouldBeEmpty() | ||
} | ||
|
||
@Test | ||
fun `should process DescriptionAnnotation of functions`() { | ||
testPackage.processDescriptionAnnotations() | ||
|
||
testFunction.description shouldBe "Important function" | ||
} | ||
|
||
@Test | ||
fun `should remove DescriptionAnnotation of functions`() { | ||
testPackage.processDescriptionAnnotations() | ||
|
||
testFunction.annotations | ||
.filterIsInstance<DescriptionAnnotation>() | ||
.shouldBeEmpty() | ||
} | ||
|
||
@Test | ||
fun `should process DescriptionAnnotation of parameters`() { | ||
testPackage.processDescriptionAnnotations() | ||
|
||
testParameter.description shouldBe "Important parameter" | ||
} | ||
|
||
@Test | ||
fun `should remove DescriptionAnnotation of parameters`() { | ||
testPackage.processDescriptionAnnotations() | ||
|
||
testParameter.annotations | ||
.filterIsInstance<DescriptionAnnotation>() | ||
.shouldBeEmpty() | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.