Search in sources :

Example 26 with Document

use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.

the class GroovyLineMarkerProvider method getLineMarkerInfo.

@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
    final PsiElement parent = element.getParent();
    if (parent instanceof PsiNameIdentifierOwner) {
        if (parent instanceof GrField && element == ((GrField) parent).getNameIdentifierGroovy()) {
            for (GrAccessorMethod method : GroovyPropertyUtils.getFieldAccessors((GrField) parent)) {
                MethodSignatureBackedByPsiMethod superSignature = SuperMethodsSearch.search(method, null, true, false).findFirst();
                if (superSignature != null) {
                    PsiMethod superMethod = superSignature.getMethod();
                    boolean overrides = method.hasModifierProperty(PsiModifier.ABSTRACT) == superMethod.hasModifierProperty(PsiModifier.ABSTRACT) || superMethod.getBody() != null && GrTraitUtil.isTrait(superMethod.getContainingClass());
                    final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
                    final MarkerType type = GroovyMarkerTypes.OVERRIDING_PROPERTY_TYPE;
                    return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, type.getTooltip(), type.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
                }
            }
        } else if (parent instanceof GrMethod && element == ((GrMethod) parent).getNameIdentifierGroovy() && hasSuperMethods((GrMethod) element.getParent())) {
            final Icon icon = AllIcons.Gutter.OverridingMethod;
            final MarkerType type = GroovyMarkerTypes.GR_OVERRIDING_METHOD;
            return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, type.getTooltip(), type.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
        }
    }
    //need to draw method separator above docComment
    if (myDaemonSettings.SHOW_METHOD_SEPARATORS && element.getFirstChild() == null) {
        PsiElement element1 = element;
        boolean isMember = false;
        while (element1 != null && !(element1 instanceof PsiFile) && element1.getPrevSibling() == null) {
            element1 = element1.getParent();
            if (element1 instanceof PsiMember || element1 instanceof GrVariableDeclarationImpl) {
                isMember = true;
                break;
            }
        }
        if (isMember && !(element1 instanceof PsiAnonymousClass || element1.getParent() instanceof PsiAnonymousClass)) {
            PsiFile file = element1.getContainingFile();
            Document document = file == null ? null : PsiDocumentManager.getInstance(file.getProject()).getLastCommittedDocument(file);
            boolean drawSeparator = false;
            if (document != null) {
                CharSequence documentChars = document.getCharsSequence();
                int category = getGroovyCategory(element1, documentChars);
                for (PsiElement child = element1.getPrevSibling(); child != null; child = child.getPrevSibling()) {
                    int category1 = getGroovyCategory(child, documentChars);
                    if (category1 == 0)
                        continue;
                    drawSeparator = category != 1 || category1 != 1;
                    break;
                }
            }
            if (drawSeparator) {
                GrDocComment comment = null;
                if (element1 instanceof GrDocCommentOwner) {
                    comment = ((GrDocCommentOwner) element1).getDocComment();
                }
                LineMarkerInfo info = new LineMarkerInfo<>(element, comment != null ? comment.getTextRange() : element.getTextRange(), null, Pass.LINE_MARKERS, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT);
                EditorColorsScheme scheme = myColorsManager.getGlobalScheme();
                info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
                info.separatorPlacement = SeparatorPlacement.TOP;
                return info;
            }
        }
    }
    return null;
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod) MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod) GrDocCommentOwner(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) Document(com.intellij.openapi.editor.Document) GrDocComment(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment) GrAccessorMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) MarkerType(com.intellij.codeInsight.daemon.impl.MarkerType) GrVariableDeclarationImpl(org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableDeclarationImpl) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 27 with Document

use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.

the class GroovyQuoteHandler method getClosingQuote.

@Override
public CharSequence getClosingQuote(HighlighterIterator iterator, int offset) {
    if (offset >= 3) {
        Document document = iterator.getDocument();
        if (document == null)
            return null;
        String quote = document.getText(new TextRange(offset - 3, offset));
        if ("'''".equals(quote))
            return quote;
        if ("\"\"\"".equals(quote))
            return quote;
    }
    if (offset >= 2) {
        Document document = iterator.getDocument();
        if (document == null)
            return null;
        String quote = document.getText(new TextRange(offset - 2, offset));
        if ("$/".equals(quote))
            return "/$";
    }
    return null;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document)

Example 28 with Document

use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.

the class FieldInitializerTailTypes method processTail.

@Override
public int processTail(Editor editor, int tailOffset) {
    CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(editor.getProject());
    Document document = editor.getDocument();
    CharSequence chars = document.getCharsSequence();
    int textLength = chars.length();
    if (tailOffset < textLength - 1 && chars.charAt(tailOffset) == ' ' && chars.charAt(tailOffset + 1) == '=') {
        return moveCaret(editor, tailOffset, 2);
    }
    if (tailOffset < textLength && chars.charAt(tailOffset) == '=') {
        return moveCaret(editor, tailOffset, 1);
    }
    if (styleSettings.SPACE_AROUND_ASSIGNMENT_OPERATORS) {
        document.insertString(tailOffset, " =");
        tailOffset = moveCaret(editor, tailOffset, 2);
    } else {
        document.insertString(tailOffset, "=");
        tailOffset = moveCaret(editor, tailOffset, 1);
    }
    if (styleSettings.SPACE_AROUND_ASSIGNMENT_OPERATORS) {
        tailOffset = insertChar(editor, tailOffset, ' ');
    }
    document.insertString(tailOffset, myText);
    return moveCaret(editor, tailOffset, myPosition);
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) Document(com.intellij.openapi.editor.Document)

Example 29 with Document

use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.

the class PsiEventsTest method testEditingInDocComment.

public void testEditingInDocComment() throws Exception {
    final Ref<Boolean> gotIt = new Ref<>(false);
    getPsiManager().addPsiTreeChangeListener(new PsiTreeChangeAdapter() {

        @Override
        public void childReplaced(@NotNull PsiTreeChangeEvent event) {
            gotIt.set(true);
        }
    });
    GroovyFile file = GroovyPsiElementFactory.getInstance(myProject).createGroovyFile("/** This is doc comment*/class C{}", true, null);
    final PsiDocumentManager docManager = PsiDocumentManager.getInstance(myProject);
    final Document doc = docManager.getDocument(file);
    assertNotNull(doc);
    CommandProcessor.getInstance().executeCommand(myProject, () -> ApplicationManager.getApplication().runWriteAction(() -> {
        doc.insertString(3, " ");
        docManager.commitDocument(doc);
    }), "file text set", this);
    assertTrue(gotIt.get());
}
Also used : Ref(com.intellij.openapi.util.Ref) PsiTreeChangeEvent(com.intellij.psi.PsiTreeChangeEvent) Document(com.intellij.openapi.editor.Document) PsiTreeChangeAdapter(com.intellij.psi.PsiTreeChangeAdapter) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 30 with Document

use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.

the class TaskCompletionTest method configureFile.

private void configureFile(String text) {
    PsiFile psiFile = myFixture.configureByText("test.txt", text);
    Document document = myFixture.getDocument(psiFile);
    final Project project = getProject();
    TextFieldWithAutoCompletion.installCompletion(document, project, new TaskAutoCompletionListProvider(project), false);
    document.putUserData(CommitMessage.DATA_KEY, new CommitMessage(project));
}
Also used : Project(com.intellij.openapi.project.Project) CommitMessage(com.intellij.openapi.vcs.ui.CommitMessage) TaskAutoCompletionListProvider(com.intellij.tasks.actions.TaskAutoCompletionListProvider) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document)

Aggregations

Document (com.intellij.openapi.editor.Document)1072 VirtualFile (com.intellij.openapi.vfs.VirtualFile)243 PsiFile (com.intellij.psi.PsiFile)191 Project (com.intellij.openapi.project.Project)163 NotNull (org.jetbrains.annotations.NotNull)138 Nullable (org.jetbrains.annotations.Nullable)129 TextRange (com.intellij.openapi.util.TextRange)122 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)117 PsiElement (com.intellij.psi.PsiElement)107 Editor (com.intellij.openapi.editor.Editor)104 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)56 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)45 IncorrectOperationException (com.intellij.util.IncorrectOperationException)43 IOException (java.io.IOException)42 RangeMarker (com.intellij.openapi.editor.RangeMarker)35 MockVirtualFile (com.intellij.mock.MockVirtualFile)33 ArrayList (java.util.ArrayList)32 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)30 File (java.io.File)30 List (java.util.List)29