com.intellij.openapi.util.io.FileUtil.loadFile()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中com.intellij.openapi.util.io.FileUtil.loadFile()方法的一些代码示例,展示了FileUtil.loadFile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.loadFile()方法的具体详情如下:
包路径:com.intellij.openapi.util.io.FileUtil
类名称:FileUtil
方法名:loadFile

FileUtil.loadFile介绍

暂无

代码示例

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

private void doTest() {
 try {
  String text = FileUtil.loadFile(new File("./" + PATH + "/" + getTestName(true) + ".go"), CharsetToolkit.UTF8);
  String actual = printTokens(StringUtil.convertLineSeparators(text.trim()), 0);
  assertSameLinesWithFile(new File(PATH + "/" + getTestName(true) + ".txt").getAbsolutePath(), actual);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

private void doTest() {
 try {
  String text = FileUtil.loadFile(new File("./" + PATH + "/" + getTestName(true) + ".s"));
  String actual = printTokens(StringUtil.convertLineSeparators(text.trim()), 0);
  assertSameLinesWithFile(new File(PATH + "/" + getTestName(true) + ".txt").getAbsolutePath(), actual);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: ballerina-platform/ballerina-lang

private void doTestFile(@NotNull File sourceFile) {
  try {
    String text = FileUtil.loadFile(sourceFile, CharsetToolkit.UTF8);
    String actual = printTokens(StringUtil.convertLineSeparators(text.trim()), 0);
    String relativePath = sourceFile.getPath().replace(getTestDataDirectoryPath(), EMPTY_STRING);
    String pathname = (getExpectedResultDirectoryPath() + relativePath).replace(".bal", "") + ".txt";
    File expectedResultFile = new File(pathname);
    assertSameLinesWithFile(expectedResultFile.getAbsolutePath(), actual);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: ballerina-platform/ballerina-lang

private void doOverwrite(File resource) {
  try {
    String text = FileUtil.loadFile(resource, CharsetToolkit.UTF8);
    String relativePath = resource.getPath().replace(getTestDataDirectoryPath(), EMPTY_STRING);
    String actual = printTokens(StringUtil.convertLineSeparators(text.trim()), 0);
    String pathname = (getExpectedResultDirectoryPath() + relativePath).replace(".bal", "") + ".txt";
    File expectedResultFile = new File(pathname);
    VfsTestUtil.overwriteTestData(expectedResultFile.toString(), actual);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

private void doTest(boolean checkErrors) throws IOException {
 String fileName = getTestName(true) + ".go";
 String text = FileUtil.loadFile(new File(getTestDataPath(), fileName));
 PsiFile file = myFixture.addFileToProject(fileName, text);
 String s = buildStubTreeText(getProject(), file.getVirtualFile(), text, checkErrors);
 ParsingTestCase.doCheckResult(getTestDataPath(), getTestName(true) + ".txt", s);
}

代码示例来源:origin: KronicDeth/intellij-elixir

private void assertParsed(File absoluteFile, Parse parse) {
    // inlines part of com.intellij.testFramework.ParsingTestCase#doTest(boolean)
    try {
      String text = FileUtil.loadFile(absoluteFile, CharsetToolkit.UTF8, true).trim();

      String nameWithoutExtension = FileUtilRt.getNameWithoutExtension(absoluteFile.toString());
      myFile = createPsiFile(nameWithoutExtension, text);
      ensureParsed(myFile);
      toParseTreeText(myFile, skipSpaces(), includeRanges());
    } catch (IOException ioException) {
      throw new RuntimeException(ioException);
    }

    switch (parse) {
      case CORRECT:
        assertWithoutLocalError();
        assertQuotedCorrectly();
        break;
      case ERROR:
        assertWithLocalError();
        Quoter.assertError(myFile);
    }
  }
}

代码示例来源:origin: JetBrains/Grammar-Kit

@Nullable
public static PsiFile parseFile(@NotNull File file, @NotNull ParserDefinition parserDefinition) throws IOException {
 String name = file.getName();
 String text = FileUtil.loadFile(file);
 return parseFile(name, text, parserDefinition);
}

代码示例来源:origin: JetBrains/Grammar-Kit

private String getStringOrFile(String classHeader) {
 try {
  File file = new File(mySourcePath, classHeader);
  if (file.exists()) return FileUtil.loadFile(file);
 }
 catch (IOException ex) {
  LOG.error(ex);
 }
 return classHeader.startsWith("//") || classHeader.startsWith("/*")? classHeader :
     StringUtil.countNewLines(classHeader) > 0 ? "/*\n" + classHeader + "\n*/" :
     "// " + classHeader;
}

代码示例来源:origin: Camelcade/Perl5-IDEA

protected String getPerlTidy() {
 try {
  return FileUtil.loadFile(new File("testData", "perlTidy.code"), CharsetToolkit.UTF8, true).trim();
 }
 catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: intellij-dlanguage/intellij-dlanguage

private String doLoadFile(final String myFullDataPath, final String name) throws IOException, URISyntaxException {
  final URI resource;
  try {
    resource = this.getClass().getClassLoader().getResource(String.format("%s/%s", myFullDataPath, name)).toURI();
  } catch (final NullPointerException e) {
    throw new IOException(e);
  }
  String text = FileUtil.loadFile(new File(resource), CharsetToolkit.UTF8).trim();
  text = StringUtil.convertLineSeparators(text);
  return text;
}

代码示例来源:origin: Camelcade/Perl5-IDEA

public void initWithPerlTidy(@NotNull String targetName) {
 try {
  initWithFileContent(targetName, getFileExtension(),
            FileUtil.loadFile(new File("testData", "perlTidy.code"), CharsetToolkit.UTF8, true).trim());
 }
 catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: Camelcade/Perl5-IDEA

protected String loadFile(@NotNull @NonNls @TestDataFile String name) throws IOException {
 String adjustedName = myFileExt.isEmpty() ? name.replace(".", "") : name.replace("." + myFileExt, ".code");
 return FileUtil.loadFile(new File(myFullDataPath, adjustedName), CharsetToolkit.UTF8, true).trim();
}

代码示例来源:origin: BashSupport/BashSupport

@NotNull
public static String loadTestCaseFile(BashTestCase testCase, @TestDataFile String path) throws IOException {
  return FileUtil.loadFile(new File(testCase.getTestDataPath(), path.replace('/', File.separatorChar)), "UTF-8");
}

代码示例来源:origin: Camelcade/Perl5-IDEA

public void initWithFile(String targetFileName, String targetFileExtension, String sourceFileNameWithExtension) throws IOException {
 initWithFileContent(targetFileName, targetFileExtension,
           FileUtil.loadFile(new File(getTestDataPath(), sourceFileNameWithExtension), CharsetToolkit.UTF8, true));
}

代码示例来源:origin: halirutan/Mathematica-IntelliJ-Plugin

PsiReference configure() throws Exception {
 final String fileName = getTestDataPath() + File.pathSeparator + getTestName(false) + ".m";
 return configureByFileText(FileUtil.loadFile(new File(fileName)));
}

代码示例来源:origin: Camelcade/Perl5-IDEA

protected void testFoldingRegions(@NotNull String verificationFileName, boolean doCheckCollapseStatus, LanguageFileType fileType) {
 String expectedContent;
 try {
  expectedContent = FileUtil.loadFile(new File(getTestDataPath() + "/" + verificationFileName + ".code"));
 }
 catch (IOException e) {
  throw new RuntimeException(e);
 }
 Assert.assertNotNull(expectedContent);
 expectedContent = StringUtil.replace(expectedContent, "\r", "");
 final String cleanContent = expectedContent.replaceAll(START_FOLD, "").replaceAll(END_FOLD, "");
 myFixture.configureByText(fileType, cleanContent);
 final String actual = ((CodeInsightTestFixtureImpl)myFixture).getFoldingDescription(doCheckCollapseStatus);
 Assert.assertEquals(expectedContent, actual);
}

代码示例来源:origin: JetBrains/Grammar-Kit

@Override
protected void doTest(String grammarFile) throws IOException {
 File grammarIOFile = new File(myFullDataPath, grammarFile);
 assertNotNull(grammarFile + "not found", grammarIOFile.exists());
 LightVirtualFile grammarVFile = new LightVirtualFile(grammarFile, FileUtil.loadFile(grammarIOFile));
 myLanguage = BnfLanguage.INSTANCE;
 BnfFile grammarPsi = (BnfFile) createFile(grammarVFile);
 myLanguage = LivePreviewHelper.getLanguageFor(grammarPsi);
 try {
  super.doTest(true);
 }
 finally {
  LivePreviewHelper.unregisterLanguageExtensions((LivePreviewLanguage) myLanguage);
 }
}

代码示例来源:origin: JetBrains/Grammar-Kit

public void doGenTest(final boolean generatePsi) throws Exception {
  final String name = getTestName(false);
  String text = loadFile(name + "." + myFileExt);
  myFile = createPsiFile(name, text.replaceAll("generatePsi=[^\n]*", "generatePsi=" + generatePsi));
  List<File> filesToCheck = ContainerUtil.newArrayList();
  filesToCheck.add(new File(FileUtilRt.getTempDirectory(), name + ".java"));
  if (generatePsi) {
   filesToCheck.add(new File(FileUtilRt.getTempDirectory(), name + ".PSI.java"));
  }
  for (File file : filesToCheck) {
   if (file.exists()) {
    assertTrue(file.delete());
   }
  }

  ParserGenerator parserGenerator = newTestGenerator();
  if (generatePsi) parserGenerator.generate();
  else parserGenerator.generateParser();

  for (File file : filesToCheck) {
   assertTrue("Generated file not found: " + file, file.exists());
   final String expectedName = FileUtil.getNameWithoutExtension(file) + ".expected.java";
   String result = FileUtil.loadFile(file, CharsetToolkit.UTF8, true);
   doCheckResult(myFullDataPath, expectedName, result);
  }
 }
}

代码示例来源:origin: cheptsov/AdvancedExpressionFolding

try {
  verificationFile = new File(verificationFileName);
  expectedContent = FileUtil.loadFile(verificationFile);

代码示例来源:origin: intellij-dlanguage/intellij-dlanguage

super.setUp();
for (final File file : getTestDataFiles()) {
  String text = FileUtil.loadFile(file, CharsetToolkit.UTF8);
  text = StringUtil.convertLineSeparators(text);
  final int referencedOffset = text.indexOf("<ref>");

相关文章