Search in sources :

Example 41 with PsiDocComment

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

the class GenerationUtil method writeDocComment.

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

Example 42 with PsiDocComment

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

the class EndOfLineCommentPredicate method satisfiedBy.

@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();
    return GroovyTokenTypes.mSL_COMMENT.equals(type);
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) IElementType(com.intellij.psi.tree.IElementType) PsiComment(com.intellij.psi.PsiComment)

Example 43 with PsiDocComment

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

the class GroovyMoveClassToInnerHandler method moveClass.

@Override
public PsiClass moveClass(@NotNull PsiClass aClass, @NotNull PsiClass targetClass) {
    if (!(aClass instanceof GrTypeDefinition))
        return null;
    GroovyChangeContextUtil.encodeContextInfo(aClass);
    PsiDocComment doc = aClass.getDocComment();
    PsiElement brace = targetClass.getRBrace();
    PsiClass newClass = (PsiClass) targetClass.addBefore(aClass, brace);
    PsiElement sibling = newClass.getPrevSibling();
    GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(targetClass.getProject());
    if (!org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isNewLine(sibling)) {
        targetClass.addBefore(factory.createLineTerminator("\n "), newClass);
    } else if (doc != null) {
        LOG.assertTrue(sibling != null);
        sibling.replace(factory.createLineTerminator(sibling.getText() + " "));
    }
    if (doc != null) {
        targetClass.addBefore(doc, newClass);
        targetClass.addBefore(factory.createLineTerminator("\n"), newClass);
    }
    if (targetClass.isInterface()) {
        PsiUtil.setModifierProperty(newClass, PsiModifier.PUBLIC, true);
    } else {
        PsiUtil.setModifierProperty(newClass, PsiModifier.STATIC, true);
    }
    GroovyChangeContextUtil.decodeContextInfo(newClass, null, null);
    return newClass;
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)

Example 44 with PsiDocComment

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

the class SourceCodeChecker method check.

private static ThreeState check(Location location, SourcePosition position, Project project) {
    Method method = DebuggerUtilsEx.getMethod(location);
    // for now skip constructors, bridges, lambdas etc.
    if (method == null || method.isConstructor() || method.isSynthetic() || method.isBridge() || method.isStaticInitializer() || (method.declaringType() instanceof ClassType && ((ClassType) method.declaringType()).isEnum()) || DebuggerUtilsEx.isLambda(method)) {
        return ThreeState.UNSURE;
    }
    List<Location> locations = DebuggerUtilsEx.allLineLocations(method);
    if (ContainerUtil.isEmpty(locations)) {
        return ThreeState.UNSURE;
    }
    if (position != null) {
        return ReadAction.compute(() -> {
            PsiFile psiFile = position.getFile();
            if (!psiFile.getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
                // only for java for now
                return ThreeState.UNSURE;
            }
            Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
            if (document == null) {
                return ThreeState.UNSURE;
            }
            boolean res = false;
            PsiElement psiMethod = DebuggerUtilsEx.getContainingMethod(position);
            if (psiMethod != null) {
                TextRange range = psiMethod.getTextRange();
                if (psiMethod instanceof PsiDocCommentOwner) {
                    PsiDocComment comment = ((PsiDocCommentOwner) psiMethod).getDocComment();
                    if (comment != null) {
                        range = new TextRange(comment.getTextRange().getEndOffset() + 1, range.getEndOffset());
                    }
                }
                int startLine = document.getLineNumber(range.getStartOffset()) + 1;
                int endLine = document.getLineNumber(range.getEndOffset()) + 1;
                res = getLinesStream(locations, psiFile).allMatch(line -> startLine <= line && line <= endLine);
                if (!res) {
                    LOG.debug("Source check failed: Method " + method.name() + ", source: " + ((NavigationItem) psiMethod).getName() + "\nLines: " + getLinesStream(locations, psiFile).joining(", ") + "\nExpected range: " + startLine + "-" + endLine);
                }
            } else {
                LOG.debug("Source check failed: method " + method.name() + " not found in sources");
            }
            if (!res) {
                FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(position.getFile().getVirtualFile());
                if (editor instanceof TextEditor) {
                    AppUIUtil.invokeOnEdt(() -> HintManager.getInstance().showErrorHint(((TextEditor) editor).getEditor(), DebuggerBundle.message("warning.source.code.not.match")));
                } else {
                    XDebugSessionImpl.NOTIFICATION_GROUP.createNotification(DebuggerBundle.message("warning.source.code.not.match"), NotificationType.WARNING).notify(project);
                }
                return ThreeState.NO;
            }
            return ThreeState.YES;
        });
    }
    return ThreeState.YES;
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) NavigationItem(com.intellij.navigation.NavigationItem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) ContainerUtil(com.intellij.util.containers.ContainerUtil) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl) ReadAction(com.intellij.openapi.application.ReadAction) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) PositionManagerImpl(com.intellij.debugger.engine.PositionManagerImpl) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) Project(com.intellij.openapi.project.Project) DebuggerBundle(com.intellij.debugger.DebuggerBundle) Logger(com.intellij.openapi.diagnostic.Logger) JavaLanguage(com.intellij.lang.java.JavaLanguage) TextEditor(com.intellij.openapi.fileEditor.TextEditor) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) NoDataException(com.intellij.debugger.NoDataException) AppUIUtil(com.intellij.ui.AppUIUtil) ThreeState(com.intellij.util.ThreeState) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) TextRange(com.intellij.openapi.util.TextRange) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NotificationType(com.intellij.notification.NotificationType) TestOnly(org.jetbrains.annotations.TestOnly) PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) List(java.util.List) LineNumbersMapping(com.intellij.execution.filters.LineNumbersMapping) StreamEx(one.util.streamex.StreamEx) Registry(com.intellij.openapi.util.registry.Registry) com.sun.jdi(com.sun.jdi) IntStreamEx(one.util.streamex.IntStreamEx) com.intellij.psi(com.intellij.psi) HintManager(com.intellij.codeInsight.hint.HintManager) SourcePosition(com.intellij.debugger.SourcePosition) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) NavigationItem(com.intellij.navigation.NavigationItem) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Example 45 with PsiDocComment

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

the class EncapsulateFieldsProcessor method generateAccessors.

private void generateAccessors() {
    // generate accessors
    myNameToGetter = new HashMap<>();
    myNameToSetter = new HashMap<>();
    for (FieldDescriptor fieldDescriptor : myFieldDescriptors) {
        final DocCommentPolicy<PsiDocComment> commentPolicy = new DocCommentPolicy<>(myDescriptor.getJavadocPolicy());
        PsiField field = fieldDescriptor.getField();
        final PsiDocComment docComment = field.getDocComment();
        if (myDescriptor.isToEncapsulateGet()) {
            final PsiMethod prototype = fieldDescriptor.getGetterPrototype();
            assert prototype != null;
            final PsiMethod getter = addOrChangeAccessor(prototype, myNameToGetter);
            if (docComment != null) {
                final PsiDocComment getterJavadoc = (PsiDocComment) getter.addBefore(docComment, getter.getFirstChild());
                commentPolicy.processNewJavaDoc(getterJavadoc);
            }
        }
        if (myDescriptor.isToEncapsulateSet() && !field.hasModifierProperty(PsiModifier.FINAL)) {
            PsiMethod prototype = fieldDescriptor.getSetterPrototype();
            assert prototype != null;
            addOrChangeAccessor(prototype, myNameToSetter);
        }
        if (docComment != null) {
            commentPolicy.processOldJavaDoc(docComment);
        }
    }
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

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