use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-plugins by JetBrains.
the class GrStepDefinitionCreator method createStepDefinition.
@Override
public boolean createStepDefinition(@NotNull GherkinStep step, @NotNull final PsiFile file) {
if (!(file instanceof GroovyFile))
return false;
final Project project = file.getProject();
final VirtualFile vFile = ObjectUtils.assertNotNull(file.getVirtualFile());
final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vFile);
FileEditorManager.getInstance(project).getAllEditors(vFile);
FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor != null) {
final TemplateManager templateManager = TemplateManager.getInstance(file.getProject());
final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
final Template template = templateManager.getActiveTemplate(editor);
if (templateState != null && template != null) {
templateState.gotoEnd();
}
}
// snippet text
final GrMethodCall element = buildStepDefinitionByStep(step);
GrMethodCall methodCall = (GrMethodCall) ((GroovyFile) file).addStatementBefore(element, null);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(methodCall);
methodCall = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(methodCall);
PsiDocumentManager.getInstance(project).commitAllDocuments();
if (ApplicationManager.getApplication().isUnitTestMode())
return true;
final TemplateBuilderImpl builder = (TemplateBuilderImpl) TemplateBuilderFactory.getInstance().createTemplateBuilder(methodCall);
// regexp str
GrLiteral pattern = GrCucumberUtil.getStepDefinitionPattern(methodCall);
assert pattern != null;
String patternText = pattern.getText();
builder.replaceElement(pattern, new TextRange(1, patternText.length() - 1), patternText.substring(1, patternText.length() - 1));
// block vars
GrClosableBlock closure = methodCall.getClosureArguments()[0];
final GrParameter[] blockVars = closure.getAllParameters();
for (GrParameter var : blockVars) {
PsiElement identifier = var.getNameIdentifierGroovy();
builder.replaceElement(identifier, identifier.getText());
}
TemplateManager manager = TemplateManager.getInstance(project);
final Editor editorToRunTemplate;
if (editor == null) {
editorToRunTemplate = IntentionUtils.positionCursor(project, file, methodCall);
} else {
editorToRunTemplate = editor;
}
Template template = builder.buildTemplate();
TextRange range = methodCall.getTextRange();
editorToRunTemplate.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
editorToRunTemplate.getCaretModel().moveToOffset(range.getStartOffset());
manager.startTemplate(editorToRunTemplate, template, new TemplateEditingAdapter() {
@Override
public void templateFinished(Template template, boolean brokenOff) {
if (brokenOff)
return;
ApplicationManager.getApplication().runWriteAction(() -> {
PsiDocumentManager.getInstance(project).commitDocument(editorToRunTemplate.getDocument());
final int offset = editorToRunTemplate.getCaretModel().getOffset();
GrMethodCall methodCall1 = PsiTreeUtil.findElementOfClassAtOffset(file, offset - 1, GrMethodCall.class, false);
if (methodCall1 != null) {
GrClosableBlock[] closures = methodCall1.getClosureArguments();
if (closures.length == 1) {
GrClosableBlock closure1 = closures[0];
selectBody(closure1, editor);
}
}
});
}
});
return true;
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-plugins by JetBrains.
the class FlexHighlightingTest method testGenerateTestClass.
@JSTestOptions({ JSTestOption.WithFlexFacet, JSTestOption.WithFlexUnit4 })
public void testGenerateTestClass() throws Exception {
JSTestUtils.disableFileHeadersInTemplates(getProject());
final String testName = getTestName(false);
configureByFiles(BASE_PATH + "/" + testName, BASE_PATH + "/" + testName + "/pack/" + testName + ".mxml");
final FlexUnitTestCreator testCreator = new FlexUnitTestCreator();
assertTrue(testCreator.isAvailable(myProject, myEditor, myFile));
testCreator.createTest(myProject, myEditor, myFile);
final VirtualFile testClassFile = ModuleRootManager.getInstance(myModule).getSourceRoots()[0].findFileByRelativePath("pack/" + testName + "Test.as");
myEditor = FileEditorManager.getInstance(myProject).openTextEditor(new OpenFileDescriptor(myProject, testClassFile), true);
myFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
checkResultByFile(BASE_PATH + "/" + testName + "/pack/" + testName + "_after.as");
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-plugins by JetBrains.
the class SwfHighlightingTest method testLineMarkersInSwf.
@JSTestOptions({ JSTestOption.WithFlexFacet, JSTestOption.WithLineMarkers })
public void testLineMarkersInSwf() throws Exception {
final String testName = getTestName(false);
myAfterCommitRunnable = () -> FlexTestUtils.addLibrary(myModule, "lib", getTestDataPath() + getBasePath() + "/", testName + ".swc", null, null);
// actual test data is in library.swf; this file is here just because we need any file
configureByFile("/" + testName + ".as");
VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(getTestDataPath() + getBasePath() + "/" + testName + ".swc");
vFile = JarFileSystem.getInstance().getJarRootForLocalFile(vFile).findChild("library.swf");
myEditor = FileEditorManager.getInstance(myProject).openTextEditor(new OpenFileDescriptor(myProject, vFile, 0), false);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
myFile = myPsiManager.findFile(vFile);
((EditorImpl) myEditor).setCaretActive();
vFile = LocalFileSystem.getInstance().findFileByPath(getTestDataPath() + getBasePath() + "/" + testName + ".as");
final String verificationText = StreamUtil.convertSeparators(VfsUtilCore.loadText(vFile));
checkHighlighting(new ExpectedHighlightingData(new DocumentImpl(verificationText), false, false, true, myFile));
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-plugins by JetBrains.
the class SwfHighlightingTest method testProtectSwf.
public void testProtectSwf() throws Exception {
configureByFiles((String) null);
VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(getTestDataPath() + getBasePath() + "/" + getTestName(false) + ".swf");
myEditor = FileEditorManager.getInstance(myProject).openTextEditor(new OpenFileDescriptor(myProject, vFile, 0), false);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
myFile = myPsiManager.findFile(vFile);
((EditorImpl) myEditor).setCaretActive();
assertFalse(FileDocumentManager.getInstance().requestWriting(myEditor.getDocument(), myProject));
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.
the class UnresolvedDependenciesReporterTest method testReportWithRegularJavaLibrary.
public void testReportWithRegularJavaLibrary() throws Exception {
loadSimpleApplication();
mySyncMessagesStub.clearReportedMessages();
when(mySyncIssue.getData()).thenReturn("com.google.guava:guava:19.0");
Module appModule = myModules.getAppModule();
VirtualFile buildFile = getGradleBuildFile(appModule);
myReporter.report(mySyncIssue, appModule, buildFile);
SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
assertNotNull(message);
assertThat(message.getText()).hasLength(1);
// @formatter:off
assertAbout(syncMessage()).that(message).hasGroup("Unresolved dependencies").hasMessageLine("Failed to resolve: com.google.guava:guava:19.0", 0);
// @formatter:on
assertThat(message.getNavigatable()).isInstanceOf(OpenFileDescriptor.class);
OpenFileDescriptor navigatable = (OpenFileDescriptor) message.getNavigatable();
assertEquals(buildFile, navigatable.getFile());
PositionInFile position = message.getPosition();
assertNotNull(position);
assertSame(buildFile, position.file);
}
Aggregations