Java 类com.intellij.psi.javadoc.PsiInlineDocTag 实例源码

项目:tools-idea    文件:JavaDocInfoGenerator.java   
private void generateValueValue(final PsiInlineDocTag tag, final StringBuilder buffer, final PsiElement element) {
  String text = createLinkText(tag.getDataElements());
  PsiField valueField = null;
  if (text.length() == 0) {
    if (myElement instanceof PsiField) valueField = (PsiField) myElement;
  }
  else {
    PsiElement target = JavaDocUtil.findReferenceTarget(PsiManager.getInstance(myProject), text, myElement);
    if (target instanceof PsiField) {
      valueField = (PsiField) target;
    }
  }

  Object value = null;
  if (valueField != null) {
    PsiExpression initializer = valueField.getInitializer();
    value = JavaConstantExpressionEvaluator.computeConstantExpression(initializer, false);
  }

  if (value != null) {
    buffer.append(value.toString());
  }
  else {
    buffer.append(element.getText());
  }
}
项目:consulo-java    文件:JavaDocLocalInspection.java   
private static String extractTagDescription(PsiDocTag tag) {
  StringBuilder buf = new StringBuilder();
  PsiElement[] children = tag.getChildren();
  for (PsiElement child : children) {
    if (child instanceof PsiDocToken) {
      PsiDocToken token = (PsiDocToken)child;
      if (token.getTokenType() == JavaDocTokenType.DOC_COMMENT_DATA) {
        buf.append(token.getText());
      }
    }
    else if (child instanceof PsiDocTagValue) {
      buf.append(child.getText());
    } else if (child instanceof PsiInlineDocTag) {
      buf.append(child.getText());
    }
  }

  String s = buf.toString();
  return s.trim();
}
项目:consulo-java    文件:JavaDocInfoGenerator.java   
protected void generateLinkValue(PsiInlineDocTag tag, StringBuilder buffer, boolean plainLink)
{
    PsiElement[] tagElements = tag.getDataElements();
    String text = createLinkText(tagElements);
    if(!text.isEmpty())
    {
        int index = JavaDocUtil.extractReference(text);
        String refText = text.substring(0, index).trim();
        String label = text.substring(index).trim();
        if(label.isEmpty())
        {
            label = null;
        }
        generateLink(buffer, refText, label, tagElements[0], plainLink);
    }
}
项目:tools-idea    文件:JavaDocInfoGenerator.java   
private static void generateLiteralValue(PsiInlineDocTag tag, StringBuilder buffer) {
  PsiElement[] elements = tag.getDataElements();

  for (PsiElement element : elements) {
    appendPlainText(element.getText(), buffer);
  }
}
项目:tools-idea    文件:JavaDocInfoGenerator.java   
private void generateLinkValue(PsiInlineDocTag tag, StringBuilder buffer, boolean plainLink) {
  PsiElement[] tagElements = tag.getDataElements();
  String text = createLinkText(tagElements);
  if (text.length() > 0) {
    int index = JavaDocUtil.extractReference(text);
    String refText = text.substring(0, index).trim();
    String label = text.substring(index).trim();
    if (label.length() == 0) {
      label = null;
    }
    generateLink(buffer, refText, label, tagElements[0], plainLink);
  }
}
项目:tools-idea    文件:UnnecessaryInheritDocInspection.java   
@Override
public void visitDocTag(PsiDocTag tag) {
  if (!(tag instanceof PsiInlineDocTag)) {
    return;
  }
  @NonNls final String name = tag.getName();
  if (!"inheritDoc".equals(name)) {
    return;
  }
  final PsiDocComment docComment = tag.getContainingComment();
  if (docComment == null) {
    return;
  }
  final PsiDocToken[] docTokens = PsiTreeUtil.getChildrenOfType(
    docComment, PsiDocToken.class);
  if (docTokens == null) {
    return;
  }
  for (PsiDocToken docToken : docTokens) {
    final IElementType tokenType = docToken.getTokenType();
    if (!JavaDocTokenType.DOC_COMMENT_DATA.equals(tokenType)) {
      continue;
    }
    if (!StringUtil.isEmptyOrSpaces(docToken.getText())) {
      return;
    }
  }
  registerError(tag);
}
项目:consulo-java    文件:JavaDocLocalInspection.java   
private void checkInlineTags(final InspectionManager inspectionManager,
                             final ArrayList<ProblemDescriptor> problems,
                             final PsiElement[] dataElements,
                             final JavadocManager manager, boolean isOnTheFly) {
  for (PsiElement dataElement : dataElements) {
    if (dataElement instanceof PsiInlineDocTag) {
      final PsiInlineDocTag inlineDocTag = (PsiInlineDocTag)dataElement;
      final PsiElement nameElement = inlineDocTag.getNameElement();
      if (manager.getTagInfo(inlineDocTag.getName()) == null) {
        checkTagInfo(inspectionManager, null, inlineDocTag, isOnTheFly, problems);
      }
      if (!IGNORE_POINT_TO_ITSELF) {
        final PsiDocTagValue value = inlineDocTag.getValueElement();
        if (value != null) {
          final PsiReference reference = value.getReference();
          if (reference != null) {
            final PsiElement ref = reference.resolve();
            if (ref != null){
              if (PsiTreeUtil.getParentOfType(inlineDocTag, PsiDocCommentOwner.class) == PsiTreeUtil.getParentOfType(ref, PsiDocCommentOwner.class, false)) {
                if (nameElement != null) {
                  problems.add(createDescriptor(nameElement, InspectionsBundle.message("inspection.javadoc.problem.pointing.to.itself"), inspectionManager,
                                                isOnTheFly));
                }
              }
            }
          }
        }
      }
    }
  }
}
项目:consulo-java    文件:UnnecessaryInheritDocInspection.java   
@Override
public void visitDocTag(PsiDocTag tag) {
  if (!(tag instanceof PsiInlineDocTag)) {
    return;
  }
  @NonNls final String name = tag.getName();
  if (!"inheritDoc".equals(name)) {
    return;
  }
  final PsiDocComment docComment = tag.getContainingComment();
  if (docComment == null) {
    return;
  }
  final PsiDocToken[] docTokens = PsiTreeUtil.getChildrenOfType(
    docComment, PsiDocToken.class);
  if (docTokens == null) {
    return;
  }
  for (PsiDocToken docToken : docTokens) {
    final IElementType tokenType = docToken.getTokenType();
    if (!JavaDocTokenType.DOC_COMMENT_DATA.equals(tokenType)) {
      continue;
    }
    if (!StringUtil.isEmptyOrSpaces(docToken.getText())) {
      return;
    }
  }
  registerError(tag);
}
项目:Android_Lint_SRP_Practice_Example    文件:PsiClassStructureDetector.java   
@Override
public void visitInlineDocTag(PsiInlineDocTag tag) {
    mVisitor.report("PsiInlineDocTag", tag.getText(), tag);
    super.visitDocTag(tag);
}
项目:intellij-ce-playground    文件:JavadocTypedHandler.java   
private static boolean isAppropriatePlace(Editor editor, PsiFile file) {
  FileViewProvider provider = file.getViewProvider();
  int offset = editor.getCaretModel().getOffset();

  final PsiElement elementAtCaret;
  if (offset < editor.getDocument().getTextLength()) {
    elementAtCaret = provider.findElementAt(offset);
  }
  else {
    elementAtCaret = provider.findElementAt(editor.getDocument().getTextLength() - 1);
  }

  PsiElement element = elementAtCaret;
  while(element instanceof PsiWhiteSpace || element != null && containsOnlyWhiteSpaces(element.getText())) {
    element = element.getPrevSibling();
  }

  if (element == null) {
    return false;
  }

  if (element instanceof PsiDocParamRef) {
    element = element.getParent();
  }

  if (element instanceof PsiDocTag) {
    PsiDocTag tag = (PsiDocTag)element;
    if ("param".equals(tag.getName()) && isTypeParamBracketClosedAfterParamTag(tag, offset)) {
      return false; 
    }
  }

  // The contents of inline tags is not HTML, so the paired tag completion isn't appropriate there.
  if (PsiTreeUtil.getParentOfType(element, PsiInlineDocTag.class, false) != null) {
    return false;
  }

  ASTNode node = element.getNode();
  return node != null 
         && (JavaDocTokenType.ALL_JAVADOC_TOKENS.contains(node.getElementType())
             || JavaDocElementType.ALL_JAVADOC_ELEMENTS.contains(node.getElementType()));
}
项目:intellij-ce-playground    文件:GroovyMethodSignatureInsertHandler.java   
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
  if (!(item.getObject() instanceof PsiMethod)) {
    return;
  }
  PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument());
  final Editor editor = context.getEditor();
  final PsiMethod method = (PsiMethod)item.getObject();

  final PsiParameter[] parameters = method.getParameterList().getParameters();
  final StringBuilder buffer = new StringBuilder();

  final CharSequence chars = editor.getDocument().getCharsSequence();
  int endOffset = editor.getCaretModel().getOffset();
  final Project project = context.getProject();
  int afterSharp = CharArrayUtil.shiftBackwardUntil(chars, endOffset - 1, "#") + 1;
  int signatureOffset = afterSharp;

  PsiElement element = context.getFile().findElementAt(signatureOffset - 1);
  final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(element.getProject());
  PsiDocTag tag = PsiTreeUtil.getParentOfType(element, PsiDocTag.class);
  if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
    final PsiDocTagValue value = tag.getValueElement();
    endOffset = value.getTextRange().getEndOffset();
  }
  editor.getDocument().deleteString(afterSharp, endOffset);
  editor.getCaretModel().moveToOffset(signatureOffset);
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  editor.getSelectionModel().removeSelection();
  buffer.append(method.getName()).append("(");
  final int afterParenth = afterSharp + buffer.length();
  for (int i = 0; i < parameters.length; i++) {
    final PsiType type = TypeConversionUtil.erasure(parameters[i].getType());
    buffer.append(type.getCanonicalText());

    if (i < parameters.length - 1) {
      buffer.append(",");
      if (styleSettings.SPACE_AFTER_COMMA) buffer.append(" ");
    }
  }
  buffer.append(")");
  if (!(tag instanceof PsiInlineDocTag)) {
    buffer.append(" ");
  }
  else {
    final int currentOffset = editor.getCaretModel().getOffset();
    if (chars.charAt(currentOffset) == '}') {
      afterSharp++;
    }
    else {
      buffer.append("} ");
    }
  }
  String insertString = buffer.toString();
  EditorModificationUtil.insertStringAtCaret(editor, insertString);
  editor.getCaretModel().moveToOffset(afterSharp + buffer.length());
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());

  shortenReferences(project, editor, context, afterParenth);
}
项目:tools-idea    文件:JavaDocInfoGenerator.java   
private void generateValue(StringBuilder buffer,
                           PsiElement[] elements,
                           int startIndex,
                           InheritDocProvider<PsiElement[]> provider) {
  int predictOffset =
    startIndex < elements.length ?
    elements[startIndex].getTextOffset() + elements[startIndex].getText().length() :
    0;

  for (int i = startIndex; i < elements.length; i++) {
    if (elements[i].getTextOffset() > predictOffset) buffer.append(" ");
    predictOffset = elements[i].getTextOffset() + elements[i].getText().length();
    PsiElement element = elements[i];
    if (element instanceof PsiInlineDocTag) {
      PsiInlineDocTag tag = (PsiInlineDocTag)element;
      final String tagName = tag.getName();
      if (tagName == null) {
        buffer.append(element.getText());
      }
      else if (tagName.equals(LINK_TAG)) {
        generateLinkValue(tag, buffer, false);
      }
      else if (tagName.equals(LITERAL_TAG)) {
        generateLiteralValue(tag, buffer);
      }
      else if (tagName.equals(CODE_TAG)) {
        generateCodeValue(tag, buffer);
      }
      else if (tagName.equals(LINKPLAIN_TAG)) {
        generateLinkValue(tag, buffer, true);
      }
      else if (tagName.equals(INHERITDOC_TAG)) {
        Pair<PsiElement[], InheritDocProvider<PsiElement[]>> inheritInfo = provider.getInheritDoc();

        if (inheritInfo != null) {
          generateValue(buffer, inheritInfo.first, inheritInfo.second);
        }
      }
      else if (tagName.equals(DOCROOT_TAG)) {
        buffer.append(getDocRoot());
      }
      else if (tagName.equals(VALUE_TAG)) {
        generateValueValue(tag, buffer, element);
      }
      else {
        buffer.append(element.getText());
      }
    }
    else {
      buffer.append(element.getText());
    }
  }
}
项目:tools-idea    文件:JavaDocInfoGenerator.java   
@SuppressWarnings({"HardCodedStringLiteral"})
private static void generateCodeValue(PsiInlineDocTag tag, StringBuilder buffer) {
  buffer.append("<code>");
  generateLiteralValue(tag, buffer);
  buffer.append("</code>");
}
项目:tools-idea    文件:GroovyMethodSignatureInsertHandler.java   
public void handleInsert(InsertionContext context, LookupElement item) {
  if (!(item.getObject() instanceof PsiMethod)) {
    return;
  }
  PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument());
  final Editor editor = context.getEditor();
  final PsiMethod method = (PsiMethod)item.getObject();

  final PsiParameter[] parameters = method.getParameterList().getParameters();
  final StringBuilder buffer = new StringBuilder();

  final CharSequence chars = editor.getDocument().getCharsSequence();
  int endOffset = editor.getCaretModel().getOffset();
  final Project project = context.getProject();
  int afterSharp = CharArrayUtil.shiftBackwardUntil(chars, endOffset - 1, "#") + 1;
  int signatureOffset = afterSharp;

  PsiElement element = context.getFile().findElementAt(signatureOffset - 1);
  final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(element.getProject());
  PsiDocTag tag = PsiTreeUtil.getParentOfType(element, PsiDocTag.class);
  if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
    final PsiDocTagValue value = tag.getValueElement();
    endOffset = value.getTextRange().getEndOffset();
  }
  editor.getDocument().deleteString(afterSharp, endOffset);
  editor.getCaretModel().moveToOffset(signatureOffset);
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  editor.getSelectionModel().removeSelection();
  buffer.append(method.getName()).append("(");
  final int afterParenth = afterSharp + buffer.length();
  for (int i = 0; i < parameters.length; i++) {
    final PsiType type = TypeConversionUtil.erasure(parameters[i].getType());
    buffer.append(type.getCanonicalText());

    if (i < parameters.length - 1) {
      buffer.append(",");
      if (styleSettings.SPACE_AFTER_COMMA) buffer.append(" ");
    }
  }
  buffer.append(")");
  if (!(tag instanceof PsiInlineDocTag)) {
    buffer.append(" ");
  }
  else {
    final int currentOffset = editor.getCaretModel().getOffset();
    if (chars.charAt(currentOffset) == '}') {
      afterSharp++;
    }
    else {
      buffer.append("} ");
    }
  }
  String insertString = buffer.toString();
  EditorModificationUtil.insertStringAtCaret(editor, insertString);
  editor.getCaretModel().moveToOffset(afterSharp + buffer.length());
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());

  shortenReferences(project, editor, context, afterParenth);
}
项目:consulo-java    文件:JavaElementVisitor.java   
public void visitInlineDocTag(PsiInlineDocTag tag)
{
    visitDocTag(tag);
}
项目:consulo-java    文件:JavaDocCompletionContributor.java   
@Override
public void handleInsert(InsertionContext context, JavaMethodCallElement item)
{
    PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument());
    final Editor editor = context.getEditor();
    final PsiMethod method = item.getObject();

    final PsiParameter[] parameters = method.getParameterList().getParameters();
    final StringBuilder buffer = new StringBuilder();

    final CharSequence chars = editor.getDocument().getCharsSequence();
    int endOffset = editor.getCaretModel().getOffset();
    final Project project = context.getProject();
    int afterSharp = CharArrayUtil.shiftBackwardUntil(chars, endOffset - 1, "#") + 1;
    int signatureOffset = afterSharp;

    PsiElement element = context.getFile().findElementAt(signatureOffset - 1);
    final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(context.getProject());
    PsiDocTag tag = PsiTreeUtil.getParentOfType(element, PsiDocTag.class);
    if(context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR && tag != null)
    {
        final PsiDocTagValue valueElement = tag.getValueElement();
        if(valueElement != null)
        {
            endOffset = valueElement.getTextRange().getEndOffset();
            context.setTailOffset(endOffset);
        }
    }
    editor.getDocument().deleteString(afterSharp, endOffset);
    editor.getCaretModel().moveToOffset(signatureOffset);
    editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    editor.getSelectionModel().removeSelection();
    buffer.append(method.getName()).append("(");
    final int afterParenth = afterSharp + buffer.length();
    for(int i = 0; i < parameters.length; i++)
    {
        final PsiType type = TypeConversionUtil.erasure(parameters[i].getType());
        buffer.append(type.getCanonicalText());

        if(i < parameters.length - 1)
        {
            buffer.append(",");
            if(styleSettings.SPACE_AFTER_COMMA)
            {
                buffer.append(" ");
            }
        }
    }
    buffer.append(")");
    if(!(tag instanceof PsiInlineDocTag))
    {
        buffer.append(" ");
    }
    else
    {
        final int currentOffset = editor.getCaretModel().getOffset();
        if(chars.charAt(currentOffset) == '}')
        {
            afterSharp++;
        }
        else
        {
            buffer.append("} ");
        }
    }
    String insertString = buffer.toString();
    EditorModificationUtil.insertStringAtCaret(editor, insertString);
    editor.getCaretModel().moveToOffset(afterSharp + buffer.length());
    editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());

    shortenReferences(project, editor, context, afterParenth);
}
项目:consulo-java    文件:JavaDocInfoGenerator.java   
private void generateValue(StringBuilder buffer, PsiElement[] elements, int startIndex, InheritDocProvider<PsiElement[]> provider)
{
    int predictOffset = startIndex < elements.length ? elements[startIndex].getTextOffset() + elements[startIndex].getText().length() : 0;
    for(int i = startIndex; i < elements.length; i++)
    {
        if(elements[i].getTextOffset() > predictOffset)
        {
            buffer.append(" ");
        }
        predictOffset = elements[i].getTextOffset() + elements[i].getText().length();
        PsiElement element = elements[i];
        if(element instanceof PsiInlineDocTag)
        {
            PsiInlineDocTag tag = (PsiInlineDocTag) element;
            final String tagName = tag.getName();
            if(tagName.equals(LINK_TAG))
            {
                generateLinkValue(tag, buffer, false);
            }
            else if(tagName.equals(LITERAL_TAG))
            {
                generateLiteralValue(buffer, tag);
            }
            else if(tagName.equals(CODE_TAG))
            {
                generateCodeValue(tag, buffer);
            }
            else if(tagName.equals(LINKPLAIN_TAG))
            {
                generateLinkValue(tag, buffer, true);
            }
            else if(tagName.equals(INHERIT_DOC_TAG))
            {
                Pair<PsiElement[], InheritDocProvider<PsiElement[]>> inheritInfo = provider.getInheritDoc();
                if(inheritInfo != null)
                {
                    generateValue(buffer, inheritInfo.first, inheritInfo.second);
                }
            }
            else if(tagName.equals(DOC_ROOT_TAG))
            {
                buffer.append(getDocRoot());
            }
            else if(tagName.equals(VALUE_TAG))
            {
                generateValueValue(tag, buffer, element);
            }
        }
        else
        {
            buffer.append(StringUtil.replaceUnicodeEscapeSequences(element.getText()));
        }
    }
}
项目:consulo-java    文件:JavaDocInfoGenerator.java   
private void generateCodeValue(PsiInlineDocTag tag, StringBuilder buffer)
{
    buffer.append("<code>");
    generateLiteralValue(buffer, tag);
    buffer.append("</code>");
}
项目:consulo-java    文件:JavaDocInfoGenerator.java   
private void generateValueValue(final PsiInlineDocTag tag, final StringBuilder buffer, final PsiElement element)
{
    String text = createLinkText(tag.getDataElements());
    PsiField valueField = null;
    if(text.isEmpty())
    {
        if(myElement instanceof PsiField)
        {
            valueField = (PsiField) myElement;
        }
    }
    else
    {
        if(text.indexOf('#') == -1)
        {
            text = "#" + text;
        }
        PsiElement target = JavaDocUtil.findReferenceTarget(PsiManager.getInstance(myProject), text, myElement);
        if(target instanceof PsiField)
        {
            valueField = (PsiField) target;
        }
    }

    Object value = null;
    if(valueField != null)
    {
        PsiExpression initializer = valueField.getInitializer();
        value = JavaConstantExpressionEvaluator.computeConstantExpression(initializer, false);
    }

    if(value != null)
    {
        String valueText = StringUtil.escapeXml(value.toString());
        if(value instanceof String)
        {
            valueText = '"' + valueText + '"';
        }
        if(valueField.equals(myElement))
        {
            buffer.append(valueText); // don't generate link to itself
        }
        else
        {
            generateLink(buffer, valueField, valueText, true);
        }
    }
    else
    {
        buffer.append(element.getText());
    }
}
项目:markdown-doclet    文件:DocCommentProcessor.java   
@Override
public void visitElement(PsiElement element) {
    if ( element instanceof PsiDocTag ) {
        PsiDocTag tag = (PsiDocTag)element;
        String tagName = null;
        switch ( tag.getName() ) {
            case "link":
            case "linkplain":
            case "see":
                // todo: @ssee
                tagName = tag.getName();
        }
        if ( tagName != null ) {
            int inlineOffset = (tag instanceof PsiInlineDocTag) ? 1 : 0;
            String linkText = tag.getText().substring(inlineOffset + 1 + tagName.length(), tag.getTextLength() - inlineOffset).trim();
            if ( !linkText.startsWith("#") ) {
                return;
            }
            StringBuilder newLink = new StringBuilder(100);
            if ( inlineOffset > 0 ) {
                newLink.append('{');
            }
            newLink.append('@').append(tagName).append(' ');
            int refEndIndex = JavaDocUtil.extractReference(linkText);
            String refText = linkText.substring(0, refEndIndex);
            PsiElement target = JavaDocUtil.findReferenceTarget(docContext.getManager(), refText, docContext, true);
            if ( target == null ) {
                return;
            }
            newLink.append(JavaDocUtil.getReferenceText(project, target)).append(' ');
            String labelText = linkText.substring(refEndIndex).trim();
            if ( labelText.isEmpty() ) {
                labelText = JavaDocUtil.getLabelText(project, docContext.getManager(), refText, docContext);
            }
            newLink.append(labelText);
            if ( inlineOffset > 0 ) {
                newLink.append('}');
            }
            int start = getStartOffsetInComment(element);
            if ( buffer == null ) {
                buffer = new StringBuilder(docText.length() + 100);
            }
            buffer.append(docText, docTextPosition, start);
            buffer.append(newLink);
            docTextPosition += start - docTextPosition + element.getTextLength();
        }
    }
    element.acceptChildren(this);
}