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

项目:intellij-ce-playground    文件:JavaFoldingBuilderBase.java   
private static String getPlaceholderText(PsiElement element) {
  if (element instanceof PsiImportList) {
    return "...";
  }
  else if (element instanceof PsiMethod || element instanceof PsiClassInitializer || element instanceof PsiClass) {
    return "{...}";
  }
  else if (element instanceof PsiDocComment) {
    return "/**...*/";
  }
  else if (element instanceof PsiFile) {
    return "/.../";
  }
  else if (element instanceof PsiAnnotation) {
    return "@{...}";
  }
  else if (element instanceof PsiReferenceParameterList) {
    return SMILEY;
  }
  else if (element instanceof PsiComment) {
    return "//...";
  }
  return "...";
}
项目:intellij-ce-playground    文件:ClsMemberImpl.java   
protected ClsMemberImpl(T stub) {
  super(stub);
  myDocComment = !isDeprecated() ? null : new AtomicNotNullLazyValue<PsiDocComment>() {
    @NotNull
    @Override
    protected PsiDocComment compute() {
      return new ClsDocCommentImpl(ClsMemberImpl.this);
    }
  };
  myNameIdentifier = new AtomicNotNullLazyValue<PsiIdentifier>() {
    @NotNull
    @Override
    protected PsiIdentifier compute() {
      return new ClsIdentifierImpl(ClsMemberImpl.this, getName());
    }
  };
}
项目:intellij-ce-playground    文件:GroovySpellcheckingStrategy.java   
@NotNull
@Override
public Tokenizer getTokenizer(PsiElement element) {
  if (TokenSets.STRING_LITERAL_SET.contains(element.getNode().getElementType())) {
    return myStringTokenizer;
  }
  if (element instanceof GrNamedElement) {
    final PsiElement name = ((GrNamedElement)element).getNameIdentifierGroovy();
    if (TokenSets.STRING_LITERAL_SET.contains(name.getNode().getElementType())) {
      return EMPTY_TOKENIZER;
    }
  }
  if (element instanceof PsiDocComment) return myDocCommentTokenizer;
  //if (element instanceof GrLiteralImpl && ((GrLiteralImpl)element).isStringLiteral()) return myStringTokenizer;
  return super.getTokenizer(element);
}
项目:intellij-ce-playground    文件:PsiFieldImpl.java   
@Override
public PsiDocComment getDocComment(){
  final PsiFieldStub stub = getStub();
  if (stub != null && !stub.hasDocComment()) return null;

  CompositeElement treeElement = getNode();
  if (getTypeElement() != null) {
    PsiElement element = treeElement.findChildByRoleAsPsiElement(ChildRole.DOC_COMMENT);
    return element instanceof PsiDocComment ? (PsiDocComment)element : null;
  }
  else {
    ASTNode prevField = treeElement.getTreePrev();
    while(prevField.getElementType() != JavaElementType.FIELD){
      prevField = prevField.getTreePrev();
    }
    return ((PsiField)SourceTreeToPsiMap.treeElementToPsi(prevField)).getDocComment();
  }
}
项目: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    文件:AdapterToListenerIntention.java   
private static void implementMethodInClass(@NotNull PsiMethod method,
                                           @NotNull PsiClass aClass) {
  final PsiMethod newMethod = (PsiMethod)aClass.add(method);
  final PsiDocComment comment = newMethod.getDocComment();
  if (comment != null) {
    comment.delete();
  }
  final PsiModifierList modifierList = newMethod.getModifierList();
  modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
  final Project project = aClass.getProject();
  final CodeStyleSettings codeStyleSettings =
    CodeStyleSettingsManager.getSettings(project);
  if (codeStyleSettings.INSERT_OVERRIDE_ANNOTATION &&
      PsiUtil.isLanguageLevel6OrHigher(aClass)) {
    modifierList.addAnnotation("java.lang.Override");
  }
  final PsiElementFactory factory =
    JavaPsiFacade.getElementFactory(project);
  final PsiCodeBlock codeBlock = factory.createCodeBlock();
  newMethod.add(codeBlock);
}
项目:intellij-ce-playground    文件:GlobalJavaInspectionContextImpl.java   
private static PsiReferenceProcessor createReferenceProcessor(@NotNull final List<UsagesProcessor> processors,
                                                              final GlobalInspectionContext context) {
  return new PsiReferenceProcessor() {
    @Override
    public boolean execute(PsiReference reference) {
      AnalysisScope scope = context.getRefManager().getScope();
      if (scope != null && scope.contains(reference.getElement()) && reference.getElement().getLanguage() == StdLanguages.JAVA ||
          PsiTreeUtil.getParentOfType(reference.getElement(), PsiDocComment.class) != null) {
        return true;
      }

      synchronized (processors) {
        UsagesProcessor[] processorsArrayed = processors.toArray(new UsagesProcessor[processors.size()]);
        for (UsagesProcessor processor : processorsArrayed) {
          if (!processor.process(reference)) {
            processors.remove(processor);
          }
        }
      }

      return !processors.isEmpty();
    }
  };
}
项目:intellij-ce-playground    文件:JavaImplementationTextSelectioner.java   
@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();
}
项目:intellij-ce-playground    文件:ModifierChooser.java   
private static boolean shouldSuggestModifiers(PsiElement element) {
  PsiElement parent = element.getParent();
  while (parent != null && (parent instanceof PsiJavaCodeReferenceElement ||
                            parent instanceof PsiErrorElement || parent instanceof PsiTypeElement ||
                            parent instanceof PsiMethod || parent instanceof PsiVariable ||
                            parent instanceof PsiDeclarationStatement || parent instanceof PsiImportList ||
                            parent instanceof PsiDocComment ||
                            element.getText().equals(parent.getText()))) {
    parent = parent.getParent();
    if (parent instanceof JspClassLevelDeclarationStatement) {
      parent = parent.getContext();
    }
  }

  if (parent == null) return false;

  PsiElement prev = FilterPositionUtil.searchNonSpaceNonCommentBack(element);

  if (parent instanceof PsiJavaFile || parent instanceof PsiClass) {
    if (prev == null || JavaKeywordCompletion.END_OF_BLOCK.getValue().isAcceptable(element, prev.getParent())) {
      return true;
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:GenerateMembersUtil.java   
private static void copyDocComment(PsiMethod source, PsiMethod target, JVMElementFactory factory) {
  final PsiElement navigationElement = source.getNavigationElement();
  if (navigationElement instanceof PsiDocCommentOwner) {
    final PsiDocComment docComment = ((PsiDocCommentOwner)navigationElement).getDocComment();
    if (docComment != null) {
      target.addAfter(factory.createDocCommentFromText(docComment.getText()), null);
    }
  }
  final PsiParameter[] sourceParameters = source.getParameterList().getParameters();
  final PsiParameterList targetParameterList = target.getParameterList();
  RefactoringUtil.fixJavadocsForParams(target, new HashSet<PsiParameter>(Arrays.asList(targetParameterList.getParameters())), new Condition<Pair<PsiParameter, String>>() {
    @Override
    public boolean value(Pair<PsiParameter, String> pair) {
      final int parameterIndex = targetParameterList.getParameterIndex(pair.first);
      if (parameterIndex >= 0 && parameterIndex < sourceParameters.length) {
        return Comparing.strEqual(pair.second, sourceParameters[parameterIndex].getName());
      }
      return false;
    }
  });
}
项目:intellij-ce-playground    文件:GenerateDelegateHandler.java   
private void clearMethod(PsiMethod method) throws IncorrectOperationException {
  LOG.assertTrue(!method.isPhysical());
  PsiCodeBlock codeBlock = JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createCodeBlock();
  if (method.getBody() != null) {
    method.getBody().replace(codeBlock);
  }
  else {
    method.add(codeBlock);
  }

  if (!myToCopyJavaDoc) {
    final PsiDocComment docComment = method.getDocComment();
    if (docComment != null) {
      docComment.delete();
    }
  }
}
项目:intellij-ce-playground    文件:FieldSelectioner.java   
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
  List<TextRange> result = super.select(e, editorText, cursorOffset, editor);
  final PsiField field = (PsiField)e;
  final TextRange range = field.getTextRange();
  final PsiIdentifier first = field.getNameIdentifier();
  final TextRange firstRange = first.getTextRange();
  final PsiElement last = field.getInitializer();
  final int end = last == null ? firstRange.getEndOffset() : last.getTextRange().getEndOffset();

  PsiDocComment comment = field.getDocComment();
  if (comment != null) {
    TextRange commentTextRange = comment.getTextRange();
    addRangeElem(result, editorText, comment, commentTextRange.getEndOffset());
  }
  addRangeElem(result, editorText, first, end);
  //addRangeElem (result, editorText, field, textLength, field.getTypeElement(), end);
  addRangeElem(result, editorText, field.getModifierList(), range.getEndOffset());
  //addRangeElem (result, editorText, field, textLength, field.getDocComment(), end);
  result.addAll(expandToWholeLine(editorText, range));
  return result;
}
项目:intellij-ce-playground    文件:SplitDeclarationAction.java   
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {

  if (element instanceof PsiCompiledElement) return false;
  if (!element.getManager().isInProject(element)) return false;
  if (!element.getLanguage().isKindOf(JavaLanguage.INSTANCE)) return false;

  final PsiElement context = PsiTreeUtil.getParentOfType(element, PsiDeclarationStatement.class, PsiClass.class);
  if (context instanceof PsiDeclarationStatement) {
    return isAvailableOnDeclarationStatement((PsiDeclarationStatement)context, element);
  }

  PsiField field = PsiTreeUtil.getParentOfType(element, PsiField.class);
  if (field != null && PsiTreeUtil.getParentOfType(element, PsiDocComment.class) == null && isAvailableOnField(field)) {
    setText(CodeInsightBundle.message("intention.split.declaration.text"));
    return true;
  }
  return false;
}
项目: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    文件:JavaSpellcheckingStrategy.java   
@NotNull
@Override
public Tokenizer getTokenizer(PsiElement element) {
  if (element instanceof PsiMethod) {
    return myMethodNameTokenizer;
  }
  if (element instanceof PsiDocComment) {
    return myDocCommentTokenizer;
  }
  if (element instanceof PsiLiteralExpression) {
    if (SuppressManager.isSuppressedInspectionName((PsiLiteralExpression)element)) {
      return EMPTY_TOKENIZER;
    }
    return myLiteralExpressionTokenizer;
  }
  if (element instanceof PsiNamedElement) {
    return myNamedElementTokenizer;
  }

  return super.getTokenizer(element);
}
项目:intellij-ce-playground    文件:CommentFormatter.java   
public void replaceCommentText(@Nullable String newCommentText, @Nullable PsiDocComment oldComment) {
  if (newCommentText != null) newCommentText = stripSpaces(newCommentText);
  if (newCommentText == null || oldComment == null || newCommentText.equals(oldComment.getText())) {
    return;
  }
  try {
    PsiComment newComment = JavaPsiFacade.getInstance(myProject).getElementFactory().createCommentFromText(
      newCommentText, null);
    final ASTNode oldNode = oldComment.getNode();
    final ASTNode newNode = newComment.getNode();
    assert oldNode != null && newNode != null;
    final ASTNode parent = oldNode.getTreeParent();
    parent.replaceChild(oldNode, newNode); //important to replace with tree operation to avoid resolve and repository update
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
项目:intellij-ce-playground    文件:EndOfLineCommentPredicate.java   
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiComment)) {
    return false;
  }
  if (element instanceof PsiDocComment) {
    return false;
  }
  final PsiComment comment = (PsiComment)element;
  final IElementType type = comment.getTokenType();
  if (!JavaTokenType.END_OF_LINE_COMMENT.equals(type)) {
    return false;
  }
  final String text = comment.getText();
  final Matcher matcher = NO_INSPECTION_PATTERN.matcher(text);
  return !matcher.matches();
}
项目:intellij-ce-playground    文件:CommentFormatter.java   
/**
 * Computes indentation of PsiClass, PsiMethod and PsiField elements after formatting
 * @param element PsiClass or PsiMethod or PsiField
 * @return indentation size
 */
private int getIndentSpecial(@NotNull PsiElement element) {
  if (element instanceof PsiDocComment) {
    return 0;
  }
  LOG.assertTrue(element instanceof PsiClass ||
                 element instanceof PsiField ||
                 element instanceof PsiMethod);

  int indentSize = mySettings.getIndentSize(JavaFileType.INSTANCE);
  boolean doNotIndentTopLevelClassMembers = mySettings.getCommonSettings(JavaLanguage.INSTANCE).DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS;

  int indent = 0;
  PsiClass top = PsiUtil.getTopLevelClass(element);
  while (top != null && !element.isEquivalentTo(top)) {
    if (doNotIndentTopLevelClassMembers && element.getParent().isEquivalentTo(top)) {
      break;
    }
    element = element.getParent();
    indent += indentSize;
  }

  return indent;
}
项目:intellij-ce-playground    文件:CStyleCommentPredicate.java   
@Override
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiComment)) {
    return false;
  }
  if (element instanceof PsiDocComment) {
    return false;
  }
  final PsiComment comment = (PsiComment) element;
  final IElementType type = comment.getTokenType();
  if (!GroovyTokenTypes.mML_COMMENT.equals(type)) {
    return false;
  }
  final PsiElement sibling = PsiTreeUtil.nextLeaf(comment);
  if(sibling == null)
  {
    return true;
  }
  if (!(isWhitespace(sibling))) {
    return false;
  }
  final String whitespaceText = sibling.getText();
  return whitespaceText.indexOf((int) '\n') >= 0 ||
      whitespaceText.indexOf((int) '\r') >= 0;
}
项目:intellij-ce-playground    文件:ParameterObjectBuilder.java   
private void outputField(ParameterSpec field, StringBuffer out) {
    final PsiParameter parameter = field.getParameter();
    final PsiDocComment docComment = getJavadocForVariable(parameter);
    if (docComment != null) {
        out.append(docComment.getText());
        out.append('\n');
    }
    final PsiType type = field.getType();
    final String typeText = type.getCanonicalText();
    final String name = field.getName();
    @NonNls String modifierString = "private ";
    if (!field.isSetterRequired()) {
        modifierString += "final ";
    }
    outputAnnotationString(parameter, out);
    out.append('\t' + modifierString + typeText + ' ' + name + ";\n");
}
项目: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    文件:GroovyGenerationInfo.java   
private static void adjustDocCommentIfExists(PsiMember member) {
  final PsiElement child = member.getFirstChild();
  if (child instanceof PsiDocComment) {
    final Project project = member.getProject();
    final GrDocComment groovyDoc = GroovyPsiElementFactory.getInstance(project).createDocCommentFromText(child.getText());
    child.delete();
    CodeStyleManager.getInstance(project).reformat(member);
    member.getParent().addBefore(groovyDoc, member);
  }
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiDocComment createDocCommentFromText(@NotNull final String text) throws IncorrectOperationException {
  final PsiMethod method = createMethodFromText(text.trim() + "void m();", null);
  final PsiDocComment comment = method.getDocComment();
  if (comment == null) {
    throw new IncorrectOperationException("Incorrect comment '" + text + "'");
  }
  return comment;
}
项目:intellij-ce-playground    文件:GenerationUtil.java   
static void writeDocComment(StringBuilder buffer, PsiMember member, boolean addLineFeed) {
  if (member instanceof PsiDocCommentOwner) {
    final PsiDocComment comment = ((PsiDocCommentOwner)member).getDocComment();
    if (comment != null) {
      final String text = comment.getText();
      buffer.append(text);
      if (addLineFeed) buffer.append('\n');
    }
  }
}
项目:intellij-ce-playground    文件:PsiEnumConstantImpl.java   
@Override
public boolean isDeprecated() {
  final PsiFieldStub stub = getStub();
  if (stub != null) {
    return stub.isDeprecated();
  }

  PsiDocComment docComment = getDocComment();
  return docComment != null && docComment.findTagByName("deprecated") != null ||
         getModifierList().findAnnotation("java.lang.Deprecated") != null;
}
项目:intellij-ce-playground    文件:PsiMethodImpl.java   
@Override
public PsiDocComment getDocComment() {
  final PsiMethodStub stub = getStub();
  if (stub != null && !stub.hasDocComment()) return null;

  return (PsiDocComment)getNode().findChildByRoleAsPsiElement(ChildRole.DOC_COMMENT);
}
项目:intellij-ce-playground    文件:PsiInlineDocTagImpl.java   
@Override
public PsiDocComment getContainingComment() {
  ASTNode scope = getTreeParent();
  while (scope.getElementType() != JavaDocElementType.DOC_COMMENT) {
    scope = scope.getTreeParent();
  }
  return (PsiDocComment)SourceTreeToPsiMap.treeElementToPsi(scope);
}
项目:intellij-ce-playground    文件:PsiImplUtil.java   
@Nullable
public static ASTNode findDocComment(@NotNull CompositeElement element) {
  TreeElement node = element.getFirstChildNode();
  while (node != null && (isWhitespaceOrComment(node) && !(node.getPsi() instanceof PsiDocComment))) {
    node = node.getTreeNext();
  }

  if (node != null && node.getElementType() == JavaDocElementType.DOC_COMMENT) {
    return node;
  }
  else {
    return null;
  }
}
项目:intellij-ce-playground    文件:JavaSuppressionUtil.java   
public static String getSuppressedInspectionIdsIn(@NotNull PsiElement element) {
  if (element instanceof PsiComment) {
    String text = element.getText();
    Matcher matcher = SuppressionUtil.SUPPRESS_IN_LINE_COMMENT_PATTERN.matcher(text);
    if (matcher.matches()) {
      return matcher.group(1).trim();
    }
  }
  if (element instanceof PsiDocCommentOwner) {
    PsiDocComment docComment = ((PsiDocCommentOwner)element).getDocComment();
    if (docComment != null) {
      PsiDocTag inspectionTag = docComment.findTagByName(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME);
      if (inspectionTag != null) {
        String valueText = "";
        for (PsiElement dataElement : inspectionTag.getDataElements()) {
          valueText += dataElement.getText();
        }
        return valueText;
      }
    }
  }
  if (element instanceof PsiModifierListOwner) {
    Collection<String> suppressedIds = getInspectionIdsSuppressedInAnnotation((PsiModifierListOwner)element);
    return suppressedIds.isEmpty() ? null : StringUtil.join(suppressedIds, ",");
  }
  return null;
}
项目:intellij-ce-playground    文件:JCiPUtil.java   
public static boolean isImmutable(PsiClass aClass) {
  final PsiAnnotation annotation = AnnotationUtil.findAnnotation(aClass, IMMUTABLE);
  if (annotation != null) {
    return true;
  }
  PsiDocComment comment = aClass.getDocComment();
  return comment != null && comment.findTagByName("@Immutable") != null;
}
项目:intellij-ce-playground    文件:ModifierPredicate.java   
@Override
public boolean satisfiedBy(PsiElement element) {
  final PsiElement parent = element.getParent();
  if (!(parent instanceof PsiClass || parent instanceof PsiField || parent instanceof PsiMethod) || parent instanceof PsiEnumConstant) {
    return false;
  }
  if (element instanceof PsiDocComment || element instanceof PsiCodeBlock) {
    return false;
  }
  if (parent instanceof PsiClass) {
    final PsiClass aClass = (PsiClass)parent;
    final PsiElement brace = aClass.getLBrace();
    if (brace != null && brace.getTextOffset() < element.getTextOffset()) {
      return false;
    }
    if (aClass.getContainingClass() == null &&
        (myModifier.equals(PsiModifier.PRIVATE) || myModifier.equals(PsiModifier.PROTECTED))) {
      return false;
    }
  }
  else if (parent instanceof PsiMethod) {
    final PsiMethod method = (PsiMethod)parent;
    final PsiClass containingClass = method.getContainingClass();
    if (containingClass == null || containingClass.isInterface() || (method.isConstructor() && containingClass.isEnum())) {
      return false;
    }
  }
  final PsiModifierListOwner owner = (PsiModifierListOwner)parent;
  final PsiModifierList modifierList = owner.getModifierList();
  return modifierList != null && !modifierList.hasModifierProperty(myModifier);
}
项目:intellij-ce-playground    文件:HighlightUtil.java   
@Nullable
static HighlightInfo checkUnclosedComment(@NotNull PsiComment comment) {
  if (!(comment instanceof PsiDocComment) && comment.getTokenType() != JavaTokenType.C_STYLE_COMMENT) return null;
  if (!comment.getText().endsWith("*/")) {
    int start = comment.getTextRange().getEndOffset() - 1;
    int end = start + 1;
    String description = JavaErrorMessages.message("unclosed.comment");
    return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(start, end).descriptionAndTooltip(description).create();
  }
  return null;
}
项目:intellij-ce-playground    文件:RemoveSuppressWarningAction.java   
private void removeFromJavaDoc(PsiDocComment docComment) throws IncorrectOperationException {
  PsiDocTag tag = docComment.findTagByName(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME);
  if (tag == null) return;
  String newText = removeFromElementText(tag.getDataElements());
  if (newText != null && newText.isEmpty()) {
    tag.delete();
  }
  else if (newText != null) {
    newText = "@" + SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME + " " + newText;
    PsiDocTag newTag = JavaPsiFacade.getInstance(tag.getProject()).getElementFactory().createDocTagFromText(newText);
    tag.replace(newTag);
  }
}
项目:intellij-ce-playground    文件:JavaMatchingVisitor.java   
@Override
public void visitField(PsiField psiField) {
  final PsiDocComment comment = psiField.getDocComment();
  final PsiField other = (PsiField)myMatchingVisitor.getElement();
  if (comment != null) {
    myMatchingVisitor.setResult(myMatchingVisitor.match(comment, other));
    if (!myMatchingVisitor.getResult()) return;
  }
  if (!checkHierarchy(other, psiField)) {
    myMatchingVisitor.setResult(false);
    return;
  }
  super.visitField(psiField);
}
项目:intellij-ce-playground    文件:JavaMatchingVisitor.java   
@Override
public void visitMethod(PsiMethod method) {
  final PsiIdentifier methodNameNode = method.getNameIdentifier();
  final boolean isTypedVar = myMatchingVisitor.getMatchContext().getPattern().isTypedVar(methodNameNode);
  final PsiMethod method2 = (PsiMethod)myMatchingVisitor.getElement();

  myMatchingVisitor.getMatchContext().pushResult();

  try {
    final PsiDocComment docComment = method.getDocComment();
    if (docComment != null) {
      myMatchingVisitor.setResult(myMatchingVisitor.match(docComment, method2));
      if (!myMatchingVisitor.getResult()) return;
    }
    if (method.hasTypeParameters()) {
      myMatchingVisitor.setResult(
        myMatchingVisitor.match(method.getTypeParameterList(), ((PsiMethod)myMatchingVisitor.getElement()).getTypeParameterList()));

      if (!myMatchingVisitor.getResult()) return;
    }

    if (!checkHierarchy(method2, method)) {
      myMatchingVisitor.setResult(false);
      return;
    }

    myMatchingVisitor.setResult((myMatchingVisitor.matchText(method.getNameIdentifier(), method2.getNameIdentifier()) || isTypedVar) &&
                                myMatchingVisitor.match(method.getModifierList(), method2.getModifierList()) &&
                                myMatchingVisitor.matchSons(method.getParameterList(), method2.getParameterList()) &&
                                myMatchingVisitor.match(method.getReturnTypeElement(), method2.getReturnTypeElement()) &&
                                                  matchInAnyOrder(method.getThrowsList(), method2.getThrowsList()) &&
                                myMatchingVisitor.matchSonsOptionally(method.getBody(), method2.getBody()));
  }
  finally {
    final PsiIdentifier methodNameNode2 = method2.getNameIdentifier();

    saveOrDropResult(methodNameNode, isTypedVar, methodNameNode2);
  }
}