Search in sources :

Example 6 with Editor

use of com.intellij.openapi.editor.Editor in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoGenerateTestMethodActionGroup method getChildren.

@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
    if (e == null) {
        return AnAction.EMPTY_ARRAY;
    }
    Project project = e.getProject();
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    if (project == null || editor == null)
        return AnAction.EMPTY_ARRAY;
    PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
    ArrayList<AnAction> children = ContainerUtil.newArrayList();
    for (GoTestFramework framework : GoTestFramework.all()) {
        if (framework.isAvailableOnFile(file)) {
            children.addAll(framework.getGenerateMethodActions());
        }
    }
    return !children.isEmpty() ? children.toArray(new AnAction[children.size()]) : AnAction.EMPTY_ARRAY;
}
Also used : Project(com.intellij.openapi.project.Project) GoTestFramework(com.goide.runconfig.testing.GoTestFramework) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) AnAction(com.intellij.openapi.actionSystem.AnAction) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with Editor

use of com.intellij.openapi.editor.Editor in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoDocumentationProviderTest method doTest.

private void doTest() {
    myFixture.configureByFile(getTestName(true) + ".go");
    Editor editor = myFixture.getEditor();
    PsiFile file = myFixture.getFile();
    PsiElement originalElement = file.findElementAt(editor.getCaretModel().getOffset());
    assertNotNull(originalElement);
    PsiElement docElement = DocumentationManager.getInstance(getProject()).findTargetElement(editor, file);
    DocumentationProvider documentationProvider = DocumentationManager.getProviderFromElement(originalElement);
    String actualDoc = StringUtil.notNullize(documentationProvider.generateDoc(docElement, originalElement));
    String quickNavigateInfo = documentationProvider.getQuickNavigateInfo(docElement, originalElement);
    actualDoc += "\n=====\n" + StringUtil.notNullize(quickNavigateInfo, "No navigation info");
    List<String> urls = documentationProvider.getUrlFor(docElement, originalElement);
    actualDoc += "\n=====\n" + (urls != null ? StringUtil.join(urls, "\n") : "No urls");
    String localUrl = GoDocumentationProvider.getLocalUrlToElement(docElement);
    actualDoc += "\n=====\n" + StringUtil.notNullize(localUrl, "No local urls");
    assertSameLinesWithFile(getTestDataPath() + "/" + getTestName(true) + ".txt", actualDoc);
    if (localUrl != null) {
        PsiElement elementForLink = documentationProvider.getDocumentationElementForLink(myFixture.getPsiManager(), localUrl, originalElement);
        assertNotNull("Link '" + localUrl + "' wasn't resolved", elementForLink);
        assertEquals("Link was resolved to unexpected element.\nExpected: " + docElement.getText() + "\n" + "Actual: " + elementForLink.getText(), docElement, elementForLink);
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider)

Example 8 with Editor

use of com.intellij.openapi.editor.Editor in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoUnwrapTestCase method assertUnwrapped.

protected void assertUnwrapped(@NotNull String codeBefore, @NotNull String codeAfter, int option) {
    myFixture.configureByText("a.go", normalizeCode(codeBefore));
    UnwrapHandler h = new UnwrapHandler() {

        @Override
        protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
            if (options.isEmpty())
                return;
            options.get(option).actionPerformed(null);
        }
    };
    h.invoke(getProject(), myFixture.getEditor(), myFixture.getFile());
    myFixture.checkResult(normalizeCode(codeAfter));
}
Also used : UnwrapHandler(com.intellij.codeInsight.unwrap.UnwrapHandler) List(java.util.List) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Example 9 with Editor

use of com.intellij.openapi.editor.Editor in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoUnwrapTestCase method assertOptions.

protected void assertOptions(@NotNull String code, String... expectedOptions) {
    myFixture.configureByText("a.go", normalizeCode(code));
    List<String> actualOptions = ContainerUtil.newArrayList();
    UnwrapHandler h = new UnwrapHandler() {

        @Override
        protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
            actualOptions.addAll(options.stream().map(each -> each.getTemplatePresentation().getText()).collect(Collectors.toList()));
        }
    };
    h.invoke(getProject(), myFixture.getEditor(), myFixture.getFile());
    assertOrderedEquals(actualOptions, expectedOptions);
}
Also used : UnwrapHandler(com.intellij.codeInsight.unwrap.UnwrapHandler) List(java.util.List) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Example 10 with Editor

use of com.intellij.openapi.editor.Editor in project intellij-elixir by KronicDeth.

the class Issue443 method isLBraceTokenBrace.

/*
     * Private Instance Methods
     */
private boolean isLBraceTokenBrace() {
    int offset = myFixture.getCaretOffset();
    Editor editor = myFixture.getEditor();
    CharSequence text = editor.getDocument().getCharsSequence();
    FileType fileType = ElixirFileType.INSTANCE;
    HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(offset);
    return BraceMatchingUtil.isLBraceToken(iterator, text, fileType);
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) ElixirFileType(org.elixir_lang.ElixirFileType) Editor(com.intellij.openapi.editor.Editor) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator)

Aggregations

Editor (com.intellij.openapi.editor.Editor)745 Project (com.intellij.openapi.project.Project)280 PsiFile (com.intellij.psi.PsiFile)169 VirtualFile (com.intellij.openapi.vfs.VirtualFile)121 NotNull (org.jetbrains.annotations.NotNull)110 Document (com.intellij.openapi.editor.Document)108 PsiElement (com.intellij.psi.PsiElement)106 Nullable (org.jetbrains.annotations.Nullable)103 TextRange (com.intellij.openapi.util.TextRange)76 FileEditor (com.intellij.openapi.fileEditor.FileEditor)67 TextEditor (com.intellij.openapi.fileEditor.TextEditor)48 ArrayList (java.util.ArrayList)39 IncorrectOperationException (com.intellij.util.IncorrectOperationException)36 List (java.util.List)36 EditorEx (com.intellij.openapi.editor.ex.EditorEx)35 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)28 DataContext (com.intellij.openapi.actionSystem.DataContext)26 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)25 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)22