mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[jps model] create correct references to modules and libraries if the new implementation of JpsModel is used (IJPL-409)
JpsModuleReferenceImpl and JpsLibraryReferenceImpl won't resolve if the new implementation is used, so parts of JpsModel which aren't converted to use the workspace model, also need to use *Bridge implementations. GitOrigin-RevId: 25eb3336d29457ae0c735d74e42960e87cc89b49
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b79f0b54e9
commit
402b82fe0e
@@ -0,0 +1,23 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.jps.model.ex;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.JpsCompositeElement;
|
||||
import org.jetbrains.jps.model.JpsElementReference;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryReference;
|
||||
import org.jetbrains.jps.model.module.JpsModuleReference;
|
||||
|
||||
/**
|
||||
* This is an internal API used to create custom implementation of {@link org.jetbrains.jps.model.JpsElementReference} if the implementation
|
||||
* of JPS Model based on the workspace model is used.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public interface JpsReferenceCustomFactory {
|
||||
boolean isEnabled();
|
||||
|
||||
@NotNull JpsModuleReference createModuleReference(@NotNull String moduleName);
|
||||
|
||||
@NotNull JpsLibraryReference createLibraryReference(@NotNull String libraryName,
|
||||
@NotNull JpsElementReference<? extends JpsCompositeElement> parentReference);
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.*;
|
||||
import org.jetbrains.jps.model.ex.JpsReferenceCustomFactory;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryReference;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryType;
|
||||
import org.jetbrains.jps.model.library.JpsTypedLibrary;
|
||||
@@ -33,9 +34,12 @@ import org.jetbrains.jps.model.module.*;
|
||||
import org.jetbrains.jps.model.module.impl.JpsModuleImpl;
|
||||
import org.jetbrains.jps.model.module.impl.JpsModuleReferenceImpl;
|
||||
import org.jetbrains.jps.model.module.impl.JpsModuleSourceRootImpl;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class JpsElementFactoryImpl extends JpsElementFactory {
|
||||
private volatile Boolean hasCustomReferenceFactory;
|
||||
|
||||
@Override
|
||||
public JpsModel createModel() {
|
||||
return new JpsModelImpl();
|
||||
@@ -72,6 +76,13 @@ public final class JpsElementFactoryImpl extends JpsElementFactory {
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsModuleReference createModuleReference(@NotNull String moduleName) {
|
||||
if (hasCustomReferenceFactory()) {
|
||||
for (JpsReferenceCustomFactory extension : JpsServiceManager.getInstance().getExtensions(JpsReferenceCustomFactory.class)) {
|
||||
if (extension.isEnabled()) {
|
||||
return extension.createModuleReference(moduleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new JpsModuleReferenceImpl(moduleName);
|
||||
}
|
||||
|
||||
@@ -79,6 +90,13 @@ public final class JpsElementFactoryImpl extends JpsElementFactory {
|
||||
@Override
|
||||
public JpsLibraryReference createLibraryReference(@NotNull String libraryName,
|
||||
@NotNull JpsElementReference<? extends JpsCompositeElement> parentReference) {
|
||||
if (hasCustomReferenceFactory()) {
|
||||
for (JpsReferenceCustomFactory extension : JpsServiceManager.getInstance().getExtensions(JpsReferenceCustomFactory.class)) {
|
||||
if (extension.isEnabled()) {
|
||||
return extension.createLibraryReference(libraryName, parentReference);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new JpsLibraryReferenceImpl(libraryName, parentReference);
|
||||
}
|
||||
|
||||
@@ -88,6 +106,20 @@ public final class JpsElementFactoryImpl extends JpsElementFactory {
|
||||
return new JpsSdkReferenceImpl<>(sdkName, sdkType, createGlobalReference());
|
||||
}
|
||||
|
||||
private boolean hasCustomReferenceFactory() {
|
||||
if (hasCustomReferenceFactory == null) {
|
||||
boolean hasEnabledFactory = false;
|
||||
for (JpsReferenceCustomFactory extension : JpsServiceManager.getInstance().getExtensions(JpsReferenceCustomFactory.class)) {
|
||||
if (extension.isEnabled()) {
|
||||
hasEnabledFactory = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
hasCustomReferenceFactory = hasEnabledFactory;
|
||||
}
|
||||
return hasCustomReferenceFactory;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsElementReference<JpsProject> createProjectReference() {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
com.intellij.platform.workspace.jps.bridge.impl.JpsReferenceCustomFactoryImpl
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.platform.workspace.jps.bridge.impl
|
||||
|
||||
import com.intellij.platform.workspace.jps.bridge.impl.library.JpsLibraryCollectionsCache
|
||||
import com.intellij.platform.workspace.jps.bridge.impl.library.JpsLibraryReferenceBridge
|
||||
import com.intellij.platform.workspace.jps.bridge.impl.module.JpsModuleReferenceBridge
|
||||
import com.intellij.platform.workspace.jps.entities.LibraryId
|
||||
import com.intellij.platform.workspace.jps.entities.LibraryTableId
|
||||
import com.intellij.platform.workspace.jps.entities.ModuleId
|
||||
import org.jetbrains.jps.model.JpsCompositeElement
|
||||
import org.jetbrains.jps.model.JpsElementReference
|
||||
import org.jetbrains.jps.model.ex.JpsReferenceCustomFactory
|
||||
import org.jetbrains.jps.model.impl.JpsGlobalElementReference
|
||||
import org.jetbrains.jps.model.impl.JpsProjectElementReference
|
||||
import org.jetbrains.jps.model.library.JpsLibraryReference
|
||||
import org.jetbrains.jps.model.module.JpsModuleReference
|
||||
import org.jetbrains.jps.model.serialization.impl.JpsSerializationViaWorkspaceModel
|
||||
|
||||
internal class JpsReferenceCustomFactoryImpl : JpsReferenceCustomFactory {
|
||||
override fun isEnabled(): Boolean = JpsSerializationViaWorkspaceModel.IS_ENABLED
|
||||
|
||||
override fun createModuleReference(moduleName: String): JpsModuleReference {
|
||||
return JpsModuleReferenceBridge(moduleName)
|
||||
}
|
||||
|
||||
override fun createLibraryReference(libraryName: String, parentReference: JpsElementReference<out JpsCompositeElement>): JpsLibraryReference {
|
||||
val tableId = when (parentReference) {
|
||||
is JpsGlobalElementReference -> JpsLibraryCollectionsCache.GLOBAL_LIBRARY_TABLE_ID
|
||||
is JpsProjectElementReference -> LibraryTableId.ProjectLibraryTableId
|
||||
is JpsModuleReference -> LibraryTableId.ModuleLibraryTableId(ModuleId(parentReference.moduleName))
|
||||
else -> throw UnsupportedOperationException("Reference to library in $parentReference is not supported") //todo support custom library tables
|
||||
}
|
||||
return JpsLibraryReferenceBridge(LibraryId(libraryName, tableId))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user