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

项目:intellij-ce-playground    文件:PsiDocCommentImpl.java   
@Override
public PsiDocTag findTagByName(String name) {
  if (getFirstChildNode().getElementType() == JavaDocElementType.DOC_COMMENT) {
    if (getFirstChildNode().getText().indexOf(name) < 0) return null;
  }

  for (ASTNode child = getFirstChildNode(); child != null; child = child.getTreeNext()) {
    if (child.getElementType() == DOC_TAG) {
      PsiDocTag tag = (PsiDocTag)SourceTreeToPsiMap.treeElementToPsi(child);
      final CharSequence nameText = ((LeafElement)tag.getNameElement()).getChars();

      if (nameText.length() > 0 && nameText.charAt(0) == '@' && CharArrayUtil.regionMatches(nameText, 1, name)) {
        return tag;
      }
    }
  }

  return null;
}
项目:intellij-ce-playground    文件:UnknownGuardInspection.java   
@Override
public void visitDocTag(PsiDocTag psiDocTag) {
  super.visitDocTag(psiDocTag);
  if (!JCiPUtil.isGuardedByTag(psiDocTag)) {
    return;
  }
  final String guardValue = JCiPUtil.getGuardValue(psiDocTag);
  if ("this".equals(guardValue)) {
    return;
  }
  final PsiClass containingClass = PsiTreeUtil.getParentOfType(psiDocTag, PsiClass.class);
  if (containingClass == null) {
    return;
  }
  final PsiField guardField = containingClass.findFieldByName(guardValue, true);
  if (guardField != null) {
    return;
  }
  myHolder.registerProblem(psiDocTag, "Unknown @GuardedBy field \"" + guardValue + "\" #loc");
}
项目:intellij-ce-playground    文件:NonFinalGuardInspection.java   
@Override
public void visitDocTag(PsiDocTag psiDocTag) {
  super.visitDocTag(psiDocTag);
  if (!JCiPUtil.isGuardedByTag(psiDocTag)) {
    return;
  }
  final String guardValue = JCiPUtil.getGuardValue(psiDocTag);
  if ("this".equals(guardValue)) {
    return;
  }
  final PsiClass containingClass = PsiTreeUtil.getParentOfType(psiDocTag, PsiClass.class);
  if (containingClass == null) {
    return;
  }
  final PsiField guardField = containingClass.findFieldByName(guardValue, true);
  if (guardField == null) {
    return;
  }
  if (guardField.hasModifierProperty(PsiModifier.FINAL)) {
    return;
  }
  myHolder.registerProblem(psiDocTag, "Non-final @GuardedBy field \"" + guardValue + "\" #loc");
}
项目:intellij-ce-playground    文件:RefJavaManagerImpl.java   
@Override
public void visitDocComment(PsiDocComment comment) {
  super.visitDocComment(comment);
  final PsiDocTag[] tags = comment.getTags();
  for (PsiDocTag tag : tags) {
    if (Comparing.strEqual(tag.getName(), SuppressionUtil.SUPPRESS_INSPECTIONS_TAG_NAME)) {
      final PsiElement[] dataElements = tag.getDataElements();
      if (dataElements != null && dataElements.length > 0) {
        final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(comment, PsiModifierListOwner.class);
        if (listOwner != null) {
          final RefElementImpl element = (RefElementImpl)myRefManager.getReference(listOwner);
          if (element != null) {
            String suppression = "";
            for (PsiElement dataElement : dataElements) {
              suppression += "," + dataElement.getText();
            }
            element.addSuppression(suppression);
          }
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:JavaDocCommentFixer.java   
@NotNull
private static Pair<TextRange, String> parseTagValue(@NotNull PsiDocTag tag, @NotNull Document document) {
  PsiDocTagValue valueElement = tag.getValueElement();
  assert valueElement != null;

  int startOffset = valueElement.getTextRange().getStartOffset();
  int endOffset = tag.getTextRange().getEndOffset();
  // Javadoc PSI is rather weird...
  CharSequence text = document.getCharsSequence();
  int i = CharArrayUtil.shiftBackward(text, endOffset - 1, " \t*");
  if (i > 0 && text.charAt(i) == '\n') {
    endOffset = i;
  }

  return Pair.create(TextRange.create(startOffset, endOffset), text.subSequence(startOffset, endOffset).toString());
}
项目:intellij-ce-playground    文件:JavadocCompletionConfidence.java   
@NotNull
@Override
public ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
  if (psiElement().inside(PsiDocTag.class).accepts(contextElement)) {
    if (findJavaReference(psiFile, offset - 1) != null) {
      return ThreeState.NO;
    }
    if (PlatformPatterns.psiElement(JavaDocTokenType.DOC_TAG_NAME).accepts(contextElement)) {
      return ThreeState.NO;
    }
    if (contextElement.textMatches("#")) {
      return ThreeState.NO;
    }
  }
  return super.shouldSkipAutopopup(contextElement, psiFile, offset);
}
项目:intellij-ce-playground    文件:BasicSelectioner.java   
public static boolean canSelectBasic(final PsiElement e) {
  return
    !(e instanceof PsiWhiteSpace) &&
    !(e instanceof PsiComment) &&
    !(e instanceof PsiCodeBlock) &&
    !(e instanceof PsiArrayInitializerExpression) &&
    !(e instanceof PsiParameterList) &&
    !(e instanceof PsiExpressionList) &&
    !(e instanceof PsiBlockStatement) &&
    !(e instanceof PsiJavaCodeReferenceElement) &&
    !(e instanceof PsiJavaToken &&
    !(e instanceof PsiKeyword)) &&
    !(e instanceof XmlToken) &&
    !(e instanceof XmlElement) &&
    !(e instanceof PsiDocTag);
}
项目:intellij-ce-playground    文件:DocCommentTokenizer.java   
@Override
public void tokenize(@NotNull PsiDocComment comment, TokenConsumer consumer) {
  final CommentSplitter splitter = CommentSplitter.getInstance();

  for (PsiElement el : comment.getChildren()) {
    if (el instanceof PsiDocTag) {
      PsiDocTag tag = (PsiDocTag)el;
      if (!excludedTags.contains(tag.getName())) {
        for (PsiElement data : tag.getDataElements()) {
          consumer.consumeToken(data, splitter);
        }
      }
    }
    else {
      consumer.consumeToken(el, splitter);
    }
  }
}
项目:intellij-ce-playground    文件:MethodJavaDocHelper.java   
public MethodJavaDocHelper(PsiMethod method) {
  myMethod = method;
  myDocComment = myMethod.getDocComment();
  if (myDocComment == null) {
    myDoCorrectJavaDoc = false;
    return;
  }
  final PsiParameter[] parameters = myMethod.getParameterList().getParameters();
  if (parameters.length != 0) {
    final PsiDocTag[] paramTags = myDocComment.findTagsByName("param");
    if (paramTags.length > 0) {
      myDoCorrectJavaDoc = true;
    } else {
      myDoCorrectJavaDoc = false;
    }
  } else {
    myDoCorrectJavaDoc = true;
  }
}
项目:intellij-ce-playground    文件:JavadocParamTagsTest.java   
public void testDeleteTag1() throws Exception {
  final PsiElementFactory factory = getFactory();
  final PsiMethod method = factory.createMethodFromText(
        "/**\n" +
        " * Javadoc\n" +
        " * @param p1\n" +
        " * @param p2\n" +
        " */" +
        "  void m() {}", null);
  final PsiDocComment docComment = method.getDocComment();
  assertNotNull(docComment);
  final PsiDocTag[] tags = docComment.getTags();
  WriteCommandAction.runWriteCommandAction(null, new Runnable() {
    @Override
    public void run() {
      tags[0].delete();
    }
  });

  assertEquals("/**\n" +
               " * Javadoc\n" +
               " * @param p2\n" +
               " */", docComment.getText());

}
项目:intellij-ce-playground    文件:JavadocParamTagsTest.java   
public void testDeleteTag2() throws Exception {
  final PsiElementFactory factory = getFactory();
  final PsiMethod method = factory.createMethodFromText(
        "/**\n" +
        " * Javadoc\n" +
        " * @param p1\n" +
        " * @param p2\n" +
        " */" +
        "  void m() {}", null);
  final PsiDocComment docComment = method.getDocComment();
  assertNotNull(docComment);
  final PsiDocTag[] tags = docComment.getTags();
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      tags[1].delete();
    }
  });

  assertEquals("/**\n" +
               " * Javadoc\n" +
               " * @param p1\n" +
               " */", docComment.getText());

}
项目:intellij-ce-playground    文件:JavadocParamTagsTest.java   
public void testDeleteTag3() throws Exception {
  final PsiElementFactory factory = getFactory();
  final PsiMethod method = factory.createMethodFromText(
        "/**\n" +
        " * Javadoc\n" +
        " * @param p1\n" +
        " * @param p2\n" +
        " * @param p3\n" +
        " */" +
        "  void m() {}", null);
  final PsiDocComment docComment = method.getDocComment();
  assertNotNull(docComment);
  final PsiDocTag[] tags = docComment.getTags();
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      tags[1].delete();
    }
  });

  assertEquals("/**\n" +
               " * Javadoc\n" +
               " * @param p1\n" +
               " * @param p3\n" +
               " */", docComment.getText());
}
项目:intellij-ce-playground    文件:JavadocParamTagsTest.java   
public void testAddTag1() throws Exception {
  final PsiElementFactory factory = getFactory();
  final PsiMethod method = factory.createMethodFromText(
        "/**\n" +
        " * Javadoc\n" +
        " * @param p1\n" +
        " */\n" +
        "void m();", null);
  final PsiDocComment docComment = method.getDocComment();
  assertNotNull(docComment);
  final PsiDocTag[] tags = docComment.getTags();
  final PsiDocTag tag2 = factory.createParamTag("p2", "");
  docComment.addAfter(tag2, tags[0]);
  assertEquals(
    "/**\n" +
    " * Javadoc\n" +
    " * @param p1\n" +
    " * @param p2\n" +
    " */", docComment.getText());
}
项目:intellij-ce-playground    文件:JavadocParamTagsTest.java   
public void testAddTag2() throws Exception {
  final PsiElementFactory factory = getFactory();
  final PsiMethod method = factory.createMethodFromText(
        "/**\n" +
        " * Javadoc\n" +
        " * @param p1\n" +
        " */\n" +
        "void m();", null);
  final PsiDocComment docComment = method.getDocComment();
  assertNotNull(docComment);
  final PsiDocTag[] tags = docComment.getTags();
  final PsiDocTag tag2 = factory.createParamTag("p2", "");
  docComment.addBefore(tag2, tags[0]);
  assertEquals(
    "/**\n" +
    " * Javadoc\n" +
    " * @param p2\n" +
    " * @param p1\n" +
    " */", docComment.getText());
}
项目:intellij-ce-playground    文件:JavadocParamTagsTest.java   
public void testAddTag4() throws Exception {
  final PsiElementFactory factory = getFactory();
  final PsiMethod method = factory.createMethodFromText(
        "/**\n" +
        " * Javadoc\n" +
        " */\n" +
        "void m();", null);
  final PsiDocComment docComment = method.getDocComment();
  assertNotNull(docComment);
  final PsiDocTag tag2 = factory.createParamTag("p2", "");
  docComment.add(tag2);
  assertEquals(
    "/**\n" +
    " * Javadoc\n" +
    " * @param p2\n" +
    " */", docComment.getText());
}
项目:intellij-ce-playground    文件:GrDocCommentTokenizer.java   
@Override
public void tokenize(@NotNull PsiDocComment comment, TokenConsumer consumer) {
  final CommentSplitter splitter = CommentSplitter.getInstance();

  for (PsiElement el : comment.getChildren()) {
    if (el instanceof PsiDocTag) {
      PsiDocTag tag = (PsiDocTag)el;
      if (!excludedTags.contains(tag.getName())) {
        for (PsiElement data : tag.getDataElements()) {
          consumer.consumeToken(data, splitter);
        }
      }
    }
    else {
      consumer.consumeToken(el, splitter);
    }
  }
}
项目:tools-idea    文件:JavaDocInfoGenerator.java   
private static DocTagLocator<PsiDocTag> parameterLocator(final String name) {
  return new DocTagLocator<PsiDocTag>() {
    @Override
    public PsiDocTag find(PsiDocComment comment) {
      if (comment == null) {
        return null;
      }

      PsiDocTag[] tags = comment.findTagsByName("param");

      for (PsiDocTag tag : tags) {
        PsiDocTagValue value = tag.getValueElement();

        if (value != null) {
          String text = value.getText();

          if (text != null && text.equals(name)) {
            return tag;
          }
        }
      }

      return null;
    }
  };
}
项目:tools-idea    文件:JavaDocInfoGenerator.java   
private static DocTagLocator<PsiDocTag> exceptionLocator(final String name) {
  return new DocTagLocator<PsiDocTag>() {
    @Override
    public PsiDocTag find(PsiDocComment comment) {
      if (comment == null) {
        return null;
      }

      PsiDocTag[] tags = getThrowsTags(comment);

      for (PsiDocTag tag : tags) {
        PsiDocTagValue value = tag.getValueElement();

        if (value != null) {
          String text = value.getText();

          if (text != null && areWeakEqual(text, name)) {
            return tag;
          }
        }
      }

      return null;
    }
  };
}
项目:tools-idea    文件:JavaDocInfoGenerator.java   
private void generateTypeParametersSection(final StringBuilder buffer, final PsiClass aClass) {
  final PsiDocComment docComment = aClass.getDocComment();
  if (docComment == null) return;
  final LinkedList<Pair<PsiDocTag, InheritDocProvider<PsiDocTag>>> result =
    new LinkedList<Pair<PsiDocTag, InheritDocProvider<PsiDocTag>>>();
  final PsiTypeParameter[] typeParameters = aClass.getTypeParameters();
  for (PsiTypeParameter typeParameter : typeParameters) {
    final DocTagLocator<PsiDocTag> locator = parameterLocator("<" + typeParameter.getName() + ">");
    final Pair<PsiDocTag, InheritDocProvider<PsiDocTag>> inClassComment = findInClassComment(aClass, locator);
    if (inClassComment != null) {
      result.add(inClassComment);
    }
    else {
      final Pair<PsiDocTag, InheritDocProvider<PsiDocTag>> pair = findInHierarchy(aClass, locator);
      if (pair != null) {
        result.add(pair);
      }
    }
  }
  generateTypeParametersSection(buffer, result);
}
项目:tools-idea    文件:JavaDocInfoGenerator.java   
private static Pair<PsiDocTag, InheritDocProvider<PsiDocTag>> findInClassComment(final PsiClass psiClass, final DocTagLocator<PsiDocTag> locator) {
  final PsiDocTag tag = locator.find(getDocComment(psiClass));
  if (tag != null) {
    return new Pair<PsiDocTag, InheritDocProvider<PsiDocTag>>(tag, new InheritDocProvider<PsiDocTag>() {
      @Override
      public Pair<PsiDocTag, InheritDocProvider<PsiDocTag>> getInheritDoc() {
        return findInHierarchy(psiClass, locator);
      }

      @Override
      public PsiClass getElement() {
        return psiClass;
      }
    });
  }
  return null;
}
项目:tools-idea    文件:JavaDocInfoGenerator.java   
private void generateTypeParametersSection(final StringBuilder buffer, final PsiMethod method) {
  final PsiDocComment docComment = method.getDocComment();
  if (docComment == null) return;
  final PsiDocTag[] localTags = docComment.findTagsByName("param");
  final PsiTypeParameter[] typeParameters = method.getTypeParameters();
  final LinkedList<Pair<PsiDocTag, InheritDocProvider<PsiDocTag>>> collectedTags = new LinkedList<Pair<PsiDocTag, InheritDocProvider<PsiDocTag>>>();
  for (PsiTypeParameter typeParameter : typeParameters) {
    final String paramName = "<" + typeParameter.getName() + ">";
    Pair<PsiDocTag, InheritDocProvider<PsiDocTag>> parmTag = findDocTag(localTags, paramName, method);

    if (parmTag != null) {
      collectedTags.addLast(parmTag);
    }
  }
  generateTypeParametersSection(buffer, collectedTags);
}
项目:tools-idea    文件:JavaDocInfoGenerator.java   
@SuppressWarnings({"HardCodedStringLiteral"})
private void generateOneParameter(final PsiElement[] elements,
                                  final StringBuilder buffer,
                                  final Pair<PsiDocTag, InheritDocProvider<PsiDocTag>> tag) {
  String text = elements[0].getText();
  buffer.append("<DD>");
  int spaceIndex = text.indexOf(' ');
  if (spaceIndex < 0) {
    spaceIndex = text.length();
  }
  String parmName = text.substring(0, spaceIndex);
  buffer.append("<code>");
  buffer.append(StringUtil.escapeXml(parmName));
  buffer.append("</code>");
  buffer.append(" - ");
  buffer.append(text.substring(spaceIndex));
  generateValue(buffer, elements, 1, mapProvider(tag.second, true));
}
项目:tools-idea    文件:PsiDocCommentImpl.java   
@Override
public PsiDocTag findTagByName(String name) {
  if (getFirstChildNode().getElementType() == JavaDocElementType.DOC_COMMENT) {
    if (getFirstChildNode().getText().indexOf(name) < 0) return null;
  }

  for (ASTNode child = getFirstChildNode(); child != null; child = child.getTreeNext()) {
    if (child.getElementType() == DOC_TAG) {
      PsiDocTag tag = (PsiDocTag)SourceTreeToPsiMap.treeElementToPsi(child);
      final CharSequence nameText = ((LeafElement)tag.getNameElement()).getChars();

      if (nameText.length() > 0 && nameText.charAt(0) == '@' && CharArrayUtil.regionMatches(nameText, 1, name)) {
        return tag;
      }
    }
  }

  return null;
}
项目:tools-idea    文件:JavaSuppressionUtil.java   
static PsiElement getDocCommentToolSuppressedIn(@NotNull PsiDocCommentOwner owner, String inspectionToolID) {
  PsiDocComment docComment = owner.getDocComment();
  if (docComment == null && owner.getParent() instanceof PsiDeclarationStatement) {
    final PsiElement el = PsiTreeUtil.skipSiblingsBackward(owner.getParent(), PsiWhiteSpace.class);
    if (el instanceof PsiDocComment) {
      docComment = (PsiDocComment)el;
    }
  }
  if (docComment != null) {
    PsiDocTag inspectionTag = docComment.findTagByName(SuppressionUtil.SUPPRESS_INSPECTIONS_TAG_NAME);
    if (inspectionTag != null) {
      final PsiElement[] dataElements = inspectionTag.getDataElements();
      for (PsiElement dataElement : dataElements) {
        String valueText = dataElement.getText();
        if (SuppressionUtil.isInspectionToolIdMentioned(valueText, inspectionToolID)) {
          return docComment;
        }
      }
    }
  }
  return null;
}
项目:tools-idea    文件:UnknownGuardInspection.java   
@Override
public void visitDocTag(PsiDocTag psiDocTag) {
  super.visitDocTag(psiDocTag);
  if (!JCiPUtil.isGuardedByTag(psiDocTag)) {
    return;
  }
  final String guardValue = JCiPUtil.getGuardValue(psiDocTag);
  if ("this".equals(guardValue)) {
    return;
  }
  final PsiClass containingClass = PsiTreeUtil.getParentOfType(psiDocTag, PsiClass.class);
  if (containingClass == null) {
    return;
  }
  final PsiField guardField = containingClass.findFieldByName(guardValue, true);
  if (guardField != null) {
    return;
  }
  myHolder.registerProblem(psiDocTag, "Unknown @GuardedBy field \"" + guardValue + "\" #loc");
}
项目:tools-idea    文件:NonFinalGuardInspection.java   
@Override
public void visitDocTag(PsiDocTag psiDocTag) {
  super.visitDocTag(psiDocTag);
  if (!JCiPUtil.isGuardedByTag(psiDocTag)) {
    return;
  }
  final String guardValue = JCiPUtil.getGuardValue(psiDocTag);
  if ("this".equals(guardValue)) {
    return;
  }
  final PsiClass containingClass = PsiTreeUtil.getParentOfType(psiDocTag, PsiClass.class);
  if (containingClass == null) {
    return;
  }
  final PsiField guardField = containingClass.findFieldByName(guardValue, true);
  if (guardField == null) {
    return;
  }
  if (guardField.hasModifierProperty(PsiModifier.FINAL)) {
    return;
  }
  myHolder.registerProblem(psiDocTag, "Non-final @GuardedBy field \"" + guardValue + "\" #loc");
}
项目:tools-idea    文件:RefJavaManagerImpl.java   
@Override
public void visitDocComment(PsiDocComment comment) {
  super.visitDocComment(comment);
  final PsiDocTag[] tags = comment.getTags();
  for (PsiDocTag tag : tags) {
    if (Comparing.strEqual(tag.getName(), SuppressionUtil.SUPPRESS_INSPECTIONS_TAG_NAME)) {
      final PsiElement[] dataElements = tag.getDataElements();
      if (dataElements != null && dataElements.length > 0) {
        final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(comment, PsiModifierListOwner.class);
        if (listOwner != null) {
          final RefElementImpl element = (RefElementImpl)myRefManager.getReference(listOwner);
          if (element != null) {
            String suppression = "";
            for (PsiElement dataElement : dataElements) {
              suppression += "," + dataElement.getText();
            }
            element.addSuppression(suppression);
          }
        }
      }
    }
  }
}
项目:tools-idea    文件:JavaDocCommentFixer.java   
@NotNull
private static Pair<TextRange, String> parseTagValue(@NotNull PsiDocTag tag, @NotNull Document document) {
  PsiDocTagValue valueElement = tag.getValueElement();
  assert valueElement != null;

  int startOffset = valueElement.getTextRange().getStartOffset();
  int endOffset = tag.getTextRange().getEndOffset();
  // Javadoc PSI is rather weird...
  CharSequence text = document.getCharsSequence();
  int i = CharArrayUtil.shiftBackward(text, endOffset - 1, " \t*");
  if (i > 0 && text.charAt(i) == '\n') {
    endOffset = i;
  }

  return Pair.create(TextRange.create(startOffset, endOffset), text.subSequence(startOffset, endOffset).toString());
}
项目:tools-idea    文件:BasicSelectioner.java   
public static boolean canSelectBasic(final PsiElement e) {
  return
    !(e instanceof PsiWhiteSpace) &&
    !(e instanceof PsiComment) &&
    !(e instanceof PsiCodeBlock) &&
    !(e instanceof PsiArrayInitializerExpression) &&
    !(e instanceof PsiParameterList) &&
    !(e instanceof PsiExpressionList) &&
    !(e instanceof PsiBlockStatement) &&
    !(e instanceof PsiJavaCodeReferenceElement) &&
    !(e instanceof PsiJavaToken &&
    !(e instanceof PsiKeyword)) &&
    !(e instanceof XmlToken) &&
    !(e instanceof XmlElement) &&
    !(e instanceof PsiDocTag);
}
项目:tools-idea    文件:MethodJavaDocHelper.java   
public MethodJavaDocHelper(PsiMethod method) {
  myMethod = method;
  myDocComment = myMethod.getDocComment();
  if (myDocComment == null) {
    myDoCorrectJavaDoc = false;
    return;
  }
  final PsiParameter[] parameters = myMethod.getParameterList().getParameters();
  if (parameters.length != 0) {
    final PsiDocTag[] paramTags = myDocComment.findTagsByName("param");
    if (paramTags.length > 0) {
      myDoCorrectJavaDoc = true;
    } else {
      myDoCorrectJavaDoc = false;
    }
  } else {
    myDoCorrectJavaDoc = true;
  }
}
项目:tools-idea    文件:JavadocParamTagsTest.java   
public void testDeleteTag1() throws Exception {
  final PsiElementFactory factory = getFactory();
  final PsiMethod method = factory.createMethodFromText(
        "/**\n" +
        " * Javadoc\n" +
        " * @param p1\n" +
        " * @param p2\n" +
        " */" +
        "  void m() {}", null);
  final PsiDocComment docComment = method.getDocComment();
  assertNotNull(docComment);
  final PsiDocTag[] tags = docComment.getTags();
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      tags[0].delete();
    }
  });

  assertEquals("/**\n" +
               " * Javadoc\n" +
               " * @param p2\n" +
               " */", docComment.getText());

}
项目:tools-idea    文件:JavadocParamTagsTest.java   
public void testDeleteTag2() throws Exception {
  final PsiElementFactory factory = getFactory();
  final PsiMethod method = factory.createMethodFromText(
        "/**\n" +
        " * Javadoc\n" +
        " * @param p1\n" +
        " * @param p2\n" +
        " */" +
        "  void m() {}", null);
  final PsiDocComment docComment = method.getDocComment();
  assertNotNull(docComment);
  final PsiDocTag[] tags = docComment.getTags();
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      tags[1].delete();
    }
  });

  assertEquals("/**\n" +
               " * Javadoc\n" +
               " * @param p1\n" +
               " */", docComment.getText());

}
项目:tools-idea    文件:JavadocParamTagsTest.java   
public void testDeleteTag3() throws Exception {
  final PsiElementFactory factory = getFactory();
  final PsiMethod method = factory.createMethodFromText(
        "/**\n" +
        " * Javadoc\n" +
        " * @param p1\n" +
        " * @param p2\n" +
        " * @param p3\n" +
        " */" +
        "  void m() {}", null);
  final PsiDocComment docComment = method.getDocComment();
  assertNotNull(docComment);
  final PsiDocTag[] tags = docComment.getTags();
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      tags[1].delete();
    }
  });

  assertEquals("/**\n" +
               " * Javadoc\n" +
               " * @param p1\n" +
               " * @param p3\n" +
               " */", docComment.getText());
}
项目:tools-idea    文件:JavadocParamTagsTest.java   
public void testAddTag1() throws Exception {
  final PsiElementFactory factory = getFactory();
  final PsiMethod method = factory.createMethodFromText(
        "/**\n" +
        " * Javadoc\n" +
        " * @param p1\n" +
        " */\n" +
        "void m();", null);
  final PsiDocComment docComment = method.getDocComment();
  assertNotNull(docComment);
  final PsiDocTag[] tags = docComment.getTags();
  final PsiDocTag tag2 = factory.createParamTag("p2", "");
  docComment.addAfter(tag2, tags[0]);
  assertEquals(
    "/**\n" +
    " * Javadoc\n" +
    " * @param p1\n" +
    " * @param p2\n" +
    " */", docComment.getText());
}
项目:tools-idea    文件:JavadocParamTagsTest.java   
public void testAddTag2() throws Exception {
  final PsiElementFactory factory = getFactory();
  final PsiMethod method = factory.createMethodFromText(
        "/**\n" +
        " * Javadoc\n" +
        " * @param p1\n" +
        " */\n" +
        "void m();", null);
  final PsiDocComment docComment = method.getDocComment();
  assertNotNull(docComment);
  final PsiDocTag[] tags = docComment.getTags();
  final PsiDocTag tag2 = factory.createParamTag("p2", "");
  docComment.addBefore(tag2, tags[0]);
  assertEquals(
    "/**\n" +
    " * Javadoc\n" +
    " * @param p2\n" +
    " * @param p1\n" +
    " */", docComment.getText());
}
项目:tools-idea    文件:JavadocParamTagsTest.java   
public void testAddTag4() throws Exception {
  final PsiElementFactory factory = getFactory();
  final PsiMethod method = factory.createMethodFromText(
        "/**\n" +
        " * Javadoc\n" +
        " */\n" +
        "void m();", null);
  final PsiDocComment docComment = method.getDocComment();
  assertNotNull(docComment);
  final PsiDocTag tag2 = factory.createParamTag("p2", "");
  docComment.add(tag2);
  assertEquals(
    "/**\n" +
    " * Javadoc\n" +
    " * @param p2\n" +
    " */", docComment.getText());
}
项目:tools-idea    文件:GrDocCommentTokenizer.java   
@Override
public void tokenize(@NotNull PsiDocComment comment, TokenConsumer consumer) {
  final CommentSplitter splitter = CommentSplitter.getInstance();

  for (PsiElement el : comment.getChildren()) {
    if (el instanceof PsiDocTag) {
      PsiDocTag tag = (PsiDocTag)el;
      if (!excludedTags.contains(tag.getName())) {
        for (PsiElement data : tag.getDataElements()) {
          consumer.consumeToken(data, splitter);
        }
      }
    }
    else {
      consumer.consumeToken(el, splitter);
    }
  }
}
项目:tools-idea    文件:DocCommentTokenizer.java   
@Override
public void tokenize(@NotNull PsiDocComment comment, TokenConsumer consumer) {
  final CommentSplitter splitter = CommentSplitter.getInstance();

  for (PsiElement el : comment.getChildren()) {
    if (el instanceof PsiDocTag) {
      PsiDocTag tag = (PsiDocTag)el;
      if (!excludedTags.contains(tag.getName())) {
        for (PsiElement data : tag.getDataElements()) {
          consumer.consumeToken(data, splitter);
        }
      }
    }
    else {
      consumer.consumeToken(el, splitter);
    }
  }
}
项目:ibatis-plugin    文件:TableColumnReferenceProvider.java   
/**
 * get tableFieldData in psiMethod
 *
 * @param psiMethod PsiMethod object
 * @return DatabaseTableFieldData object
 */
@Nullable
public static DatabaseTableFieldData getDatabaseTableFieldData(PsiMethod psiMethod) {
    PsiDocComment docComment = psiMethod.getDocComment();
    if (docComment != null && docComment.findTagByName("column") != null) {
        PsiDocTag psiDocTag = docComment.findTagByName("column");
        String columnName = psiDocTag.getValueElement().getText().trim();
        if (StringUtil.isNotEmpty(columnName)) {
            PsiClass psiClass = PsiTreeUtil.getParentOfType(psiMethod, PsiClass.class);
            if (psiClass != null) {
                DatabaseTableData tableData = getDatabaseTableData(psiClass);
                if (tableData != null)
                    return tableData.findColumnByName(columnName);
            }
        }
    }
    return null;
}
项目:consulo-java    文件:PsiElementFactoryImpl.java   
@NotNull
@Override
public PsiDocTag createParamTag(@NotNull final String parameterName, @NonNls final String description) throws IncorrectOperationException
{
    final StringBuilder builder = new StringBuilder();
    builder.append(" * @param ");
    builder.append(parameterName);
    builder.append(" ");
    final String[] strings = description.split("\\n");
    for(int i = 0; i < strings.length; i++)
    {
        if(i > 0)
        {
            builder.append("\n * ");
        }
        builder.append(strings[i]);
    }
    return createDocTagFromText(builder.toString());
}