use of com.intellij.psi.xml.XmlComment in project intellij-community by JetBrains.
the class SuppressInspectionAction method createComment.
@NotNull
private static XmlComment createComment(Project project, String s) throws IncorrectOperationException {
final XmlTag element = XmlElementFactory.getInstance(project).createTagFromText("<foo><!-- " + s + " --></foo>", XMLLanguage.INSTANCE);
final XmlComment newComment = PsiTreeUtil.getChildOfType(element, XmlComment.class);
assert newComment != null;
return newComment;
}
use of com.intellij.psi.xml.XmlComment in project intellij-community by JetBrains.
the class SuppressInspectionAction method addNoinspectionComment.
private void addNoinspectionComment(Project project, XmlTag anchor) throws IncorrectOperationException {
final XmlComment newComment = createComment(project, "noinspection " + myToolId);
PsiElement parent = anchor.getParentTag();
if (parent == null) {
parent = PsiTreeUtil.getPrevSiblingOfType(anchor, XmlProlog.class);
if (parent != null) {
CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(parent.add(newComment));
}
} else {
CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(parent.addBefore(newComment, anchor));
}
}
use of com.intellij.psi.xml.XmlComment in project intellij-plugins by JetBrains.
the class MxmlEnterHandler method preprocessEnter.
public Result preprocessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull Ref<Integer> caretOffset, @NotNull Ref<Integer> caretAdvance, @NotNull DataContext dataContext, EditorActionHandler originalHandler) {
int offset = caretOffset.get().intValue();
if (file instanceof JSFile) {
PsiElement context = InjectedLanguageManager.getInstance(file.getProject()).getInjectionHost(file);
if (context instanceof XmlComment) {
file = context.getContainingFile();
editor = ((EditorWindow) editor).getDelegate();
offset = editor.getCaretModel().getOffset();
}
}
if (!JavaScriptSupportLoader.isFlexMxmFile(file))
return Result.Continue;
if (CodeInsightSettings.getInstance().INSERT_BRACE_ON_ENTER && isAfterUnmatchedMxmlComment(editor, file, offset)) {
String indent = "";
CharSequence buffer = editor.getDocument().getCharsSequence();
int lineStart = CharArrayUtil.shiftBackwardUntil(buffer, offset - 1, "\n") + 1;
int current = lineStart;
while (current < offset && Character.isWhitespace(buffer.charAt(current))) ++current;
if (current > lineStart) {
indent = buffer.subSequence(lineStart, current).toString();
}
editor.getDocument().insertString(offset, "\n" + indent + "-->");
originalHandler.execute(editor, dataContext);
return Result.Stop;
}
return Result.Continue;
}
use of com.intellij.psi.xml.XmlComment in project android by JetBrains.
the class AttributeDefinitionsImpl method getCommentBeforeEatComment.
@Nullable
private static String getCommentBeforeEatComment(XmlTag tag) {
PsiElement comment = XmlDocumentationProvider.findPreviousComment(tag);
for (int i = 0; i < 5; ++i) {
if (comment == null) {
break;
}
String value = StringUtil.trim(XmlUtil.getCommentText((XmlComment) comment));
// <!-- ============== -->
if (!StringUtil.isEmpty(value) && value.charAt(0) != '*' && value.charAt(0) != '=') {
return value;
}
comment = XmlDocumentationProvider.findPreviousComment(comment.getPrevSibling());
}
return null;
}
use of com.intellij.psi.xml.XmlComment in project intellij-community by JetBrains.
the class SuppressInspectionAction method invoke.
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
final XmlTag anchor = getAnchor(element);
if (anchor == null)
return;
PsiElement prevSibling = anchor.getPrevSibling();
while (prevSibling instanceof PsiWhiteSpace || prevSibling instanceof XmlText) {
prevSibling = prevSibling.getPrevSibling();
}
if (prevSibling instanceof XmlProlog) {
prevSibling = prevSibling.getLastChild();
if (prevSibling != null && !(prevSibling instanceof XmlComment)) {
prevSibling = PsiTreeUtil.getPrevSiblingOfType(prevSibling, XmlComment.class);
}
}
if (prevSibling instanceof XmlComment) {
final XmlComment comment = (XmlComment) prevSibling;
final String text = XmlUtil.getCommentText(comment);
if (text != null && InspectionUtil.SUPPRESSION_PATTERN.matcher(text).matches()) {
final String s = text.trim() + ", " + myToolId;
final XmlComment newComment = createComment(project, s);
CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(comment.replace(newComment));
} else {
addNoinspectionComment(project, anchor);
}
} else {
addNoinspectionComment(project, anchor);
}
}
Aggregations