mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
LibraryScope: duplicated code removed, fixed 'getDisplayName' for disposed library
This commit is contained in:
+4
-13
@@ -18,8 +18,7 @@ package com.intellij.openapi.module.impl.scopes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.openapi.roots.libraries.LibraryUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -27,26 +26,18 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class LibraryScope extends LibraryScopeBase {
|
||||
private final Library myLibrary;
|
||||
private final String myLibraryName;
|
||||
|
||||
public LibraryScope(Project project, Library library) {
|
||||
super(project, library.getFiles(OrderRootType.CLASSES), library.getFiles(OrderRootType.SOURCES));
|
||||
myLibraryName = LibraryUtil.getPresentableName(library);
|
||||
myLibrary = library;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
String name = myLibrary.getName();
|
||||
if (name == null) {
|
||||
String[] urls = myLibrary.getUrls(OrderRootType.CLASSES);
|
||||
if (urls.length > 0) {
|
||||
name = PathUtil.getFileName(VfsUtilCore.urlToPath(urls[0]));
|
||||
}
|
||||
else {
|
||||
name = "empty";
|
||||
}
|
||||
}
|
||||
return "Library '" + name + "'";
|
||||
return "Library '" + myLibraryName + "'";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
@@ -169,7 +170,10 @@ public class LibraryUtil {
|
||||
if (name != null) {
|
||||
return name;
|
||||
}
|
||||
final VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
|
||||
return files.length > 0 ? files[0].getName() : "Empty Library";
|
||||
String[] urls = library.getUrls(OrderRootType.CLASSES);
|
||||
if (urls.length > 0) {
|
||||
return PathUtil.getFileName(VfsUtilCore.urlToPath(urls[0]));
|
||||
}
|
||||
return "Empty Library";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user