Java Code Examples for com.intellij.openapi.util.io.FileUtilRt#getExtension()

The following examples show how to use com.intellij.openapi.util.io.FileUtilRt#getExtension() . 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: BlazeLanguageKindCalculatorHelper.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public OCLanguageKind getLanguageByExtension(Project project, String name) {
  if (Blaze.isBlazeProject(project)) {
    String extension = FileUtilRt.getExtension(name);
    if (CFileExtensions.C_FILE_EXTENSIONS.contains(extension)) {
      return CLanguageKind.C;
    }
    if (CFileExtensions.CXX_FILE_EXTENSIONS.contains(extension)) {
      return CLanguageKind.CPP;
    }
    if (CFileExtensions.CXX_ONLY_HEADER_EXTENSIONS.contains(extension)) {
      return CLanguageKind.CPP;
    }
  }
  return null;
}
 
Example 2
Source File: FilePathCompletionContributor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean filenameMatchesPrefixOrType(final String fileName,
                                                   final String prefix,
                                                   final FileType[] suitableFileTypes,
                                                   final int invocationCount) {
  final boolean prefixMatched = prefix.length() == 0 || StringUtil.startsWithIgnoreCase(fileName, prefix);
  if (prefixMatched && (suitableFileTypes.length == 0 || invocationCount > 2)) return true;

  if (prefixMatched) {
    final String extension = FileUtilRt.getExtension(fileName);
    if (extension.length() == 0) return false;

    for (final FileType fileType : suitableFileTypes) {
      for (final FileNameMatcher matcher : FileTypeManager.getInstance().getAssociations(fileType)) {
        if (matcher.accept(fileName)) return true;
      }
    }
  }

  return false;
}
 
Example 3
Source File: ArtifactEditorImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void updateOutputPath(@Nonnull String oldArtifactName, @Nonnull final String newArtifactName) {
  final String oldDefaultPath = ArtifactUtil.getDefaultArtifactOutputPath(oldArtifactName, myProject);
  if (Comparing.equal(oldDefaultPath, getConfiguredOutputPath())) {
    setOutputPath(ArtifactUtil.getDefaultArtifactOutputPath(newArtifactName, myProject));
    final CompositePackagingElement<?> root = getRootElement();
    if (root instanceof ArchivePackagingElement) {
      String oldFileName = ArtifactUtil.suggestArtifactFileName(oldArtifactName);
      final String name = ((ArchivePackagingElement)root).getArchiveFileName();
      final String fileName = FileUtil.getNameWithoutExtension(name);
      final String extension = FileUtilRt.getExtension(name);
      if (fileName.equals(oldFileName) && extension.length() > 0) {
        myLayoutTreeComponent.editLayout(new Runnable() {
          @Override
          public void run() {
            ((ArchivePackagingElement)getRootElement()).setArchiveFileName(ArtifactUtil.suggestArtifactFileName(newArtifactName) + "." + extension);
          }
        });
        myLayoutTreeComponent.updateRootNode();
      }
    }
  }
}
 
Example 4
Source File: PsiViewerDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void updateExtensionsCombo() {
  final Object source = getSource();
  if (source instanceof LanguageFileType) {
    final List<String> extensions = getAllExtensions((LanguageFileType)source);
    if (extensions.size() > 1) {
      final ExtensionComparator comp = new ExtensionComparator(extensions.get(0));
      Collections.sort(extensions, comp);
      final SortedComboBoxModel<String> model = new SortedComboBoxModel<String>(comp);
      model.setAll(extensions);
      myExtensionComboBox.setModel(model);
      myExtensionComboBox.setVisible(true);
      myExtensionLabel.setVisible(true);
      String fileExt = myCurrentFile != null ? FileUtilRt.getExtension(myCurrentFile.getName()) : "";
      if (fileExt.length() > 0 && extensions.contains(fileExt)) {
        myExtensionComboBox.setSelectedItem(fileExt);
        return;
      }
      myExtensionComboBox.setSelectedIndex(0);
      return;
    }
  }
  myExtensionComboBox.setVisible(false);
  myExtensionLabel.setVisible(false);
}
 
Example 5
Source File: BlazeConfigurationResolver.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static boolean containsCompiledSources(TargetIdeInfo target) {
  Predicate<ArtifactLocation> isCompiled =
      location -> {
        String locationExtension = FileUtilRt.getExtension(location.getRelativePath());
        return CFileExtensions.SOURCE_EXTENSIONS.contains(locationExtension);
      };
  return target.getcIdeInfo() != null
      && target.getcIdeInfo().getSources().stream()
          .filter(ArtifactLocation::isSource)
          .anyMatch(isCompiled);
}
 
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: Restarter.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static File createTempExecutable(File executable) throws IOException {
  String ext = FileUtilRt.getExtension(executable.getName());
  File copy = FileUtilRt.createTempFile(FileUtilRt.getNameWithoutExtension(executable.getName()), StringUtil.isEmptyOrSpaces(ext) ? ".tmp" : ("." + ext), false);
  FileUtilRt.copy(executable, copy);
  if (!copy.setExecutable(executable.canExecute())) throw new IOException("Cannot make file executable: " + copy);
  return copy;
}
 
Example 8
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 9
Source File: NewBashFileAction.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
static String computeFilename(String inputFilename) {
    String usedExtension = FileUtilRt.getExtension(inputFilename);
    boolean withExtension = !usedExtension.isEmpty();

    return withExtension ? inputFilename : (inputFilename + "." + SH_EXTENSION);
}
 
Example 10
Source File: LightFileTypeRegistry.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public FileType getFileTypeByFileName(@Nonnull @NonNls String fileName) {
  final String extension = FileUtilRt.getExtension(fileName);
  return getFileTypeByExtension(extension);
}
 
Example 11
Source File: LightFileTypeRegistry.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public FileType getFileTypeByFileName(@Nonnull @NonNls CharSequence fileName) {
  final String extension = FileUtilRt.getExtension(fileName.toString());
  return getFileTypeByExtension(extension);
}
 
Example 12
Source File: FileTypeManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public String getExtension(@Nonnull String fileName) {
  return FileUtilRt.getExtension(fileName);
}
 
Example 13
Source File: CoreFileTypeRegistry.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public FileType getFileTypeByFileName(@Nonnull @NonNls String fileName) {
  final String extension = FileUtilRt.getExtension(fileName);
  return getFileTypeByExtension(extension);
}
 
Example 14
Source File: CoreFileTypeRegistry.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public FileType getFileTypeByFileName(@Nonnull @NonNls CharSequence fileName) {
  final String extension = FileUtilRt.getExtension(fileName.toString());
  return getFileTypeByExtension(extension);
}