Search in sources :

Example 31 with PsiDocComment

use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.

the class SuppressFix method suppressByDocComment.

private void suppressByDocComment(@NotNull Project project, PsiJavaDocumentedElement container) {
    PsiDocComment docComment = container.getDocComment();
    PsiManager manager = PsiManager.getInstance(project);
    if (docComment == null) {
        String commentText = "/** @" + SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME + " " + getID(container) + "*/";
        docComment = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocCommentFromText(commentText);
        PsiElement firstChild = container.getFirstChild();
        container.addBefore(docComment, firstChild);
    } else {
        PsiDocTag noInspectionTag = docComment.findTagByName(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME);
        if (noInspectionTag != null) {
            String tagText = noInspectionTag.getText() + ", " + getID(container);
            noInspectionTag.replace(JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocTagFromText(tagText));
        } else {
            String tagText = "@" + SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME + " " + getID(container);
            docComment.add(JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocTagFromText(tagText));
        }
    }
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) PsiDocTag(com.intellij.psi.javadoc.PsiDocTag)

Example 32 with PsiDocComment

use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.

the class MoveJavaInnerHandler method copyClass.

@NotNull
@Override
public PsiClass copyClass(@NotNull final MoveInnerOptions options) {
    PsiClass innerClass = options.getInnerClass();
    PsiClass newClass;
    if (options.getTargetContainer() instanceof PsiDirectory) {
        newClass = createNewClass(options);
        PsiDocComment defaultDocComment = newClass.getDocComment();
        if (defaultDocComment != null && innerClass.getDocComment() == null) {
            final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(defaultDocComment.getProject());
            innerClass = (PsiClass) codeStyleManager.reformat(innerClass.addAfter(defaultDocComment, null).getParent());
        }
        newClass = (PsiClass) newClass.replace(innerClass);
        PsiUtil.setModifierProperty(newClass, PsiModifier.STATIC, false);
        PsiUtil.setModifierProperty(newClass, PsiModifier.PRIVATE, false);
        PsiUtil.setModifierProperty(newClass, PsiModifier.PROTECTED, false);
        final boolean makePublic = needPublicAccess(options.getOuterClass(), options.getTargetContainer());
        if (makePublic) {
            PsiUtil.setModifierProperty(newClass, PsiModifier.PUBLIC, true);
        }
    } else {
        newClass = (PsiClass) options.getTargetContainer().add(innerClass);
    }
    newClass.setName(options.getNewClassName());
    return newClass;
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with PsiDocComment

use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.

the class JavaRefactoringSupportProvider method isElementWithComment.

private static boolean isElementWithComment(final PsiElement[] scopeElements) {
    if (scopeElements.length > 2)
        return false;
    PsiDocComment comment = null;
    PsiDocCommentOwner owner = null;
    for (PsiElement element : scopeElements) {
        if (element instanceof PsiDocComment) {
            comment = (PsiDocComment) element;
        } else if (element instanceof PsiDocCommentOwner)
            owner = (PsiDocCommentOwner) element;
    }
    return comment != null && comment.getOwner() == owner;
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment)

Example 34 with PsiDocComment

use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.

the class JavaFoldingBuilderBase method addElementsToFold.

private void addElementsToFold(@NotNull List<FoldingDescriptor> list, @NotNull PsiClass aClass, @NotNull Document document, boolean foldJavaDocs, boolean quick) {
    if (!(aClass.getParent() instanceof PsiJavaFile) || ((PsiJavaFile) aClass.getParent()).getClasses().length > 1) {
        addToFold(list, aClass, document, true);
    }
    PsiDocComment docComment;
    if (foldJavaDocs) {
        docComment = aClass.getDocComment();
        if (docComment != null) {
            addToFold(list, docComment, document, true);
        }
    }
    addAnnotationsToFold(aClass.getModifierList(), list, document);
    PsiElement[] children = aClass.getChildren();
    Set<PsiElement> processedComments = new HashSet<>();
    for (PsiElement child : children) {
        ProgressIndicatorProvider.checkCanceled();
        if (child instanceof PsiMethod) {
            PsiMethod method = (PsiMethod) child;
            boolean oneLiner = addOneLineMethodFolding(list, method);
            if (!oneLiner) {
                addToFold(list, method, document, true);
            }
            addAnnotationsToFold(method.getModifierList(), list, document);
            if (foldJavaDocs) {
                docComment = method.getDocComment();
                if (docComment != null) {
                    addToFold(list, docComment, document, true);
                }
            }
            PsiCodeBlock body = method.getBody();
            if (body != null && !oneLiner) {
                addCodeBlockFolds(body, list, processedComments, document, quick);
            }
        } else if (child instanceof PsiField) {
            PsiField field = (PsiField) child;
            if (foldJavaDocs) {
                docComment = field.getDocComment();
                if (docComment != null) {
                    addToFold(list, docComment, document, true);
                }
            }
            addAnnotationsToFold(field.getModifierList(), list, document);
            PsiExpression initializer = field.getInitializer();
            if (initializer != null) {
                addCodeBlockFolds(initializer, list, processedComments, document, quick);
            } else if (field instanceof PsiEnumConstant) {
                addCodeBlockFolds(field, list, processedComments, document, quick);
            }
        } else if (child instanceof PsiClassInitializer) {
            PsiClassInitializer initializer = (PsiClassInitializer) child;
            addToFold(list, initializer, document, true);
            addCodeBlockFolds(initializer, list, processedComments, document, quick);
        } else if (child instanceof PsiClass) {
            addElementsToFold(list, (PsiClass) child, document, true, quick);
        } else if (child instanceof PsiComment) {
            addCommentFolds((PsiComment) child, processedComments, list);
        }
    }
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) HashSet(java.util.HashSet)

Example 35 with PsiDocComment

use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.

the class JCiPUtil method isImmutable.

public static boolean isImmutable(@NotNull PsiClass aClass) {
    final PsiAnnotation annotation = AnnotationUtil.findAnnotation(aClass, ConcurrencyAnnotationsManager.getInstance(aClass.getProject()).getImmutableAnnotations());
    if (annotation != null) {
        return true;
    }
    final PsiDocComment comment = aClass.getDocComment();
    return comment != null && comment.findTagByName("@Immutable") != null;
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment)

Aggregations

PsiDocComment (com.intellij.psi.javadoc.PsiDocComment)54 PsiDocTag (com.intellij.psi.javadoc.PsiDocTag)14 Project (com.intellij.openapi.project.Project)8 TextRange (com.intellij.openapi.util.TextRange)6 PsiElement (com.intellij.psi.PsiElement)6 IElementType (com.intellij.psi.tree.IElementType)6 NotNull (org.jetbrains.annotations.NotNull)5 ASTNode (com.intellij.lang.ASTNode)4 PsiComment (com.intellij.psi.PsiComment)4 CodeStyleManager (com.intellij.psi.codeStyle.CodeStyleManager)4 JavaCodeStyleManager (com.intellij.psi.codeStyle.JavaCodeStyleManager)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 ArrayList (java.util.ArrayList)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiField (com.intellij.psi.PsiField)2 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)2 PsiDocParamRef (com.intellij.psi.impl.source.javadoc.PsiDocParamRef)2 HashMap (com.intellij.util.containers.HashMap)2 HashSet (java.util.HashSet)2 Matcher (java.util.regex.Matcher)2