live template context type for comments in Kotlin; disable other contexts inside doc comments

#KT-6735 fixed
This commit is contained in:
Dmitry Jemerov
2015-02-04 18:37:44 +01:00
parent 3253754395
commit 621276aafe
2 changed files with 30 additions and 1 deletions
+1
View File
@@ -305,6 +305,7 @@
<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$Expression"/>
<liveTemplateContext implementation="org.jetbrains.kotlin.idea.liveTemplates.JetTemplateContextType$Comment"/>
<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.JetFunctionParametersMacro"/>
@@ -43,9 +43,12 @@ public abstract class JetTemplateContextType extends TemplateContextType {
public boolean isInContext(@NotNull PsiFile file, int offset) {
if (PsiUtilBase.getLanguageAtOffset(file, offset).isKindOf(JetLanguage.INSTANCE)) {
PsiElement element = file.findElementAt(offset);
if (element instanceof PsiWhiteSpace || element instanceof PsiComment) {
if (element instanceof PsiWhiteSpace) {
return false;
}
else if (PsiTreeUtil.getParentOfType(element, PsiComment.class, false) != null) {
return isCommentInContext();
}
else if (PsiTreeUtil.getParentOfType(element, JetPackageDirective.class) != null
|| PsiTreeUtil.getParentOfType(element, JetImportDirective.class) != null) {
return false;
@@ -71,6 +74,10 @@ public abstract class JetTemplateContextType extends TemplateContextType {
return false;
}
protected boolean isCommentInContext() {
return false;
}
protected abstract boolean isInContext(@NotNull PsiElement element);
public static class Generic extends JetTemplateContextType {
@@ -82,6 +89,11 @@ public abstract class JetTemplateContextType extends TemplateContextType {
protected boolean isInContext(@NotNull PsiElement element) {
return true;
}
@Override
protected boolean isCommentInContext() {
return true;
}
}
public static class TopLevel extends JetTemplateContextType {
@@ -170,4 +182,20 @@ public abstract class JetTemplateContextType extends TemplateContextType {
&& !(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;
}
}
}