use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class PsiViewerDialog method updateEditor.
private void updateEditor() {
final Object source = getSource();
final String fileName = "Dummy." + (source instanceof FileType ? ((FileType) source).getDefaultExtension() : "txt");
final LightVirtualFile lightFile;
if (source instanceof PsiViewerExtension) {
lightFile = new LightVirtualFile(fileName, ((PsiViewerExtension) source).getDefaultFileType(), "");
} else if (source instanceof LanguageFileType) {
lightFile = new LightVirtualFile(fileName, ObjectUtils.chooseNotNull((Language) myDialectComboBox.getSelectedItem(), ((LanguageFileType) source).getLanguage()), "");
} else if (source instanceof FileType) {
lightFile = new LightVirtualFile(fileName, (FileType) source, "");
} else {
return;
}
EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, lightFile);
try {
myEditor.setHighlighter(highlighter);
} catch (Throwable e) {
LOG.warn(e);
}
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class BinaryContent method getFile.
@Override
@Nullable
public VirtualFile getFile() {
if (myFileType instanceof UIBasedFileType) {
final VirtualFile file = findVirtualFile();
if (file != null) {
final LightVirtualFile lightFile = new LightVirtualFile(file, new String(myBytes), 1);
lightFile.setOriginalFile(file);
return lightFile;
}
}
return null;
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class TemplateDataElementType method createPsiFileFromSource.
protected PsiFile createPsiFileFromSource(final Language language, CharSequence sourceCode, PsiManager manager) {
@NonNls final LightVirtualFile virtualFile = new LightVirtualFile("foo", createTemplateFakeFileType(language), sourceCode, LocalTimeCounter.currentTime());
FileViewProvider viewProvider = new SingleRootFileViewProvider(manager, virtualFile, false) {
@Override
@NotNull
public Language getBaseLanguage() {
return language;
}
};
// Since we're already inside a template language PSI that was built regardless of the file size (for whatever reason),
// there should also be no file size checks for template data files.
SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);
return viewProvider.getPsi(language);
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class LoadTextUtilTest method doTest.
private static void doTest(String source, String expected, String expectedSeparator) {
final LightVirtualFile vFile = new LightVirtualFile("test.txt");
final CharSequence real = LoadTextUtil.getTextByBinaryPresentation(source.getBytes(), vFile);
assertTrue("content", Comparing.equal(expected, real));
if (expectedSeparator != null) {
assertEquals("detected line separator", expectedSeparator, FileDocumentManager.getInstance().getLineSeparator(vFile, null));
}
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class ReadonlyStatusHandlerImpl method ensureFilesWritable.
@Override
public OperationStatus ensureFilesWritable(@NotNull VirtualFile... files) {
if (files.length == 0) {
return new OperationStatusImpl(VirtualFile.EMPTY_ARRAY);
}
checkThreading();
Set<VirtualFile> realFiles = new THashSet<>(files.length);
for (VirtualFile file : files) {
if (file instanceof LightVirtualFile) {
VirtualFile originalFile = ((LightVirtualFile) file).getOriginalFile();
if (originalFile != null) {
file = originalFile;
}
}
if (file instanceof VirtualFileWindow)
file = ((VirtualFileWindow) file).getDelegate();
if (file != null) {
realFiles.add(file);
}
}
files = VfsUtilCore.toVirtualFileArray(realFiles);
for (final WritingAccessProvider accessProvider : myAccessProviders) {
Collection<VirtualFile> denied = ContainerUtil.filter(files, virtualFile -> !accessProvider.isPotentiallyWritable(virtualFile));
if (denied.isEmpty()) {
denied = accessProvider.requestWriting(files);
}
if (!denied.isEmpty()) {
return new OperationStatusImpl(VfsUtilCore.toVirtualFileArray(denied));
}
}
final FileInfo[] fileInfos = createFileInfos(files);
if (fileInfos.length == 0) {
// if all files are already writable
return createResultStatus(files);
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
if (myClearReadOnlyInTests) {
processFiles(new ArrayList<>(Arrays.asList(fileInfos)), null);
}
return createResultStatus(files);
}
// This event count hack is necessary to allow actions that called this stuff could still get data from their data contexts.
// Otherwise data manager stuff will fire up an assertion saying that event count has been changed (due to modal dialog show-up)
// The hack itself is safe since we guarantee that focus will return to the same component had it before modal dialog have been shown.
final int savedEventCount = IdeEventQueue.getInstance().getEventCount();
if (myState.SHOW_DIALOG) {
new ReadOnlyStatusDialog(myProject, fileInfos).show();
} else {
// the collection passed is modified
processFiles(new ArrayList<>(Arrays.asList(fileInfos)), null);
}
IdeEventQueue.getInstance().setEventCount(savedEventCount);
return createResultStatus(files);
}
Aggregations