TemplateContextType find context of Comment

已回答

Hi I wondered if it is possible to create a TemplateContextType so that my live tempålate only activates while in comments?

I have tried this: 

public class CommentContext extends TemplateContextType {

public CommentContext() {
super("COMMENT", "Comment");
}

@Override
public boolean isInContext(@NotNull TemplateActionContext templateActionContext) {

Collection<PsiComment> comments = collectElementsOfType(templateActionContext.getFile(), PsiComment.class);
for (PsiElement comment : comments) {
return comment instanceof PsiComment;
}
return false;
}
}

But with no success. Any help would be greatly appreciated!

1

See com.intellij.codeInsight.template.JavaCommentContextType as a reference implementation

1

请先登录再写评论。