本文整理汇总了Java中com.intellij.openapi.fileEditor.impl.LoadTextUtil类的典型用法代码示例。如果您正苦于以下问题:Java LoadTextUtil类的具体用法?Java LoadTextUtil怎么用?Java LoadTextUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LoadTextUtil类属于com.intellij.openapi.fileEditor.impl包,在下文中一共展示了LoadTextUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:ImportHelperTest.java
示例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());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:MiscPsiTest.java
示例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));
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:AddClassToFileTest.java
示例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);
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:AbstractConvertLineSeparatorsAction.java
示例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);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ParsingTestCase.java
示例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;
}
});
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:EncodingManagerImpl.java
示例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;
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:EncodingUtil.java
示例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;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:FileContentImpl.java
示例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()]);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:LossyEncodingInspection.java
示例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);
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:PythonSourceRootConfigurator.java
示例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());
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:ExternalJavadocPresentationTest.java
示例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);
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:ParsingTestCase.java
示例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;
}
});
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:EncodingManagerImpl.java
示例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);
}
});
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:27,代码来源:EncodingUtil.java
示例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);
}
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:AbstractConvertLineSeparatorsAction.java
示例16: getText
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
@Override
public CharSequence getText() {
final VirtualFile virtualFile = getVirtualFile();
if (virtualFile instanceof LightVirtualFile) {
Document doc = getCachedDocument();
if (doc != null) return doc.getCharsSequence();
return ((LightVirtualFile)virtualFile).getContent();
}
final Document document = getDocument();
if (document == null) {
return LoadTextUtil.loadText(virtualFile);
}
else {
return document.getCharsSequence();
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:SingleRootFileViewProvider.java
示例17: showMergeDialog
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
private static ApplyPatchStatus showMergeDialog(Project project,
VirtualFile file,
CharSequence content,
final String patchedContent,
final PatchMergeRequestFactory mergeRequestFactory,
boolean reverse,
@Nullable String leftPanelTitle, @Nullable String rightPanelTitle) {
final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document document = fileDocumentManager.getDocument(file);
if (document != null) {
fileDocumentManager.saveDocument(document);
}
CharSequence fileContent = LoadTextUtil.loadText(file);
if (fileContent == null || content == null) {
return ApplyPatchStatus.FAILURE;
}
final MergeRequest request = mergeRequestFactory.createMergeRequest(fileContent.toString(), patchedContent, content.toString(), file,
project, reverse, leftPanelTitle, rightPanelTitle);
DiffManager.getInstance().getDiffTool().show(request);
if (request.getResult() == DialogWrapper.OK_EXIT_CODE) {
return ApplyPatchStatus.SUCCESS;
}
request.restoreOriginalContent();
return ApplyPatchStatus.FAILURE;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:ApplyPatchAction.java
示例18: 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;
if (file.getViewProvider().getBaseLanguage() != file.getLanguage()) return null;
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) return null;
if (virtualFile.getFileSystem() != LocalFileSystem.getInstance()
// tests
&& virtualFile.getFileSystem() != TempFileSystem.getInstance()) return null;
String text = file.getText();
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, text, virtualFile, charset, descriptors);
if (ok) {
checkIfCharactersWillBeLostAfterSave(file, manager, isOnTheFly, text, charset, descriptors);
}
return descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:LossyEncodingInspection.java
示例19: recalculateFileOffset
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
private int recalculateFileOffset(@NotNull PsiFile file, @NotNull PsiElement position, Editor editor) {
int offset = position.getTextOffset();;
VirtualFile virtualFile = file.getVirtualFile();
if (null == virtualFile) { // In memory file, the position doesn't change.
return offset;
}
// Get the separator, checking the file if we don't know yet. May still return null.
String separator = LoadTextUtil.detectLineSeparator(virtualFile, true);
// IntelliJ IDEA normalizes file line endings, so if file line endings is
// CRLF - then we have to shift an offset so Haxe compiler could get proper offset
if (LineSeparator.CRLF.getSeparatorString().equals(separator)) {
int lineNumber =
com.intellij.openapi.util.text.StringUtil.offsetToLineNumber(editor.getDocument().getText(), offset);
offset += lineNumber;
}
return offset;
}
开发者ID:HaxeFoundation,项目名称:intellij-haxe,代码行数:21,代码来源:HaxeCompilerServices.java
示例20: doTest
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入依赖的package包/类
protected void doTest(boolean checkResult) {
String name = getTestName(false);
try {
String text = loadFile(name + "." + myExtension);
myFile = createPsiFile(name, text);
ensureParsed(myFile);
FileViewProvider viewProvider = myFile.getViewProvider();
VirtualFile virtualFile = viewProvider.getVirtualFile();
if (virtualFile instanceof LightVirtualFile) {
assertEquals("light virtual file text mismatch", text, ((LightVirtualFile)virtualFile).getContent());
}
assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(virtualFile));
assertEquals("doc text mismatch", text, viewProvider.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);
}
}
开发者ID:consulo,项目名称:consulo,代码行数:26,代码来源:ParsingTestCase.java
注:本文中的com.intellij.openapi.fileEditor.impl.LoadTextUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论