use of com.intellij.psi.PsiDocCommentOwner in project intellij-community by JetBrains.
the class AddJavadocIntention method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException {
final PsiDocCommentOwner docCommentOwner = (PsiDocCommentOwner) element.getParent();
FixDocCommentAction.generateOrFixComment(docCommentOwner, project, editor);
}
use of com.intellij.psi.PsiDocCommentOwner in project intellij-community by JetBrains.
the class JavaImplementationTextSelectioner method getTextStartOffset.
@Override
public int getTextStartOffset(@NotNull final PsiElement parent) {
PsiElement element = parent;
if (element instanceof PsiDocCommentOwner) {
PsiDocComment comment = ((PsiDocCommentOwner) element).getDocComment();
if (comment != null) {
element = comment.getNextSibling();
while (element instanceof PsiWhiteSpace) {
element = element.getNextSibling();
}
}
}
if (element != null) {
TextRange range = element.getTextRange();
if (range != null) {
return range.getStartOffset();
}
LOG.error("Range should not be null: " + element + "; " + element.getClass());
}
LOG.error("Element should not be null: " + parent.getText());
return parent.getTextRange().getStartOffset();
}
use of com.intellij.psi.PsiDocCommentOwner in project intellij-community by JetBrains.
the class GrDeprecatedAPIUsageInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitReferenceExpression(@NotNull GrReferenceExpression ref) {
super.visitReferenceExpression(ref);
checkRef(ref);
}
@Override
public void visitCodeReferenceElement(@NotNull GrCodeReferenceElement ref) {
super.visitCodeReferenceElement(ref);
checkRef(ref);
}
private void checkRef(GrReferenceElement ref) {
PsiElement resolved = ref.resolve();
if (isDeprecated(resolved)) {
PsiElement toHighlight = getElementToHighlight(ref);
registerError(toHighlight, GroovyBundle.message("0.is.deprecated", ref.getReferenceName()), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.LIKE_DEPRECATED);
}
}
@NotNull
public PsiElement getElementToHighlight(@NotNull GrReferenceElement refElement) {
final PsiElement refNameElement = refElement.getReferenceNameElement();
return refNameElement != null ? refNameElement : refElement;
}
private boolean isDeprecated(PsiElement resolved) {
if (resolved instanceof PsiDocCommentOwner) {
return ((PsiDocCommentOwner) resolved).isDeprecated();
}
if (resolved instanceof PsiModifierListOwner && PsiImplUtil.isDeprecatedByAnnotation((PsiModifierListOwner) resolved)) {
return true;
}
return false;
}
};
}
use of com.intellij.psi.PsiDocCommentOwner in project markdown-doclet by Abnaxos.
the class DocCommentProcessor method processDocComment.
/**
* Process the given `PsiDocComment` using Markdown and return a new `PsiDocComment`
* representing the resulting HTML. The resulting `PsiDocComment` can then be passed
* to IDEA's default QuickDoc implementation.
*
* @todo Error reporting ({@link com.sun.javadoc.DocErrorReporter} without {@link com.sun.javadoc.RootDoc}).
*
* @param docComment The `PsiDocComment` to process.
*
* @return A `PsiDocComment` representing the resulting HTML.
*/
public PsiDocComment processDocComment(PsiDocComment docComment) {
if (!isEnabled() || docComment == null) {
return docComment;
}
final Map<String, URL> umlDiagrams = generateUmlDiagrams(docComment);
Options options = new Options() {
@Override
protected ToHtmlSerializer createDocletSerializer() {
return new DocletSerializer(this, getLinkRenderer()) {
@Override
protected void printImageTag(LinkRenderer.Rendering rendering) {
URL diagram = umlDiagrams.get(rendering.href);
if (diagram != null) {
super.printImageTag(mapHref(rendering, diagram.toString()));
} else if (!ABSOLUTE_IMG_RE.matcher(rendering.href).matches() || rendering.href.contains("{@}")) {
URL baseUrl = VfsUtilCore.convertToURL(file.getVirtualFile().getUrl());
if (baseUrl != null) {
try {
super.printImageTag(mapHref(rendering, new URL(baseUrl, rendering.href).toString()));
} catch (MalformedURLException e) {
super.printImageTag(rendering);
}
}
} else {
super.printImageTag(rendering);
}
}
private LinkRenderer.Rendering mapHref(LinkRenderer.Rendering rendering, String newHref) {
LinkRenderer.Rendering mapped = new LinkRenderer.Rendering(newHref, rendering.text);
mapped.attributes.addAll(rendering.attributes);
return mapped;
}
};
}
};
PsiDocCommentOwner context = PsiTreeUtil.getParentOfType(docComment, PsiDocCommentOwner.class);
markdownOptions.applyTo(options);
MarkdownDoclet doclet = new MarkdownDoclet(options, null);
MarkdownTaglets.instance().setDocErrorReporter(doclet);
StringBuilder buf = new StringBuilder();
StringBuilder tagBlock = new StringBuilder();
boolean start = true;
// List<String> tagBlockInlineTags = new ArrayList<>();
for (PsiElement elem : docComment.getChildren()) {
if (elem instanceof PsiDocToken) {
IElementType tokenType = ((PsiDocToken) elem).getTokenType();
if (tokenType == JavaDocTokenType.DOC_COMMENT_START || tokenType == JavaDocTokenType.DOC_COMMENT_END) {
continue;
}
}
if (start && elem instanceof PsiWhiteSpace) {
continue;
} else if (elem instanceof PsiInlineDocTag) {
start = false;
if (tagBlock.length() == 0) {
// inlineTags.add(elem.getText());
buf.append(elem.getText());
} else {
// tagBlockInlineTags.add(elem.getText());
tagBlock.append(elem.getText());
}
} else if (elem instanceof PsiDocTag) {
PsiDocTag docTag = (PsiDocTag) elem;
switch(docTag.getName()) {
case "see":
tagBlock.append('\n');
renderSeeTag(doclet, tagBlock, docTag);
break;
case "param":
case "throws":
case "exception":
renderSimpleTag(doclet, tagBlock, docTag, true);
break;
case "return":
renderSimpleTag(doclet, tagBlock, docTag, false);
break;
case "todo":
renderTodoTag(doclet, tagBlock, docTag);
break;
default:
tagBlock.append('\n').append(stripLead(elem.getText()));
break;
}
} else {
start = false;
if (tagBlock.length() == 0) {
buf.append(elem.getText());
} else {
tagBlock.append(elem.getText());
}
}
}
String markdown = stripLead(buf.toString());
Plugin.print("Markdown source", markdown);
String docCommentText = "/**\n" + escapeAsterisks(doclet.toHtml(markdown, false)) + "\n" + escapeAsterisks(tagBlock.toString()) + "\n*/";
Plugin.print("Processed DocComment", docCommentText);
PsiDocComment processedDocComment = docCommentFromText(context, docCommentText);
LinkExpander linkExpander = new LinkExpander(context, processedDocComment, docCommentText);
processedDocComment = linkExpander.apply();
return processedDocComment;
}
Aggregations