visitAnnotation() could return null for light classes
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
<root>
|
||||||
|
<item name='org.jetbrains.asm4.ClassVisitor org.jetbrains.asm4.AnnotationVisitor visitAnnotation(java.lang.String, boolean)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.Nullable'/>
|
||||||
|
</item>
|
||||||
|
<item name='org.jetbrains.asm4.FieldVisitor org.jetbrains.asm4.AnnotationVisitor visitAnnotation(java.lang.String, boolean)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.Nullable'/>
|
||||||
|
</item>
|
||||||
|
<item name='org.jetbrains.asm4.MethodVisitor org.jetbrains.asm4.AnnotationVisitor visitAnnotation(java.lang.String, boolean)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.Nullable'/>
|
||||||
|
</item>
|
||||||
|
<item name='org.jetbrains.asm4.MethodVisitor org.jetbrains.asm4.AnnotationVisitor visitAnnotationDefault()'>
|
||||||
|
<annotation name='org.jetbrains.annotations.Nullable'/>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
name='org.jetbrains.asm4.MethodVisitor org.jetbrains.asm4.AnnotationVisitor visitParameterAnnotation(int, java.lang.String, boolean)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.Nullable'/>
|
||||||
|
</item>
|
||||||
|
</root>
|
||||||
@@ -42,6 +42,8 @@ import java.util.*;
|
|||||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
|
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
|
||||||
|
|
||||||
public abstract class AnnotationCodegen {
|
public abstract class AnnotationCodegen {
|
||||||
|
private static final AnnotationVisitor NO_ANNOTATION_VISITOR = new AnnotationVisitor(Opcodes.ASM4) {};
|
||||||
|
|
||||||
private final JetTypeMapper typeMapper;
|
private final JetTypeMapper typeMapper;
|
||||||
private final BindingContext bindingContext;
|
private final BindingContext bindingContext;
|
||||||
|
|
||||||
@@ -271,50 +273,61 @@ public abstract class AnnotationCodegen {
|
|||||||
return RetentionPolicy.CLASS;
|
return RetentionPolicy.CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
abstract AnnotationVisitor visitAnnotation(String descr, boolean visible);
|
abstract AnnotationVisitor visitAnnotation(String descr, boolean visible);
|
||||||
|
|
||||||
public static AnnotationCodegen forClass(final ClassVisitor cv, JetTypeMapper mapper) {
|
public static AnnotationCodegen forClass(final ClassVisitor cv, JetTypeMapper mapper) {
|
||||||
return new AnnotationCodegen(mapper) {
|
return new AnnotationCodegen(mapper) {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
AnnotationVisitor visitAnnotation(String descr, boolean visible) {
|
AnnotationVisitor visitAnnotation(String descr, boolean visible) {
|
||||||
return cv.visitAnnotation(descr, visible);
|
return safe(cv.visitAnnotation(descr, visible));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AnnotationCodegen forMethod(final MethodVisitor mv, JetTypeMapper mapper) {
|
public static AnnotationCodegen forMethod(final MethodVisitor mv, JetTypeMapper mapper) {
|
||||||
return new AnnotationCodegen(mapper) {
|
return new AnnotationCodegen(mapper) {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
AnnotationVisitor visitAnnotation(String descr, boolean visible) {
|
AnnotationVisitor visitAnnotation(String descr, boolean visible) {
|
||||||
return mv.visitAnnotation(descr, visible);
|
return safe(mv.visitAnnotation(descr, visible));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AnnotationCodegen forField(final FieldVisitor fv, JetTypeMapper mapper) {
|
public static AnnotationCodegen forField(final FieldVisitor fv, JetTypeMapper mapper) {
|
||||||
return new AnnotationCodegen(mapper) {
|
return new AnnotationCodegen(mapper) {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
AnnotationVisitor visitAnnotation(String descr, boolean visible) {
|
AnnotationVisitor visitAnnotation(String descr, boolean visible) {
|
||||||
return fv.visitAnnotation(descr, visible);
|
return safe(fv.visitAnnotation(descr, visible));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AnnotationCodegen forParameter(final int parameter, final MethodVisitor mv, JetTypeMapper mapper) {
|
public static AnnotationCodegen forParameter(final int parameter, final MethodVisitor mv, JetTypeMapper mapper) {
|
||||||
return new AnnotationCodegen(mapper) {
|
return new AnnotationCodegen(mapper) {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
AnnotationVisitor visitAnnotation(String descr, boolean visible) {
|
AnnotationVisitor visitAnnotation(String descr, boolean visible) {
|
||||||
return mv.visitParameterAnnotation(parameter, descr, visible);
|
return safe(mv.visitParameterAnnotation(parameter, descr, visible));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AnnotationCodegen forAnnotationDefaultValue(final MethodVisitor mv, JetTypeMapper mapper) {
|
public static AnnotationCodegen forAnnotationDefaultValue(final MethodVisitor mv, JetTypeMapper mapper) {
|
||||||
return new AnnotationCodegen(mapper) {
|
return new AnnotationCodegen(mapper) {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
AnnotationVisitor visitAnnotation(String descr, boolean visible) {
|
AnnotationVisitor visitAnnotation(String descr, boolean visible) {
|
||||||
return mv.visitAnnotationDefault();
|
return safe(mv.visitAnnotationDefault());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static AnnotationVisitor safe(@Nullable AnnotationVisitor av) {
|
||||||
|
return av == null ? NO_ANNOTATION_VISITOR : av;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,11 +203,13 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
|
|
||||||
AnnotationVisitor av =
|
AnnotationVisitor av =
|
||||||
mv.visitParameterAnnotation(i, asmDescByFqNameWithoutInnerClasses(fqNameByClass(JetValueParameter.class)), true);
|
mv.visitParameterAnnotation(i, asmDescByFqNameWithoutInnerClasses(fqNameByClass(JetValueParameter.class)), true);
|
||||||
av.visit("name", name);
|
if (av != null) {
|
||||||
if (nullableType) {
|
av.visit("name", name);
|
||||||
av.visit("type", "?");
|
if (nullableType) {
|
||||||
|
av.visit("type", "?");
|
||||||
|
}
|
||||||
|
av.visitEnd();
|
||||||
}
|
}
|
||||||
av.visitEnd();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +221,9 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
// see MethodWriter.visitParameterAnnotation()
|
// see MethodWriter.visitParameterAnnotation()
|
||||||
|
|
||||||
AnnotationVisitor av = mv.visitParameterAnnotation(i, "Ljava/lang/Synthetic;", true);
|
AnnotationVisitor av = mv.visitParameterAnnotation(i, "Ljava/lang/Synthetic;", true);
|
||||||
av.visitEnd();
|
if (av != null) {
|
||||||
|
av.visitEnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
public final class Synthetic implements jet.JetObject {
|
||||||
|
@org.jetbrains.annotations.NotNull
|
||||||
|
private final void foo() { /* compiled code */ }
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.NotNull
|
||||||
|
public Synthetic() { /* compiled code */ }
|
||||||
|
|
||||||
|
public final class Inner implements jet.JetObject {
|
||||||
|
@org.jetbrains.annotations.NotNull
|
||||||
|
public final void test() { /* compiled code */ }
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.NotNull
|
||||||
|
public Inner() { /* compiled code */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
class Synthetic {
|
||||||
|
inner class Inner {
|
||||||
|
fun test() {
|
||||||
|
foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun foo() {}
|
||||||
|
}
|
||||||
@@ -61,6 +61,10 @@ public class NullabilityAnnotationsTest extends KotlinAsJavaTestBase {
|
|||||||
doTest(getTestName(false));
|
doTest(getTestName(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSynthetic() throws Exception {
|
||||||
|
doTest(getTestName(false));
|
||||||
|
}
|
||||||
|
|
||||||
private void doTest(@NotNull String fqName) {
|
private void doTest(@NotNull String fqName) {
|
||||||
PsiClass psiClass = finder.findClass(fqName, GlobalSearchScope.allScope(getProject()));
|
PsiClass psiClass = finder.findClass(fqName, GlobalSearchScope.allScope(getProject()));
|
||||||
if (!(psiClass instanceof KotlinLightClass)) {
|
if (!(psiClass instanceof KotlinLightClass)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user