Java Code Examples for com.intellij.openapi.util.io.FileUtil#getNameWithoutExtension()

The following examples show how to use com.intellij.openapi.util.io.FileUtil#getNameWithoutExtension() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TargetNameHeuristic.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matchesSource(
    Project project,
    TargetInfo target,
    @Nullable PsiFile sourcePsiFile,
    File sourceFile,
    @Nullable TestSize testSize) {
  String filePathWithoutExtension = FileUtil.getNameWithoutExtension(sourceFile.getPath());
  String targetName = target.label.targetName().toString();
  if (!filePathWithoutExtension.endsWith(targetName)) {
    return false;
  }
  int i = filePathWithoutExtension.length() - targetName.length() - 1;
  if (i < 0) {
    // Equal length
    return true;
  }
  return filePathWithoutExtension.charAt(i) == '/';
}
 
Example 2
Source File: SwitchToHeaderOrSourceSearch.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private static OCFile correlateTestToHeader(OCFile file) {
  // Quickly check foo_test.cc -> foo.h as well. "getAssociatedFileWithSameName" only does
  // foo.cc <-> foo.h. However, if you do goto-related-symbol again, it will go from
  // foo.h -> foo.cc instead of back to foo_test.cc.
  PsiManager psiManager = PsiManager.getInstance(file.getProject());
  String pathWithoutExtension = FileUtil.getNameWithoutExtension(file.getVirtualFile().getPath());
  for (String testSuffix : PartnerFilePatterns.DEFAULT_PARTNER_SUFFIXES) {
    if (pathWithoutExtension.endsWith(testSuffix)) {
      String possibleHeaderName = StringUtil.trimEnd(pathWithoutExtension, testSuffix) + ".h";
      VirtualFile virtualFile = VfsUtil.findFileByIoFile(new File(possibleHeaderName), false);
      if (virtualFile != null) {
        PsiFile psiFile = psiManager.findFile(virtualFile);
        if (psiFile instanceof OCFile) {
          return (OCFile) psiFile;
        }
      }
    }
  }
  return null;
}
 
Example 3
Source File: PyBinaryContextProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private static TargetInfo getTargetLabel(PsiFile psiFile) {
  VirtualFile vf = psiFile.getVirtualFile();
  if (vf == null) {
    return null;
  }
  BlazeProjectData projectData =
      BlazeProjectDataManager.getInstance(psiFile.getProject()).getBlazeProjectData();
  if (projectData == null) {
    return null;
  }
  File file = new File(vf.getPath());
  String fileName = FileUtil.getNameWithoutExtension(file);
  return SourceToTargetFinder.findTargetsForSourceFile(
          psiFile.getProject(), file, Optional.of(RuleType.BINARY))
      .stream()
      .filter(t -> acceptTarget(fileName, t))
      .findFirst()
      .orElse(null);
}
 
Example 4
Source File: CoverageDataManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void removeCoverageSuite(final CoverageSuite suite) {
  final String fileName = suite.getCoverageDataFileName();

  boolean deleteTraces = suite.isTracingEnabled();
  if (!FileUtil.isAncestor(ContainerPathManager.get().getSystemPath(), fileName, false)) {
    String message = "Would you like to delete file \'" + fileName + "\' ";
    if (deleteTraces) {
      message += "and traces directory \'" + FileUtil.getNameWithoutExtension(new File(fileName)) + "\' ";
    }
    message += "on disk?";
    if (Messages.showYesNoDialog(myProject, message, CommonBundle.getWarningTitle(), Messages.getWarningIcon()) == Messages.YES) {
      deleteCachedCoverage(fileName, deleteTraces);
    }
  }
  else {
    deleteCachedCoverage(fileName, deleteTraces);
  }

  myCoverageSuites.remove(suite);
  if (myCurrentSuitesBundle != null && myCurrentSuitesBundle.contains(suite)) {
    CoverageSuite[] suites = myCurrentSuitesBundle.getSuites();
    suites = ArrayUtil.remove(suites, suite);
    chooseSuitesBundle(suites.length > 0 ? new CoverageSuitesBundle(suites) : null);
  }
}
 
Example 5
Source File: ShowCoveringTestsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
private static File[] getTraceFiles(Project project) {
  final CoverageSuitesBundle currentSuite = CoverageDataManager.getInstance(project).getCurrentSuitesBundle();
  if (currentSuite == null) return null;
  final List<File> files = new ArrayList<File>();
  for (CoverageSuite coverageSuite : currentSuite.getSuites()) {

    final String filePath = coverageSuite.getCoverageDataFileName();
    final String dirName = FileUtil.getNameWithoutExtension(new File(filePath).getName());

    final File parentDir = new File(filePath).getParentFile();
    final File tracesDir = new File(parentDir, dirName);
    final File[] suiteFiles = tracesDir.listFiles();
    if (suiteFiles != null) {
      Collections.addAll(files, suiteFiles);
    }
  }

  return files.isEmpty() ? null : files.toArray(new File[files.size()]);
}
 
Example 6
Source File: CodeInsightTestUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void doActionTest(AnAction action, String file, CodeInsightTestFixture fixture) {
  String extension = FileUtilRt.getExtension(file);
  String name = FileUtil.getNameWithoutExtension(file);
  fixture.configureByFile(file);
  fixture.testAction(action);
  fixture.checkResultByFile(name + "_after." + extension);
}
 
Example 7
Source File: JavascriptTestContextProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static String getTestFilter(PsiFile file) {
  Project project = file.getProject();
  WorkspaceRoot root = WorkspaceRoot.fromProject(project);
  WorkspacePath path = root.workspacePathFor(file.getVirtualFile());
  return '^'
      + root.directory().getName()
      + '/'
      + FileUtil.getNameWithoutExtension(path.relativePath())
      + '$';
}
 
Example 8
Source File: HaxeFile.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public PsiElement setName(@NotNull String newName) throws IncorrectOperationException {
  final String oldName = FileUtil.getNameWithoutExtension(getName());
  final PsiElement result = super.setName(newName);
  final HaxeClass haxeClass = HaxeResolveUtil.findComponentDeclaration(this, oldName);
  if (haxeClass != null) {
    haxeClass.setName(FileUtil.getNameWithoutExtension(newName));
  }
  return result;
}
 
Example 9
Source File: ImageLoader.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static ImageDescList create(@Nonnull String path, @Nullable Class cls, boolean dark, boolean allowFloatScaling, JBUI.ScaleContext ctx) {
  // Prefer retina images for HiDPI scale, because downscaling
  // retina images provides a better result than up-scaling non-retina images.
  boolean retina = JBUI.isHiDPI(ctx.getScale(PIX_SCALE));

  Builder list = new Builder(FileUtil.getNameWithoutExtension(path), FileUtilRt.getExtension(path), cls, true, adjustScaleFactor(allowFloatScaling, ctx.getScale(PIX_SCALE)));

  if (path.contains("://") && !path.startsWith("file:")) {
    list.add(StringUtil.endsWithIgnoreCase(path, ".svg") ? SVG : IMG);
  }
  else if (retina && dark) {
    list.add(true, true);
    list.add(true, false); // fallback to non-dark
  }
  else if (dark) {
    list.add(false, true);
    list.add(false, false); // fallback to non-dark
  }
  else if (retina) {
    list.add(true, false);
  }
  else {
    list.add(false, false);
  }

  return list.build();
}
 
Example 10
Source File: HaxeIconProvider.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Icon getHaxeFileIcon(HaxeFile file, @Iconable.IconFlags int flags) {
  final String fileName = FileUtil.getNameWithoutExtension(file.getName());
  for (HaxeComponent component : HaxeResolveUtil.findComponentDeclarations(file)) {
    if (fileName.equals(component.getName())) {
      return component.getIcon(flags);
    }
  }
  return null;
}
 
Example 11
Source File: ImportTestsFromHistoryAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String getPresentableText(Project project, String name) {
  String nameWithoutExtension = FileUtil.getNameWithoutExtension(name);
  final int lastIndexOf = nameWithoutExtension.lastIndexOf(" - ");
  if (lastIndexOf > 0) {
    final String date = nameWithoutExtension.substring(lastIndexOf + 3);
    try {
      final Date creationDate = new SimpleDateFormat(SMTestRunnerResultsForm.HISTORY_DATE_FORMAT).parse(date);
      final String configurationName = TestHistoryConfiguration.getInstance(project).getConfigurationName(name);
      return (configurationName != null ? configurationName : nameWithoutExtension.substring(0, lastIndexOf)) +
             " (" + DateFormatUtil.formatDateTime(creationDate) + ")";
    }
    catch (ParseException ignore) {}
  }
  return nameWithoutExtension;
}
 
Example 12
Source File: InspectionProfileLoadUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static String getProfileName(@Nonnull File file, @Nonnull Element element) {
  String name = getRootElementAttribute(PROFILE_NAME_TAG, element);
  return name != null ? name : FileUtil.getNameWithoutExtension(file);
}
 
Example 13
Source File: UnpackedAars.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static String cacheKeyInternal(String key) {
  String name = FileUtil.getNameWithoutExtension(PathUtil.getFileName(key));
  return name + "_" + Integer.toHexString(key.hashCode());
}
 
Example 14
Source File: AnalysisScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static String pathToName(@Nonnull String path) {
  File file = new File(path);
  return FileUtil.getNameWithoutExtension(file);
}
 
Example 15
Source File: CoverageDataManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private File getTracesDirectory(final String fileName) {
  return new File(new File(fileName).getParentFile(), FileUtil.getNameWithoutExtension(new File(fileName)));
}
 
Example 16
Source File: LibraryTypeServiceImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static String suggestLibraryName(@Nonnull VirtualFile[] classesRoots) {
  if (classesRoots.length >= 1) {
    return FileUtil.getNameWithoutExtension(PathUtil.getFileName(classesRoots[0].getPath()));
  }
  return DEFAULT_LIBRARY_NAME;
}
 
Example 17
Source File: HaxeFileModel.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@NotNull
public String getName() {
  return FileUtil.getNameWithoutExtension(file.getName());
}
 
Example 18
Source File: CSharpMsilFileRepresentationProvider.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public String getRepresentFileName(@Nonnull MsilFile msilFile)
{
	return FileUtil.getNameWithoutExtension(msilFile.getName()) + CSharpFileType.DOT_EXTENSION;
}
 
Example 19
Source File: JarCache.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static String cacheKeyInternal(BlazeArtifact output) {
  String key = artifactKey(output);
  String name = FileUtil.getNameWithoutExtension(PathUtil.getFileName(key));
  return name + "_" + Integer.toHexString(key.hashCode());
}
 
Example 20
Source File: LibraryTypeServiceImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static String suggestLibraryName(@Nonnull List<OrderRoot> roots) {
  if (roots.size() >= 1) {
    return FileUtil.getNameWithoutExtension(PathUtil.getFileName(roots.get(0).getFile().getPath()));
  }
  return DEFAULT_LIBRARY_NAME;
}