com.intellij.lang.CodeDocumentationAwareCommenter Java Examples
The following examples show how to use
com.intellij.lang.CodeDocumentationAwareCommenter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LineLayout.java From consulo with Apache License 2.0 | 5 votes |
private static String getLineCommentPrefix(IElementType token) { if (token == null) return null; Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(token.getLanguage()); if (!(commenter instanceof CodeDocumentationAwareCommenter) || !token.equals(((CodeDocumentationAwareCommenter)commenter).getLineCommentTokenType())) return null; String prefix = commenter.getLineCommentPrefix(); return prefix == null ? null : StringUtil.trimTrailing(prefix); // some commenters (e.g. for Python) include space in comment prefix }
Example #2
Source File: CodeDocumentationUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static String createLine(String lineData, CodeDocumentationAwareCommenter commenter, DocCommentSettings settings) { if (!settings.isLeadingAsteriskEnabled()) { return " " + lineData + " "; } else { if (lineData.length() == 0) { return commenter.getDocumentationCommentLinePrefix() + " "; } else { return commenter.getDocumentationCommentLinePrefix() + " " + lineData + " "; } } }
Example #3
Source File: CodeDocumentationUtil.java From consulo with Apache License 2.0 | 5 votes |
static CommentContext tryParseCommentContext(@Nullable Commenter langCommenter, @Nonnull CharSequence chars, int lineStartOffset) { final boolean isInsideCommentLikeCode = langCommenter instanceof CodeDocumentationAwareCommenter; if (!isInsideCommentLikeCode) { return new CommentContext(); } final CodeDocumentationAwareCommenter commenter = (CodeDocumentationAwareCommenter)langCommenter; int commentStartOffset = CharArrayUtil.shiftForward(chars, lineStartOffset, " \t"); boolean docStart = commenter.getDocumentationCommentPrefix() != null && CharArrayUtil.regionMatches(chars, commentStartOffset, commenter.getDocumentationCommentPrefix()); boolean docAsterisk = commenter.getDocumentationCommentLinePrefix() != null && CharArrayUtil.regionMatches(chars, commentStartOffset, commenter.getDocumentationCommentLinePrefix()); return new CommentContext(commenter, docStart, docAsterisk, commentStartOffset); }
Example #4
Source File: LineCommentSelectioner.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean canSelect(PsiElement e) { if (e instanceof PsiComment) { final Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(e.getLanguage()); if (!(commenter instanceof CodeDocumentationAwareCommenter)) return true; return !((CodeDocumentationAwareCommenter) commenter).isDocumentationComment((PsiComment)e); } return false; }
Example #5
Source File: JoinLinesHandler.java From consulo with Apache License 2.0 | 5 votes |
private static boolean tryConvertEndOfLineComment(PsiElement commentElement) { Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(commentElement.getLanguage()); if (commenter instanceof CodeDocumentationAwareCommenter) { CodeDocumentationAwareCommenter docCommenter = (CodeDocumentationAwareCommenter)commenter; String lineCommentPrefix = commenter.getLineCommentPrefix(); String blockCommentPrefix = commenter.getBlockCommentPrefix(); String blockCommentSuffix = commenter.getBlockCommentSuffix(); if (commentElement.getNode().getElementType() == docCommenter.getLineCommentTokenType() && blockCommentPrefix != null && blockCommentSuffix != null && lineCommentPrefix != null) { String commentText = StringUtil.trimStart(commentElement.getText(), lineCommentPrefix); String suffix = docCommenter.getBlockCommentSuffix(); if (suffix != null && suffix.length() > 1) { String fixedSuffix = suffix.charAt(0) + " " + suffix.substring(1); commentText = commentText.replace(suffix, fixedSuffix); } try { Project project = commentElement.getProject(); PsiParserFacade parserFacade = PsiParserFacade.SERVICE.getInstance(project); PsiComment newComment = parserFacade.createBlockCommentFromText(commentElement.getLanguage(), commentText); commentElement.replace(newComment); return true; } catch (IncorrectOperationException e) { LOG.info("Failed to replace line comment with block comment", e); } } } return false; }
Example #6
Source File: EditorSmartKeysConfigurable.java From consulo with Apache License 2.0 | 5 votes |
private static boolean hasAnyDocAwareCommenters() { final Collection<Language> languages = Language.getRegisteredLanguages(); for (Language language : languages) { final Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(language); if (commenter instanceof CodeDocumentationAwareCommenter) { final CodeDocumentationAwareCommenter docCommenter = (CodeDocumentationAwareCommenter)commenter; if (docCommenter.getDocumentationCommentLinePrefix() != null) { return true; } } } return false; }
Example #7
Source File: CommentLiteralEscaper.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isOneLine() { final Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(myHost.getLanguage()); if (commenter instanceof CodeDocumentationAwareCommenter) { return myHost.getTokenType() == ((CodeDocumentationAwareCommenter) commenter).getLineCommentTokenType(); } return false; }
Example #8
Source File: CodeDocumentationUtil.java From consulo with Apache License 2.0 | 4 votes |
/** * @deprecated Use createDocCommentLine(lineData,file,commenter) instead. */ @SuppressWarnings("unused") @Deprecated public static String createDocCommentLine(String lineData, Project project, CodeDocumentationAwareCommenter commenter) { return createLine(lineData, commenter, DocCommentSettings.DEFAULTS); }
Example #9
Source File: CodeDocumentationUtil.java From consulo with Apache License 2.0 | 4 votes |
public static String createDocCommentLine(String lineData, PsiFile file, CodeDocumentationAwareCommenter commenter) { DocCommentSettings settings = CodeStyleManager.getInstance(file.getProject()).getDocCommentSettings(file); return createLine(lineData, commenter, settings); }
Example #10
Source File: CodeDocumentationUtil.java From consulo with Apache License 2.0 | 4 votes |
public CommentContext(CodeDocumentationAwareCommenter commenter, boolean docStart, boolean docAsterisk, int lineStart) { this.docStart = docStart; this.docAsterisk = docAsterisk; this.commenter = commenter; this.lineStart = lineStart; }
Example #11
Source File: CommentCompleteHandler.java From consulo with Apache License 2.0 | votes |
boolean isCommentComplete(PsiComment comment, CodeDocumentationAwareCommenter commenter, Editor editor);
Example #12
Source File: CommentCompleteHandler.java From consulo with Apache License 2.0 | votes |
boolean isApplicable(PsiComment comment, CodeDocumentationAwareCommenter commenter);