本文整理匯總了Java中com.intellij.openapi.util.io.FileUtil.getNameWithoutExtension方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtil.getNameWithoutExtension方法的具體用法?Java FileUtil.getNameWithoutExtension怎麽用?Java FileUtil.getNameWithoutExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.util.io.FileUtil
的用法示例。
在下文中一共展示了FileUtil.getNameWithoutExtension方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: transformTestFile
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static void transformTestFile(@NotNull Project project, int toSubtaskIndex, VirtualFile taskDir) {
String subtaskTestFileName = getTestFileName(project, toSubtaskIndex);
if (subtaskTestFileName == null) {
return;
}
String nameWithoutExtension = FileUtil.getNameWithoutExtension(subtaskTestFileName);
String extension = FileUtilRt.getExtension(subtaskTestFileName);
VirtualFile subtaskTestFile = taskDir.findChild(nameWithoutExtension + ".txt");
if (subtaskTestFile != null) {
ApplicationManager.getApplication().runWriteAction(() -> {
try {
subtaskTestFile.rename(project, nameWithoutExtension + "." + extension);
}
catch (IOException e) {
LOG.error(e);
}
});
}
}
示例2: getSubtaskIndex
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public static int getSubtaskIndex(@NotNull Project project, @NotNull VirtualFile file) {
String fileName = file.getName();
String name = FileUtil.getNameWithoutExtension(fileName);
if (!isTestsFile(project, file)) {
return -1;
}
if (!name.contains(EduNames.SUBTASK_MARKER)) {
return 0;
}
int markerIndex = name.indexOf(EduNames.SUBTASK_MARKER);
String index = name.substring(markerIndex + EduNames.SUBTASK_MARKER.length());
if (index.isEmpty()) {
return -1;
}
try {
return Integer.valueOf(index);
}
catch (NumberFormatException e) {
return -1;
}
}
示例3: getAllAnswerTaskFiles
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static List<VirtualFile> getAllAnswerTaskFiles(@NotNull Course course, @NotNull Project project) {
List<VirtualFile> result = new ArrayList<>();
for (Lesson lesson : course.getLessons()) {
for (Task task : lesson.getTaskList()) {
for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
String name = entry.getKey();
String answerName = FileUtil.getNameWithoutExtension(name) + CCUtils.ANSWER_EXTENSION_DOTTED + FileUtilRt.getExtension(name);
String taskPath = FileUtil.join(project.getBasePath(), EduNames.LESSON + lesson.getIndex(), EduNames.TASK + task.getIndex());
VirtualFile taskFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.join(taskPath, answerName));
if (taskFile == null) {
taskFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.join(taskPath, EduNames.SRC, answerName));
}
if (taskFile != null) {
result.add(taskFile);
}
}
}
}
return result;
}
示例4: getTestsFile
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Nullable
@Override
protected VirtualFile getTestsFile() {
String testFileName = EduJavaPluginConfigurator.TEST_JAVA;
if (myTask instanceof TaskWithSubtasks) {
int activeSubtaskIndex = ((TaskWithSubtasks) myTask).getActiveSubtaskIndex();
testFileName = FileUtil.getNameWithoutExtension(testFileName) + EduNames.SUBTASK_MARKER + activeSubtaskIndex + "." + FileUtilRt.getExtension(EduJavaPluginConfigurator.TEST_JAVA);
}
VirtualFile taskDir = myTask.getTaskDir(myProject);
if (taskDir == null) {
return null;
}
VirtualFile srcDir = taskDir.findChild(EduNames.SRC);
if (srcDir != null) {
taskDir = srcDir;
}
VirtualFile virtualFile = taskDir.findChild(testFileName);
if (virtualFile != null) {
return virtualFile;
}
return null;
}
示例5: getNewFileName
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static String getNewFileName(GroovyFile file) {
final PsiDirectory dir = file.getContainingDirectory();
LOG.assertTrue(dir != null);
final PsiFile[] files = dir.getFiles();
Set<String> fileNames = new HashSet<String>();
for (PsiFile psiFile : files) {
fileNames.add(psiFile.getName());
}
String prefix = FileUtil.getNameWithoutExtension(file.getName());
String fileName = prefix + ".java";
int index = 1;
while (fileNames.contains(fileName)) {
fileName = prefix + index + ".java";
}
return fileName;
}
示例6: getTraceFiles
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@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()]);
}
示例7: updateOutputPath
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public void updateOutputPath(@NotNull String oldArtifactName, @NotNull 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();
}
}
}
示例8: matchesSource
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@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) == '/';
}
示例9: process
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static List<IdeaPluginDescriptor> process(@Nullable String repositoryUrl, List<IdeaPluginDescriptor> list) {
for (Iterator<IdeaPluginDescriptor> i = list.iterator(); i.hasNext(); ) {
PluginNode node = (PluginNode)i.next();
if (node.getPluginId() == null || repositoryUrl != null && node.getDownloadUrl() == null) {
LOG.warn("Malformed plugin record (id:" + node.getPluginId() + " repository:" + repositoryUrl + ")");
i.remove();
continue;
}
if (repositoryUrl != null) {
node.setRepositoryName(repositoryUrl);
}
if (node.getName() == null) {
String url = node.getDownloadUrl();
String name = FileUtil.getNameWithoutExtension(url.substring(url.lastIndexOf('/') + 1));
node.setName(name);
}
}
return list;
}
示例10: correlateTestToHeader
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@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 : TEST_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;
}
示例11: getSubtaskTestsFileName
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@NotNull
public static String getSubtaskTestsFileName(int index) {
return index == 0 ? TESTS_PY : FileUtil.getNameWithoutExtension(TESTS_PY) +
EduNames.SUBTASK_MARKER +
index + "." +
FileUtilRt.getExtension(TESTS_PY);
}
示例12: createCheckProcess
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
Process createCheckProcess(@NotNull final Project project, @NotNull final String executablePath) throws ExecutionException {
final Sdk sdk = PythonSdkType.findPythonSdk(ModuleManager.getInstance(project).getModules()[0]);
PyEduPluginConfigurator configurator = new PyEduPluginConfigurator();
String testsFileName = configurator.getTestFileName();
if (myTask instanceof TaskWithSubtasks) {
testsFileName = FileUtil.getNameWithoutExtension(testsFileName);
int index = ((TaskWithSubtasks)myTask).getActiveSubtaskIndex();
testsFileName += EduNames.SUBTASK_MARKER + index + "." + FileUtilRt.getExtension(configurator.getTestFileName());
}
final File testRunner = new File(myTaskDir.getPath(), testsFileName);
myCommandLine = new GeneralCommandLine();
myCommandLine.withWorkDirectory(myTaskDir.getPath());
final Map<String, String> env = myCommandLine.getEnvironment();
final VirtualFile courseDir = project.getBaseDir();
if (courseDir != null) {
env.put(PYTHONPATH, courseDir.getPath());
}
if (sdk != null) {
String pythonPath = sdk.getHomePath();
if (pythonPath != null) {
myCommandLine.setExePath(pythonPath);
myCommandLine.addParameter(testRunner.getPath());
myCommandLine.addParameter(FileUtil.toSystemDependentName(executablePath));
return myCommandLine.createProcess();
}
}
return null;
}
示例13: getTestFileName
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Nullable
private static String getTestFileName(@NotNull Project project, int subtaskIndex) {
Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return null;
}
EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(course.getLanguageById());
if (configurator == null) {
return null;
}
String defaultTestFileName = configurator.getTestFileName();
String nameWithoutExtension = FileUtil.getNameWithoutExtension(defaultTestFileName);
String extension = FileUtilRt.getExtension(defaultTestFileName);
return nameWithoutExtension + EduNames.SUBTASK_MARKER + subtaskIndex + "." + extension;
}
示例14: replaceWithSubtask
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static void replaceWithSubtask(JsonObject fileWrapper) {
final String file = fileWrapper.get(NAME).getAsString();
final String extension = FileUtilRt.getExtension(file);
final String name = FileUtil.getNameWithoutExtension(file);
if (!name.contains(EduNames.SUBTASK_MARKER)) {
fileWrapper.remove(NAME);
fileWrapper.add(NAME, new JsonPrimitive(name + "_subtask0." + extension));
}
}
示例15: loadState
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Override
public void loadState(Element state) {
try {
Element courseElement = getChildWithName(state, COURSE).getChild(COURSE_TITLED);
for (Element lesson : getChildList(courseElement, LESSONS, true)) {
int lessonIndex = getAsInt(lesson, INDEX);
for (Element task : getChildList(lesson, TASK_LIST, true)) {
int taskIndex = getAsInt(task, INDEX);
Map<String, Element> taskFiles = getChildMap(task, TASK_FILES, true);
for (Map.Entry<String, Element> entry : taskFiles.entrySet()) {
Element taskFileElement = entry.getValue();
String name = entry.getKey();
String answerName = FileUtil.getNameWithoutExtension(name) + CCUtils.ANSWER_EXTENSION_DOTTED + FileUtilRt.getExtension(name);
Document document = StudyUtils.getDocument(myProject.getBasePath(), lessonIndex, taskIndex, answerName);
if (document == null) {
document = StudyUtils.getDocument(myProject.getBasePath(), lessonIndex, taskIndex, name);
if (document == null) {
continue;
}
}
for (Element placeholder : getChildList(taskFileElement, ANSWER_PLACEHOLDERS, true)) {
Element lineElement = getChildWithName(placeholder, LINE, true);
int line = lineElement != null ? Integer.valueOf(lineElement.getAttributeValue(VALUE)) : 0;
Element startElement = getChildWithName(placeholder, START, true);
int start = startElement != null ? Integer.valueOf(startElement.getAttributeValue(VALUE)) : 0;
int offset = document.getLineStartOffset(line) + start;
addChildWithName(placeholder, OFFSET, offset);
addChildWithName(placeholder, "useLength", "false");
}
}
}
}
XmlSerializer.deserializeInto(this, state);
} catch (StudyUnrecognizedFormatException e) {
LOG.error(e);
}
}