Rewrite Java resolve to use static class scope instead of synthesized packages

#KT-4149 Fixed
 #KT-4839 Fixed
This commit is contained in:
Alexander Udalov
2014-09-03 14:42:03 +04:00
parent 75df4a9ad8
commit bcfb5f3b09
41 changed files with 217 additions and 419 deletions
@@ -43,7 +43,6 @@ import org.jetbrains.jet.lang.resolve.constants.StringValue;
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassStaticsPackageFragmentDescriptor;
import org.jetbrains.jet.lang.resolve.java.jvmSignature.JvmMethodParameterKind;
import org.jetbrains.jet.lang.resolve.java.jvmSignature.JvmMethodParameterSignature;
import org.jetbrains.jet.lang.resolve.java.jvmSignature.JvmMethodSignature;
@@ -110,10 +109,7 @@ public class JetTypeMapper {
}
DeclarationDescriptor container = descriptor.getContainingDeclaration();
if (container instanceof JavaClassStaticsPackageFragmentDescriptor) {
return mapClass(((JavaClassStaticsPackageFragmentDescriptor) container).getCorrespondingClass());
}
else if (container instanceof PackageFragmentDescriptor) {
if (container instanceof PackageFragmentDescriptor) {
return Type.getObjectType(internalNameForPackage(
(PackageFragmentDescriptor) container,
(CallableMemberDescriptor) descriptor,
@@ -0,0 +1,18 @@
// KT-4149 static members of Java private nested class are accessible from Kotlin
// FILE: javaPackage/Foo.java
package javaPackage;
public class Foo {
private static class Bar {
public static void doSmth() {
}
}
}
// FILE: 1.kt
fun main(args: Array<String>) {
javaPackage.Foo.Bar.<!INVISIBLE_MEMBER!>doSmth<!>()
}
@@ -2,30 +2,29 @@ package test
public open class InnerOfGeneric {
public constructor InnerOfGeneric()
public abstract inner class A</*0*/ K> {
public constructor A</*0*/ K>()
public abstract inner class Inner : test.InnerOfGeneric.S<K> {
public constructor Inner()
public abstract override /*1*/ /*fake_override*/ fun iterator(): kotlin.MutableIterator<K>?
}
}
public open inner class B</*0*/ L> : test.InnerOfGeneric.A<L> {
public constructor B</*0*/ L>()
public open inner class SubInner : test.InnerOfGeneric.A.Inner {
public constructor SubInner()
public open override /*1*/ fun iterator(): kotlin.MutableIterator<L>?
}
}
public trait S</*0*/ E> {
public abstract fun iterator(): kotlin.MutableIterator<E>?
}
}
package test.InnerOfGeneric {
public /*synthesized*/ fun </*0*/ E> S(/*0*/ function: () -> kotlin.MutableIterator<E>?): test.InnerOfGeneric.S<E>
// Static members
public final /*synthesized*/ fun </*0*/ E> S(/*0*/ function: () -> kotlin.MutableIterator<E>?): test.InnerOfGeneric.S<E>
}
@@ -6,26 +6,24 @@ public open class PrivateMembers {
private open fun method(): kotlin.Unit
private final /*synthesized*/ fun samAdapter(/*0*/ p0: (() -> kotlin.Unit)?): kotlin.Unit
private open fun samAdapter(/*0*/ p0: test.PrivateMembers.SamInterface?): kotlin.Unit
private open inner class Inner {
private constructor Inner()
}
private open class Nested {
private constructor Nested()
// Static members
private open fun staticMethodInNested(): kotlin.Unit
}
private trait SamInterface {
public abstract fun foo(): kotlin.Unit
}
}
package test.PrivateMembers {
private var staticField: kotlin.Int
private /*synthesized*/ fun SamInterface(/*0*/ function: () -> kotlin.Unit): test.PrivateMembers.SamInterface
// Static members
private final var staticField: kotlin.Int
private final /*synthesized*/ fun SamInterface(/*0*/ function: () -> kotlin.Unit): test.PrivateMembers.SamInterface
private open fun staticMethod(): kotlin.Unit
package test.PrivateMembers.Nested {
private open fun staticMethodInNested(): kotlin.Unit
}
}
@@ -1,15 +1,14 @@
package test
public trait RawTypeWithUpperBound {
public trait Bar {
public abstract fun f(/*0*/ p0: test.RawTypeWithUpperBound.Foo<out kotlin.CharSequence?>?): kotlin.Unit
}
public trait Foo</*0*/ T : kotlin.CharSequence?> {
}
}
package test.RawTypeWithUpperBound {
public /*synthesized*/ fun Bar(/*0*/ function: (test.RawTypeWithUpperBound.Foo<out kotlin.CharSequence?>?) -> kotlin.Unit): test.RawTypeWithUpperBound.Bar
// Static members
public final /*synthesized*/ fun Bar(/*0*/ function: (test.RawTypeWithUpperBound.Foo<out kotlin.CharSequence?>?) -> kotlin.Unit): test.RawTypeWithUpperBound.Bar
}
@@ -1,17 +1,16 @@
package test
public trait StringConstantInParam {
public final annotation class Anno : kotlin.Annotation {
public constructor Anno(/*0*/ value: kotlin.String)
public abstract fun value(): kotlin.String
}
test.StringConstantInParam.Anno(value = "hello": kotlin.String) public open class Class {
public constructor Class()
}
}
package test.StringConstantInParam {
public val HEL: kotlin.String = "hel"
// Static members
public final val HEL: kotlin.String = "hel"
}
@@ -1,31 +1,29 @@
package test
public trait Nested {
public trait Deeper1 {
public trait Runnable {
public abstract fun run(): kotlin.Unit
public abstract fun run2(): kotlin.Unit
}
}
public trait Deeper2 {
public trait Runnable {
public abstract fun run(): kotlin.Unit
}
// Static members
public final /*synthesized*/ fun Runnable(/*0*/ function: () -> kotlin.Unit): test.Nested.Deeper2.Runnable
}
public trait Runnable {
public abstract fun run(): kotlin.Unit
}
}
package test.Nested {
public /*synthesized*/ fun Runnable(/*0*/ function: () -> kotlin.Unit): test.Nested.Runnable
package test.Nested.Deeper2 {
public /*synthesized*/ fun Runnable(/*0*/ function: () -> kotlin.Unit): test.Nested.Deeper2.Runnable
}
// Static members
public final /*synthesized*/ fun Runnable(/*0*/ function: () -> kotlin.Unit): test.Nested.Runnable
}
@@ -1,22 +1,21 @@
package test
public trait SamSubinterfaceOfTwo {
public trait Sub : test.SamSubinterfaceOfTwo.Super1, test.SamSubinterfaceOfTwo.Super2<kotlin.String> {
public abstract override /*2*/ /*fake_override*/ fun f(): kotlin.String?
}
public trait Super1 {
public abstract fun f(): kotlin.CharSequence?
}
public trait Super2</*0*/ T> {
public abstract fun f(): T?
}
}
package test.SamSubinterfaceOfTwo {
public /*synthesized*/ fun Sub(/*0*/ function: () -> kotlin.String?): test.SamSubinterfaceOfTwo.Sub
public /*synthesized*/ fun Super1(/*0*/ function: () -> kotlin.CharSequence?): test.SamSubinterfaceOfTwo.Super1
public /*synthesized*/ fun </*0*/ T> Super2(/*0*/ function: () -> T?): test.SamSubinterfaceOfTwo.Super2<T>
// Static members
public final /*synthesized*/ fun Sub(/*0*/ function: () -> kotlin.String?): test.SamSubinterfaceOfTwo.Sub
public final /*synthesized*/ fun Super1(/*0*/ function: () -> kotlin.CharSequence?): test.SamSubinterfaceOfTwo.Super1
public final /*synthesized*/ fun </*0*/ T> Super2(/*0*/ function: () -> T?): test.SamSubinterfaceOfTwo.Super2<T>
}
@@ -4,9 +4,8 @@ public open class Basic {
public constructor Basic()
public final /*synthesized*/ fun foo(/*0*/ p0: (() -> kotlin.Unit)?): kotlin.Unit
public open fun foo(/*0*/ p0: java.lang.Runnable?): kotlin.Unit
}
package test.Basic {
public /*synthesized*/ fun bar(/*0*/ p0: (() -> kotlin.Unit)?): kotlin.Unit
// Static members
public final /*synthesized*/ fun bar(/*0*/ p0: (() -> kotlin.Unit)?): kotlin.Unit
public open fun bar(/*0*/ p0: java.lang.Runnable?): kotlin.Unit
}
@@ -1,19 +1,18 @@
package test
public trait DeepSamLoop {
public trait Bar {
public final /*synthesized*/ fun foo(/*0*/ p0: ((test.DeepSamLoop.Bar?) -> kotlin.Unit)?): kotlin.Unit
public abstract fun foo(/*0*/ p0: test.DeepSamLoop.Foo?): kotlin.Unit
}
public trait Foo {
public final /*synthesized*/ fun foo(/*0*/ p0: ((test.DeepSamLoop.Foo?) -> kotlin.Unit)?): kotlin.Unit
public abstract fun foo(/*0*/ p0: test.DeepSamLoop.Bar?): kotlin.Unit
}
}
package test.DeepSamLoop {
public /*synthesized*/ fun Bar(/*0*/ function: (test.DeepSamLoop.Foo?) -> kotlin.Unit): test.DeepSamLoop.Bar
public /*synthesized*/ fun Foo(/*0*/ function: (test.DeepSamLoop.Bar?) -> kotlin.Unit): test.DeepSamLoop.Foo
// Static members
public final /*synthesized*/ fun Bar(/*0*/ function: (test.DeepSamLoop.Foo?) -> kotlin.Unit): test.DeepSamLoop.Bar
public final /*synthesized*/ fun Foo(/*0*/ function: (test.DeepSamLoop.Bar?) -> kotlin.Unit): test.DeepSamLoop.Foo
}
@@ -2,9 +2,8 @@ package test
public open class SeveralSamParameters {
public constructor SeveralSamParameters()
}
package test.SeveralSamParameters {
public /*synthesized*/ fun findMaxAndInvokeCallback(/*0*/ p0: ((kotlin.String, kotlin.String) -> kotlin.Int)?, /*1*/ p1: kotlin.String?, /*2*/ p2: kotlin.String?, /*3*/ p3: (() -> kotlin.Unit)?): kotlin.String?
// Static members
public final /*synthesized*/ fun findMaxAndInvokeCallback(/*0*/ p0: ((kotlin.String, kotlin.String) -> kotlin.Int)?, /*1*/ p1: kotlin.String?, /*2*/ p2: kotlin.String?, /*3*/ p3: (() -> kotlin.Unit)?): kotlin.String?
public open fun findMaxAndInvokeCallback(/*0*/ p0: java.util.Comparator<kotlin.String>?, /*1*/ p1: kotlin.String?, /*2*/ p2: kotlin.String?, /*3*/ p3: java.lang.Runnable?): kotlin.String?
}
@@ -2,13 +2,12 @@ package test
public open class TypeParameterOfMethod {
public constructor TypeParameterOfMethod()
}
package test.TypeParameterOfMethod {
public /*synthesized*/ fun </*0*/ T> max(/*0*/ p0: ((T, T) -> kotlin.Int)?, /*1*/ p1: T?, /*2*/ p2: T?): T?
// Static members
public final /*synthesized*/ fun </*0*/ T> max(/*0*/ p0: ((T, T) -> kotlin.Int)?, /*1*/ p1: T?, /*2*/ p2: T?): T?
public open fun </*0*/ T> max(/*0*/ p0: java.util.Comparator<T>?, /*1*/ p1: T?, /*2*/ p2: T?): T?
public /*synthesized*/ fun </*0*/ T : kotlin.CharSequence?> max2(/*0*/ p0: ((T, T) -> kotlin.Int)?, /*1*/ p1: T?, /*2*/ p2: T?): T?
public final /*synthesized*/ fun </*0*/ T : kotlin.CharSequence?> max2(/*0*/ p0: ((T, T) -> kotlin.Int)?, /*1*/ p1: T?, /*2*/ p2: T?): T?
public open fun </*0*/ T : kotlin.CharSequence?> max2(/*0*/ p0: java.util.Comparator<T>?, /*1*/ p1: T?, /*2*/ p2: T?): T?
public /*synthesized*/ fun </*0*/ A : kotlin.CharSequence?, /*1*/ B : kotlin.List<A>?> method(/*0*/ p0: ((A, A) -> kotlin.Int)?, /*1*/ p1: B?): kotlin.Unit
public final /*synthesized*/ fun </*0*/ A : kotlin.CharSequence?, /*1*/ B : kotlin.List<A>?> method(/*0*/ p0: ((A, A) -> kotlin.Int)?, /*1*/ p1: B?): kotlin.Unit
public open fun </*0*/ A : kotlin.CharSequence?, /*1*/ B : kotlin.List<A>?> method(/*0*/ p0: java.util.Comparator<A>?, /*1*/ p1: B?): kotlin.Unit
}
@@ -1,18 +1,17 @@
package test
public trait AdapterDoesntOverrideDeclaration {
public trait Sub : test.AdapterDoesntOverrideDeclaration.Super {
public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: (() -> kotlin.Unit)?): kotlin.Unit
public final /*synthesized*/ fun foo(/*0*/ p0: (() -> kotlin.Unit)?): kotlin.Unit
public abstract fun foo(/*0*/ p0: java.lang.Runnable?): kotlin.Unit
}
public trait Super {
public abstract fun foo(/*0*/ p0: (() -> kotlin.Unit)?): kotlin.Unit
}
}
package test.AdapterDoesntOverrideDeclaration {
public /*synthesized*/ fun Super(/*0*/ function: ((() -> kotlin.Unit)?) -> kotlin.Unit): test.AdapterDoesntOverrideDeclaration.Super
// Static members
public final /*synthesized*/ fun Super(/*0*/ function: ((() -> kotlin.Unit)?) -> kotlin.Unit): test.AdapterDoesntOverrideDeclaration.Super
}
@@ -1,25 +1,24 @@
package test
public trait InheritedSameAdapters {
public trait Sub : test.InheritedSameAdapters.Super1, test.InheritedSameAdapters.Super2 {
public final override /*2*/ /*fake_override*/ fun foo(/*0*/ p0: (() -> kotlin.Unit)?): kotlin.Unit
public abstract override /*2*/ /*fake_override*/ fun foo(/*0*/ p0: java.lang.Runnable?): kotlin.Unit
}
public trait Super1 {
public final /*synthesized*/ fun foo(/*0*/ p0: (() -> kotlin.Unit)?): kotlin.Unit
public abstract fun foo(/*0*/ p0: java.lang.Runnable?): kotlin.Unit
}
public trait Super2 {
public final /*synthesized*/ fun foo(/*0*/ p0: (() -> kotlin.Unit)?): kotlin.Unit
public abstract fun foo(/*0*/ p0: java.lang.Runnable?): kotlin.Unit
}
}
package test.InheritedSameAdapters {
public /*synthesized*/ fun Sub(/*0*/ function: (java.lang.Runnable?) -> kotlin.Unit): test.InheritedSameAdapters.Sub
public /*synthesized*/ fun Super1(/*0*/ function: (java.lang.Runnable?) -> kotlin.Unit): test.InheritedSameAdapters.Super1
public /*synthesized*/ fun Super2(/*0*/ function: (java.lang.Runnable?) -> kotlin.Unit): test.InheritedSameAdapters.Super2
// Static members
public final /*synthesized*/ fun Sub(/*0*/ function: (java.lang.Runnable?) -> kotlin.Unit): test.InheritedSameAdapters.Sub
public final /*synthesized*/ fun Super1(/*0*/ function: (java.lang.Runnable?) -> kotlin.Unit): test.InheritedSameAdapters.Super1
public final /*synthesized*/ fun Super2(/*0*/ function: (java.lang.Runnable?) -> kotlin.Unit): test.InheritedSameAdapters.Super2
}
@@ -1,31 +1,30 @@
package test
public trait InheritedSameAdaptersWithSubstitution {
public trait Sub : test.InheritedSameAdaptersWithSubstitution.Super1, test.InheritedSameAdaptersWithSubstitution.Super2Substituted {
public final override /*2*/ /*fake_override*/ fun foo(/*0*/ p0: ((kotlin.String, kotlin.String) -> kotlin.Int)?): kotlin.Unit
public abstract override /*2*/ /*fake_override*/ fun foo(/*0*/ p0: java.util.Comparator<kotlin.String>?): kotlin.Unit
}
public trait Super1 {
public final /*synthesized*/ fun foo(/*0*/ p0: ((kotlin.String, kotlin.String) -> kotlin.Int)?): kotlin.Unit
public abstract fun foo(/*0*/ p0: java.util.Comparator<kotlin.String>?): kotlin.Unit
}
public trait Super2</*0*/ T> {
public final /*synthesized*/ fun foo(/*0*/ p0: ((T, T) -> kotlin.Int)?): kotlin.Unit
public abstract fun foo(/*0*/ p0: java.util.Comparator<T>?): kotlin.Unit
}
public trait Super2Substituted : test.InheritedSameAdaptersWithSubstitution.Super2<kotlin.String> {
public final override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: ((kotlin.String, kotlin.String) -> kotlin.Int)?): kotlin.Unit
public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: java.util.Comparator<kotlin.String>?): kotlin.Unit
}
}
package test.InheritedSameAdaptersWithSubstitution {
public /*synthesized*/ fun Sub(/*0*/ function: (java.util.Comparator<kotlin.String>?) -> kotlin.Unit): test.InheritedSameAdaptersWithSubstitution.Sub
public /*synthesized*/ fun Super1(/*0*/ function: (java.util.Comparator<kotlin.String>?) -> kotlin.Unit): test.InheritedSameAdaptersWithSubstitution.Super1
public /*synthesized*/ fun </*0*/ T> Super2(/*0*/ function: (java.util.Comparator<T>?) -> kotlin.Unit): test.InheritedSameAdaptersWithSubstitution.Super2<T>
public /*synthesized*/ fun Super2Substituted(/*0*/ function: (java.util.Comparator<kotlin.String>?) -> kotlin.Unit): test.InheritedSameAdaptersWithSubstitution.Super2Substituted
// Static members
public final /*synthesized*/ fun Sub(/*0*/ function: (java.util.Comparator<kotlin.String>?) -> kotlin.Unit): test.InheritedSameAdaptersWithSubstitution.Sub
public final /*synthesized*/ fun Super1(/*0*/ function: (java.util.Comparator<kotlin.String>?) -> kotlin.Unit): test.InheritedSameAdaptersWithSubstitution.Super1
public final /*synthesized*/ fun </*0*/ T> Super2(/*0*/ function: (java.util.Comparator<T>?) -> kotlin.Unit): test.InheritedSameAdaptersWithSubstitution.Super2<T>
public final /*synthesized*/ fun Super2Substituted(/*0*/ function: (java.util.Comparator<kotlin.String>?) -> kotlin.Unit): test.InheritedSameAdaptersWithSubstitution.Super2Substituted
}
@@ -1,19 +1,18 @@
package test
public trait InheritedSimple {
public trait Sub : test.InheritedSimple.Super {
public final override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: (() -> kotlin.Unit)?): kotlin.Unit
public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: java.lang.Runnable?): kotlin.Unit
}
public trait Super {
public final /*synthesized*/ fun foo(/*0*/ p0: (() -> kotlin.Unit)?): kotlin.Unit
public abstract fun foo(/*0*/ p0: java.lang.Runnable?): kotlin.Unit
}
}
package test.InheritedSimple {
public /*synthesized*/ fun Sub(/*0*/ function: (java.lang.Runnable?) -> kotlin.Unit): test.InheritedSimple.Sub
public /*synthesized*/ fun Super(/*0*/ function: (java.lang.Runnable?) -> kotlin.Unit): test.InheritedSimple.Super
// Static members
public final /*synthesized*/ fun Sub(/*0*/ function: (java.lang.Runnable?) -> kotlin.Unit): test.InheritedSimple.Sub
public final /*synthesized*/ fun Super(/*0*/ function: (java.lang.Runnable?) -> kotlin.Unit): test.InheritedSimple.Super
}
@@ -2,17 +2,16 @@ package test
public open class RawSuperType {
public constructor RawSuperType()
public open inner class Derived : test.RawSuperType.Super<kotlin.Any?> {
public constructor Derived()
public open override /*1*/ fun foo(/*0*/ p0: kotlin.Any?): kotlin.Unit
}
public trait Super</*0*/ T> {
public abstract fun foo(/*0*/ p0: T?): kotlin.Unit
}
}
package test.RawSuperType {
public /*synthesized*/ fun </*0*/ T> Super(/*0*/ function: (T?) -> kotlin.Unit): test.RawSuperType.Super<T>
// Static members
public final /*synthesized*/ fun </*0*/ T> Super(/*0*/ function: (T?) -> kotlin.Unit): test.RawSuperType.Super<T>
}
@@ -4,17 +4,16 @@ public /*synthesized*/ fun TwoSuperclassesInconsistentGenericTypes(/*0*/ functio
public trait TwoSuperclassesInconsistentGenericTypes {
public abstract fun foo(): kotlin.MutableList<kotlin.String?>
public trait Other {
public abstract fun foo(): kotlin.MutableList<kotlin.String>?
}
public open class Sub : test.TwoSuperclassesInconsistentGenericTypes, test.TwoSuperclassesInconsistentGenericTypes.Other {
public constructor Sub()
public open override /*2*/ fun foo(): kotlin.MutableList<kotlin.String>
}
}
package test.TwoSuperclassesInconsistentGenericTypes {
public /*synthesized*/ fun Other(/*0*/ function: () -> kotlin.MutableList<kotlin.String>?): test.TwoSuperclassesInconsistentGenericTypes.Other
// Static members
public final /*synthesized*/ fun Other(/*0*/ function: () -> kotlin.MutableList<kotlin.String>?): test.TwoSuperclassesInconsistentGenericTypes.Other
}
@@ -1,22 +1,21 @@
package test
public trait TwoSuperclassesVarargAndNot {
public trait Sub : test.TwoSuperclassesVarargAndNot.Super1, test.TwoSuperclassesVarargAndNot.Super2 {
public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ vararg p0: kotlin.String? /*kotlin.Array<kotlin.String?>*/): kotlin.Unit
public abstract override /*1*/ fun foo(/*0*/ s: kotlin.Array<out kotlin.String?>?): kotlin.Unit
}
public trait Super1 {
public abstract fun foo(/*0*/ vararg p0: kotlin.String? /*kotlin.Array<kotlin.String?>*/): kotlin.Unit
}
public trait Super2 {
public abstract fun foo(/*0*/ s: kotlin.Array<out kotlin.String?>?): kotlin.Unit
}
}
package test.TwoSuperclassesVarargAndNot {
public /*synthesized*/ fun Super1(/*0*/ function: (kotlin.Array<kotlin.String?>) -> kotlin.Unit): test.TwoSuperclassesVarargAndNot.Super1
public /*synthesized*/ fun Super2(/*0*/ function: (kotlin.Array<out kotlin.String?>?) -> kotlin.Unit): test.TwoSuperclassesVarargAndNot.Super2
// Static members
public final /*synthesized*/ fun Super1(/*0*/ function: (kotlin.Array<kotlin.String?>) -> kotlin.Unit): test.TwoSuperclassesVarargAndNot.Super1
public final /*synthesized*/ fun Super2(/*0*/ function: (kotlin.Array<out kotlin.String?>?) -> kotlin.Unit): test.TwoSuperclassesVarargAndNot.Super2
}
@@ -2,21 +2,14 @@ package test
public open class DeeplyNestedStatic {
public constructor DeeplyNestedStatic()
public open class Foo {
public constructor Foo()
public open class Bar {
public constructor Bar()
}
}
}
package test.DeeplyNestedStatic {
package test.DeeplyNestedStatic.Foo {
package test.DeeplyNestedStatic.Foo.Bar {
// Static members
public open fun method(): kotlin.Unit
}
}
@@ -3,8 +3,7 @@ package test
public open class Simple {
public constructor Simple()
public open fun foo(): kotlin.Unit
}
package test.Simple {
// Static members
public open fun bar(): kotlin.Unit
}
@@ -2,8 +2,7 @@ package test
public open class StaticFinal {
public constructor StaticFinal()
}
package test.StaticFinal {
public val foo: kotlin.String = "aaa"
// Static members
public final val foo: kotlin.String = "aaa"
}
@@ -4,29 +4,28 @@ public final enum class StaticMembersInEnum : kotlin.Enum<test.StaticMembersInEn
private constructor StaticMembersInEnum()
public final override /*1*/ /*fake_override*/ fun name(): kotlin.String
public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int
public class object <class-object-for-StaticMembersInEnum> {
private constructor <class-object-for-StaticMembersInEnum>()
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): test.StaticMembersInEnum
public final /*synthesized*/ fun values(): kotlin.Array<test.StaticMembersInEnum>
}
public enum entry ENTRY : test.StaticMembersInEnum {
private constructor ENTRY()
public final override /*1*/ /*fake_override*/ fun name(): kotlin.String
public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int
public class object <class-object-for-ENTRY> : test.StaticMembersInEnum.ENTRY {
private constructor <class-object-for-ENTRY>()
public final override /*1*/ /*fake_override*/ fun name(): kotlin.String
public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int
}
}
}
package test.StaticMembersInEnum {
public val CONSTANT: test.StaticMembersInEnum
public var STATIC_FIELD: kotlin.Int
// Static members
public final val CONSTANT: test.StaticMembersInEnum
public final var STATIC_FIELD: kotlin.Int
public open fun foo(): kotlin.Unit
public open fun valueOf(/*0*/ p0: kotlin.Int): kotlin.Unit
public open fun values(/*0*/ p0: kotlin.Int): kotlin.Unit
@@ -6,6 +6,9 @@ public fun topLevelFunction(): kotlin.Unit
public open class JavaClass {
public constructor JavaClass()
public open fun instanceMethod(): kotlin.Unit
// Static members
public open fun staticMethod(): kotlin.Unit
}
public final class KotlinClass {
@@ -16,18 +19,13 @@ public trait SamInterface {
public abstract fun instanceMethod(): kotlin.Unit
}
package test.JavaClass {
public open fun staticMethod(): kotlin.Unit
}
package test.sub {
public open class JavaClassInSubpackage {
public constructor JavaClassInSubpackage()
public open fun instanceMethod(): kotlin.Unit
}
package test.sub.JavaClassInSubpackage {
// Static members
public open fun staticMethod(): kotlin.Unit
}
}
@@ -6151,6 +6151,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("privateNestedClassStaticMember.kt")
public void testPrivateNestedClassStaticMember() throws Exception {
doTest("compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.kt");
}
@TestMetadata("protectedStaticSamePackage.kt")
public void testProtectedStaticSamePackage() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/protectedStaticSamePackage.kt");
@@ -20,8 +20,6 @@ import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassDescriptor;
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassStaticsPackageFragmentDescriptor;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
@@ -170,13 +168,6 @@ public class DescriptorValidator {
public Boolean visitPackageFragmentDescriptor(
PackageFragmentDescriptor descriptor, DiagnosticCollector collector
) {
if (descriptor instanceof JavaClassStaticsPackageFragmentDescriptor) {
JavaClassDescriptor correspondingClass = ((JavaClassStaticsPackageFragmentDescriptor) descriptor).getCorrespondingClass();
JavaClassStaticsPackageFragmentDescriptor correspondingPackageFragment = correspondingClass.getCorrespondingPackageFragment();
if (correspondingPackageFragment != descriptor) {
report(collector, descriptor, "Corresponding class bound to another descriptor: " + correspondingPackageFragment);
}
}
validateScope(descriptor.getMemberScope(), collector);
return true;
}
@@ -251,17 +242,6 @@ public class DescriptorValidator {
}
}
if (descriptor instanceof JavaClassDescriptor) {
JavaClassStaticsPackageFragmentDescriptor
correspondingPackageFragment = ((JavaClassDescriptor) descriptor).getCorrespondingPackageFragment();
if (correspondingPackageFragment != null) {
JavaClassDescriptor correspondingClass = correspondingPackageFragment.getCorrespondingClass();
if (correspondingClass != descriptor) {
report(collector, descriptor, "Corresponding package bound to another descriptor: " + correspondingClass);
}
}
}
return true;
}
@@ -95,6 +95,12 @@ public class RecursiveDescriptorComparator {
if (descriptor instanceof ClassDescriptor) {
ClassDescriptor klass = (ClassDescriptor) descriptor;
appendSubDescriptors(klass.getDefaultType().getMemberScope(), getConstructorsAndClassObject(klass), printer);
JetScope staticScope = klass.getStaticScope();
if (!staticScope.getAllDescriptors().isEmpty()) {
printer.println();
printer.println("// Static members");
appendSubDescriptors(staticScope, Collections.<DeclarationDescriptor>emptyList(), printer);
}
}
else if (descriptor instanceof PackageFragmentDescriptor) {
appendSubDescriptors(((PackageFragmentDescriptor) descriptor).getMemberScope(),
@@ -16,29 +16,16 @@
package org.jetbrains.jet.lang.resolve.java
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor
import org.jetbrains.jet.lang.descriptors.*
import org.jetbrains.jet.lang.resolve.java.structure.*
import org.jetbrains.jet.lang.resolve.java.lazy.LazyJavaPackageFragmentProvider
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
import org.jetbrains.jet.lang.resolve.scopes.JetScope
import org.jetbrains.jet.lang.resolve.java.structure.JavaField
import org.jetbrains.jet.lang.resolve.java.structure.JavaMember
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
import org.jetbrains.jet.lang.resolve.java.sources.JavaSourceElement
import org.jetbrains.jet.lang.resolve.java.structure.JavaElement
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorWithSource
public class JavaDescriptorResolver(public val packageFragmentProvider: LazyJavaPackageFragmentProvider, private val module: ModuleDescriptor) {
public fun resolveClass(javaClass: JavaClass): ClassDescriptor? {
return packageFragmentProvider.getClass(javaClass)
}
public fun getPackageFragment(javaClass: JavaClass): PackageFragmentDescriptor? {
return packageFragmentProvider.getPackageFragment(javaClass)
}
}
public fun JavaDescriptorResolver.resolveMethod(method: JavaMethod): FunctionDescriptor? {
@@ -54,12 +41,12 @@ public fun JavaDescriptorResolver.resolveField(field: JavaField): PropertyDescri
return getContainingScope(field)?.getProperties(field.getName())?.findByJavaElement(field) as? PropertyDescriptor
}
private fun JavaDescriptorResolver.getContainingScope(method: JavaMember): JetScope? {
val containingClass = method.getContainingClass()
return if (method.isStatic())
getPackageFragment(containingClass)?.getMemberScope()
private fun JavaDescriptorResolver.getContainingScope(member: JavaMember): JetScope? {
val containingClass = resolveClass(member.getContainingClass())
return if (member.isStatic())
containingClass?.getStaticScope()
else
resolveClass(containingClass)?.getDefaultType()?.getMemberScope()
containingClass?.getDefaultType()?.getMemberScope()
}
private fun <T : DeclarationDescriptorWithSource> Collection<T>.findByJavaElement(javaElement: JavaElement): T? {
@@ -17,10 +17,8 @@
package org.jetbrains.jet.lang.resolve.java;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassStaticsPackageFragmentDescriptor;
public class JavaVisibilities {
private JavaVisibilities() {
@@ -61,20 +59,9 @@ public class JavaVisibilities {
ClassDescriptor fromClass = DescriptorUtils.getParentOfType(from, ClassDescriptor.class, false);
if (fromClass == null) return false;
ClassDescriptor whatClass;
// protected static class
if (what instanceof ClassDescriptor) {
DeclarationDescriptor containingDeclaration = what.getContainingDeclaration();
assert containingDeclaration instanceof ClassDescriptor : "Only static nested classes can have protected_static visibility";
whatClass = (ClassDescriptor) containingDeclaration;
}
// protected static function or property
else {
DeclarationDescriptor whatDeclarationDescriptor = what.getContainingDeclaration();
assert whatDeclarationDescriptor instanceof JavaClassStaticsPackageFragmentDescriptor
: "Only static declarations can have protected_static visibility";
whatClass = ((JavaClassStaticsPackageFragmentDescriptor) whatDeclarationDescriptor).getCorrespondingClass();
}
DeclarationDescriptor containingDeclaration = what.getContainingDeclaration();
assert containingDeclaration instanceof ClassDescriptor : "Only class members can have protected_static visibility";
ClassDescriptor whatClass = (ClassDescriptor) containingDeclaration;
if (DescriptorUtils.isSubclass(fromClass, whatClass)) {
return true;
@@ -134,18 +121,8 @@ public class JavaVisibilities {
};
private static boolean areInSamePackage(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
PackageFragmentDescriptor whatPackage = getPackageStaticsAware(first);
PackageFragmentDescriptor fromPackage = getPackageStaticsAware(second);
PackageFragmentDescriptor whatPackage = DescriptorUtils.getParentOfType(first, PackageFragmentDescriptor.class, false);
PackageFragmentDescriptor fromPackage = DescriptorUtils.getParentOfType(second, PackageFragmentDescriptor.class, false);
return fromPackage != null && whatPackage != null && whatPackage.getFqName().equals(fromPackage.getFqName());
}
@Nullable
private static PackageFragmentDescriptor getPackageStaticsAware(@NotNull DeclarationDescriptor member) {
PackageFragmentDescriptor packageFragment = DescriptorUtils.getParentOfType(member, PackageFragmentDescriptor.class, false);
if (packageFragment instanceof JavaClassStaticsPackageFragmentDescriptor) {
ClassDescriptor classForPackage = ((JavaClassStaticsPackageFragmentDescriptor) packageFragment).getCorrespondingClass();
return DescriptorUtils.getParentOfType(classForPackage, PackageFragmentDescriptor.class, false);
}
return packageFragment;
}
}
@@ -23,7 +23,4 @@ import org.jetbrains.jet.lang.types.JetType;
public interface JavaClassDescriptor extends ClassDescriptor {
@Nullable
JetType getFunctionTypeForSamInterface();
@Nullable
JavaClassStaticsPackageFragmentDescriptor getCorrespondingPackageFragment();
}
@@ -19,7 +19,3 @@ package org.jetbrains.jet.lang.resolve.java.descriptor
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor
public trait JavaPackageFragmentDescriptor : PackageFragmentDescriptor
public trait JavaClassStaticsPackageFragmentDescriptor : JavaPackageFragmentDescriptor {
public fun getCorrespondingClass(): JavaClassDescriptor
}
@@ -21,13 +21,9 @@ import org.jetbrains.jet.storage.MemoizedFunctionToNullable
import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.LazyPackageFragmentForJavaPackage
import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.LazyPackageFragmentForJavaClass
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils
import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.*
import org.jetbrains.jet.lang.resolve.java.resolver.JavaPackageFragmentProvider
import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.LazyJavaPackageFragment
import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass
import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.LazyJavaClassDescriptor
public class LazyJavaPackageFragmentProvider(
outerContext: GlobalJavaResolverContext,
@@ -53,20 +49,15 @@ public class LazyJavaPackageFragmentProvider(
override fun getModule() = _module
private val _packageFragments: MemoizedFunctionToNullable<FqName, LazyJavaPackageFragment> = c.storageManager.createMemoizedFunctionWithNullableValues {
fqName ->
val jPackage = c.finder.findPackage(fqName)
if (jPackage != null) {
LazyPackageFragmentForJavaPackage(c, _module, jPackage)
}
else {
val jClass = c.findJavaClass(fqName)
if (jClass != null) {
packageFragmentsForClasses(jClass)
private val _packageFragments: MemoizedFunctionToNullable<FqName, LazyJavaPackageFragment> =
c.storageManager.createMemoizedFunctionWithNullableValues {
fqName ->
val jPackage = c.finder.findPackage(fqName)
if (jPackage != null) {
LazyJavaPackageFragment(c, _module, jPackage)
}
else null
}
else null
}
}
private val topLevelClasses = c.storageManager.createMemoizedFunctionWithNullableValues @lambda {
(jClass: JavaClass): LazyJavaClassDescriptor? ->
@@ -84,17 +75,7 @@ public class LazyJavaPackageFragmentProvider(
)
}
private val packageFragmentsForClasses: MemoizedFunctionToNullable<JavaClass, LazyPackageFragmentForJavaClass> = c.storageManager.createMemoizedFunctionWithNullableValues {
jClass ->
if (DescriptorResolverUtils.hasStaticMembers(jClass)) {
val correspondingClass = c.javaClassResolver.resolveClass(jClass)
if (correspondingClass != null) LazyPackageFragmentForJavaClass(c, _module, jClass) else null
}
else null
}
override fun getPackageFragment(fqName: FqName) = _packageFragments(fqName)
fun getPackageFragment(javaClass: JavaClass) = packageFragmentsForClasses(javaClass)
fun getPackageFragment(fqName: FqName) = _packageFragments(fqName)
override fun getPackageFragments(fqName: FqName) = getPackageFragment(fqName)?.let {listOf(it)}.orEmpty()
@@ -120,4 +101,4 @@ public class LazyJavaPackageFragmentProvider(
return outerClassScope?.getClassifier(javaClass.getName()) as? ClassDescriptor
}
}
}
}
@@ -16,16 +16,13 @@
package org.jetbrains.jet.lang.resolve.java.lazy.descriptors
import org.jetbrains.jet.lang.descriptors.*
import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.lang.descriptors.impl.ClassDescriptorBase
import org.jetbrains.jet.lang.resolve.scopes.JetScope
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor
import org.jetbrains.jet.lang.types.JetType
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.types.TypeConstructor
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
import org.jetbrains.jet.lang.resolve.java.lazy.LazyJavaResolverContextWithTypes
import org.jetbrains.jet.lang.resolve.java.lazy.child
import org.jetbrains.jet.lang.resolve.java.resolver.TypeUsage
@@ -36,18 +33,13 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.utils.*
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor
import org.jetbrains.jet.lang.types.TypeUtils
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassDescriptor
import org.jetbrains.jet.lang.descriptors.Modality
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
import org.jetbrains.jet.lang.descriptors.ClassKind
import java.util.ArrayList
import org.jetbrains.jet.lang.types.checker.JetTypeChecker
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassStaticsPackageFragmentDescriptor
import org.jetbrains.jet.lang.types.AbstractClassTypeConstructor
import org.jetbrains.jet.lang.descriptors.impl.EnumClassObjectDescriptor
import org.jetbrains.jet.lang.resolve.scopes.StaticScopeForKotlinClass
class LazyJavaClassDescriptor(
private val outerC: LazyJavaResolverContextWithTypes,
@@ -91,7 +83,8 @@ class LazyJavaClassDescriptor(
private val _innerClassesScope = InnerClassesScopeWrapper(getScopeForMemberLookup())
override fun getUnsubstitutedInnerClassesScope(): JetScope = _innerClassesScope
override fun getStaticScope(): JetScope = StaticScopeForKotlinClass(this) // TODO
private val _staticScope = LazyJavaStaticClassScope(c, jClass, this)
override fun getStaticScope(): JetScope = _staticScope
override fun getUnsubstitutedPrimaryConstructor(): ConstructorDescriptor? = null
@@ -102,9 +95,6 @@ class LazyJavaClassDescriptor(
else null
}
override fun getCorrespondingPackageFragment() =
c.packageFragmentProvider.getPackageFragment(fqName) as? JavaClassStaticsPackageFragmentDescriptor
override fun getClassObjectDescriptor(): ClassDescriptor? = _classObjectDescriptor()
override fun getClassObjectType(): JetType? = getClassObjectDescriptor()?.let { d -> d.getDefaultType() }
@@ -18,55 +18,21 @@ package org.jetbrains.jet.lang.resolve.java.lazy.descriptors
import org.jetbrains.jet.lang.resolve.java.lazy.LazyJavaResolverContext
import org.jetbrains.jet.lang.resolve.java.structure.JavaPackage
import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass
import org.jetbrains.kotlin.util.sure
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaPackageFragmentDescriptor
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassStaticsPackageFragmentDescriptor
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassDescriptor
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
import org.jetbrains.jet.lang.descriptors.impl.PackageFragmentDescriptorImpl
import kotlin.properties.Delegates
class LazyPackageFragmentForJavaPackage(
c: LazyJavaResolverContext,
containingDeclaration: ModuleDescriptor,
class LazyJavaPackageFragment(
private val c: LazyJavaResolverContext,
module: ModuleDescriptor,
private val jPackage: JavaPackage
) : LazyJavaPackageFragment(c, containingDeclaration, jPackage.getFqName()) {
override fun createMemberScope() = LazyPackageFragmentScopeForJavaPackage(c, jPackage, this)
}
public class LazyPackageFragmentForJavaClass(
c: LazyJavaResolverContext,
containingDeclaration: ModuleDescriptor,
private val jClass: JavaClass
) : JavaClassStaticsPackageFragmentDescriptor,
LazyJavaPackageFragment(c, containingDeclaration,
jClass.getFqName().sure("Attempt to build a package of an anonymous/local class: $jClass")) {
override fun createMemberScope() = LazyPackageFragmentScopeForJavaClass(c, jClass, this)
override fun getCorrespondingClass(): JavaClassDescriptor {
val classDescriptor = c.javaClassResolver.resolveClass(jClass)
if (classDescriptor !is JavaClassDescriptor) {
throw AssertionError("Corresponding class not found for package with static members: $this")
}
return classDescriptor
}
}
abstract class LazyJavaPackageFragment(
protected val c: LazyJavaResolverContext,
containingDeclaration: ModuleDescriptor,
fqName: FqName
) : PackageFragmentDescriptorImpl(containingDeclaration, fqName),
) : PackageFragmentDescriptorImpl(module, jPackage.getFqName()),
JavaPackageFragmentDescriptor, LazyJavaDescriptor
{
private val _memberScope by Delegates.lazy { createMemberScope() }
private val _memberScope by Delegates.lazy { LazyPackageFragmentScopeForJavaPackage(c, jPackage, this) }
abstract fun createMemberScope(): LazyJavaPackageFragmentScope
override fun getMemberScope() = _memberScope
override fun getMemberScope(): LazyJavaPackageFragmentScope = _memberScope
override fun toString() = "lazy java package fragment: " + fqName
}
override fun toString() = "lazy java package fragment: $fqName"
}
@@ -28,7 +28,6 @@ import org.jetbrains.jet.utils.flatten
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass
import org.jetbrains.kotlin.util.inn
import org.jetbrains.kotlin.util.sure
import org.jetbrains.jet.lang.resolve.java.lazy.findJavaClass
import org.jetbrains.jet.lang.resolve.java.lazy.findClassInJava
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils
import org.jetbrains.jet.lang.resolve.scopes.JetScope
@@ -40,16 +39,16 @@ import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptor
import org.jetbrains.jet.lang.resolve.name.SpecialNames
import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass
public abstract class LazyJavaPackageFragmentScope(
public abstract class LazyJavaStaticScope(
c: LazyJavaResolverContext,
packageFragment: LazyJavaPackageFragment
) : LazyJavaMemberScope(c.withTypes(), packageFragment) {
descriptor: ClassOrPackageFragmentDescriptor
) : LazyJavaMemberScope(c.withTypes(), descriptor) {
protected val fqName: FqName = DescriptorUtils.getFqName(packageFragment).toSafe()
protected val fqName: FqName = DescriptorUtils.getFqName(descriptor).toSafe()
protected fun computeMemberIndexForSamConstructors(delegate: MemberIndex): MemberIndex = object : MemberIndex by delegate {
override fun getAllMethodNames(): Collection<Name> {
val jClass = c.findJavaClass(fqName)
val jClass = c.findClassInJava(fqName).jClass
return delegate.getAllMethodNames() +
// For SAM-constructors
getAllClassNames() +
@@ -76,11 +75,11 @@ public abstract class LazyJavaPackageFragmentScope(
//no undeclared properties
}
override fun getContainingDeclaration() = super.getContainingDeclaration() as LazyJavaPackageFragment
override fun getContainingDeclaration() = super.getContainingDeclaration() as ClassOrPackageFragmentDescriptor
fun ClassifierDescriptor.createSamConstructor(): SamConstructorDescriptor? {
if (this is LazyJavaClassDescriptor && this.getFunctionTypeForSamInterface() != null) {
return SingleAbstractMethodUtils.createSamConstructorFunction(this@LazyJavaPackageFragmentScope.getContainingDeclaration(), this)
return SingleAbstractMethodUtils.createSamConstructorFunction(this@LazyJavaStaticScope.getContainingDeclaration(), this)
}
return null
}
@@ -89,8 +88,8 @@ public abstract class LazyJavaPackageFragmentScope(
public class LazyPackageFragmentScopeForJavaPackage(
c: LazyJavaResolverContext,
private val jPackage: JavaPackage,
packageFragment: LazyPackageFragmentForJavaPackage
) : LazyJavaPackageFragmentScope(c, packageFragment) {
packageFragment: LazyJavaPackageFragment
) : LazyJavaStaticScope(c, packageFragment) {
// TODO: Storing references is a temporary hack until modules infrastructure is implemented.
// See JetTypeMapperWithOutDirectories for details
@@ -143,7 +142,7 @@ public class LazyPackageFragmentScopeForJavaPackage(
listOf(
// We do not filter by hasStaticMembers() because it's slow (e.g. it triggers light class generation),
// and there's no harm in having some names in the result that can not be resolved
jPackage.getClasses().map { c -> c.getFqName().sure("Toplevel class has no fqName: $c}") },
jPackage.getClasses().map { c -> c.getFqName().sure("Toplevel class has no fqName: $c") },
jPackage.getSubPackages().map { sp -> sp.getFqName() }
).flatten()
},
@@ -162,32 +161,30 @@ public class LazyPackageFragmentScopeForJavaPackage(
override fun getAllPropertyNames() = Collections.emptyList<Name>()
}
public class LazyPackageFragmentScopeForJavaClass(
public class LazyJavaStaticClassScope(
c: LazyJavaResolverContext,
private val jClass: JavaClass,
packageFragment: LazyPackageFragmentForJavaClass
) : LazyJavaPackageFragmentScope(c, packageFragment) {
descriptor: LazyJavaClassDescriptor
) : LazyJavaStaticScope(c, descriptor) {
override fun computeMemberIndex(): MemberIndex = computeMemberIndexForSamConstructors(ClassMemberIndex(jClass, { m -> m.isStatic() }))
// nested classes are loaded as members of their outer classes, not packages
override fun getAllClassNames(): Collection<Name> = listOf()
override fun getClassifier(name: Name): ClassifierDescriptor? = null
// We do not filter by hasStaticMembers() because it's slow (e.g. it triggers light class generation),
// and there's no harm in having some names in the result that can not be resolved
override fun getSubPackages(): Collection<FqName> = jClass.getInnerClasses().stream()
.filter { c -> c.isStatic() }
.map { c -> c.getFqName().sure("Nested class has no fqName: $c}") }.toList()
.filter { c -> c.isStatic() }
.map { c -> c.getFqName().sure("Nested class has no fqName: $c") }.toList()
override fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name) {
//NOTE: assuming that all sam constructors are created for interfaces which are static and should be placed in this scope
val samConstructor = getContainingDeclaration().getCorrespondingClass().getUnsubstitutedInnerClassesScope().getClassifier(name)
?.createSamConstructor()
val samConstructor = getContainingDeclaration().getUnsubstitutedInnerClassesScope().getClassifier(name)?.createSamConstructor()
if (samConstructor != null) {
result.add(samConstructor)
}
}
override fun getContainingDeclaration() = super.getContainingDeclaration() as LazyPackageFragmentForJavaClass
override fun getContainingDeclaration() = super.getContainingDeclaration() as LazyJavaClassDescriptor
}
@@ -24,7 +24,6 @@ import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.LazyJavaTypeParamete
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils
import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass
import org.jetbrains.jet.lang.resolve.resolveTopLevelClass
@@ -65,8 +64,6 @@ class LazyJavaTypeParameterResolver(
}
}
fun LazyJavaResolverContext.findJavaClass(fqName: FqName): JavaClass? = findClassInJava(fqName).jClass
data class JavaClassLookupResult(val jClass: JavaClass? = null, val kClass: ClassDescriptor? = null)
fun LazyJavaResolverContext.lookupBinaryClass(javaClass: JavaClass): ClassDescriptor? {
@@ -23,16 +23,13 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
import org.jetbrains.jet.lang.resolve.OverridingUtil;
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils;
import org.jetbrains.jet.lang.resolve.java.structure.*;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.TypeConstructor;
import org.jetbrains.jet.lang.types.TypeProjection;
import org.jetbrains.jet.lang.types.TypeProjectionImpl;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import java.util.*;
@@ -262,29 +259,4 @@ public final class DescriptorResolverUtils {
}
return TypeSubstitutor.create(typeSubstitutionContext);
}
public static boolean hasStaticMembers(@NotNull JavaClass javaClass) {
for (JavaMethod method : javaClass.getMethods()) {
if (method.isStatic() && !shouldBeInEnumClassObject(method)) {
return true;
}
}
for (JavaField field : javaClass.getFields()) {
if (field.isStatic() && !field.isEnumEntry()) {
return true;
}
}
for (JavaClass nestedClass : javaClass.getInnerClasses()) {
if (SingleAbstractMethodUtils.isSamInterface(nestedClass)) {
return true;
}
if (nestedClass.isStatic() && hasStaticMembers(nestedClass)) {
return true;
}
}
return false;
}
}
@@ -17,16 +17,10 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.descriptors.PackageFragmentProvider;
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaPackageFragmentDescriptor;
import org.jetbrains.jet.lang.resolve.name.FqName;
public interface JavaPackageFragmentProvider extends PackageFragmentProvider {
@Nullable
JavaPackageFragmentDescriptor getPackageFragment(@NotNull FqName fqName);
@NotNull
ModuleDescriptor getModule();
}
@@ -280,10 +280,6 @@ public class SingleAbstractMethodUtils {
return new TypeParameters(typeParameters, typeParametersSubstitutor);
}
public static boolean isSamInterface(@NotNull JavaClass javaClass) {
return getSamInterfaceMethod(javaClass) != null;
}
// Returns null if not SAM interface
@Nullable
public static JavaMethod getSamInterfaceMethod(@NotNull JavaClass javaClass) {
@@ -24,14 +24,10 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
import org.jetbrains.jet.plugin.quickfix.ImportInsertHelper;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.HashSet;
import com.intellij.psi.util.PsiTreeUtil
import java.util.ArrayList
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaPropertyDescriptor
import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.LazyPackageFragmentForJavaClass
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaMethodDescriptor
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiDocumentManager
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
@@ -245,19 +241,9 @@ public object ShortenReferences {
refExpression: JetReferenceExpression,
bindingContext: BindingContext
): PsiElement {
val receiverExpression = qualifiedExpression.getReceiverExpression()
val target = bindingContext[BindingContext.REFERENCE_TARGET, refExpression]
if (target != null) {
if ((target is JavaPropertyDescriptor || target is JavaMethodDescriptor) && receiverExpression is JetDotQualifiedExpression) {
val containingDescriptor = target.getContainingDeclaration()
if (containingDescriptor is LazyPackageFragmentForJavaClass) {
return shortenIfPossibleByDescriptor(receiverExpression, containingDescriptor.getCorrespondingClass(), bindingContext)
}
}
return shortenIfPossibleByDescriptor(qualifiedExpression, target, bindingContext)
}
return qualifiedExpression
if (target == null) return qualifiedExpression
return shortenIfPossibleByDescriptor(qualifiedExpression, target, bindingContext)
}
private fun instantiatedClass(calleeExpression: JetReferenceExpression): ClassDescriptor? {
@@ -18,16 +18,9 @@ package org.jetbrains.jet.plugin.completion.smart
import com.intellij.codeInsight.lookup.LookupElement
import org.jetbrains.jet.lang.types.TypeUtils
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.descriptors.*
import org.jetbrains.jet.lang.resolve.scopes.JetScope
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorWithVisibility
import org.jetbrains.jet.lang.descriptors.Visibilities
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
import org.jetbrains.jet.lang.descriptors.ClassKind
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassDescriptor
import org.jetbrains.jet.lang.resolve.DescriptorUtils
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
import com.intellij.codeInsight.lookup.LookupElementDecorator
import com.intellij.codeInsight.lookup.LookupElementPresentation
import org.jetbrains.jet.renderer.DescriptorRenderer
@@ -95,12 +88,7 @@ class StaticMembers(val bindingContext: BindingContext, val resolveSession: Reso
collection.addLookupElements(expectedInfos, classifier, { createLookupElement(descriptor, classDescriptor) })
}
if (classDescriptor is JavaClassDescriptor) {
val pseudoPackage = classDescriptor.getCorrespondingPackageFragment()
if (pseudoPackage != null) {
pseudoPackage.getMemberScope().getAllDescriptors().forEach(::processMember)
}
}
classDescriptor.getStaticScope().getAllDescriptors().forEach(::processMember)
val classObject = classDescriptor.getClassObjectDescriptor()
if (classObject != null) {