Skip to content

Commit 76e417c

Browse files
authored
Merge pull request github#14940 from igfoo/igfoo/comments
Kotlin 2: Comment improvements
2 parents 49d6d3f + 5d3166c commit 76e417c

File tree

5 files changed

+17
-51
lines changed

5 files changed

+17
-51
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ open class KotlinFileExtractor(
205205
}
206206

207207
@OptIn(ObsoleteDescriptorBasedAPI::class)
208-
private fun isFake(d: IrDeclarationWithVisibility): Boolean {
208+
fun isFake(d: IrDeclarationWithVisibility): Boolean {
209209
val hasFakeVisibility =
210210
d.visibility.let {
211211
it is DelegatedDescriptorVisibility && it.delegate == Visibilities.InvisibleFake

java/kotlin-extractor/src/main/kotlin/comments/CommentExtractor.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ open class CommentExtractor(
4141
tw.getExistingLabelFor<DbTop>(label)
4242
}
4343
if (existingLabel == null) {
44-
logger.warn("Couldn't get existing label for $label")
44+
// Sometimes we don't extract elements.
45+
// The actual extractor logic is a bit more nuanced than
46+
// just "isFake", but just checking isFake is good enough
47+
// to not bother with a warning.
48+
if (element !is IrDeclarationWithVisibility || !fileExtractor.isFake(element)) {
49+
logger.warn("Couldn't get existing label for $label")
50+
}
4551
return null
4652
}
4753
return existingLabel

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/CommentExtractorLighterAST.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import org.jetbrains.kotlin.kdoc.lexer.KDocTokens
1515
import org.jetbrains.kotlin.lexer.KtTokens
1616
import org.jetbrains.kotlin.util.getChildren
1717

18+
// TODO: This doesn't give owners to as many comments as the PSI extractor does.
19+
// See the library-tests/comments tests for details.
20+
1821
class CommentExtractorLighterAST(
1922
fileExtractor: KotlinFileExtractor,
2023
file: IrFile,

java/ql/test-kotlin2/library-tests/comments/comments.expected

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,68 +15,27 @@ comments
1515
| comments.kt:71:9:73:11 | /**\n * An anonymous function comment\n */ | /**\n * An anonymous function comment\n */ |
1616
| comments.kt:79:9:81:11 | /**\n * A local function comment\n */ | /**\n * A local function comment\n */ |
1717
| comments.kt:88:10:90:11 | /**\n * An anonymous object comment\n */ | /**\n * An anonymous object comment\n */ |
18-
| comments.kt:95:1:95:163 | // Diagnostic Matches: % Couldn't get owner of KDoc. The comment is extracted without an owner. ...while extracting a file (comments.kt) at %comments.kt:1:1:96:0% | // Diagnostic Matches: % Couldn't get owner of KDoc. The comment is extracted without an owner. ...while extracting a file (comments.kt) at %comments.kt:1:1:96:0% |
1918
commentOwners
2019
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | comments.kt:12:1:31:1 | Group |
21-
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | comments.kt:12:1:31:1 | Group |
20+
| comments.kt:14:5:16:7 | /**\n * Members of this group.\n */ | comments.kt:17:5:17:46 | getMembers$private |
2221
| comments.kt:14:5:16:7 | /**\n * Members of this group.\n */ | comments.kt:17:5:17:46 | members |
2322
| comments.kt:14:5:16:7 | /**\n * Members of this group.\n */ | comments.kt:17:5:17:46 | members |
24-
| comments.kt:14:5:16:7 | /**\n * Members of this group.\n */ | comments.kt:17:13:17:46 | getMembers$private |
2523
| comments.kt:19:5:22:7 | /**\n * Adds a [member] to this group.\n * @return the new size of the group.\n */ | comments.kt:23:5:26:5 | add |
26-
| comments.kt:35:5:35:34 | /** Medium is in the middle */ | comments.kt:36:5:36:14 | Medium |
27-
| comments.kt:37:5:37:23 | /** This is high */ | comments.kt:38:5:38:11 | High |
28-
| comments.kt:48:1:50:3 | /**\n * A type alias comment\n */ | comments.kt:51:1:51:24 | MyType |
29-
| comments.kt:54:5:56:7 | /**\n * An init block comment\n */ | comments.kt:53:1:58:1 | InitBlock |
3024
| comments.kt:61:5:63:7 | /**\n * A prop comment\n */ | comments.kt:64:5:68:17 | prop |
3125
| comments.kt:65:9:67:11 | /**\n * An accessor comment\n */ | comments.kt:68:9:68:17 | getProp |
32-
| comments.kt:71:9:73:11 | /**\n * An anonymous function comment\n */ | comments.kt:70:5:76:10 | getL |
33-
| comments.kt:71:9:73:11 | /**\n * An anonymous function comment\n */ | comments.kt:70:5:76:10 | l |
34-
| comments.kt:71:9:73:11 | /**\n * An anonymous function comment\n */ | comments.kt:70:5:76:10 | l |
3526
| comments.kt:79:9:81:11 | /**\n * A local function comment\n */ | comments.kt:82:9:82:24 | localFn |
36-
| comments.kt:88:10:90:11 | /**\n * An anonymous object comment\n */ | comments.kt:87:15:92:5 | |
3727
| comments.kt:88:10:90:11 | /**\n * An anonymous object comment\n */ | comments.kt:87:15:92:5 | new X(...) { ... } |
3828
commentNoOwners
3929
| comments.kt:1:1:1:25 | /** Kdoc with no owner */ |
4030
| comments.kt:24:9:24:25 | // A line comment |
4131
| comments.kt:28:5:30:6 | /*\n A block comment\n */ |
32+
| comments.kt:35:5:35:34 | /** Medium is in the middle */ |
33+
| comments.kt:37:5:37:23 | /** This is high */ |
4234
| comments.kt:42:5:44:7 | /**\n * A variable.\n */ |
43-
| comments.kt:95:1:95:163 | // Diagnostic Matches: % Couldn't get owner of KDoc. The comment is extracted without an owner. ...while extracting a file (comments.kt) at %comments.kt:1:1:96:0% |
35+
| comments.kt:48:1:50:3 | /**\n * A type alias comment\n */ |
36+
| comments.kt:54:5:56:7 | /**\n * An init block comment\n */ |
37+
| comments.kt:71:9:73:11 | /**\n * An anonymous function comment\n */ |
4438
commentSections
45-
| comments.kt:1:1:1:25 | /** Kdoc with no owner */ | Kdoc with no owner |
46-
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | A group of *members*.\n\nThis class has no useful logic; it's just a documentation example.\n\n |
47-
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | Creates an empty group. |
48-
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | the name of this group. |
49-
| comments.kt:14:5:16:7 | /**\n * Members of this group.\n */ | Members of this group. |
50-
| comments.kt:19:5:22:7 | /**\n * Adds a [member] to this group.\n * @return the new size of the group.\n */ | Adds a [member] to this group.\n |
51-
| comments.kt:35:5:35:34 | /** Medium is in the middle */ | Medium is in the middle |
52-
| comments.kt:37:5:37:23 | /** This is high */ | This is high |
53-
| comments.kt:42:5:44:7 | /**\n * A variable.\n */ | A variable. |
54-
| comments.kt:48:1:50:3 | /**\n * A type alias comment\n */ | A type alias comment |
55-
| comments.kt:54:5:56:7 | /**\n * An init block comment\n */ | An init block comment |
56-
| comments.kt:61:5:63:7 | /**\n * A prop comment\n */ | A prop comment |
57-
| comments.kt:65:9:67:11 | /**\n * An accessor comment\n */ | An accessor comment |
58-
| comments.kt:71:9:73:11 | /**\n * An anonymous function comment\n */ | An anonymous function comment |
59-
| comments.kt:79:9:81:11 | /**\n * A local function comment\n */ | A local function comment |
60-
| comments.kt:88:10:90:11 | /**\n * An anonymous object comment\n */ | An anonymous object comment |
6139
commentSectionContents
62-
| A group of *members*.\n\nThis class has no useful logic; it's just a documentation example.\n\n | A group of *members*.\n\nThis class has no useful logic; it's just a documentation example.\n\n |
63-
| A local function comment | A local function comment |
64-
| A prop comment | A prop comment |
65-
| A type alias comment | A type alias comment |
66-
| A variable. | A variable. |
67-
| Adds a [member] to this group.\n | Adds a [member] to this group.\n |
68-
| An accessor comment | An accessor comment |
69-
| An anonymous function comment | An anonymous function comment |
70-
| An anonymous object comment | An anonymous object comment |
71-
| An init block comment | An init block comment |
72-
| Creates an empty group. | Creates an empty group. |
73-
| Kdoc with no owner | Kdoc with no owner |
74-
| Medium is in the middle | Medium is in the middle |
75-
| Members of this group. | Members of this group. |
76-
| This is high | This is high |
77-
| the name of this group. | the name of this group. |
7840
commentSectionNames
79-
| Creates an empty group. | constructor |
80-
| the name of this group. | property |
8141
commentSectionSubjectNames
82-
| the name of this group. | name |

java/ql/test-kotlin2/library-tests/comments/comments.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,3 @@ class XX {
9191
X() {
9292
}
9393
}
94-
95-
// Diagnostic Matches: % Couldn't get owner of KDoc. The comment is extracted without an owner. ...while extracting a file (comments.kt) at %comments.kt:1:1:96:0%

0 commit comments

Comments
 (0)