当前位置: 首页>>代码示例>>Java>>正文


Java CharsetToolkit.forName方法代码示例

本文整理汇总了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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:LossyEncodingTest.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:LoadTextUtil.java

示例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()));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:EncodingReference.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:HtmlFileType.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:UnnecessaryUnicodeEscapeInspectionTest.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:XmlLikeFileType.java


注:本文中的com.intellij.openapi.vfs.CharsetToolkit.forName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。