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();
}
}
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);
}
}
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;
}
}
Aggregations