Support platform/impl modifiers for functions
Also add a new capability for ModuleDescriptor, which is used to obtain the platform in the multi-platform scenario in tests. Suppress the following errors for platform functions: "function has no body" and "nothing to inline". Also do not report redeclaration between platform and non-platform functions because this is the case when the common + platform-specific code are analyzed together. Note that some diagnostics reported in tests are not yet implemented in this commit, they appear in subsequent commits
This commit is contained in:
@@ -25,6 +25,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import kotlin.text.StringsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
@@ -148,7 +149,7 @@ public abstract class AbstractDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
LanguageVersionSettings languageVersionSettings = loadLanguageVersionSettings(testFilesInModule);
|
||||
ModuleContext moduleContext = ContextKt.withModule(ContextKt.withProject(context, getProject()), module);
|
||||
|
||||
boolean separateModules = groupedByModule.size() == 1;
|
||||
boolean separateModules = groupedByModule.size() == 1 && groupedByModule.keySet().iterator().next() == null;
|
||||
AnalysisResult result = analyzeModuleContents(moduleContext, jetFiles, moduleTrace, languageVersionSettings, separateModules);
|
||||
if (separateModules) {
|
||||
modules.put(testModule, (ModuleDescriptorImpl) result.getModuleDescriptor());
|
||||
@@ -448,7 +449,7 @@ public abstract class AbstractDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
ModuleDescriptorImpl module =
|
||||
testModule == null ?
|
||||
createSealedModule(storageManager) :
|
||||
createModule("<" + testModule.getName() + ">", storageManager);
|
||||
createModule(testModule.getName(), storageManager);
|
||||
|
||||
modules.put(testModule, module);
|
||||
}
|
||||
@@ -471,13 +472,24 @@ public abstract class AbstractDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@SuppressWarnings("unchecked")
|
||||
protected ModuleDescriptorImpl createModule(@NotNull String moduleName, @NotNull StorageManager storageManager) {
|
||||
return new ModuleDescriptorImpl(Name.special(moduleName), storageManager, new JvmBuiltIns(storageManager));
|
||||
String nameSuffix = StringsKt.substringAfterLast(moduleName, "-", "");
|
||||
MultiTargetPlatform platform =
|
||||
nameSuffix.isEmpty() ? null :
|
||||
nameSuffix.equals("common") ? MultiTargetPlatform.Common.INSTANCE : new MultiTargetPlatform.Specific(nameSuffix);
|
||||
Map capabilities =
|
||||
platform == null
|
||||
? Collections.emptyMap()
|
||||
: Collections.singletonMap(MultiTargetPlatform.CAPABILITY, platform);
|
||||
return new ModuleDescriptorImpl(
|
||||
Name.special("<" + moduleName + ">"), storageManager, new JvmBuiltIns(storageManager), capabilities
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected ModuleDescriptorImpl createSealedModule(@NotNull StorageManager storageManager) {
|
||||
ModuleDescriptorImpl moduleDescriptor = createModule("<test-module>", storageManager);
|
||||
ModuleDescriptorImpl moduleDescriptor = createModule("test-module", storageManager);
|
||||
moduleDescriptor.setDependencies(moduleDescriptor, moduleDescriptor.getBuiltIns().getBuiltInsModule());
|
||||
return moduleDescriptor;
|
||||
}
|
||||
|
||||
+2
-2
@@ -88,13 +88,13 @@ public abstract class AbstractDiagnosticsTestWithJsStdLib extends AbstractDiagno
|
||||
@NotNull
|
||||
@Override
|
||||
protected ModuleDescriptorImpl createModule(@NotNull String moduleName, @NotNull StorageManager storageManager) {
|
||||
return new ModuleDescriptorImpl(Name.special(moduleName), storageManager, JsPlatform.INSTANCE.getBuiltIns());
|
||||
return new ModuleDescriptorImpl(Name.special("<" + moduleName + ">"), storageManager, JsPlatform.INSTANCE.getBuiltIns());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected ModuleDescriptorImpl createSealedModule(@NotNull StorageManager storageManager) {
|
||||
ModuleDescriptorImpl module = createModule("<kotlin-js-test-module>", storageManager);
|
||||
ModuleDescriptorImpl module = createModule("kotlin-js-test-module", storageManager);
|
||||
|
||||
List<ModuleDescriptorImpl> dependencies = new ArrayList<ModuleDescriptorImpl>();
|
||||
dependencies.add(module);
|
||||
|
||||
@@ -12548,6 +12548,90 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Multiplatform extends AbstractDiagnosticsTest {
|
||||
public void testAllFilesPresentInMultiplatform() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class TopLevelFun extends AbstractDiagnosticsTest {
|
||||
public void testAllFilesPresentInTopLevelFun() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/topLevelFun"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("callPlatformFun.kt")
|
||||
public void testCallPlatformFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/callPlatformFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("conflictingPlatformDeclarations.kt")
|
||||
public void testConflictingPlatformDeclarations() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingPlatformDeclarations.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("conflictingPlatformDefinitions.kt")
|
||||
public void testConflictingPlatformDefinitions() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingPlatformDefinitions.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("declarationAndDefinitionInDIfferentPackages.kt")
|
||||
public void testDeclarationAndDefinitionInDIfferentPackages() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/declarationAndDefinitionInDIfferentPackages.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("declarationWithoutDefinition.kt")
|
||||
public void testDeclarationWithoutDefinition() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/declarationWithoutDefinition.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("defaultArguments.kt")
|
||||
public void testDefaultArguments() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/defaultArguments.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("definitionWithoutDeclaration.kt")
|
||||
public void testDefinitionWithoutDeclaration() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/definitionWithoutDeclaration.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inlineFun.kt")
|
||||
public void testInlineFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/inlineFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("platformDeclarationWithBody.kt")
|
||||
public void testPlatformDeclarationWithBody() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/platformDeclarationWithBody.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("platformDefinitionWithoutBody.kt")
|
||||
public void testPlatformDefinitionWithoutBody() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/platformDefinitionWithoutBody.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simplePlatformFun.kt")
|
||||
public void testSimplePlatformFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/simplePlatformFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/namedArguments")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user