Convert ProjectLibraryTable to an interface IDEA-CR-36811

IDEA-199211 Refactor code dependent on project model implementation
This commit is contained in:
Leonid Shalupov
2018-10-02 11:48:04 +03:00
parent 9f81d64ea8
commit c8e1a99841
7 changed files with 35 additions and 30 deletions
@@ -243,7 +243,7 @@
serviceImplementation="com.intellij.psi.impl.PsiCachedValuesFactory"/>
<projectService serviceInterface="com.intellij.openapi.roots.impl.libraries.ProjectLibraryTableInterface"
<projectService serviceInterface="com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable"
serviceImplementation="com.intellij.openapi.roots.impl.libraries.ProjectLibraryTableImpl"/>
<projectService serviceInterface="com.intellij.psi.search.ProjectScopeBuilder"
@@ -24,6 +24,7 @@ import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.impl.ProjectRootManagerImpl;
import com.intellij.openapi.roots.impl.libraries.LibraryStateSplitter;
import com.intellij.openapi.roots.impl.libraries.LibraryTableBase;
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable;
import com.intellij.openapi.vfs.VirtualFile;
@@ -79,7 +80,7 @@ public class CoreProjectLoader {
VirtualFile libraries = dotIdea.findChild("libraries");
if (libraries != null) {
Map<String, Element> data = DirectoryStorageUtil.loadFrom(libraries, PathMacroManager.getInstance(project));
Element libraryTable = DefaultStateSerializerKt.deserializeState(DirectoryStorageUtil.getCompositeState(data, new ProjectLibraryTable.LibraryStateSplitter()), Element.class, null);
Element libraryTable = DefaultStateSerializerKt.deserializeState(DirectoryStorageUtil.getCompositeState(data, new LibraryStateSplitter()), Element.class, null);
((LibraryTableBase) ProjectLibraryTable.getInstance(project)).loadState(libraryTable);
}
@@ -246,7 +246,7 @@ public class LibraryImpl extends TraceableDisposable implements LibraryEx.Modifi
@NotNull
private VirtualFilePointerListener getListener() {
Project project = myLibraryTable instanceof ProjectLibraryTableInterface ? ((ProjectLibraryTableInterface)myLibraryTable).getProject() : null;
Project project = myLibraryTable instanceof ProjectLibraryTable ? ((ProjectLibraryTable)myLibraryTable).getProject() : null;
return myRootModel != null ? ((RootModelImpl)myRootModel).getRootsChangedListener() : project != null ? ProjectRootManagerImpl
.getInstanceImpl(project).getRootsValidityChangedListener() : ProjectJdkImpl.getGlobalVirtualFilePointerListener();
}
@@ -371,7 +371,7 @@ public class LibraryImpl extends TraceableDisposable implements LibraryEx.Modifi
Module module = getModule();
Project project;
if (module == null) {
project = myLibraryTable instanceof ProjectLibraryTableInterface ? ((ProjectLibraryTableInterface)myLibraryTable).getProject() : null;
project = myLibraryTable instanceof ProjectLibraryTable ? ((ProjectLibraryTable)myLibraryTable).getProject() : null;
}
else {
project = module.getProject();
@@ -0,0 +1,11 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.roots.impl.libraries
import com.intellij.openapi.components.StateSplitterEx
import com.intellij.openapi.util.Pair
import org.jdom.Element
class LibraryStateSplitter : StateSplitterEx() {
override fun splitState(state: Element): MutableList<Pair<Element, String>> = splitState(
state, LibraryImpl.LIBRARY_NAME_ATTR)
}
@@ -0,0 +1,14 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.roots.impl.libraries;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.libraries.LibraryTable;
public interface ProjectLibraryTable extends LibraryTable {
static LibraryTable getInstance(Project project) {
return ServiceManager.getService(project, ProjectLibraryTable.class);
}
Project getProject();
}
@@ -1,24 +0,0 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.roots.impl.libraries
import com.intellij.openapi.components.StateSplitterEx
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.libraries.LibraryTable
import com.intellij.openapi.util.Pair
import org.jdom.Element
class ProjectLibraryTable private constructor() {
companion object {
@JvmStatic
fun getInstance(project: Project): LibraryTable = project.service<ProjectLibraryTableInterface>()
}
class LibraryStateSplitter : StateSplitterEx() {
override fun splitState(state: Element): MutableList<Pair<Element, String>> = StateSplitterEx.splitState(state, LibraryImpl.LIBRARY_NAME_ATTR)
}
}
interface ProjectLibraryTableInterface: LibraryTable {
val project: Project
}
@@ -8,10 +8,13 @@ import com.intellij.openapi.project.ProjectBundle
import com.intellij.openapi.roots.libraries.LibraryTablePresentation
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar
@State(name = "libraryTable", storages = [(Storage(value = "libraries", stateSplitter = ProjectLibraryTable.LibraryStateSplitter::class))])
class ProjectLibraryTableImpl(override val project: Project) : LibraryTableBase(), ProjectLibraryTableInterface {
@State(name = "libraryTable", storages = [(Storage(value = "libraries", stateSplitter = LibraryStateSplitter::class))])
class ProjectLibraryTableImpl(val parentProject: Project) : LibraryTableBase(), ProjectLibraryTable {
override fun getProject(): Project = parentProject
override fun getTableLevel(): String = LibraryTablesRegistrar.PROJECT_LEVEL
override fun getPresentation(): LibraryTablePresentation = PROJECT_LIBRARY_TABLE_PRESENTATION
}
private val PROJECT_LIBRARY_TABLE_PRESENTATION = object : LibraryTablePresentation() {