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

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

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

FileUtil.getNameWithoutExtension介绍

暂无

代码示例

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

@NotNull
public static String getBinaryFileNameForPath(@NotNull String path) {
 String resultBinaryName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(path));
 return SystemInfo.isWindows ? resultBinaryName + ".exe" : resultBinaryName;
}

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

@NotNull
public static String getBinaryFileNameForPath(@NotNull String path) {
  String resultBinaryName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(path));
  return SystemInfo.isWindows ? resultBinaryName + ".bat" : resultBinaryName;
}

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

public boolean matchFileName(@NotNull String fileName) {
 String name = StringUtil.substringAfter(fileName, "_");
 if (StringUtil.isEmpty(name)) {
  return true;
 }
 name = StringUtil.trimEnd(FileUtil.getNameWithoutExtension(name), GoConstants.TEST_SUFFIX);
 List<String> parts = StringUtil.split(name, "_");
 int n = parts.size();
 if (n >= 2 && GoConstants.KNOWN_OS.contains(parts.get(n - 2)) && GoConstants.KNOWN_ARCH.contains(parts.get(n - 1))) {
  if (!myTarget.arch.equals(parts.get(n - 1))) {
   return false;
  }
  return matchOS(parts.get(n - 2));
 }
 if (n >= 1) {
  if (GoConstants.KNOWN_OS.contains(parts.get(n - 1))) {
   return matchOS(parts.get(n - 1));
  }
  if (GoConstants.KNOWN_ARCH.contains(parts.get(n - 1))) {
   return myTarget.arch.equals(parts.get(n - 1));
  }
 }
 return true;
}

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

@NotNull
@Override
public Collection<PsiElement> findTestsForClass(@NotNull PsiElement element) {
 PsiFile file = InjectedLanguageUtil.getTopLevelFile(element);
 if (file instanceof GoFile) {
  PsiDirectory directory = file.getContainingDirectory();
  PsiFile testFile = directory.findFile(FileUtil.getNameWithoutExtension(file.getName()) + GoConstants.TEST_SUFFIX_WITH_EXTENSION);
  if (testFile != null) {
   return ContainerUtil.newSmartList(testFile);
  }
 }
 return Collections.emptyList();
}

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

@NotNull
 @Override
 protected GoRunFileRunningState newRunningState(@NotNull ExecutionEnvironment env, @NotNull Module module) {
  String path = getFilePath();
  if (!"go".equals(PathUtil.getFileExtension(path))) {
   VirtualFile f = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
   if (f != null && f.getFileType() == ScratchFileType.INSTANCE) {
    String suffixWithoutExt = "." + UUID.randomUUID().toString().substring(0, 4);
    String suffix = suffixWithoutExt + ".go";
    String before = f.getName();
    String beforeWithoutExt = FileUtil.getNameWithoutExtension(before);
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
     @Override
     public void run() {
      try {
       f.rename(this, before + suffix);
      }
      catch (IOException ignored) {
      }
     }
    });
    setFilePath(path + suffix);
    setName(getName().replace(beforeWithoutExt, beforeWithoutExt + suffixWithoutExt));
   }
  } 
  return new GoRunFileRunningState(env, module, this);
 }
}

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

static String getGrammarName(BnfFile bnfFile) {
 String parser = bnfFile.findAttributeValue(null, KnownAttribute.PARSER_CLASS, null);
 if (!KnownAttribute.PARSER_CLASS.getDefaultValue().equals(parser)) {
  String shortName = StringUtil.getShortName(parser);
  int len = "Parser".length();
  String result = shortName.endsWith("Parser") ? shortName.substring(0, shortName.length() - len) : shortName;
  if (StringUtil.isNotEmpty(result)) return result;
 }
 return StringUtil.capitalize(FileUtil.getNameWithoutExtension(bnfFile.getName()));
}

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

@Override
 protected PrintWriter openOutputInner(File file) throws IOException {
  String grammarName = FileUtil.getNameWithoutExtension(myFile.getName());
  String fileName = FileUtil.getNameWithoutExtension(file);
  String name = grammarName + (fileName.startsWith(grammarName) || fileName.endsWith("Parser") ? "" : ".PSI") + ".java";
  File targetFile = new File(FileUtilRt.getTempDirectory(), name);
  targetFile.getParentFile().mkdirs();
  FileOutputStream outputStream = new FileOutputStream(targetFile, true);
  PrintWriter out = new PrintWriter(new OutputStreamWriter(outputStream, CharsetToolkit.UTF8));
  out.println("// ---- " + file.getName() + " -----------------");
  return out;
 }
};

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

private void doRename(String... sourceFiles) {
    myFixture.setTestDataPath(getTestDataPath() + getTestName(true));

    List<String> filenames = Lists.newArrayList(sourceFiles);
    myFixture.configureByFiles(filenames.toArray(new String[filenames.size()]));

    myFixture.renameElementAtCaret("a_renamed");

    for (String filename : filenames) {
      myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);
    }
  }
}

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

private void doMove(String[] checkedFiles, String movedFileSource, String moveTargetDir) {
  myFixture.setTestDataPath(getTestDataPath() + getTestName(true));
  Set<String> filenames = Sets.newHashSet(checkedFiles);
  filenames.add(movedFileSource);
  myFixture.configureByFiles(filenames.toArray(new String[filenames.size()]));
  VirtualFile sourceVirtualFile = myFixture.findFileInTempDir(movedFileSource);
  Assert.assertNotNull(sourceVirtualFile);
  PsiFile sourceFile = myFixture.getPsiManager().findFile(sourceVirtualFile);
  moveFile(moveTargetDir, sourceFile);
  for (String filename : checkedFiles) {
    myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);
  }
  myFixture.checkResultByFile(moveTargetDir + "/" + movedFileSource, moveTargetDir + "/" + FileUtil.getNameWithoutExtension(movedFileSource) + "_after." + FileUtilRt.getExtension(movedFileSource), false);
}

代码示例来源: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: BashSupport/BashSupport

myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);

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

myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);

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

myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);

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

private void doRename(Runnable renameLogic, String newName, String... sourceFiles) {
    myFixture.setTestDataPath(getTestDataPath() + getTestName(true));
    myFixture.configureByFiles(sourceFiles);

    renameLogic.run();

    for (String filename : sourceFiles) {
      myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);
    }

    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    Assert.assertNotNull("caret element is null", psiElement);

    while (psiElement.getReference() == null) {
      if (psiElement.getParent() == null) {
        break;
      }

      psiElement = psiElement.getParent();
    }

    PsiReference psiReference = psiElement.getReference();
    Assert.assertNotNull("target file reference wasn't found", psiReference);
    Assert.assertTrue("Renamed reference wasn't found in the canonical text: " + psiReference.getCanonicalText(), psiReference.getCanonicalText().contains(newName));

    PsiElement targetMarker = psiReference.resolve();
    Assert.assertNotNull("target file resolve result wasn't found", targetMarker);
    Assert.assertTrue("target is not a psi file", targetMarker instanceof BashHereDocMarker);
  }
}

相关文章