forked from JetBrains/kotlin
-
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.
Show calls of TODO() function in TODO view
#KT-8617 Fixed
- Loading branch information
Showing
6 changed files
with
131 additions
and
1 deletion.
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
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
65 changes: 65 additions & 0 deletions
65
idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinTodoSearcher.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,65 @@ | ||
/* | ||
* Copyright 2010-2017 JetBrains s.r.o. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.idea.search.ideaExtensions | ||
|
||
import com.intellij.openapi.application.QueryExecutorBase | ||
import com.intellij.openapi.util.TextRange | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.psi.impl.cache.TodoCacheManager | ||
import com.intellij.psi.search.IndexPattern | ||
import com.intellij.psi.search.IndexPatternOccurrence | ||
import com.intellij.psi.search.searches.IndexPatternSearch | ||
import com.intellij.util.Processor | ||
import org.jetbrains.kotlin.psi.KtCallExpression | ||
import org.jetbrains.kotlin.psi.KtTreeVisitorVoid | ||
|
||
data class KotlinTodoOccurrence(private val _file: PsiFile, private val _textRange: TextRange, private val _pattern: IndexPattern) : IndexPatternOccurrence { | ||
override fun getFile() = _file | ||
override fun getPattern() = _pattern | ||
override fun getTextRange() = _textRange | ||
} | ||
|
||
class KotlinTodoSearcher : QueryExecutorBase<IndexPatternOccurrence, IndexPatternSearch.SearchParameters>(true) { | ||
override fun processQuery(queryParameters: IndexPatternSearch.SearchParameters, consumer: Processor<IndexPatternOccurrence>) { | ||
var pattern = queryParameters.pattern | ||
if (pattern != null && !pattern.patternString.contains("TODO", true)) return | ||
if (pattern == null) { | ||
pattern = queryParameters.patternProvider.indexPatterns.firstOrNull { it.patternString.contains("TODO", true) } ?: return | ||
} | ||
|
||
val file = queryParameters.file | ||
|
||
val cacheManager = TodoCacheManager.SERVICE.getInstance(file.project) | ||
val patternProvider = queryParameters.patternProvider | ||
val count = if (patternProvider != null) { | ||
cacheManager.getTodoCount(file.virtualFile, patternProvider)} | ||
else | ||
cacheManager.getTodoCount(file.virtualFile, pattern) | ||
if (count == 0) return | ||
|
||
file.accept(object : KtTreeVisitorVoid() { | ||
override fun visitCallExpression(expression: KtCallExpression) { | ||
if (expression.calleeExpression?.text == "TODO") { | ||
val argList = expression.valueArgumentList | ||
if (argList?.arguments?.size == 1) { | ||
consumer.process(KotlinTodoOccurrence(file, expression.textRange, pattern)) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} |
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 @@ | ||
fun foo() = TODO("Fix me") |
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,4 @@ | ||
fun TODO() { | ||
} | ||
|
||
val TODO = 1 |
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,43 @@ | ||
/* | ||
* Copyright 2010-2017 JetBrains s.r.o. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.search | ||
|
||
import com.intellij.psi.search.PsiTodoSearchHelper | ||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase | ||
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor | ||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase | ||
import java.io.File | ||
|
||
class TodoSearchTest : KotlinLightCodeInsightFixtureTestCase() { | ||
override fun getProjectDescriptor(): KotlinLightProjectDescriptor = KotlinLightProjectDescriptor.INSTANCE | ||
|
||
override fun getTestDataPath(): String { | ||
return File(PluginTestCaseBase.getTestDataPathBase(), "/search/todo").path + File.separator | ||
} | ||
|
||
fun testTodoCall() { | ||
val file = myFixture.configureByFile("todoCall.kt") | ||
val todoItems = PsiTodoSearchHelper.SERVICE.getInstance(myFixture.project).findTodoItems(file) | ||
assertEquals(1, todoItems.size) | ||
assertEquals("TODO(\"Fix me\")", todoItems[0].textRange.substring(todoItems[0].file.text)) | ||
} | ||
|
||
fun testTodoDef() { | ||
val file = myFixture.configureByFile("todoDecl.kt") | ||
assertEquals(0, PsiTodoSearchHelper.SERVICE.getInstance(myFixture.project).getTodoItemsCount(file)) | ||
} | ||
} |