use of com.intellij.lang.Commenter in project intellij-community by JetBrains.
the class CommentByBlockCommentAction method isValidFor.
@Override
protected boolean isValidFor(@NotNull Project project, @NotNull Editor editor, @NotNull Caret caret, @NotNull final PsiFile file) {
final FileType fileType = file.getFileType();
if (fileType instanceof AbstractFileType) {
return ((AbstractFileType) fileType).getCommenter() != null;
}
Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(file.getLanguage());
if (commenter == null)
commenter = LanguageCommenters.INSTANCE.forLanguage(file.getViewProvider().getBaseLanguage());
if (commenter == null)
return false;
return commenter.getBlockCommentPrefix() != null && commenter.getBlockCommentSuffix() != null;
}
use of com.intellij.lang.Commenter in project intellij-community by JetBrains.
the class XmlDeclareIdInCommentAction method applyFix.
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
final PsiFile psiFile = psiElement.getContainingFile();
new WriteCommandAction(project, psiFile) {
@Override
protected void run(@NotNull final Result result) throws Throwable {
final XmlTag tag = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class);
if (tag == null)
return;
final Language language = psiFile.getViewProvider().getBaseLanguage();
final Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(language);
if (commenter == null)
return;
final PsiFile tempFile = PsiFileFactory.getInstance(project).createFileFromText("dummy", language.getAssociatedFileType(), commenter.getBlockCommentPrefix() + "@declare id=\"" + myId + "\"" + commenter.getBlockCommentSuffix() + "\n");
final XmlTag parent = tag.getParentTag();
if (parent != null && parent.isValid()) {
final XmlTag[] tags = parent.getSubTags();
if (tags.length > 0) {
final PsiFile psi = tempFile.getViewProvider().getPsi(language);
if (psi != null) {
final PsiElement element = psi.findElementAt(1);
if (element instanceof PsiComment) {
parent.getNode().addChild(element.getNode(), tags[0].getNode());
}
}
}
}
}
}.execute();
}
Aggregations