Constructor for protected_static nested class should be protected
This commit is contained in:
+8
@@ -118,6 +118,14 @@ public final class DescriptorResolverUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Visibility getConstructorVisibility(ClassDescriptor classDescriptor) {
|
||||||
|
Visibility containingClassVisibility = classDescriptor.getVisibility();
|
||||||
|
if (containingClassVisibility == JavaDescriptorResolver.PROTECTED_STATIC_VISIBILITY) {
|
||||||
|
return Visibilities.PROTECTED;
|
||||||
|
}
|
||||||
|
return containingClassVisibility;
|
||||||
|
}
|
||||||
|
|
||||||
public static void checkPsiClassIsNotJet(@Nullable PsiClass psiClass) {
|
public static void checkPsiClassIsNotJet(@Nullable PsiClass psiClass) {
|
||||||
if (psiClass instanceof JetJavaMirrorMarker) {
|
if (psiClass instanceof JetJavaMirrorMarker) {
|
||||||
throw new IllegalStateException("trying to resolve fake jet PsiClass as regular PsiClass: " + psiClass.getQualifiedName());
|
throw new IllegalStateException("trying to resolve fake jet PsiClass as regular PsiClass: " + psiClass.getQualifiedName());
|
||||||
|
|||||||
+3
-3
@@ -85,6 +85,7 @@ public final class JavaConstructorResolver {
|
|||||||
constructors.add(trace.get(BindingContext.CONSTRUCTOR, psiClass));
|
constructors.add(trace.get(BindingContext.CONSTRUCTOR, psiClass));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Visibility constructorVisibility = DescriptorResolverUtils.getConstructorVisibility(containingClass);
|
||||||
// We need to create default constructors for classes and abstract classes.
|
// We need to create default constructors for classes and abstract classes.
|
||||||
// Example:
|
// Example:
|
||||||
// class Kotlin() : Java() {}
|
// class Kotlin() : Java() {}
|
||||||
@@ -94,8 +95,7 @@ public final class JavaConstructorResolver {
|
|||||||
containingClass,
|
containingClass,
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
true);
|
true);
|
||||||
constructorDescriptor.initialize(typeParameters, Collections.<ValueParameterDescriptor>emptyList(), containingClass
|
constructorDescriptor.initialize(typeParameters, Collections.<ValueParameterDescriptor>emptyList(), constructorVisibility, isStatic);
|
||||||
.getVisibility(), isStatic);
|
|
||||||
constructors.add(constructorDescriptor);
|
constructors.add(constructorDescriptor);
|
||||||
trace.record(BindingContext.CONSTRUCTOR, psiClass, constructorDescriptor);
|
trace.record(BindingContext.CONSTRUCTOR, psiClass, constructorDescriptor);
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ public final class JavaConstructorResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructorDescriptor.initialize(typeParameters, valueParameters, containingClass.getVisibility(), isStatic);
|
constructorDescriptor.initialize(typeParameters, valueParameters, constructorVisibility, isStatic);
|
||||||
constructors.add(constructorDescriptor);
|
constructors.add(constructorDescriptor);
|
||||||
trace.record(BindingContext.CONSTRUCTOR, psiClass, constructorDescriptor);
|
trace.record(BindingContext.CONSTRUCTOR, psiClass, constructorDescriptor);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public class ConstructorInProtectedStaticNestedClass {
|
||||||
|
protected static class Inner {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
public open class ConstructorInProtectedStaticNestedClass : java.lang.Object {
|
||||||
|
public constructor ConstructorInProtectedStaticNestedClass()
|
||||||
|
|
||||||
|
protected_static open class Inner : java.lang.Object {
|
||||||
|
protected constructor Inner()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -94,6 +94,12 @@ public final class LoadJavaCustomTest extends KotlinTestWithEnvironment {
|
|||||||
doSimpleTest();
|
doSimpleTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testProtectedStaticVisibility() throws Exception {
|
||||||
|
String dir = PATH + "/protectedStaticVisibility/constructor/";
|
||||||
|
doTest(dir + "ConstructorInProtectedStaticNestedClass.txt",
|
||||||
|
dir + "ConstructorInProtectedStaticNestedClass.java");
|
||||||
|
}
|
||||||
|
|
||||||
public void testStaticFinal() throws Exception {
|
public void testStaticFinal() throws Exception {
|
||||||
String dir = "/staticFinal/";
|
String dir = "/staticFinal/";
|
||||||
doTest(PATH + dir + "expected.txt",
|
doTest(PATH + dir + "expected.txt",
|
||||||
|
|||||||
Reference in New Issue
Block a user