Dropping package facades:
- light classes: do not generate light class for package facade - drop package facades as multifile classes compilation mode support - get rid of some additional package facade fqName usages - update tests for light classes
This commit is contained in:
-35
@@ -133,41 +133,6 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
return KotlinLightClassForExplicitDeclaration.create(psiManager, classOrObject)
|
||||
}
|
||||
|
||||
override fun getPackageClasses(packageFqName: FqName, scope: GlobalSearchScope): Collection<PsiClass> {
|
||||
val filesWithCallables = PackagePartClassUtils.getFilesWithCallables(findFilesForPackage(packageFqName, scope))
|
||||
val filesByModule = filesWithCallables.groupBy { it.getModuleInfo() }
|
||||
return filesByModule.flatMap {
|
||||
createLightClassForPackageFacade(it.value, it.key, packageFqName)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createLightClassForPackageFacade(
|
||||
files: List<JetFile>,
|
||||
moduleInfo: IdeaModuleInfo,
|
||||
packageFqName: FqName
|
||||
): List<PsiClass> {
|
||||
if (moduleInfo is ModuleSourceInfo) {
|
||||
val lightClassForFacade = KotlinLightClassForFacade.createForPackageFacade(
|
||||
psiManager, packageFqName, moduleInfo.contentScope(), files
|
||||
)
|
||||
return withFakeLightClasses(lightClassForFacade, files)
|
||||
|
||||
}
|
||||
else {
|
||||
val packageClassName = PackageClassUtils.getPackageClassName(packageFqName)
|
||||
val virtualFileForPackageClass = files.asSequence().map {
|
||||
it.virtualFile?.parent?.findChild("$packageClassName.class")
|
||||
}.firstOrNull { it != null } ?: return emptyList()
|
||||
|
||||
val clsClassFromPackageClass = createClsJavaClassFromVirtualFile(
|
||||
mirrorFile = files.first(),
|
||||
classFile = virtualFileForPackageClass,
|
||||
correspondingClassOrObject = null
|
||||
) ?: return emptyList()
|
||||
return listOf(KotlinLightClassForDecompiledDeclaration(clsClassFromPackageClass, null))
|
||||
}
|
||||
}
|
||||
|
||||
private fun withFakeLightClasses(
|
||||
lightClassForFacade: KotlinLightClassForFacade?,
|
||||
facadeFiles: List<JetFile>
|
||||
|
||||
@@ -240,7 +240,6 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
|
||||
!enableInline,
|
||||
!enableOptimization,
|
||||
/*useTypeTableInSerializer=*/false,
|
||||
/*packageFacadesAsMultifileClasses=*/false,
|
||||
sink);
|
||||
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
||||
}
|
||||
|
||||
@@ -301,8 +301,7 @@ public class JetRunConfiguration extends ModuleBasedConfiguration<RunConfigurati
|
||||
if (StringUtil.isEmpty(MAIN_CLASS_NAME)) {
|
||||
return null;
|
||||
}
|
||||
return StringUtil.trimEnd(MAIN_CLASS_NAME,
|
||||
"." + PackageClassUtils.getPackageClassName(new FqName(MAIN_CLASS_NAME).parent()));
|
||||
return MAIN_CLASS_NAME;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package test3
|
||||
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package test3
|
||||
|
||||
fun bar() {
|
||||
|
||||
}
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
package test
|
||||
|
||||
fun foo() = 42
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
package test
|
||||
|
||||
fun bar() = 239 + foo()
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
package client;
|
||||
|
||||
import server.ServerPackage;
|
||||
import server.KotlintopLevelMethodUsages_0Kt;
|
||||
|
||||
class JClient {
|
||||
String s = ServerPackage.processRequest();
|
||||
String s = KotlintopLevelMethodUsages_0Kt.processRequest();
|
||||
|
||||
String sendRequest() {
|
||||
return ServerPackage.processRequest();
|
||||
return KotlintopLevelMethodUsages_0Kt.processRequest();
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package client;
|
||||
|
||||
import server.KotlinTopLevelMethodUsages_0Kt;
|
||||
|
||||
class JClient {
|
||||
String s = KotlinTopLevelMethodUsages_0Kt.processRequest();
|
||||
|
||||
String sendRequest() {
|
||||
return KotlinTopLevelMethodUsages_0Kt.processRequest();
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,11 +1,11 @@
|
||||
package client;
|
||||
|
||||
import server.ServerPackage;
|
||||
import server.KotlinTopLevelPropertyUsages_0Kt;
|
||||
|
||||
class JClient {
|
||||
void fooBar() {
|
||||
System.out.println("foo = " + ServerPackage.getFoo());
|
||||
System.out.println("length: " + ServerPackage.getFoo().length());
|
||||
ServerPackage.setFoo("");
|
||||
System.out.println("foo = " + KotlinTopLevelPropertyUsages_0Kt.getFoo());
|
||||
System.out.println("length: " + KotlinTopLevelPropertyUsages_0Kt.getFoo().length());
|
||||
KotlinTopLevelPropertyUsages_0Kt.setFoo("");
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package client;
|
||||
|
||||
import server.KotlinTopLevelPropertyUsages_0Kt;
|
||||
|
||||
class JClient {
|
||||
void fooBar() {
|
||||
System.out.println("foo = " + KotlinTopLevelPropertyUsages_0Kt.getFoo());
|
||||
System.out.println("length: " + KotlinTopLevelPropertyUsages_0Kt.getFoo().length());
|
||||
KotlinTopLevelPropertyUsages_0Kt.setFoo("");
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import foo.Obj;
|
||||
|
||||
class usedInJava {
|
||||
public static void main(String[] args) {
|
||||
FooPackage.getUsedByGetter();
|
||||
FooPackage.setUsedBySetter(":|");
|
||||
UsedInJavaKt.getUsedByGetter();
|
||||
UsedInJavaKt.setUsedBySetter(":|");
|
||||
System.out.println(Obj.CONST);
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -2,22 +2,22 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import test.TestPackage;
|
||||
import test.*;
|
||||
|
||||
class AssignMappedKotlinType {
|
||||
void test() {
|
||||
int i1 = TestPackage.getInt();
|
||||
Integer i2 = TestPackage.getInt();
|
||||
Number number = TestPackage.getNumber();
|
||||
String str = TestPackage.getString();
|
||||
int i1 = AssignMappedKotlinTypeKt.getInt();
|
||||
Integer i2 = AssignMappedKotlinTypeKt.getInt();
|
||||
Number number = AssignMappedKotlinTypeKt.getNumber();
|
||||
String str = AssignMappedKotlinTypeKt.getString();
|
||||
|
||||
Collection<Integer> intCollection = TestPackage.getList();
|
||||
List<Integer> intList = TestPackage.getList();
|
||||
Collection<Integer> intCollection = AssignMappedKotlinTypeKt.getList();
|
||||
List<Integer> intList = AssignMappedKotlinTypeKt.getList();
|
||||
|
||||
Collection<Integer> intMutableCollection = TestPackage.getMutableList();
|
||||
List<Integer> intMutableList = TestPackage.getMutableList();
|
||||
Collection<Integer> intMutableCollection = AssignMappedKotlinTypeKt.getMutableList();
|
||||
List<Integer> intMutableList = AssignMappedKotlinTypeKt.getMutableList();
|
||||
|
||||
Collection<String> stringsCollection = TestPackage.getArrayList();
|
||||
ArrayList<String> arrayListCollection = TestPackage.getArrayList();
|
||||
Collection<String> stringsCollection = AssignMappedKotlinTypeKt.getArrayList();
|
||||
ArrayList<String> arrayListCollection = AssignMappedKotlinTypeKt.getArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import test.kotlin.A;
|
||||
|
||||
import static test.kotlin.KotlinPackage.foo;
|
||||
import static test.kotlin.JvmOverloadsFunctionsKt.foo;
|
||||
|
||||
class JvmOverloadsFunctions {
|
||||
public static void main(String[] args) {
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package test;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import test.kotlin.KotlinPackage;
|
||||
import test.kotlin.*;
|
||||
|
||||
public class TopLevelFunctionInDataFlowInspection {
|
||||
void other(@NotNull Object some) {
|
||||
Object foo = KotlinPackage.foo(some);
|
||||
Object foo = TopLevelFunctionInDataFlowInspectionKt.foo(some);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import test.TestPackage;
|
||||
package test;
|
||||
|
||||
// Check absence of 'Static method reference via subclass warning' for kotlin usages
|
||||
public class UsingKotlinPackageDeclarations {
|
||||
public static int test() {
|
||||
TestPackage.foo();
|
||||
TestPackage.setBar(15);
|
||||
return TestPackage.getBar();
|
||||
UsingKotlinPackageDeclarationsKt.foo();
|
||||
UsingKotlinPackageDeclarationsKt.setBar(15);
|
||||
return UsingKotlinPackageDeclarationsKt.getBar();
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.asJava;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.kotlin.idea.test.JetLightProjectDescriptor;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class FakeLightClassForPackageTest extends JetLightCodeInsightFixtureTestCase {
|
||||
private static final String TEST_DATA_PATH = "idea/testData/fakeLightClassForPackage/";
|
||||
|
||||
public void testMultiFile() {
|
||||
myFixture.configureByFiles(TEST_DATA_PATH + "1.kt", TEST_DATA_PATH + "2.kt");
|
||||
GlobalSearchScope searchScope = GlobalSearchScope.allScope(getProject());
|
||||
PsiClass[] classes = JavaElementFinder.getInstance(getProject()).findClasses("test.TestPackage", searchScope);
|
||||
|
||||
assertEquals(3, classes.length);
|
||||
|
||||
assertInstanceOf(classes[0], KotlinLightClassForFacade.class);
|
||||
|
||||
Set<JetFile> expectedFiles = Sets.newHashSet(
|
||||
LightClassGenerationSupport.getInstance(getProject()).findFilesForPackage(new FqName("test"), searchScope)
|
||||
);
|
||||
|
||||
Set<PsiFile> actualFiles = Sets.newHashSet();
|
||||
for (int i = 1; i < classes.length; i++) {
|
||||
assertInstanceOf(classes[i], FakeLightClassForFileOfPackage.class);
|
||||
actualFiles.add(((FakeLightClassForFileOfPackage) classes[i]).getContainingFile());
|
||||
}
|
||||
|
||||
assertEquals(expectedFiles, actualFiles);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JetLightProjectDescriptor.INSTANCE;
|
||||
}
|
||||
}
|
||||
@@ -31,12 +31,8 @@ class LightClassesClasspathSortingTest : KotlinCodeInsightTestCase() {
|
||||
doTest("test1.A")
|
||||
}
|
||||
|
||||
fun testPackageClassOneFile() {
|
||||
doTest("test2.Test2Package")
|
||||
}
|
||||
|
||||
fun testPackageClassTwoFiles() {
|
||||
doTest("test3.Test3Package")
|
||||
fun testFileClass() {
|
||||
doTest("test2.FileKt")
|
||||
}
|
||||
|
||||
private fun doTest(fqName: String) {
|
||||
|
||||
-4
@@ -60,10 +60,6 @@ public class NavigateToDecompiledLibraryTest extends LightCodeInsightFixtureTest
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLibrariesPackage() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSimpleClass() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.intellij.testFramework.PsiTestUtil
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils.getPackageClassFqName
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils.getPackageClassName
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.test.MockLibraryUtil
|
||||
@@ -109,11 +108,11 @@ public class JetExceptionFilterTest : MultiFileTestCase() {
|
||||
}
|
||||
|
||||
public fun testBreakpointReachedAt() {
|
||||
doTest("breakpointReachedAt.kt", 2, { getPackageClassName(FqName.ROOT) }, linePrefix = "Breakpoint reached at ")
|
||||
doTest("breakpointReachedAt.kt", 2, { "BreakpointReachedAtKt" }, linePrefix = "Breakpoint reached at ")
|
||||
}
|
||||
|
||||
public fun testSimple() {
|
||||
doTest("simple.kt", 2, { getPackageClassName(FqName.ROOT) })
|
||||
doTest("simple.kt", 2, { "SimpleKt" })
|
||||
}
|
||||
|
||||
public fun testKt2489() {
|
||||
|
||||
Reference in New Issue
Block a user