Minor, Nullable/NotNull annotations
This commit is contained in:
@@ -28,14 +28,13 @@ import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl;
|
|||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.asm4.Opcodes.*;
|
import static org.jetbrains.asm4.Opcodes.*;
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.*;
|
import static org.jetbrains.jet.codegen.AsmUtil.genMethodThrow;
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.enumEntryNeedSubclass;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.enumEntryNeedSubclass;
|
||||||
|
|
||||||
public abstract class ClassBodyCodegen extends MemberCodegen {
|
public abstract class ClassBodyCodegen extends MemberCodegen {
|
||||||
|
|||||||
@@ -17,8 +17,12 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.asm4.*;
|
import org.jetbrains.asm4.AnnotationVisitor;
|
||||||
|
import org.jetbrains.asm4.ClassVisitor;
|
||||||
|
import org.jetbrains.asm4.FieldVisitor;
|
||||||
|
import org.jetbrains.asm4.MethodVisitor;
|
||||||
|
|
||||||
public abstract class ClassBuilder {
|
public abstract class ClassBuilder {
|
||||||
private String thisName;
|
private String thisName;
|
||||||
@@ -26,11 +30,12 @@ public abstract class ClassBuilder {
|
|||||||
public static class Concrete extends ClassBuilder {
|
public static class Concrete extends ClassBuilder {
|
||||||
private final ClassVisitor v;
|
private final ClassVisitor v;
|
||||||
|
|
||||||
public Concrete(ClassVisitor v) {
|
public Concrete(@NotNull ClassVisitor v) {
|
||||||
this.v = v;
|
this.v = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public ClassVisitor getVisitor() {
|
public ClassVisitor getVisitor() {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@@ -39,8 +44,8 @@ public abstract class ClassBuilder {
|
|||||||
public FieldVisitor newField(
|
public FieldVisitor newField(
|
||||||
@Nullable PsiElement origin,
|
@Nullable PsiElement origin,
|
||||||
int access,
|
int access,
|
||||||
String name,
|
@NotNull String name,
|
||||||
String desc,
|
@NotNull String desc,
|
||||||
@Nullable String signature,
|
@Nullable String signature,
|
||||||
@Nullable Object value
|
@Nullable Object value
|
||||||
) {
|
) {
|
||||||
@@ -50,18 +55,16 @@ public abstract class ClassBuilder {
|
|||||||
public MethodVisitor newMethod(
|
public MethodVisitor newMethod(
|
||||||
@Nullable PsiElement origin,
|
@Nullable PsiElement origin,
|
||||||
int access,
|
int access,
|
||||||
String name,
|
@NotNull String name,
|
||||||
String desc,
|
@NotNull String desc,
|
||||||
@Nullable String signature,
|
@Nullable String signature,
|
||||||
@Nullable String[] exceptions
|
@Nullable String[] exceptions
|
||||||
) {
|
) {
|
||||||
return getVisitor().visitMethod(access, name, desc, signature, exceptions);
|
return getVisitor().visitMethod(access, name, desc, signature, exceptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnnotationVisitor newAnnotation(
|
@NotNull
|
||||||
String desc,
|
public AnnotationVisitor newAnnotation(@NotNull String desc, boolean visible) {
|
||||||
boolean visible
|
|
||||||
) {
|
|
||||||
return getVisitor().visitAnnotation(desc, visible);
|
return getVisitor().visitAnnotation(desc, visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,34 +72,37 @@ public abstract class ClassBuilder {
|
|||||||
getVisitor().visitEnd();
|
getVisitor().visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public abstract ClassVisitor getVisitor();
|
public abstract ClassVisitor getVisitor();
|
||||||
|
|
||||||
public void defineClass(
|
public void defineClass(
|
||||||
PsiElement origin,
|
@Nullable PsiElement origin,
|
||||||
int version,
|
int version,
|
||||||
int access,
|
int access,
|
||||||
String name,
|
@NotNull String name,
|
||||||
@Nullable String signature,
|
@Nullable String signature,
|
||||||
String superName,
|
@NotNull String superName,
|
||||||
String[] interfaces
|
@NotNull String[] interfaces
|
||||||
) {
|
) {
|
||||||
thisName = name;
|
thisName = name;
|
||||||
getVisitor().visit(version, access, name, signature, superName, interfaces);
|
getVisitor().visit(version, access, name, signature, superName, interfaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void visitSource(String name, @Nullable String debug) {
|
public void visitSource(@NotNull String name, @Nullable String debug) {
|
||||||
getVisitor().visitSource(name, debug);
|
getVisitor().visitSource(name, debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void visitOuterClass(String owner, @Nullable String name, @Nullable String desc) {
|
public void visitOuterClass(@NotNull String owner, @Nullable String name, @Nullable String desc) {
|
||||||
getVisitor().visitOuterClass(owner, name, desc);
|
getVisitor().visitOuterClass(owner, name, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void visitInnerClass(String name, String outerName, String innerName, int access) {
|
public void visitInnerClass(@NotNull String name, @Nullable String outerName, @Nullable String innerName, int access) {
|
||||||
getVisitor().visitInnerClass(name, outerName, innerName, access);
|
getVisitor().visitInnerClass(name, outerName, innerName, access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public String getThisName() {
|
public String getThisName() {
|
||||||
|
assert thisName != null : "This name isn't set";
|
||||||
return thisName;
|
return thisName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1542,6 +1542,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
protected void generateDeclaration(PropertyCodegen propertyCodegen, JetDeclaration declaration) {
|
protected void generateDeclaration(PropertyCodegen propertyCodegen, JetDeclaration declaration) {
|
||||||
if (declaration instanceof JetEnumEntry) {
|
if (declaration instanceof JetEnumEntry) {
|
||||||
String name = declaration.getName();
|
String name = declaration.getName();
|
||||||
|
assert name != null : "Enum entry has no name: " + declaration.getText();
|
||||||
String desc = "L" + classAsmType.getInternalName() + ";";
|
String desc = "L" + classAsmType.getInternalName() + ";";
|
||||||
v.newField(declaration, ACC_PUBLIC | ACC_ENUM | ACC_STATIC | ACC_FINAL, name, desc, null, null);
|
v.newField(declaration, ACC_PUBLIC | ACC_ENUM | ACC_STATIC | ACC_FINAL, name, desc, null, null);
|
||||||
myEnumConstants.add((JetEnumEntry) declaration);
|
myEnumConstants.add((JetEnumEntry) declaration);
|
||||||
|
|||||||
@@ -107,7 +107,9 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
public void generateConstructorPropertyAsMethodForAnnotationClass(JetParameter p, PropertyDescriptor descriptor) {
|
public void generateConstructorPropertyAsMethodForAnnotationClass(JetParameter p, PropertyDescriptor descriptor) {
|
||||||
Type type = state.getTypeMapper().mapType(descriptor);
|
Type type = state.getTypeMapper().mapType(descriptor);
|
||||||
MethodVisitor visitor = v.newMethod(p, ACC_PUBLIC | ACC_ABSTRACT, p.getName(), "()" + type.getDescriptor(), null, null);
|
String name = p.getName();
|
||||||
|
assert name != null : "Annotation parameter has no name: " + p.getText();
|
||||||
|
MethodVisitor visitor = v.newMethod(p, ACC_PUBLIC | ACC_ABSTRACT, name, "()" + type.getDescriptor(), null, null);
|
||||||
JetExpression defaultValue = p.getDefaultValue();
|
JetExpression defaultValue = p.getDefaultValue();
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
CompileTimeConstant<?> constant = state.getBindingContext().get(BindingContext.COMPILE_TIME_VALUE, defaultValue);
|
CompileTimeConstant<?> constant = state.getBindingContext().get(BindingContext.COMPILE_TIME_VALUE, defaultValue);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.intellij.psi.impl.compiled.StubBuildingVisitor;
|
|||||||
import com.intellij.psi.stubs.StubBase;
|
import com.intellij.psi.stubs.StubBase;
|
||||||
import com.intellij.psi.stubs.StubElement;
|
import com.intellij.psi.stubs.StubElement;
|
||||||
import com.intellij.util.containers.Stack;
|
import com.intellij.util.containers.Stack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.asm4.ClassReader;
|
import org.jetbrains.asm4.ClassReader;
|
||||||
import org.jetbrains.asm4.ClassVisitor;
|
import org.jetbrains.asm4.ClassVisitor;
|
||||||
@@ -29,7 +30,6 @@ import org.jetbrains.asm4.FieldVisitor;
|
|||||||
import org.jetbrains.asm4.MethodVisitor;
|
import org.jetbrains.asm4.MethodVisitor;
|
||||||
import org.jetbrains.jet.codegen.ClassBuilder;
|
import org.jetbrains.jet.codegen.ClassBuilder;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
@@ -53,11 +53,12 @@ public class StubClassBuilder extends ClassBuilder {
|
|||||||
private final Stack<StubElement> parentStack;
|
private final Stack<StubElement> parentStack;
|
||||||
private boolean isNamespace = false;
|
private boolean isNamespace = false;
|
||||||
|
|
||||||
public StubClassBuilder(Stack<StubElement> parentStack) {
|
public StubClassBuilder(@NotNull Stack<StubElement> parentStack) {
|
||||||
this.parentStack = parentStack;
|
this.parentStack = parentStack;
|
||||||
this.parent = parentStack.peek();
|
this.parent = parentStack.peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ClassVisitor getVisitor() {
|
public ClassVisitor getVisitor() {
|
||||||
assert v != null : "Called before class is defined";
|
assert v != null : "Called before class is defined";
|
||||||
@@ -65,7 +66,15 @@ public class StubClassBuilder extends ClassBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void defineClass(PsiElement origin, int version, int access, String name, @Nullable String signature, String superName, String[] interfaces) {
|
public void defineClass(
|
||||||
|
PsiElement origin,
|
||||||
|
int version,
|
||||||
|
int access,
|
||||||
|
@NotNull String name,
|
||||||
|
@Nullable String signature,
|
||||||
|
@NotNull String superName,
|
||||||
|
@NotNull String[] interfaces
|
||||||
|
) {
|
||||||
assert v == null : "defineClass() called twice?";
|
assert v == null : "defineClass() called twice?";
|
||||||
v = new StubBuildingVisitor<Object>(null, EMPTY_STRATEGY, parent, access);
|
v = new StubBuildingVisitor<Object>(null, EMPTY_STRATEGY, parent, access);
|
||||||
|
|
||||||
@@ -88,7 +97,14 @@ public class StubClassBuilder extends ClassBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MethodVisitor newMethod(@Nullable PsiElement origin, int access, String name, String desc, @Nullable String signature, @Nullable String[] exceptions) {
|
public MethodVisitor newMethod(
|
||||||
|
@Nullable PsiElement origin,
|
||||||
|
int access,
|
||||||
|
@NotNull String name,
|
||||||
|
@NotNull String desc,
|
||||||
|
@Nullable String signature,
|
||||||
|
@Nullable String[] exceptions
|
||||||
|
) {
|
||||||
MethodVisitor internalVisitor = super.newMethod(origin, access, name, desc, signature, exceptions);
|
MethodVisitor internalVisitor = super.newMethod(origin, access, name, desc, signature, exceptions);
|
||||||
|
|
||||||
if (internalVisitor != null) {
|
if (internalVisitor != null) {
|
||||||
@@ -100,7 +116,14 @@ public class StubClassBuilder extends ClassBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldVisitor newField(@Nullable PsiElement origin, int access, String name, String desc, @Nullable String signature, @Nullable Object value) {
|
public FieldVisitor newField(
|
||||||
|
@Nullable PsiElement origin,
|
||||||
|
int access,
|
||||||
|
@NotNull String name,
|
||||||
|
@NotNull String desc,
|
||||||
|
@Nullable String signature,
|
||||||
|
@Nullable Object value
|
||||||
|
) {
|
||||||
FieldVisitor internalVisitor = super.newField(origin, access, name, desc, signature, value);
|
FieldVisitor internalVisitor = super.newField(origin, access, name, desc, signature, value);
|
||||||
|
|
||||||
if (internalVisitor != null) {
|
if (internalVisitor != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user