Java Code Examples for com.intellij.util.PathUtil#getFileName()

The following examples show how to use com.intellij.util.PathUtil#getFileName() . 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: DirectoryElementType.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public CompositePackagingElement<?> createComposite(CompositePackagingElement<?> parent,
                                                    String baseName,
                                                    @Nonnull ArtifactEditorContext context) {
  final String initialValue = PackagingElementFactoryImpl.suggestFileName(parent, baseName != null ? baseName : "folder", "");
  String path = Messages
    .showInputDialog(context.getProject(), "Enter directory name: ", "New Directory", null, initialValue, new FilePathValidator());
  if (path == null) {
    return null;
  }
  path = FileUtil.toSystemIndependentName(path);
  final String parentPath = PathUtil.getParentPath(path);
  final String fileName = PathUtil.getFileName(path);
  final PackagingElement<?> element = new DirectoryPackagingElement(fileName);
  return (CompositePackagingElement<?>)PackagingElementFactoryImpl.getInstance(context.getProject()).createParentDirectories(parentPath, element);

}
 
Example 2
Source File: FileCopyPresentation.java    From consulo with Apache License 2.0 6 votes vote down vote up
public FileCopyPresentation(String filePath, String outputFileName) {
  myOutputFileName = outputFileName;

  String parentPath;
  myFile = LocalFileSystem.getInstance().findFileByPath(filePath);
  if (myFile != null) {
    final VirtualFile parent = myFile.getParent();
    parentPath = parent != null ? FileUtil.toSystemDependentName(parent.getPath()) : "";
  }
  else {
    parentPath = FileUtil.toSystemDependentName(PathUtil.getParentPath(filePath));
  }

  String sourceFileName = PathUtil.getFileName(filePath);
  if (!sourceFileName.equals(myOutputFileName)) {
    mySourcePath = parentPath + "/" + sourceFileName;
  }
  else {
    mySourcePath = parentPath;
  }
}
 
Example 3
Source File: SmartBashFileReference.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public PsiElement resolveInner() {
    final String referencedName = cmd.getReferencedCommandName();
    if (referencedName == null) {
        return null;
    }

    String fileName = PathUtil.getFileName(referencedName);
    GlobalSearchScope scope = BashSearchScopes.moduleScope(cmd.getContainingFile());

    PsiFileSystemItem[] files = FilenameIndex.getFilesByName(cmd.getProject(), fileName, scope, false);
    if (files.length == 0) {
        return null;
    }

    PsiFile currentFile = cmd.getContainingFile();
    return BashPsiFileUtils.findRelativeFile(currentFile, referencedName);
}
 
Example 4
Source File: RemoteOutputsCache.java    From intellij with Apache License 2.0 6 votes vote down vote up
/**
 * The cache key used to disambiguate output artifacts. This is also the file name in the local
 * cache.
 */
@VisibleForTesting
static String getCacheKey(RemoteOutputArtifact output) {
  String key = output.getKey();
  String fileName = PathUtil.getFileName(key);
  List<String> components = Splitter.on('.').limit(2).splitToList(fileName);
  StringBuilder builder =
      new StringBuilder(components.get(0))
          .append('_')
          .append(Integer.toHexString(key.hashCode()));
  if (components.size() > 1) {
    // file extension(s)
    builder.append('.').append(components.get(1));
  }
  return builder.toString();
}
 
Example 5
Source File: BlazeCidrRunConfigurationRunner.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Basic heuristic for choosing between multiple output files. Currently just looks for a filename
 * matching the target name.
 */
@Nullable
private static File findExecutable(Label target, List<File> outputs) {
  if (outputs.size() == 1) {
    return outputs.get(0);
  }
  String name = PathUtil.getFileName(target.targetName().toString());
  for (File file : outputs) {
    if (file.getName().equals(name)) {
      return file;
    }
  }
  return null;
}
 
Example 6
Source File: PackagingElementFactoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void addFileCopy(@Nonnull CompositePackagingElement<?> root, @Nonnull String outputDirectoryPath, @Nonnull String sourceFilePath, @Nullable String outputFileName) {
  final String fileName = PathUtil.getFileName(sourceFilePath);
  if (outputFileName != null && outputFileName.equals(fileName)) {
    outputFileName = null;
  }
  getOrCreateDirectory(root, outputDirectoryPath).addOrFindChild(createFileCopy(sourceFilePath, outputFileName));
}
 
Example 7
Source File: BlazeGoRunConfigurationRunner.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Basic heuristic for choosing between multiple output files. Currently just looks for a filename
 * matching the target name.
 */
@Nullable
private static File findExecutable(Label target, List<File> outputs) {
  if (outputs.size() == 1) {
    return outputs.get(0);
  }
  String name = PathUtil.getFileName(target.targetName().toString());
  for (File file : outputs) {
    if (file.getName().equals(name)) {
      return file;
    }
  }
  return null;
}
 
Example 8
Source File: BlazePyRunConfigurationRunner.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Basic heuristic for choosing between multiple output files. Currently just looks for a filename
 * matching the target name.
 */
@VisibleForTesting
@Nullable
static File findExecutable(Label target, List<File> outputs) {
  if (outputs.size() == 1) {
    return outputs.get(0);
  }
  String name = PathUtil.getFileName(target.targetName().toString());
  for (File file : outputs) {
    if (file.getName().equals(name)) {
      return file;
    }
  }
  return null;
}
 
Example 9
Source File: WidgetPerfTable.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public final Component getTableCellRendererComponent(JTable table, @Nullable Object value,
                                                     boolean isSelected, boolean hasFocus, int row, int col) {
  final JPanel panel = new JPanel();
  if (value == null) return panel;
  panel.setLayout(new BorderLayout());

  if (value instanceof SlidingWindowStatsSummary) {
    final SlidingWindowStatsSummary stats = (SlidingWindowStatsSummary)value;
    final SimpleTextAttributes attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
    final Location location = stats.getLocation();
    final String path = location.path;
    final String filename = PathUtil.getFileName(path);
    append(filename, attributes);

    final JBLabel label = new JBLabel(filename);
    label.setHorizontalAlignment(SwingConstants.RIGHT);
    panel.add(Box.createHorizontalGlue());
    panel.add(label, BorderLayout.CENTER);

    final JBLabel lineLabel = new JBLabel(":" + location.line);
    panel.add(lineLabel, BorderLayout.EAST);

    if (isSelected) {
      label.setForeground(table.getSelectionForeground());
      lineLabel.setForeground(table.getSelectionForeground());
    }
  }

  clear();
  setPaintFocusBorder(hasFocus && table.getCellSelectionEnabled());
  acquireState(table, isSelected, hasFocus, row, col);
  getCellState().updateRenderer(this);

  if (isSelected) {
    panel.setBackground(table.getSelectionBackground());
  }

  return panel;
}
 
Example 10
Source File: LibraryScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public String getDisplayName() {
  String name = myLibrary.getName();
  if (name == null) {
    String[] urls = myLibrary.getUrls(BinariesOrderRootType.getInstance());
    if (urls.length > 0) {
      name = PathUtil.getFileName(VfsUtilCore.urlToPath(urls[0]));
    }
    else {
      name = "empty";
    }
  }
  return "Library '" + name + "'";
}
 
Example 11
Source File: ObservatoryFile.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private static LightVirtualFile createSnapshot(@NotNull Script script) {
  // LightVirtualFiles have no parent directory, so just use the filename.
  final String filename = PathUtil.getFileName(script.getUri());
  final String scriptSource = script.getSource();
  if (scriptSource == null) {
    return null;
  }

  final LightVirtualFile snapshot = new LightVirtualFile(filename, DartFileType.INSTANCE, scriptSource);
  snapshot.setWritable(false);
  return snapshot;
}
 
Example 12
Source File: ScratchFileServiceImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public VirtualFile findFile(@Nonnull RootType rootType, @Nonnull String pathName, @Nonnull Option option) throws IOException {
  ApplicationManager.getApplication().assertReadAccessAllowed();

  String fullPath = getRootPath(rootType) + "/" + pathName;
  if (option != Option.create_new_always) {
    VirtualFile file = LocalFileSystem.getInstance().findFileByPath(fullPath);
    if (file != null && !file.isDirectory()) return file;
    if (option == Option.existing_only) return null;
  }
  String ext = PathUtil.getFileExtension(pathName);
  String fileNameExt = PathUtil.getFileName(pathName);
  String fileName = StringUtil.trimEnd(fileNameExt, ext == null ? "" : "." + ext);
  AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass());
  try {
    VirtualFile dir = VfsUtil.createDirectories(PathUtil.getParentPath(fullPath));
    if (option == Option.create_new_always) {
      return VfsUtil.createChildSequent(LocalFileSystem.getInstance(), dir, fileName, StringUtil.notNullize(ext));
    }
    else {
      return dir.createChildData(LocalFileSystem.getInstance(), fileNameExt);
    }
  }
  finally {
    token.finish();
  }
}
 
Example 13
Source File: WidgetPerfTable.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public final Component getTableCellRendererComponent(JTable table, @Nullable Object value,
                                                     boolean isSelected, boolean hasFocus, int row, int col) {
  final JPanel panel = new JPanel();
  if (value == null) return panel;
  panel.setLayout(new BorderLayout());

  if (value instanceof SlidingWindowStatsSummary) {
    final SlidingWindowStatsSummary stats = (SlidingWindowStatsSummary)value;
    final SimpleTextAttributes attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
    final Location location = stats.getLocation();
    final String path = location.path;
    final String filename = PathUtil.getFileName(path);
    append(filename, attributes);

    final JBLabel label = new JBLabel(filename);
    label.setHorizontalAlignment(SwingConstants.RIGHT);
    panel.add(Box.createHorizontalGlue());
    panel.add(label, BorderLayout.CENTER);

    final JBLabel lineLabel = new JBLabel(":" + location.line);
    panel.add(lineLabel, BorderLayout.EAST);

    if (isSelected) {
      label.setForeground(table.getSelectionForeground());
      lineLabel.setForeground(table.getSelectionForeground());
    }
  }

  clear();
  setPaintFocusBorder(hasFocus && table.getCellSelectionEnabled());
  acquireState(table, isSelected, hasFocus, row, col);
  getCellState().updateRenderer(this);

  if (isSelected) {
    panel.setBackground(table.getSelectionBackground());
  }

  return panel;
}
 
Example 14
Source File: LibraryUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String getPresentableName(@Nonnull Library library) {
  final String name = library.getName();
  if (name != null) {
    return name;
  }
  if (library instanceof LibraryEx && ((LibraryEx)library).isDisposed()) {
    return "Disposed Library";
  }
  String[] urls = library.getUrls(BinariesOrderRootType.getInstance());
  if (urls.length > 0) {
    return PathUtil.getFileName(VfsUtilCore.urlToPath(urls[0]));
  }
  return "Empty Library";
}
 
Example 15
Source File: DartTestEventsConverterZ.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
String getBaseName() {
  // Virtual test that represents loading or compiling a test suite. See lib/src/runner/loader.dart -> Loader.loadFile() in pkg/test source code
  if (this instanceof Test && getParent() == null) {
    if (myName.startsWith(LOADING_PREFIX)) {
      return LOADING_PREFIX + PathUtil.getFileName(myName.substring(LOADING_PREFIX.length()));
    }
    else if (myName.startsWith(COMPILING_PREFIX)) {
      return COMPILING_PREFIX + PathUtil.getFileName(myName.substring(COMPILING_PREFIX.length()));
    }
    return myName; // can't happen
  }

  // file-level group
  if (this instanceof Group && NO_NAME.equals(myName) && myParent == null && hasSuite()) {
    return PathUtil.getFileName(getSuite().getPath());
  }

  // top-level group in suite
  if (this instanceof Group && myParent != null && myParent.getParent() == null && NO_NAME.equals(myParent.getName())) {
    return myName;
  }

  if (hasValidParent()) {
    final String parentName = getParent().getName();
    if (myName.startsWith(parentName + " ")) {
      return myName.substring(parentName.length() + 1);
    }
  }

  return myName;
}
 
Example 16
Source File: ShelvedBinaryFilePatch.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private static String getFileName(String filePath) {
  return filePath != null ? PathUtil.getFileName(filePath) : null;
}
 
Example 17
Source File: ExtractedDirectoryPresentation.java    From consulo with Apache License 2.0 4 votes vote down vote up
public String getPresentableName() {
  return PathUtil.getFileName(myJarPath) + myPathInJar;
}
 
Example 18
Source File: LocalFilePath.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public String getName() {
  return PathUtil.getFileName(myPath);
}
 
Example 19
Source File: SdkRunConfig.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
@Nullable
public String suggestedName() {
  final String filePath = fields.getFilePath();
  return filePath == null ? null : PathUtil.getFileName(filePath);
}
 
Example 20
Source File: FileCopyPackagingElement.java    From consulo with Apache License 2.0 4 votes vote down vote up
public String getOutputFileName() {
  return myRenamedOutputFileName != null ? myRenamedOutputFileName : PathUtil.getFileName(myFilePath);
}