Hide Kotlin live template macros from non-Kotlin contexts
#KT-16635 Fixed
This commit is contained in:
+1
-1
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered
|
import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered
|
||||||
|
|
||||||
class AnonymousSuperMacro : Macro() {
|
class AnonymousSuperMacro : KotlinMacro() {
|
||||||
override fun getName() = "anonymousSuper"
|
override fun getName() = "anonymousSuper"
|
||||||
override fun getPresentableName() = "anonymousSuper()"
|
override fun getPresentableName() = "anonymousSuper()"
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -17,7 +17,10 @@
|
|||||||
package org.jetbrains.kotlin.idea.liveTemplates.macro
|
package org.jetbrains.kotlin.idea.liveTemplates.macro
|
||||||
|
|
||||||
import com.intellij.codeInsight.lookup.LookupElement
|
import com.intellij.codeInsight.lookup.LookupElement
|
||||||
import com.intellij.codeInsight.template.*
|
import com.intellij.codeInsight.template.Expression
|
||||||
|
import com.intellij.codeInsight.template.ExpressionContext
|
||||||
|
import com.intellij.codeInsight.template.Result
|
||||||
|
import com.intellij.codeInsight.template.TextResult
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
@@ -39,7 +42,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
|
|
||||||
abstract class BaseKotlinVariableMacro<TState> : Macro() {
|
abstract class BaseKotlinVariableMacro<TState> : KotlinMacro() {
|
||||||
private fun getVariables(params: Array<Expression>, context: ExpressionContext): Collection<VariableDescriptor> {
|
private fun getVariables(params: Array<Expression>, context: ExpressionContext): Collection<VariableDescriptor> {
|
||||||
if (params.size != 0) return emptyList()
|
if (params.size != 0) return emptyList()
|
||||||
|
|
||||||
|
|||||||
+1
-4
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiDocumentManager
|
|||||||
import org.jetbrains.kotlin.psi.KtFunction
|
import org.jetbrains.kotlin.psi.KtFunction
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class FunctionParametersMacro : Macro() {
|
class FunctionParametersMacro : KotlinMacro() {
|
||||||
override fun getName() = "functionParameters"
|
override fun getName() = "functionParameters"
|
||||||
override fun getPresentableName() = "functionParameters()"
|
override fun getPresentableName() = "functionParameters()"
|
||||||
|
|
||||||
@@ -46,7 +46,4 @@ class FunctionParametersMacro : Macro() {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isAcceptableInContext(context: TemplateContextType?) = context is JavaCodeContextType
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -13,15 +13,17 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.liveTemplates.macro
|
package org.jetbrains.kotlin.idea.liveTemplates.macro
|
||||||
|
|
||||||
import com.intellij.codeInsight.template.*
|
import com.intellij.codeInsight.template.Expression
|
||||||
import org.jetbrains.kotlin.idea.liveTemplates.KotlinTemplateContextType
|
import com.intellij.codeInsight.template.ExpressionContext
|
||||||
|
import com.intellij.codeInsight.template.Result
|
||||||
|
import com.intellij.codeInsight.template.TextResult
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||||
|
|
||||||
class KotlinClassNameMacro : Macro() {
|
class KotlinClassNameMacro : KotlinMacro() {
|
||||||
override fun getName() = "kotlinClassName"
|
override fun getName() = "kotlinClassName"
|
||||||
override fun getPresentableName() = "kotlinClassName()"
|
override fun getPresentableName() = "kotlinClassName()"
|
||||||
|
|
||||||
@@ -29,6 +31,4 @@ class KotlinClassNameMacro : Macro() {
|
|||||||
val element = context.psiElementAtStartOffset?.parentsWithSelf?.firstOrNull { it is KtClassOrObject && it.name != null } ?: return null
|
val element = context.psiElementAtStartOffset?.parentsWithSelf?.firstOrNull { it is KtClassOrObject && it.name != null } ?: return null
|
||||||
return TextResult((element as KtClassOrObject).name!!)
|
return TextResult((element as KtClassOrObject).name!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isAcceptableInContext(context: TemplateContextType?): Boolean = context is KotlinTemplateContextType
|
|
||||||
}
|
}
|
||||||
+5
-6
@@ -16,12 +16,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.liveTemplates.macro
|
package org.jetbrains.kotlin.idea.liveTemplates.macro
|
||||||
|
|
||||||
import com.intellij.codeInsight.template.*
|
import com.intellij.codeInsight.template.Expression
|
||||||
import org.jetbrains.kotlin.idea.liveTemplates.KotlinTemplateContextType
|
import com.intellij.codeInsight.template.ExpressionContext
|
||||||
|
import com.intellij.codeInsight.template.Result
|
||||||
|
import com.intellij.codeInsight.template.TextResult
|
||||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||||
|
|
||||||
class KotlinFunctionNameMacro : Macro() {
|
class KotlinFunctionNameMacro : KotlinMacro() {
|
||||||
override fun getName() = "kotlinFunctionName"
|
override fun getName() = "kotlinFunctionName"
|
||||||
override fun getPresentableName() = "kotlinFunctionName()"
|
override fun getPresentableName() = "kotlinFunctionName()"
|
||||||
|
|
||||||
@@ -30,7 +32,4 @@ class KotlinFunctionNameMacro : Macro() {
|
|||||||
val name = element?.name ?: return null
|
val name = element?.name ?: return null
|
||||||
return TextResult(name)
|
return TextResult(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isAcceptableInContext(context: TemplateContextType?) = context is KotlinTemplateContextType
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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.liveTemplates.macro
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.template.Macro
|
||||||
|
import com.intellij.codeInsight.template.TemplateContextType
|
||||||
|
import org.jetbrains.kotlin.idea.liveTemplates.KotlinTemplateContextType
|
||||||
|
|
||||||
|
abstract class KotlinMacro : Macro() {
|
||||||
|
override fun isAcceptableInContext(context: TemplateContextType?): Boolean {
|
||||||
|
return context is KotlinTemplateContextType
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -47,7 +47,7 @@
|
|||||||
<orderEntry type="module" module-name="js.serializer" />
|
<orderEntry type="module" module-name="js.serializer" />
|
||||||
<orderEntry type="module" module-name="daemon-client" />
|
<orderEntry type="module" module-name="daemon-client" />
|
||||||
<orderEntry type="module" module-name="idea-repl" scope="TEST" />
|
<orderEntry type="module" module-name="idea-repl" scope="TEST" />
|
||||||
<orderEntry type="module" module-name="idea-live-templates" exported="" scope="RUNTIME" />
|
<orderEntry type="module" module-name="idea-live-templates" exported="" />
|
||||||
<orderEntry type="module" module-name="tests-common" scope="TEST" />
|
<orderEntry type="module" module-name="tests-common" scope="TEST" />
|
||||||
<orderEntry type="library" scope="TEST" name="kotlin-test" level="project" />
|
<orderEntry type="library" scope="TEST" name="kotlin-test" level="project" />
|
||||||
<orderEntry type="module" module-name="lint-idea" scope="PROVIDED" />
|
<orderEntry type="module" module-name="lint-idea" scope="PROVIDED" />
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ package org.jetbrains.kotlin.idea.liveTemplates.macro
|
|||||||
|
|
||||||
import com.intellij.codeInsight.lookup.LookupElement
|
import com.intellij.codeInsight.lookup.LookupElement
|
||||||
import com.intellij.codeInsight.lookup.LookupElementBuilder
|
import com.intellij.codeInsight.lookup.LookupElementBuilder
|
||||||
import com.intellij.codeInsight.template.*
|
import com.intellij.codeInsight.template.Expression
|
||||||
|
import com.intellij.codeInsight.template.ExpressionContext
|
||||||
|
import com.intellij.codeInsight.template.Result
|
||||||
|
import com.intellij.codeInsight.template.TextResult
|
||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
@@ -34,7 +37,7 @@ import org.jetbrains.kotlin.psi.KtFile
|
|||||||
import org.jetbrains.kotlin.psi.KtForExpression
|
import org.jetbrains.kotlin.psi.KtForExpression
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
|
|
||||||
class SuggestVariableNameMacro : Macro() {
|
class SuggestVariableNameMacro : KotlinMacro() {
|
||||||
override fun getName() = "kotlinSuggestVariableName"
|
override fun getName() = "kotlinSuggestVariableName"
|
||||||
override fun getPresentableName() = "kotlinSuggestVariableName()"
|
override fun getPresentableName() = "kotlinSuggestVariableName()"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user