本文整理汇总了Java中com.intellij.openapi.fileEditor.impl.LoadTextUtil类的典型用法代码示例。如果您正苦于以下问题:Java LoadTextUtil类的具体用法?Java LoadTextUtil怎么用?Java LoadTextUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LoadTextUtil类属于com.intellij.openapi.fileEditor.impl包,在下文中一共展示了LoadTextUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReimportConflictingClasses
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
@WrapInCommand
public void testReimportConflictingClasses() throws Exception {
configureByFile(BASE_PATH+"/x/Usage.java", BASE_PATH);
assertEmpty(highlightErrors());
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
settings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 2;
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
try {
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile());
}
}.execute().throwException();
}
finally {
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
}
@NonNls String fullPath = getTestDataPath() + BASE_PATH + "/x/Usage_afterOptimize.txt";
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/'));
String text = LoadTextUtil.loadText(vFile).toString();
assertEquals(text, getFile().getText());
}
示例2: testPsiModificationNotAffectingDocument
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
public void testPsiModificationNotAffectingDocument() {
final PsiJavaFile file = (PsiJavaFile)myFixture.addFileToProject("a.java", "class A{public static void foo() { }}");
PsiClass aClass = file.getClasses()[0];
//noinspection ResultOfMethodCallIgnored
aClass.getNode();
PlatformTestUtil.tryGcSoftlyReachableObjects();
PsiKeyword kw = assertInstanceOf(aClass.getMethods()[0].getModifierList().getFirstChild(), PsiKeyword.class);
kw.delete();
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
assertNotNull(document);
assertTrue(document.getModificationStamp() != file.getVirtualFile().getModificationStamp());
assertEquals(document.getModificationStamp(), file.getViewProvider().getModificationStamp());
FileDocumentManager.getInstance().saveDocument(document);
assertEquals(file.getText(), LoadTextUtil.loadText(file.getVirtualFile()).toString());
}
示例3: testFileModified
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
public void testFileModified() throws Exception {
VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, myFilesToDelete);
VirtualFile pkg = root.createChildDirectory(this, "foo");
PsiDirectory dir = myPsiManager.findDirectory(pkg);
assertNotNull(dir);
String text = "package foo;\n\nclass A {}";
PsiElement created = dir.add(PsiFileFactory.getInstance(getProject()).createFileFromText("A.java", JavaFileType.INSTANCE, text));
VirtualFile virtualFile = created.getContainingFile().getVirtualFile();
assertNotNull(virtualFile);
String fileText = LoadTextUtil.loadText(virtualFile).toString();
assertEquals(text, fileText);
Document doc = FileDocumentManager.getInstance().getDocument(virtualFile);
assertNotNull(doc);
assertFalse(FileDocumentManager.getInstance().isDocumentUnsaved(doc));
assertFalse(FileDocumentManager.getInstance().isFileModified(virtualFile));
}
示例4: update
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
@Override
public void update(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project != null) {
final VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
final Presentation presentation = e.getPresentation();
if (virtualFiles != null) {
if (virtualFiles.length == 1) {
presentation.setEnabled(!mySeparator.equals(LoadTextUtil.detectLineSeparator(virtualFiles[0], false)));
}
else {
presentation.setEnabled(true);
}
}
else {
presentation.setEnabled(false);
}
}
}
示例5: doTest
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
protected void doTest(boolean checkResult) {
String name = getTestName(myLowercaseFirstLetter);
try {
String text = loadFile(name + "." + myFileExt);
myFile = createPsiFile(name, text);
ensureParsed(myFile);
assertEquals("light virtual file text mismatch", text, ((LightVirtualFile)myFile.getVirtualFile()).getContent().toString());
assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(myFile.getVirtualFile()));
assertEquals("doc text mismatch", text, myFile.getViewProvider().getDocument().getText());
assertEquals("psi text mismatch", text, myFile.getText());
ensureCorrectReparse(myFile);
if (checkResult){
checkResult(name, myFile);
}
else{
toParseTreeText(myFile, skipSpaces(), includeRanges());
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
示例6: computeCharsetFromContent
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
@Nullable("returns null if charset set cannot be determined from content")
Charset computeCharsetFromContent(@NotNull final VirtualFile virtualFile) {
final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
if (document == null) {
return null;
}
Charset cached = EncodingManager.getInstance().getCachedCharsetFromContent(document);
if (cached != null) {
return cached;
}
final Project project = ProjectLocator.getInstance().guessProjectForFile(virtualFile);
return ApplicationManager.getApplication().runReadAction(new Computable<Charset>() {
@Override
public Charset compute() {
Charset charsetFromContent = LoadTextUtil.charsetFromContentOrNull(project, virtualFile, document.getImmutableCharSequence());
if (charsetFromContent != null) {
setCachedCharsetFromContent(charsetFromContent, null, document);
}
return charsetFromContent;
}
});
}
示例7: isSafeToConvertTo
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
static Magic8 isSafeToConvertTo(@NotNull VirtualFile virtualFile, @NotNull String text, @NotNull byte[] bytesOnDisk, @NotNull Charset charset) {
try {
String lineSeparator = FileDocumentManager.getInstance().getLineSeparator(virtualFile, null);
String textToSave = lineSeparator.equals("\n") ? text : StringUtil.convertLineSeparators(text, lineSeparator);
Pair<Charset, byte[]> chosen = LoadTextUtil.chooseMostlyHarmlessCharset(virtualFile.getCharset(), charset, textToSave);
byte[] saved = chosen.second;
CharSequence textLoadedBack = LoadTextUtil.getTextByBinaryPresentation(saved, charset);
return !text.equals(textLoadedBack.toString()) ? Magic8.NO_WAY : Arrays.equals(saved, bytesOnDisk) ? Magic8.ABSOLUTELY : Magic8.WELL_IF_YOU_INSIST;
}
catch (UnsupportedOperationException e) { // unsupported encoding
return Magic8.NO_WAY;
}
}
示例8: getContentAsText
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
@NotNull
@Override
public CharSequence getContentAsText() {
if (myFileType.isBinary()) {
throw new IllegalDataException("Cannot obtain text for binary file type : " + myFileType.getDescription());
}
final CharSequence content = getUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY);
if (content != null) {
return content;
}
if (myContentAsText == null) {
if (myContent != null) {
myContentAsText = LoadTextUtil.getTextByBinaryPresentation(myContent, myCharset);
myContent = null; // help gc, indices are expected to use bytes or chars but not both
}
}
return myContentAsText;
}
示例9: checkFile
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
@Override
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
if (InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) return null;
if (!file.isPhysical()) return null;
FileViewProvider viewProvider = file.getViewProvider();
if (viewProvider.getBaseLanguage() != file.getLanguage()) return null;
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) return null;
if (!virtualFile.isInLocalFileSystem()) return null;
CharSequence text = viewProvider.getContents();
Charset charset = LoadTextUtil.extractCharsetFromFileContent(file.getProject(), virtualFile, text);
// no sense in checking transparently decoded file: all characters there are already safely encoded
if (charset instanceof Native2AsciiCharset) return null;
List<ProblemDescriptor> descriptors = new SmartList<ProblemDescriptor>();
boolean ok = checkFileLoadedInWrongEncoding(file, manager, isOnTheFly, virtualFile, charset, descriptors);
if (ok) {
checkIfCharactersWillBeLostAfterSave(file, manager, isOnTheFly, text, charset, descriptors);
}
return descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
}
示例10: configureProject
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
@Override
public void configureProject(Project project, @NotNull VirtualFile baseDir, Ref<Module> moduleRef) {
VirtualFile setupPy = baseDir.findChild(SETUP_PY);
if (setupPy != null) {
final CharSequence content = LoadTextUtil.loadText(setupPy);
PyFile setupPyFile = (PyFile) PsiFileFactory.getInstance(project).createFileFromText(SETUP_PY, PythonFileType.INSTANCE, content.toString());
final SetupCallVisitor visitor = new SetupCallVisitor();
setupPyFile.accept(visitor);
String dir = visitor.getRootPackageDir();
if (dir != null) {
final VirtualFile rootPackageVFile = baseDir.findFileByRelativePath(dir);
addSourceRoot(project, baseDir, rootPackageVFile, true);
}
}
}
示例11: doTest
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
private void doTest(@NonNls String url, @NonNls String pageText, @NonNls String expected) throws Exception {
final String basePath = getTestDataPath() + TEST_ROOT;
final VirtualFile pageTextFile = LocalFileSystem.getInstance().findFileByPath(basePath + pageText);
assertNotNull(pageTextFile);
final VirtualFile expectedTextFile = LocalFileSystem.getInstance().findFileByPath(basePath + expected);
assertNotNull(expectedTextFile);
class JavadocExternalTestFilter extends JavaDocExternalFilter {
public JavadocExternalTestFilter(Project project) {
super(project);
}
@Override
public void doBuildFromStream(String surl, Reader input, StringBuffer data, boolean search4Encoding) throws IOException {
super.doBuildFromStream(surl, input, data, search4Encoding);
}
}
JavadocExternalTestFilter filter = new JavadocExternalTestFilter(getProject());
final StringBuffer extractedData = new StringBuffer();
filter.doBuildFromStream(url, new StringReader(LoadTextUtil.loadText(pageTextFile).toString()), extractedData, false);
assertEquals(LoadTextUtil.loadText(expectedTextFile).toString(), extractedData.toString());
}
示例12: doTest
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
protected void doTest(boolean checkResult) {
String name = getTestName(false);
try {
String text = loadFile(name + "." + myFileExt);
myFile = createPsiFile(name, text);
ensureParsed(myFile);
assertEquals("light virtual file text mismatch", text, ((LightVirtualFile)myFile.getVirtualFile()).getContent().toString());
assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(myFile.getVirtualFile()));
assertEquals("doc text mismatch", text, myFile.getViewProvider().getDocument().getText());
assertEquals("psi text mismatch", text, myFile.getText());
if (checkResult){
checkResult(name, myFile);
}
else{
toParseTreeText(myFile, skipSpaces(), includeRanges());
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
示例13: computeCharsetFromContent
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
@Nullable("returns null if charset set cannot be determined from content")
public Charset computeCharsetFromContent(@NotNull final VirtualFile virtualFile) {
final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
if (document == null) return null;
final Charset cached = EncodingManager.getInstance().getCachedCharsetFromContent(document);
if (cached != null) return cached;
final Project project = ProjectLocator.getInstance().guessProjectForFile(virtualFile);
return ApplicationManager.getApplication().runReadAction(new Computable<Charset>() {
@Override
public Charset compute() {
Charset charsetFromContent = LoadTextUtil.charsetFromContentOrNull(project, virtualFile, document.getText());
if (charsetFromContent != null) {
setCachedCharsetFromContent(charsetFromContent, cached, document);
}
return charsetFromContent;
}
});
}
示例14: saveIn
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
public static void saveIn(@NotNull final Document document, final Editor editor, @NotNull final VirtualFile virtualFile, @NotNull final Charset charset) {
FileDocumentManager documentManager = FileDocumentManager.getInstance();
documentManager.saveDocument(document);
final Project project = ProjectLocator.getInstance().guessProjectForFile(virtualFile);
boolean writable = project == null ? virtualFile.isWritable() : ReadonlyStatusHandler.ensureFilesWritable(project, virtualFile);
if (!writable) {
CommonRefactoringUtil.showErrorHint(project, editor, "Cannot save the file " + virtualFile.getPresentableUrl(), "Unable to Save", null);
return;
}
// first, save the file in the new charset and then mark the file as having the correct encoding
virtualFile.setCharset(charset);
try {
LoadTextUtil.write(project, virtualFile, virtualFile, document.getText(), document.getModificationStamp());
}
catch (IOException io) {
Messages.showErrorDialog(project, io.getMessage(), "Error Writing File");
}
EncodingProjectManagerImpl.suppressReloadDuring(new Runnable() {
@Override
public void run() {
EncodingManager.getInstance().setEncoding(virtualFile, charset);
}
});
}
示例15: update
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
@Override
public void update(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
if (project != null) {
final VirtualFile[] virtualFiles = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
final Presentation presentation = e.getPresentation();
if (virtualFiles != null) {
if (virtualFiles.length == 1) {
presentation.setEnabled(!mySeparator.equals(LoadTextUtil.detectLineSeparator(virtualFiles[0], false)));
}
else {
presentation.setEnabled(true);
}
}
else {
presentation.setEnabled(false);
}
}
}