Search in sources :

Example 16 with PsiDocComment

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

the class GenerateDelegateHandler method clearMethod.

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();
        }
    }
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment)

Example 17 with PsiDocComment

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

the class JavaImplementationTextSelectioner method getTextStartOffset.

@Override
public int getTextStartOffset(@NotNull final PsiElement parent) {
    PsiElement element = parent;
    if (element instanceof PsiDocCommentOwner) {
        PsiDocComment comment = ((PsiDocCommentOwner) element).getDocComment();
        if (comment != null) {
            element = comment.getNextSibling();
            while (element instanceof PsiWhiteSpace) {
                element = element.getNextSibling();
            }
        }
    }
    if (element != null) {
        TextRange range = element.getTextRange();
        if (range != null) {
            return range.getStartOffset();
        }
        LOG.error("Range should not be null: " + element + "; " + element.getClass());
    }
    LOG.error("Element should not be null: " + parent.getText());
    return parent.getTextRange().getStartOffset();
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) PsiDocCommentOwner(com.intellij.psi.PsiDocCommentOwner) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 18 with PsiDocComment

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

the class JavaFoldingBuilderBase method isRegionCollapsedByDefault.

@Override
protected boolean isRegionCollapsedByDefault(@NotNull ASTNode node) {
    final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(node);
    JavaCodeFoldingSettings settings = JavaCodeFoldingSettings.getInstance();
    if (element instanceof PsiNewExpression || element instanceof PsiJavaToken && element.getParent() instanceof PsiAnonymousClass) {
        return settings.isCollapseLambdas();
    }
    if (element instanceof PsiJavaToken && element.getParent() instanceof PsiCodeBlock && element.getParent().getParent() instanceof PsiMethod) {
        return settings.isCollapseOneLineMethods();
    }
    if (element instanceof PsiReferenceParameterList) {
        return settings.isCollapseConstructorGenericParameters();
    }
    if (element instanceof PsiImportList) {
        return settings.isCollapseImports();
    } else if (element instanceof PsiMethod || element instanceof PsiClassInitializer || element instanceof PsiCodeBlock) {
        if (element instanceof PsiMethod) {
            if (!settings.isCollapseAccessors() && !settings.isCollapseMethods()) {
                return false;
            }
            if (isSimplePropertyAccessor((PsiMethod) element)) {
                return settings.isCollapseAccessors();
            }
        }
        return settings.isCollapseMethods();
    } else if (element instanceof PsiAnonymousClass) {
        return settings.isCollapseAnonymousClasses();
    } else if (element instanceof PsiClass) {
        return !(element.getParent() instanceof PsiFile) && settings.isCollapseInnerClasses();
    } else if (element instanceof PsiDocComment) {
        PsiElement parent = element.getParent();
        if (parent instanceof PsiJavaFile) {
            if (((PsiJavaFile) parent).getName().equals(PsiPackage.PACKAGE_INFO_FILE)) {
                return false;
            }
            PsiElement firstChild = parent.getFirstChild();
            if (firstChild instanceof PsiWhiteSpace) {
                firstChild = firstChild.getNextSibling();
            }
            if (element.equals(firstChild)) {
                return settings.isCollapseFileHeader();
            }
        }
        return settings.isCollapseJavadocs();
    } else if (element instanceof PsiJavaFile) {
        return settings.isCollapseFileHeader();
    } else if (element instanceof PsiAnnotation) {
        return settings.isCollapseAnnotations();
    } else if (element instanceof PsiComment) {
        return settings.isCollapseEndOfLineComments();
    } else if (element instanceof PsiLambdaExpression) {
        return settings.isCollapseAnonymousClasses();
    } else {
        LOG.error("Unknown element:" + element);
        return false;
    }
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) JavaCodeFoldingSettings(com.intellij.codeInsight.folding.JavaCodeFoldingSettings)

Example 19 with PsiDocComment

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

the class JavadocParamTagsTest method testAddTag2.

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());
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) PsiDocTag(com.intellij.psi.javadoc.PsiDocTag)

Example 20 with PsiDocComment

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

the class JavadocParamTagsTest method testDeleteTag2.

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(() -> tags[1].delete());
    assertEquals("/**\n" + " * Javadoc\n" + " * @param p1\n" + " */", docComment.getText());
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) PsiDocTag(com.intellij.psi.javadoc.PsiDocTag)

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