live template context type for comments in Kotlin; disable other contexts inside doc comments
#KT-6735 fixed
This commit is contained in:
@@ -305,6 +305,7 @@
|
|||||||
<liveTemplateContext implementation="org.jetbrains.kotlin.idea.liveTemplates.JetTemplateContextType$Statement"/>
|
<liveTemplateContext implementation="org.jetbrains.kotlin.idea.liveTemplates.JetTemplateContextType$Statement"/>
|
||||||
<liveTemplateContext implementation="org.jetbrains.kotlin.idea.liveTemplates.JetTemplateContextType$Class"/>
|
<liveTemplateContext implementation="org.jetbrains.kotlin.idea.liveTemplates.JetTemplateContextType$Class"/>
|
||||||
<liveTemplateContext implementation="org.jetbrains.kotlin.idea.liveTemplates.JetTemplateContextType$Expression"/>
|
<liveTemplateContext implementation="org.jetbrains.kotlin.idea.liveTemplates.JetTemplateContextType$Expression"/>
|
||||||
|
<liveTemplateContext implementation="org.jetbrains.kotlin.idea.liveTemplates.JetTemplateContextType$Comment"/>
|
||||||
<defaultLiveTemplatesProvider implementation="org.jetbrains.kotlin.idea.liveTemplates.JetLiveTemplatesProvider"/>
|
<defaultLiveTemplatesProvider implementation="org.jetbrains.kotlin.idea.liveTemplates.JetLiveTemplatesProvider"/>
|
||||||
<liveTemplateMacro implementation="org.jetbrains.kotlin.idea.liveTemplates.macro.JetAnyVariableMacro"/>
|
<liveTemplateMacro implementation="org.jetbrains.kotlin.idea.liveTemplates.macro.JetAnyVariableMacro"/>
|
||||||
<liveTemplateMacro implementation="org.jetbrains.kotlin.idea.liveTemplates.macro.JetFunctionParametersMacro"/>
|
<liveTemplateMacro implementation="org.jetbrains.kotlin.idea.liveTemplates.macro.JetFunctionParametersMacro"/>
|
||||||
|
|||||||
@@ -43,9 +43,12 @@ public abstract class JetTemplateContextType extends TemplateContextType {
|
|||||||
public boolean isInContext(@NotNull PsiFile file, int offset) {
|
public boolean isInContext(@NotNull PsiFile file, int offset) {
|
||||||
if (PsiUtilBase.getLanguageAtOffset(file, offset).isKindOf(JetLanguage.INSTANCE)) {
|
if (PsiUtilBase.getLanguageAtOffset(file, offset).isKindOf(JetLanguage.INSTANCE)) {
|
||||||
PsiElement element = file.findElementAt(offset);
|
PsiElement element = file.findElementAt(offset);
|
||||||
if (element instanceof PsiWhiteSpace || element instanceof PsiComment) {
|
if (element instanceof PsiWhiteSpace) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
else if (PsiTreeUtil.getParentOfType(element, PsiComment.class, false) != null) {
|
||||||
|
return isCommentInContext();
|
||||||
|
}
|
||||||
else if (PsiTreeUtil.getParentOfType(element, JetPackageDirective.class) != null
|
else if (PsiTreeUtil.getParentOfType(element, JetPackageDirective.class) != null
|
||||||
|| PsiTreeUtil.getParentOfType(element, JetImportDirective.class) != null) {
|
|| PsiTreeUtil.getParentOfType(element, JetImportDirective.class) != null) {
|
||||||
return false;
|
return false;
|
||||||
@@ -71,6 +74,10 @@ public abstract class JetTemplateContextType extends TemplateContextType {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isCommentInContext() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract boolean isInContext(@NotNull PsiElement element);
|
protected abstract boolean isInContext(@NotNull PsiElement element);
|
||||||
|
|
||||||
public static class Generic extends JetTemplateContextType {
|
public static class Generic extends JetTemplateContextType {
|
||||||
@@ -82,6 +89,11 @@ public abstract class JetTemplateContextType extends TemplateContextType {
|
|||||||
protected boolean isInContext(@NotNull PsiElement element) {
|
protected boolean isInContext(@NotNull PsiElement element) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isCommentInContext() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TopLevel extends JetTemplateContextType {
|
public static class TopLevel extends JetTemplateContextType {
|
||||||
@@ -170,4 +182,20 @@ public abstract class JetTemplateContextType extends TemplateContextType {
|
|||||||
&& !(element.getParent() instanceof JetParameter);
|
&& !(element.getParent() instanceof JetParameter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Comment extends JetTemplateContextType {
|
||||||
|
public Comment() {
|
||||||
|
super("KOTLIN_COMMENT", "Comment", Generic.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isInContext(@NotNull PsiElement element) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isCommentInContext() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user