Annotate fields from traits' class object properties
This commit is contained in:
@@ -24,10 +24,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.AnnotationVisitor;
|
||||
import org.jetbrains.asm4.Label;
|
||||
import org.jetbrains.asm4.MethodVisitor;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.asm4.*;
|
||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||
import org.jetbrains.asm4.commons.Method;
|
||||
import org.jetbrains.jet.codegen.binding.CalculatedClosure;
|
||||
@@ -1072,8 +1069,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
for (PropertyAndDefaultValue propertyInfo : classObjectPropertiesToCopy) {
|
||||
PropertyDescriptor propertyDescriptor = propertyInfo.propertyDescriptor;
|
||||
|
||||
v.newField(null, ACC_STATIC | ACC_FINAL | ACC_PUBLIC, context.getFieldName(propertyDescriptor),
|
||||
typeMapper.mapType(propertyDescriptor).getDescriptor(), null, propertyInfo.defaultValue);
|
||||
FieldVisitor fv = v.newField(null, ACC_STATIC | ACC_FINAL | ACC_PUBLIC, context.getFieldName(propertyDescriptor),
|
||||
typeMapper.mapType(propertyDescriptor).getDescriptor(), null, propertyInfo.defaultValue);
|
||||
|
||||
AnnotationCodegen.forField(fv, typeMapper).genAnnotations(propertyDescriptor);
|
||||
|
||||
//This field are always static and final so if it has constant initializer don't do anything in clinit,
|
||||
//field would be initialized via default value in v.newField(...) - see JVM SPEC Ch.4
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
public final class ClassObjectField implements jet.JetObject {
|
||||
@org.jetbrains.annotations.Nullable
|
||||
public static final java.lang.String x = "";
|
||||
private static final java.lang.String y = "";
|
||||
public static final ClassObjectField.object object$;
|
||||
|
||||
@org.jetbrains.annotations.NotNull
|
||||
public ClassObjectField() { /* compiled code */ }
|
||||
|
||||
public static final class object implements jet.JetObject {
|
||||
@org.jetbrains.annotations.Nullable
|
||||
public final java.lang.String getX() { /* compiled code */ }
|
||||
|
||||
private final java.lang.String getY() { /* compiled code */ }
|
||||
|
||||
private object() { /* compiled code */ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class ClassObjectField {
|
||||
class object {
|
||||
val x: String? = ""
|
||||
private val y: String? = ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
public interface TraitClassObjectField extends jet.JetObject {
|
||||
TraitClassObjectField.object object$;
|
||||
@org.jetbrains.annotations.Nullable
|
||||
java.lang.String x = "";
|
||||
|
||||
static final class object implements jet.JetObject {
|
||||
@org.jetbrains.annotations.Nullable
|
||||
private final java.lang.String x = "";
|
||||
private final java.lang.String y = "";
|
||||
|
||||
@org.jetbrains.annotations.Nullable
|
||||
public final java.lang.String getX() { /* compiled code */ }
|
||||
|
||||
private final java.lang.String getY() { /* compiled code */ }
|
||||
|
||||
private object() { /* compiled code */ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
trait TraitClassObjectField {
|
||||
class object {
|
||||
val x: String? = ""
|
||||
private val y: String? = ""
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,14 @@ public class NullabilityAnnotationsTest extends KotlinAsJavaTestBase {
|
||||
doTest(getTestName(false));
|
||||
}
|
||||
|
||||
public void testClassObjectField() throws Exception {
|
||||
doTest(getTestName(false));
|
||||
}
|
||||
|
||||
public void testTraitClassObjectField() throws Exception {
|
||||
doTest(getTestName(false));
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String fqName) {
|
||||
PsiClass psiClass = finder.findClass(fqName, GlobalSearchScope.allScope(getProject()));
|
||||
if (!(psiClass instanceof KotlinLightClass)) {
|
||||
|
||||
Reference in New Issue
Block a user