From f1907e692b6b41b950047df4ca90bac54a11cd21 Mon Sep 17 00:00:00 2001 From: Bart van Helvert Date: Wed, 19 Jan 2022 19:00:31 +0100 Subject: [PATCH] [kssr] KTIJ-20735 Change `Val/Var only filter` to `Also match Val/Var modifier` GitOrigin-RevId: a41f66bf93fc884d7ca414feaeede00731869918 --- .../messages/KotlinBundle.properties | 17 +++++---- .../KotlinPredefinedConfigurations.kt | 23 +++++------- .../KotlinStructuralSearchProfile.kt | 19 +++++----- .../filters/AlsoMatchValModifier.kt | 15 ++++++++ .../filters/AlsoMatchVarModifier.kt | 15 ++++++++ .../filters/KotlinFilterProvider.kt | 9 +++++ .../filters/VarValOnlyFilter.kt | 35 ------------------- .../KotlinAlsoMatchValVarPredicate.kt | 12 +++++++ .../predicates/KotlinVarValOnlyPredicate.kt | 16 --------- .../visitor/KotlinMatchingVisitor.kt | 15 ++++---- .../filters/KotlinSSCustomFilterTests.kt | 16 --------- .../filters/KotlinSSValVarModifierTests.kt | 26 ++++++++++++++ .../customFilter/valOnlyFilter.kt | 8 ----- .../customFilter/varOnlyFilter.kt | 8 ----- .../testData/structuralsearch/property/val.kt | 2 +- .../property/valInitializer.kt | 2 +- .../testData/structuralsearch/property/var.kt | 2 +- 17 files changed, 112 insertions(+), 128 deletions(-) create mode 100644 plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/AlsoMatchValModifier.kt create mode 100644 plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/AlsoMatchVarModifier.kt create mode 100644 plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/KotlinFilterProvider.kt delete mode 100644 plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/VarValOnlyFilter.kt create mode 100644 plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/predicates/KotlinAlsoMatchValVarPredicate.kt delete mode 100644 plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/predicates/KotlinVarValOnlyPredicate.kt delete mode 100644 plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/structuralsearch/filters/KotlinSSCustomFilterTests.kt create mode 100644 plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/structuralsearch/search/filters/KotlinSSValVarModifierTests.kt delete mode 100644 plugins/kotlin/idea/tests/testData/structuralsearch/customFilter/valOnlyFilter.kt delete mode 100644 plugins/kotlin/idea/tests/testData/structuralsearch/customFilter/varOnlyFilter.kt diff --git a/plugins/kotlin/frontend-independent/resources-en/messages/KotlinBundle.properties b/plugins/kotlin/frontend-independent/resources-en/messages/KotlinBundle.properties index f50323aa2943..694e4952a021 100644 --- a/plugins/kotlin/frontend-independent/resources-en/messages/KotlinBundle.properties +++ b/plugins/kotlin/frontend-independent/resources-en/messages/KotlinBundle.properties @@ -1958,15 +1958,15 @@ error.expected.catch.or.finally=Expecting 'catch' or 'finally' error.param.can.t.be.null.at.index.0.in.1=Param can''t be null at index {0} in {1}. error.type.filter.node=Kotlin matching element should either be an expression or a statement. -filter.match.only.vals=Match only vals -filter.match.only.vars=Match only vars +modifier.match.val=Match val +modifier.match.var=Match var -label.match.only.vals=Only matches vals -label.match.only.vars=Only matches vars +modifier.also.match.val=Also match val +modifier.also.match.var=Also match var predefined.configuration.all.methods.of.the.class=All methods of a class -predefined.configuration.all.vars.of.the.class=All vars/vals of a class -predefined.configuration.all.vars.of.the.object=All vars/vals of an object or companion object +predefined.configuration.all.vars.of.the.class=All vars of a class +predefined.configuration.all.vars.of.the.object=All vars of an object or companion object predefined.configuration.annotations=Annotations predefined.configuration.anonymous.class=Anonymous class predefined.configuration.array.access=Array access @@ -1991,9 +1991,8 @@ predefined.configuration.string.literals=String literals predefined.configuration.strings=Strings predefined.configuration.strings.with.long.template=Strings containing a long template predefined.configuration.trys=Try's -predefined.configuration.vals.only=Vals only -predefined.configuration.vars.of.given.type=Vars and vals of given type -predefined.configuration.vars.only=Vars only +predefined.configuration.vars.of.given.type=Vars of given type +predefined.configuration.also.match.vals=Match both vars and vals predefined.configuration.when=When expressions predefined.configuration.while=While loops diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/KotlinPredefinedConfigurations.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/KotlinPredefinedConfigurations.kt index b4035b4a3612..86bf17997f5a 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/KotlinPredefinedConfigurations.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/KotlinPredefinedConfigurations.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea.structuralsearch @@ -9,9 +9,8 @@ import org.jetbrains.annotations.Nls import org.jetbrains.annotations.NonNls import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinFileType +import org.jetbrains.kotlin.idea.structuralsearch.filters.AlsoMatchValModifier import org.jetbrains.kotlin.idea.structuralsearch.filters.OneStateFilter -import org.jetbrains.kotlin.idea.structuralsearch.filters.ValOnlyFilter -import org.jetbrains.kotlin.idea.structuralsearch.filters.VarOnlyFilter object KotlinPredefinedConfigurations { private val CLASS_TYPE get() = KotlinBundle.message("category.class") @@ -33,7 +32,7 @@ object KotlinPredefinedConfigurations { // Classes searchTemplate( KotlinBundle.message("predefined.configuration.all.vars.of.the.class"), - "all vars/vals of a class", + "all vars of a class", """ class '_Class { var 'Field+ = '_Init? @@ -53,7 +52,7 @@ object KotlinPredefinedConfigurations { ), searchTemplate( KotlinBundle.message("predefined.configuration.all.vars.of.the.object"), - "all vars/vals of an object or companion object", + "all vars of an object or companion object", """ object '_Object { var 'Field+ = '_Init? @@ -139,20 +138,14 @@ object KotlinPredefinedConfigurations { EXPRESSION_TYPE ), searchTemplate( - KotlinBundle.message("predefined.configuration.vars.only"), - "vars only", - """var '_Variable:[_${VarOnlyFilter.CONSTRAINT_NAME}(${OneStateFilter.ENABLED})]""", - EXPRESSION_TYPE - ), - searchTemplate( - KotlinBundle.message("predefined.configuration.vals.only"), - "vals only", - """val '_Value:[_${ValOnlyFilter.CONSTRAINT_NAME}(${OneStateFilter.ENABLED})]""", + KotlinBundle.message("predefined.configuration.also.match.vals"), + "var also match vals", + """var '_Variable:[_${AlsoMatchValModifier.CONSTRAINT_NAME}(${OneStateFilter.ENABLED})]""", EXPRESSION_TYPE ), searchTemplate( KotlinBundle.message("predefined.configuration.vars.of.given.type"), - "vars and vals of given type", + "vars of a given type", """var '_Variable:[exprtype(Int)] = '_Init""", EXPRESSION_TYPE ), diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/KotlinStructuralSearchProfile.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/KotlinStructuralSearchProfile.kt index fba3ac93b351..e13372382f83 100755 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/KotlinStructuralSearchProfile.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/KotlinStructuralSearchProfile.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea.structuralsearch @@ -28,11 +28,11 @@ import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.idea.KotlinLanguage import org.jetbrains.kotlin.idea.liveTemplates.KotlinTemplateContextType +import org.jetbrains.kotlin.idea.structuralsearch.filters.AlsoMatchValModifier +import org.jetbrains.kotlin.idea.structuralsearch.filters.AlsoMatchVarModifier import org.jetbrains.kotlin.idea.structuralsearch.filters.OneStateFilter -import org.jetbrains.kotlin.idea.structuralsearch.filters.ValOnlyFilter -import org.jetbrains.kotlin.idea.structuralsearch.filters.VarOnlyFilter +import org.jetbrains.kotlin.idea.structuralsearch.predicates.KotlinAlsoMatchValVarPredicate import org.jetbrains.kotlin.idea.structuralsearch.predicates.KotlinExprTypePredicate -import org.jetbrains.kotlin.idea.structuralsearch.predicates.KotlinVarValOnlyPredicate import org.jetbrains.kotlin.idea.structuralsearch.visitor.KotlinCompilingVisitor import org.jetbrains.kotlin.idea.structuralsearch.visitor.KotlinMatchingVisitor import org.jetbrains.kotlin.idea.structuralsearch.visitor.KotlinRecursiveElementWalkingVisitor @@ -205,8 +205,8 @@ class KotlinStructuralSearchProfile : StructuralSearchProfile() { UIUtil.MAXIMUM_UNLIMITED -> isApplicableMaxCount(variableNode) || isApplicableMinMaxCount(variableNode) UIUtil.TEXT_HIERARCHY -> isApplicableTextHierarchy(variableNode) UIUtil.REFERENCE -> isApplicableReference(variableNode) - ValOnlyFilter.CONSTRAINT_NAME -> variableNode.parent is KtProperty && !(variableNode.parent as KtProperty).isVar - VarOnlyFilter.CONSTRAINT_NAME -> variableNode.parent is KtProperty && (variableNode.parent as KtProperty).isVar + AlsoMatchVarModifier.CONSTRAINT_NAME -> variableNode.parent is KtProperty && !(variableNode.parent as KtProperty).isVar + AlsoMatchValModifier.CONSTRAINT_NAME -> variableNode.parent is KtProperty && (variableNode.parent as KtProperty).isVar else -> super.isApplicableConstraint(constraintName, variableNode, completePattern, target) } @@ -331,10 +331,9 @@ class KotlinStructuralSearchProfile : StructuralSearchProfile() { ) result.add(if (isInvertExprType) NotPredicate(predicate) else predicate) } - if (getAdditionalConstraint(VarOnlyFilter.CONSTRAINT_NAME) == OneStateFilter.ENABLED) - result.add(KotlinVarValOnlyPredicate(true)) - else if (getAdditionalConstraint(ValOnlyFilter.CONSTRAINT_NAME) == OneStateFilter.ENABLED) - result.add(KotlinVarValOnlyPredicate(false)) + if (getAdditionalConstraint(AlsoMatchValModifier.CONSTRAINT_NAME) == OneStateFilter.ENABLED || + getAdditionalConstraint(AlsoMatchVarModifier.CONSTRAINT_NAME) == OneStateFilter.ENABLED + ) result.add(KotlinAlsoMatchValVarPredicate()) } return result } diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/AlsoMatchValModifier.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/AlsoMatchValModifier.kt new file mode 100644 index 000000000000..1606447072d5 --- /dev/null +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/AlsoMatchValModifier.kt @@ -0,0 +1,15 @@ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.kotlin.idea.structuralsearch.filters + +import org.jetbrains.annotations.NonNls +import org.jetbrains.kotlin.idea.KotlinBundle + +class AlsoMatchValModifier : OneStateFilter( + KotlinBundle.lazyMessage("modifier.match.val"), + KotlinBundle.message("modifier.also.match.val"), + CONSTRAINT_NAME +) { + companion object { + const val CONSTRAINT_NAME: @NonNls String = "kotlinAlsoMatchVal" + } +} \ No newline at end of file diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/AlsoMatchVarModifier.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/AlsoMatchVarModifier.kt new file mode 100644 index 000000000000..78548aa6d628 --- /dev/null +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/AlsoMatchVarModifier.kt @@ -0,0 +1,15 @@ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.kotlin.idea.structuralsearch.filters + +import org.jetbrains.annotations.NonNls +import org.jetbrains.kotlin.idea.KotlinBundle + +class AlsoMatchVarModifier : OneStateFilter( + KotlinBundle.lazyMessage("modifier.match.var"), + KotlinBundle.message("modifier.also.match.var"), + CONSTRAINT_NAME +) { + companion object { + const val CONSTRAINT_NAME: @NonNls String = "kotlinAlsoMatchVar" + } +} \ No newline at end of file diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/KotlinFilterProvider.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/KotlinFilterProvider.kt new file mode 100644 index 000000000000..39fcd59f85a2 --- /dev/null +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/KotlinFilterProvider.kt @@ -0,0 +1,9 @@ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.kotlin.idea.structuralsearch.filters + +import com.intellij.structuralsearch.plugin.ui.filters.FilterAction +import com.intellij.structuralsearch.plugin.ui.filters.FilterProvider + +class KotlinFilterProvider : FilterProvider { + override fun getFilters(): List = listOf(AlsoMatchValModifier(), AlsoMatchVarModifier()) +} \ No newline at end of file diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/VarValOnlyFilter.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/VarValOnlyFilter.kt deleted file mode 100644 index e70150b308f4..000000000000 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/filters/VarValOnlyFilter.kt +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package org.jetbrains.kotlin.idea.structuralsearch.filters - -import com.intellij.structuralsearch.plugin.ui.filters.FilterAction -import com.intellij.structuralsearch.plugin.ui.filters.FilterProvider -import org.jetbrains.kotlin.idea.KotlinBundle - -class KotlinFilterProvider : FilterProvider { - override fun getFilters(): List = listOf(VarOnlyFilter(), ValOnlyFilter()) -} - -class VarOnlyFilter : OneStateFilter( - KotlinBundle.lazyMessage("filter.match.only.vars"), - KotlinBundle.message("label.match.only.vars"), - CONSTRAINT_NAME -) { - - companion object { - const val CONSTRAINT_NAME: String = "kotlinVarOnly" - } - -} - -class ValOnlyFilter : OneStateFilter( - KotlinBundle.lazyMessage("filter.match.only.vals"), - KotlinBundle.message("label.match.only.vals"), - CONSTRAINT_NAME -) { - - companion object { - const val CONSTRAINT_NAME: String = "kotlinValOnly" - } - -} \ No newline at end of file diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/predicates/KotlinAlsoMatchValVarPredicate.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/predicates/KotlinAlsoMatchValVarPredicate.kt new file mode 100644 index 000000000000..0f40fdc05f5c --- /dev/null +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/predicates/KotlinAlsoMatchValVarPredicate.kt @@ -0,0 +1,12 @@ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + +package org.jetbrains.kotlin.idea.structuralsearch.predicates + +import com.intellij.psi.PsiElement +import com.intellij.structuralsearch.impl.matcher.MatchContext +import com.intellij.structuralsearch.impl.matcher.predicates.MatchPredicate + +/** When applying also match val/var modifier, always match property */ +class KotlinAlsoMatchValVarPredicate : MatchPredicate() { + override fun match(matchedNode: PsiElement, start: Int, end: Int, context: MatchContext): Boolean = true +} \ No newline at end of file diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/predicates/KotlinVarValOnlyPredicate.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/predicates/KotlinVarValOnlyPredicate.kt deleted file mode 100644 index 8b57327937ec..000000000000 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/predicates/KotlinVarValOnlyPredicate.kt +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package org.jetbrains.kotlin.idea.structuralsearch.predicates - -import com.intellij.psi.PsiElement -import com.intellij.structuralsearch.impl.matcher.MatchContext -import com.intellij.structuralsearch.impl.matcher.predicates.MatchPredicate -import org.jetbrains.kotlin.psi.KtProperty - -class KotlinVarValOnlyPredicate(private val isVar: Boolean) : MatchPredicate() { - override fun match(matchedNode: PsiElement, start: Int, end: Int, context: MatchContext): Boolean { - val parent = matchedNode.parent - if (parent !is KtProperty) return false - return parent.isVar == isVar - } -} \ No newline at end of file diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/visitor/KotlinMatchingVisitor.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/visitor/KotlinMatchingVisitor.kt index f5c94afcadaf..e45eef0a889d 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/visitor/KotlinMatchingVisitor.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/structuralsearch/visitor/KotlinMatchingVisitor.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea.structuralsearch.visitor @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.idea.search.declarationsSearch.HierarchySearchReques import org.jetbrains.kotlin.idea.search.declarationsSearch.searchInheritors import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor import org.jetbrains.kotlin.idea.structuralsearch.* +import org.jetbrains.kotlin.idea.structuralsearch.predicates.KotlinAlsoMatchValVarPredicate import org.jetbrains.kotlin.idea.util.safeAnalyzeNonSourceRootCode import org.jetbrains.kotlin.kdoc.lexer.KDocTokens import org.jetbrains.kotlin.kdoc.psi.api.KDoc @@ -1080,19 +1081,17 @@ class KotlinMatchingVisitor(private val myMatchingVisitor: GlobalMatchingVisitor override fun visitProperty(property: KtProperty) { val other = getTreeElementDepar() ?: return - - myMatchingVisitor.result = matchTypeReferenceWithDeclaration(property.typeReference, other) + val handler = getHandler(property.nameIdentifier!!) + myMatchingVisitor.result = ( + property.isVar == other.isVar || (handler is SubstitutionHandler && handler.predicate is KotlinAlsoMatchValVarPredicate) + ) && matchTypeReferenceWithDeclaration(property.typeReference, other) && myMatchingVisitor.match(property.modifierList, other.modifierList) && matchTextOrVariable(property.nameIdentifier, other.nameIdentifier) && myMatchingVisitor.match(property.docComment, other.docComment) - && myMatchingVisitor.matchOptionally( - property.delegateExpressionOrInitializer, - other.delegateExpressionOrInitializer - ) + && myMatchingVisitor.matchOptionally(property.delegateExpressionOrInitializer, other.delegateExpressionOrInitializer) && myMatchingVisitor.match(property.getter, other.getter) && myMatchingVisitor.match(property.setter, other.setter) && myMatchingVisitor.match(property.receiverTypeReference, other.receiverTypeReference) - val handler = getHandler(property.nameIdentifier!!) if (myMatchingVisitor.result && handler is SubstitutionHandler) { handler.handle(other.nameIdentifier, myMatchingVisitor.matchContext) diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/structuralsearch/filters/KotlinSSCustomFilterTests.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/structuralsearch/filters/KotlinSSCustomFilterTests.kt deleted file mode 100644 index 4341a6850fd7..000000000000 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/structuralsearch/filters/KotlinSSCustomFilterTests.kt +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package org.jetbrains.kotlin.idea.structuralsearch.filters - -import org.jetbrains.kotlin.idea.structuralsearch.KotlinSSResourceInspectionTest - -class KotlinSSCustomFilterTests: KotlinSSResourceInspectionTest() { - override fun getBasePath(): String = "customFilter" - - private val enabled = OneStateFilter.ENABLED - - fun testVarOnlyFilter() { doTest("var '_:[_${VarOnlyFilter.CONSTRAINT_NAME}($enabled)]") } - - fun testValOnlyFilter() { doTest("val '_:[_${ValOnlyFilter.CONSTRAINT_NAME}($enabled)]") } - -} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/structuralsearch/search/filters/KotlinSSValVarModifierTests.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/structuralsearch/search/filters/KotlinSSValVarModifierTests.kt new file mode 100644 index 000000000000..9a095ae16010 --- /dev/null +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/structuralsearch/search/filters/KotlinSSValVarModifierTests.kt @@ -0,0 +1,26 @@ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + +package org.jetbrains.kotlin.idea.structuralsearch.search.filters + +import org.jetbrains.kotlin.idea.structuralsearch.KotlinSSResourceInspectionTest +import org.jetbrains.kotlin.idea.structuralsearch.filters.AlsoMatchValModifier +import org.jetbrains.kotlin.idea.structuralsearch.filters.AlsoMatchVarModifier +import org.jetbrains.kotlin.idea.structuralsearch.filters.OneStateFilter + +class KotlinSSValVarModifierTests: KotlinSSResourceInspectionTest() { + fun testAlsoMatchValModifier() { doTest("var '_:[_${AlsoMatchValModifier.CONSTRAINT_NAME}(${OneStateFilter.ENABLED})]", """ + fun main() { + var x = 1 + val y = 1 + print(x + y) + } + """.trimIndent()) } + + fun testAlsoMatchVarModifier() { doTest("val '_:[_${AlsoMatchVarModifier.CONSTRAINT_NAME}(${OneStateFilter.ENABLED})]", """ + fun main() { + var x = 1 + val y = 1 + print(x + y) + } + """.trimIndent()) } +} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/structuralsearch/customFilter/valOnlyFilter.kt b/plugins/kotlin/idea/tests/testData/structuralsearch/customFilter/valOnlyFilter.kt deleted file mode 100644 index 6d9838488bbd..000000000000 --- a/plugins/kotlin/idea/tests/testData/structuralsearch/customFilter/valOnlyFilter.kt +++ /dev/null @@ -1,8 +0,0 @@ -fun main() { - - var x = 1 - val y = 1 - - print(x + y) - -} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/structuralsearch/customFilter/varOnlyFilter.kt b/plugins/kotlin/idea/tests/testData/structuralsearch/customFilter/varOnlyFilter.kt deleted file mode 100644 index 74bbe1353f58..000000000000 --- a/plugins/kotlin/idea/tests/testData/structuralsearch/customFilter/varOnlyFilter.kt +++ /dev/null @@ -1,8 +0,0 @@ -fun main() { - - var x = 1 - val y = 1 - - print(x + y) - -} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/structuralsearch/property/val.kt b/plugins/kotlin/idea/tests/testData/structuralsearch/property/val.kt index 8329ec6ba377..d03a9defaac6 100644 --- a/plugins/kotlin/idea/tests/testData/structuralsearch/property/val.kt +++ b/plugins/kotlin/idea/tests/testData/structuralsearch/property/val.kt @@ -1,5 +1,5 @@ fun main() { val foo = 1 - var bar: Int = 1 + var bar: Int = 1 print(foo + bar) } diff --git a/plugins/kotlin/idea/tests/testData/structuralsearch/property/valInitializer.kt b/plugins/kotlin/idea/tests/testData/structuralsearch/property/valInitializer.kt index 3f16b7859d9f..dadc99591f3c 100644 --- a/plugins/kotlin/idea/tests/testData/structuralsearch/property/valInitializer.kt +++ b/plugins/kotlin/idea/tests/testData/structuralsearch/property/valInitializer.kt @@ -1,7 +1,7 @@ fun main() { val foo = 1 val foo2: Int - var bar: Int = 1 + var bar: Int = 1 foo2 = 1 val bar2: Int = 1 val bar3: Int = (1) diff --git a/plugins/kotlin/idea/tests/testData/structuralsearch/property/var.kt b/plugins/kotlin/idea/tests/testData/structuralsearch/property/var.kt index c586171ea80d..ee7595dd1068 100644 --- a/plugins/kotlin/idea/tests/testData/structuralsearch/property/var.kt +++ b/plugins/kotlin/idea/tests/testData/structuralsearch/property/var.kt @@ -1,5 +1,5 @@ fun main() { - val foo = 1 + val foo = 1 var bar = 1 print(foo + bar) }