Search in sources :

Example 1 with EditorInfo

use of com.intellij.codeInsight.EditorInfo in project intellij-plugins by JetBrains.

the class FlexCompletionInTextFieldBase method doTestForEditorTextField.

protected void doTestForEditorTextField(JSExpressionCodeFragment fragment, String suffix, String ext, final String file) throws Exception {
    JSTestUtils.initJSIndexes(getProject());
    JSEditorTextField editorTextField = null;
    try {
        myFile = fragment;
        Document document = PsiDocumentManager.getInstance(myProject).getDocument(fragment);
        editorTextField = new JSEditorTextField(myProject, document);
        final String text = StringUtil.convertLineSeparators(VfsUtilCore.loadText(getVirtualFile(file)));
        EditorInfo editorInfo = new EditorInfo(text);
        // initialize editor
        editorTextField.addNotify();
        myEditor = editorTextField.getEditor();
        myEditorsToRelease.add(myEditor);
        editorTextField.setText(editorInfo.getNewFileText());
        editorInfo.applyToEditor(myEditor);
        complete();
    } finally {
        // dispose editor
        if (editorTextField != null)
            editorTextField.removeNotify();
    }
}
Also used : EditorInfo(com.intellij.codeInsight.EditorInfo) Document(com.intellij.openapi.editor.Document) JSEditorTextField(com.intellij.lang.javascript.refactoring.ui.JSEditorTextField)

Example 2 with EditorInfo

use of com.intellij.codeInsight.EditorInfo in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testRehighlightInDebuggerExpressionFragment.

public void testRehighlightInDebuggerExpressionFragment() throws Exception {
    PsiExpressionCodeFragment fragment = JavaCodeFragmentFactory.getInstance(getProject()).createExpressionCodeFragment("+ <caret>\"a\"", null, PsiType.getJavaLangObject(getPsiManager(), GlobalSearchScope.allScope(getProject())), true);
    myFile = fragment;
    Document document = PsiDocumentManager.getInstance(getProject()).getDocument(fragment);
    myEditor = EditorFactory.getInstance().createEditor(document, getProject(), StdFileTypes.JAVA, false);
    ProperTextRange visibleRange = makeEditorWindowVisible(new Point(0, 0), myEditor);
    assertEquals(document.getTextLength(), visibleRange.getLength());
    try {
        final EditorInfo editorInfo = new EditorInfo(document.getText());
        final String newFileText = editorInfo.getNewFileText();
        ApplicationManager.getApplication().runWriteAction(() -> {
            if (!document.getText().equals(newFileText)) {
                document.setText(newFileText);
            }
            editorInfo.applyToEditor(myEditor);
        });
        PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
        List<HighlightInfo> errors = highlightErrors();
        HighlightInfo error = assertOneElement(errors);
        assertEquals("Operator '+' cannot be applied to 'java.lang.String'", error.getDescription());
        type(" ");
        Collection<HighlightInfo> afterTyping = highlightErrors();
        HighlightInfo after = assertOneElement(afterTyping);
        assertEquals("Operator '+' cannot be applied to 'java.lang.String'", after.getDescription());
    } finally {
        EditorFactory.getInstance().releaseEditor(myEditor);
    }
}
Also used : EditorInfo(com.intellij.codeInsight.EditorInfo) ProperTextRange(com.intellij.openapi.util.ProperTextRange)

Example 3 with EditorInfo

use of com.intellij.codeInsight.EditorInfo in project intellij-plugins by JetBrains.

the class FlexMoveInnerClassTest method performAction.

private void performAction(VirtualFile rootDir, String fromFilePath, String className, final String targetPackage, boolean searchInStringsAndComments, boolean searchTextOccurences, String[] conflicts) {
    PsiFile sourceFile = myPsiManager.findFile(rootDir.findFileByRelativePath(fromFilePath));
    final EditorInfo editorInfo = new EditorInfo(sourceFile.getText());
    assertEquals("Wrong number of carets", 1, editorInfo.caretState.carets.size());
    assertNotNull("No caret specified", editorInfo.caretState.carets.get(0).position);
    final Document doc = PsiDocumentManager.getInstance(myProject).getDocument(sourceFile);
    final PsiDirectory targetDirectory = WriteAction.compute(() -> {
        doc.setText(editorInfo.getNewFileText());
        PsiDocumentManager.getInstance(myProject).commitDocument(doc);
        final VirtualFile srcRootFile = ModuleRootManager.getInstance(myModule).getSourceRoots()[0];
        final VirtualFile file = VfsUtilCore.findRelativeFile(targetPackage.replace('.', File.separatorChar), srcRootFile);
        if (file != null) {
            return myPsiManager.findDirectory(file);
        } else {
            PsiDirectory srcRoot = myPsiManager.findDirectory(srcRootFile);
            return DirectoryUtil.createSubdirectories(targetPackage, srcRoot, ".");
        }
    });
    PsiElement element = sourceFile.findElementAt(editorInfo.caretState.carets.get(0).getCaretOffset(doc));
    while (true) {
        assertFalse("inner element to move not found", element instanceof JSFile);
        final JSQualifiedNamedElement adjusted = FlexMoveFileRefactoringHandler.adjustForMove(element);
        if (adjusted != null) {
            element = adjusted;
            break;
        }
        element = element.getParent();
    }
    try {
        new FlexMoveInnerClassProcessor((JSQualifiedNamedElement) element, targetDirectory, className, targetPackage, searchInStringsAndComments, searchTextOccurences, null).run();
        assertEquals("Conflicts expected:\n" + StringUtil.join(conflicts, "\n"), 0, conflicts.length);
    } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
        assertTrue("Conflicts not expected but found:" + e.getMessage(), conflicts.length > 0);
        assertSameElements(e.getMessages(), conflicts);
        myDoCompare = false;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlexMoveInnerClassProcessor(com.intellij.javascript.flex.refactoring.moveClass.FlexMoveInnerClassProcessor) BaseRefactoringProcessor(com.intellij.refactoring.BaseRefactoringProcessor) EditorInfo(com.intellij.codeInsight.EditorInfo) PsiDirectory(com.intellij.psi.PsiDirectory) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

EditorInfo (com.intellij.codeInsight.EditorInfo)3 Document (com.intellij.openapi.editor.Document)2 FlexMoveInnerClassProcessor (com.intellij.javascript.flex.refactoring.moveClass.FlexMoveInnerClassProcessor)1 JSFile (com.intellij.lang.javascript.psi.JSFile)1 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)1 JSEditorTextField (com.intellij.lang.javascript.refactoring.ui.JSEditorTextField)1 ProperTextRange (com.intellij.openapi.util.ProperTextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 BaseRefactoringProcessor (com.intellij.refactoring.BaseRefactoringProcessor)1