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;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (psiClass instanceof JetJavaMirrorMarker) {
|
||||
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));
|
||||
}
|
||||
else {
|
||||
Visibility constructorVisibility = DescriptorResolverUtils.getConstructorVisibility(containingClass);
|
||||
// We need to create default constructors for classes and abstract classes.
|
||||
// Example:
|
||||
// class Kotlin() : Java() {}
|
||||
@@ -94,8 +95,7 @@ public final class JavaConstructorResolver {
|
||||
containingClass,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
true);
|
||||
constructorDescriptor.initialize(typeParameters, Collections.<ValueParameterDescriptor>emptyList(), containingClass
|
||||
.getVisibility(), isStatic);
|
||||
constructorDescriptor.initialize(typeParameters, Collections.<ValueParameterDescriptor>emptyList(), constructorVisibility, isStatic);
|
||||
constructors.add(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);
|
||||
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();
|
||||
}
|
||||
|
||||
public void testProtectedStaticVisibility() throws Exception {
|
||||
String dir = PATH + "/protectedStaticVisibility/constructor/";
|
||||
doTest(dir + "ConstructorInProtectedStaticNestedClass.txt",
|
||||
dir + "ConstructorInProtectedStaticNestedClass.java");
|
||||
}
|
||||
|
||||
public void testStaticFinal() throws Exception {
|
||||
String dir = "/staticFinal/";
|
||||
doTest(PATH + dir + "expected.txt",
|
||||
|
||||
Reference in New Issue
Block a user