Use target platform configured in facet in module analysis
This commit is contained in:
+33
-13
@@ -30,37 +30,57 @@ import com.intellij.psi.util.CachedValuesManager;
|
|||||||
import com.intellij.util.Processor;
|
import com.intellij.util.Processor;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.config.KotlinFacetSettings;
|
||||||
|
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider;
|
||||||
|
import org.jetbrains.kotlin.config.TargetPlatformKind;
|
||||||
import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil;
|
import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil;
|
||||||
|
import org.jetbrains.kotlin.js.resolve.JsPlatform;
|
||||||
|
import org.jetbrains.kotlin.resolve.TargetPlatform;
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
|
||||||
|
|
||||||
public class ProjectStructureUtil {
|
public class ProjectStructureUtil {
|
||||||
private static final Key<CachedValue<Boolean>> IS_KOTLIN_JS_MODULE = Key.create("IS_KOTLIN_JS_MODULE");
|
private static final Key<CachedValue<TargetPlatform>> PLATFORM_FOR_MODULE = Key.create("PLATFORM_FOR_MODULE");
|
||||||
|
|
||||||
private ProjectStructureUtil() {
|
private ProjectStructureUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isJsKotlinModule(@NotNull final Module module) {
|
/* package */ static TargetPlatform getCachedPlatformForModule(@NotNull final Module module) {
|
||||||
CachedValue<Boolean> result = module.getUserData(IS_KOTLIN_JS_MODULE);
|
CachedValue<TargetPlatform> result = module.getUserData(PLATFORM_FOR_MODULE);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result = CachedValuesManager.getManager(module.getProject()).createCachedValue(new CachedValueProvider<Boolean>() {
|
result = CachedValuesManager.getManager(module.getProject()).createCachedValue(new CachedValueProvider<TargetPlatform>() {
|
||||||
@Override
|
@Override
|
||||||
public Result<Boolean> compute() {
|
public Result<TargetPlatform> compute() {
|
||||||
return Result.create(
|
TargetPlatform configuredInFacet = getPlatformConfiguredInFacet(module);
|
||||||
getJSStandardLibrary(module) != null,
|
TargetPlatform platform =
|
||||||
ProjectRootModificationTracker.getInstance(module.getProject()));
|
configuredInFacet != null ? configuredInFacet :
|
||||||
|
hasJsStandardLibraryInDependencies(module) ? JsPlatform.INSTANCE : JvmPlatform.INSTANCE;
|
||||||
|
return Result.create(platform, ProjectRootModificationTracker.getInstance(module.getProject()));
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
module.putUserData(IS_KOTLIN_JS_MODULE, result);
|
module.putUserData(PLATFORM_FOR_MODULE, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.getValue();
|
return result.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static Library getJSStandardLibrary(final Module module) {
|
private static TargetPlatform getPlatformConfiguredInFacet(@NotNull Module module) {
|
||||||
return ApplicationManager.getApplication().runReadAction(new Computable<Library>() {
|
KotlinFacetSettings settings = KotlinFacetSettingsProvider.Companion.getInstance(module.getProject()).getSettings(module);
|
||||||
|
TargetPlatformKind<?> kind = settings.getVersionInfo().getTargetPlatformKind();
|
||||||
|
if (kind instanceof TargetPlatformKind.Jvm) {
|
||||||
|
return JvmPlatform.INSTANCE;
|
||||||
|
}
|
||||||
|
if (kind instanceof TargetPlatformKind.JavaScript) {
|
||||||
|
return JsPlatform.INSTANCE;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasJsStandardLibraryInDependencies(@NotNull final Module module) {
|
||||||
|
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public Library compute() {
|
public Boolean compute() {
|
||||||
final Ref<Library> jsLibrary = Ref.create();
|
final Ref<Library> jsLibrary = Ref.create();
|
||||||
|
|
||||||
ModuleRootManager.getInstance(module).orderEntries().librariesOnly().forEachLibrary(new Processor<Library>() {
|
ModuleRootManager.getInstance(module).orderEntries().librariesOnly().forEachLibrary(new Processor<Library>() {
|
||||||
@@ -75,7 +95,7 @@ public class ProjectStructureUtil {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return jsLibrary.get();
|
return jsLibrary.get() != null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -23,7 +23,6 @@ import com.intellij.openapi.vfs.VirtualFile;
|
|||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.js.resolve.JsPlatform;
|
|
||||||
import org.jetbrains.kotlin.psi.KtCodeFragment;
|
import org.jetbrains.kotlin.psi.KtCodeFragment;
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
import org.jetbrains.kotlin.psi.KtFile;
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
|
import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
|
||||||
@@ -66,10 +65,7 @@ public class TargetPlatformDetector {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static TargetPlatform getPlatform(@NotNull Module module) {
|
public static TargetPlatform getPlatform(@NotNull Module module) {
|
||||||
if (ProjectStructureUtil.isJsKotlinModule(module)) {
|
return ProjectStructureUtil.getCachedPlatformForModule(module);
|
||||||
return JsPlatform.INSTANCE;
|
|
||||||
}
|
|
||||||
return JvmPlatform.INSTANCE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user