mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-26 19:06:24 +07:00
JavaFileManager: remove dead code, use volatile
This commit is contained in:
+1
-142
@@ -21,12 +21,8 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.vfs.VirtualFileWithId;
|
||||
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiManagerEx;
|
||||
import com.intellij.psi.impl.file.PsiPackageImpl;
|
||||
@@ -38,7 +34,6 @@ import com.intellij.util.containers.ConcurrentHashMap;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
|
||||
@@ -50,15 +45,10 @@ import java.util.*;
|
||||
*/
|
||||
public abstract class JavaFileManagerBase implements JavaFileManager, Disposable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.file.impl.JavaFileManagerImpl");
|
||||
@NonNls private static final String JAVA_EXTENSION = ".java";
|
||||
@NonNls private static final String CLASS_EXTENSION = ".class";
|
||||
private final ConcurrentHashMap<GlobalSearchScope, PsiClass> myCachedObjectClassMap = new ConcurrentHashMap<GlobalSearchScope, PsiClass>();
|
||||
private final Map<String,PsiClass> myNameToClassMap = new ConcurrentHashMap<String, PsiClass>(); // used only in mode without repository
|
||||
private final PsiManagerEx myManager;
|
||||
private final ProjectRootManager myProjectRootManager;
|
||||
private final FileManager myFileManager;
|
||||
private final boolean myUseRepository;
|
||||
private Set<String> myNontrivialPackagePrefixes = null;
|
||||
private volatile Set<String> myNontrivialPackagePrefixes = null;
|
||||
private boolean myInitialized = false;
|
||||
private boolean myDisposed = false;
|
||||
private final PackageIndex myPackageIndex;
|
||||
@@ -68,28 +58,13 @@ public abstract class JavaFileManagerBase implements JavaFileManager, Disposable
|
||||
final PsiManagerEx manager, final ProjectRootManager projectRootManager,
|
||||
final MessageBus bus) {
|
||||
myManager = manager;
|
||||
myFileManager = manager.getFileManager();
|
||||
myProjectRootManager = projectRootManager;
|
||||
myUseRepository = true;
|
||||
myPackageIndex = PackageIndex.getInstance(myManager.getProject());
|
||||
myConnection = bus.connect();
|
||||
myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
|
||||
@Override
|
||||
public void rootsChanged(final ModuleRootEvent event) {
|
||||
myNontrivialPackagePrefixes = null;
|
||||
clearNonRepositoryMaps();
|
||||
}
|
||||
});
|
||||
|
||||
myConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
|
||||
@Override
|
||||
public void before(@NotNull final List<? extends VFileEvent> events) {
|
||||
clearNonRepositoryMaps();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(@NotNull final List<? extends VFileEvent> events) {
|
||||
clearNonRepositoryMaps();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -99,8 +74,6 @@ public abstract class JavaFileManagerBase implements JavaFileManager, Disposable
|
||||
myCachedObjectClassMap.clear();
|
||||
}
|
||||
});
|
||||
|
||||
Disposer.register(myManager.getProject(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,12 +87,6 @@ public abstract class JavaFileManagerBase implements JavaFileManager, Disposable
|
||||
myCachedObjectClassMap.clear();
|
||||
}
|
||||
|
||||
protected void clearNonRepositoryMaps() {
|
||||
if (!myUseRepository) {
|
||||
myNameToClassMap.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiPackage findPackage(@NotNull String packageName) {
|
||||
@@ -169,10 +136,6 @@ public abstract class JavaFileManagerBase implements JavaFileManager, Disposable
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiClass findClass(@NotNull String qName, @NotNull GlobalSearchScope scope) {
|
||||
if (!myUseRepository) {
|
||||
return findClassWithoutRepository(qName);
|
||||
}
|
||||
|
||||
if (!myInitialized) {
|
||||
LOG.error("Access to psi files should be performed only after startup activity");
|
||||
return null;
|
||||
@@ -194,89 +157,6 @@ public abstract class JavaFileManagerBase implements JavaFileManager, Disposable
|
||||
return findClassInIndex(qName, scope);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiClass findClassWithoutRepository(String qName) {
|
||||
PsiClass aClass = myNameToClassMap.get(qName);
|
||||
if (aClass != null) {
|
||||
return aClass;
|
||||
}
|
||||
|
||||
aClass = _findClassWithoutRepository(qName);
|
||||
myNameToClassMap.put(qName, aClass);
|
||||
return aClass;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiClass _findClassWithoutRepository(String qName) {
|
||||
VirtualFile[] sourcePath = myProjectRootManager.orderEntries().sources().usingCache().getRoots();
|
||||
VirtualFile[] classPath = myProjectRootManager.orderEntries().withoutModuleSourceEntries().classes().usingCache().getRoots();
|
||||
|
||||
int index = 0;
|
||||
while (index < qName.length()) {
|
||||
int index1 = qName.indexOf('.', index);
|
||||
if (index1 < 0) {
|
||||
index1 = qName.length();
|
||||
}
|
||||
String name = qName.substring(index, index1);
|
||||
|
||||
final int sourceType = 0;
|
||||
//final int compiledType = 1;
|
||||
|
||||
for (int type = 0; type < 2; type++) {
|
||||
VirtualFile[] vDirs = type == sourceType ? sourcePath : classPath;
|
||||
for (VirtualFile vDir : vDirs) {
|
||||
if (vDir != null) {
|
||||
VirtualFile vChild = type == sourceType
|
||||
? vDir.findChild(name + JAVA_EXTENSION)
|
||||
: vDir.findChild(name + CLASS_EXTENSION);
|
||||
if (vChild != null) {
|
||||
PsiFile file = myFileManager.findFile(vChild);
|
||||
if (file instanceof PsiJavaFile) {
|
||||
PsiClass aClass = findClassByName((PsiJavaFile)file, name);
|
||||
if (aClass != null) {
|
||||
index = index1 + 1;
|
||||
while (index < qName.length()) {
|
||||
index1 = qName.indexOf('.', index);
|
||||
if (index1 < 0) {
|
||||
index1 = qName.length();
|
||||
}
|
||||
name = qName.substring(index, index1);
|
||||
aClass = findClassByName(aClass, name);
|
||||
if (aClass == null) return null;
|
||||
index = index1 + 1;
|
||||
}
|
||||
return aClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean existsDir = false;
|
||||
for (int type = 0; type < 2; type++) {
|
||||
VirtualFile[] vDirs = type == sourceType ? sourcePath : classPath;
|
||||
for (int i = 0; i < vDirs.length; i++) {
|
||||
if (vDirs[i] != null) {
|
||||
VirtualFile vDirChild = vDirs[i].findChild(name);
|
||||
if (vDirChild != null) {
|
||||
PsiDirectory dir = myFileManager.findDirectory(vDirChild);
|
||||
if (dir != null) {
|
||||
vDirs[i] = vDirChild;
|
||||
existsDir = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
vDirs[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!existsDir) return null;
|
||||
index = index1 + 1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiClass findClassInIndex(String qName, GlobalSearchScope scope) {
|
||||
VirtualFile bestFile = null;
|
||||
@@ -347,25 +227,4 @@ public abstract class JavaFileManagerBase implements JavaFileManager, Disposable
|
||||
return myNontrivialPackagePrefixes;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiClass findClassByName(PsiJavaFile scope, String name) {
|
||||
PsiClass[] classes = scope.getClasses();
|
||||
for (PsiClass aClass : classes) {
|
||||
if (name.equals(aClass.getName())) {
|
||||
return aClass;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiClass findClassByName(PsiClass scope, String name) {
|
||||
PsiClass[] classes = scope.getInnerClasses();
|
||||
for (PsiClass aClass : classes) {
|
||||
if (name.equals(aClass.getName())) {
|
||||
return aClass;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user