本文整理汇总了Java中com.intellij.openapi.vfs.CharsetToolkit.forName方法的典型用法代码示例。如果您正苦于以下问题:Java CharsetToolkit.forName方法的具体用法?Java CharsetToolkit.forName怎么用?Java CharsetToolkit.forName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.vfs.CharsetToolkit
的用法示例。
在下文中一共展示了CharsetToolkit.forName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testText
import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
public void testText() throws Exception {
doTest("Text.txt");
Charset ascii = CharsetToolkit.forName("US-ASCII");
VirtualFile myVFile = myFile.getVirtualFile();
FileDocumentManager.getInstance().saveAllDocuments();
EncodingManager.getInstance().setEncoding(myVFile, ascii);
UIUtil.dispatchAllInvocationEvents(); // wait for reload requests to bubble up
assertEquals(ascii, myVFile.getCharset());
int start = myEditor.getCaretModel().getOffset();
type((char)0x445);
type((char)0x438);
int end = myEditor.getCaretModel().getOffset();
Collection<HighlightInfo> infos = doHighlighting();
HighlightInfo info = assertOneElement(infos);
assertEquals("Unsupported characters for the charset 'US-ASCII'", info.getDescription());
assertEquals(start, info.startOffset);
assertEquals(end, info.endOffset);
backspace();
backspace();
doDoTest(true, false);
}
示例2: detectCharset
import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
@NotNull
public static Charset detectCharset(@NotNull VirtualFile virtualFile, @NotNull byte[] content, @NotNull FileType fileType) {
Charset charset = null;
Trinity<Charset,CharsetToolkit.GuessedEncoding, byte[]> guessed = guessFromContent(virtualFile, content, content.length);
if (guessed != null && guessed.first != null) {
charset = guessed.first;
}
else {
String charsetName = fileType.getCharset(virtualFile, content);
if (charsetName == null) {
Charset specifiedExplicitly = EncodingRegistry.getInstance().getEncoding(virtualFile, true);
if (specifiedExplicitly != null) {
charset = specifiedExplicitly;
}
}
else {
charset = CharsetToolkit.forName(charsetName);
}
}
if (charset == null) {
charset = EncodingRegistry.getInstance().getDefaultCharset();
}
if (fileType.getName().equals("Properties") && EncodingRegistry.getInstance().isNative2Ascii(virtualFile)) {
charset = Native2AsciiCharset.wrap(charset);
}
virtualFile.setCharset(charset);
return charset;
}
示例3: resolve
import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
@Override
@Nullable
public PsiElement resolve() {
return CharsetToolkit.forName(myCharsetName) == null ? null : myElement;
//if (ApplicationManager.getApplication().isUnitTestMode()) return myValue; // tests do not have full JDK
//String fqn = charset.getClass().getName();
//return myValue.getManager().findClass(fqn, GlobalSearchScope.allScope(myValue.getProject()));
}
示例4: extractCharsetFromFileContent
import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
@Override
public Charset extractCharsetFromFileContent(@Nullable final Project project, @Nullable final VirtualFile file, @NotNull final CharSequence content) {
String name = XmlCharsetDetector.extractXmlEncodingFromProlog(content);
Charset charset = CharsetToolkit.forName(name);
if (charset != null) {
return charset;
}
return HtmlUtil.detectCharsetFromMetaTag(content);
}
示例5: testUnnecessaryUnicodeEscape
import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
public void testUnnecessaryUnicodeEscape() {
myFixture.configureByFile(getTestName(false) + ".java");
final VirtualFile vFile = myFixture.getFile().getVirtualFile();
Charset ascii = CharsetToolkit.forName("US-ASCII");
EncodingManager.getInstance().setEncoding(vFile, ascii);
UIUtil.dispatchAllInvocationEvents(); // reload in invokeLater
assertEquals(ascii, vFile.getCharset());
myFixture.testHighlighting(true, false, false);
}
示例6: extractCharsetFromFileContent
import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
@Override
public Charset extractCharsetFromFileContent(final Project project, @Nullable final VirtualFile file, @NotNull final CharSequence content) {
String name = XmlCharsetDetector.extractXmlEncodingFromProlog(content);
Charset charset = CharsetToolkit.forName(name);
return charset == null ? CharsetToolkit.UTF8_CHARSET : charset;
}