提交 133fc683 编写于 作者: S Stepan Koltsov

merge @JetProperty and @JetMethod

because:
* have common parts
* reduce class size

Also add helper JetMethodAnnotationWriter class

And also do not generate @Jet* annotations for closures
上级 6603a431
......@@ -24,7 +24,6 @@ import org.objectweb.asm.commons.Method;
import org.objectweb.asm.signature.SignatureWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
......@@ -184,7 +183,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
final CodegenContext.ClosureContext closureContext = context.intoClosure(funDescriptor, function, name, this, state.getTypeMapper());
FunctionCodegen fc = new FunctionCodegen(closureContext, cv, state);
JvmMethodSignature jvmMethodSignature = invokeSignature(funDescriptor);
fc.generateMethod(body, jvmMethodSignature, null, funDescriptor);
fc.generateMethod(body, jvmMethodSignature, false, null, funDescriptor);
return closureContext.outerWasUsed;
}
......
package org.jetbrains.jet.codegen;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
......@@ -44,21 +43,26 @@ public class FunctionCodegen {
final NamedFunctionDescriptor functionDescriptor = state.getBindingContext().get(BindingContext.FUNCTION, f);
assert functionDescriptor != null;
JvmMethodSignature method = typeMapper.mapToCallableMethod(functionDescriptor, false, owner.getContextKind()).getSignature();
generateMethod(f, method, null, functionDescriptor);
generateMethod(f, method, true, null, functionDescriptor);
}
public void generateMethod(JetDeclarationWithBody f, JvmMethodSignature jvmMethod, @Nullable String propertyTypeSignature, FunctionDescriptor functionDescriptor) {
public void generateMethod(JetDeclarationWithBody f,
JvmMethodSignature jvmMethod, boolean needJetAnnotations,
@Nullable String propertyTypeSignature, FunctionDescriptor functionDescriptor) {
CodegenContext.MethodContext funContext = owner.intoFunction(functionDescriptor);
final JetExpression bodyExpression = f.getBodyExpression();
generatedMethod(bodyExpression, jvmMethod, propertyTypeSignature, funContext, functionDescriptor, f);
generatedMethod(bodyExpression, jvmMethod, needJetAnnotations, propertyTypeSignature, funContext, functionDescriptor, f);
}
private void generatedMethod(JetExpression bodyExpressions,
JvmMethodSignature jvmSignature,
@Nullable String propertyTypeSignature,
CodegenContext.MethodContext context,
FunctionDescriptor functionDescriptor, JetDeclarationWithBody fun)
JvmMethodSignature jvmSignature,
boolean needJetAnnotations, @Nullable String propertyTypeSignature,
CodegenContext.MethodContext context,
FunctionDescriptor functionDescriptor,
JetDeclarationWithBody fun
)
{
List<ValueParameterDescriptor> paramDescrs = functionDescriptor.getValueParameters();
List<TypeParameterDescriptor> typeParameters = (functionDescriptor instanceof PropertyAccessorDescriptor ? ((PropertyAccessorDescriptor)functionDescriptor).getCorrespondingProperty(): functionDescriptor).getTypeParameters();
......@@ -77,6 +81,10 @@ public class FunctionCodegen {
}
OwnerKind kind = context.getContextKind();
if (kind == OwnerKind.TRAIT_IMPL) {
needJetAnnotations = false;
}
ReceiverDescriptor expectedThisObject = functionDescriptor.getExpectedThisObject();
ReceiverDescriptor receiverParameter = functionDescriptor.getReceiverParameter();
......@@ -92,62 +100,52 @@ public class FunctionCodegen {
final MethodVisitor mv = v.newMethod(fun, flags, jvmSignature.getAsmMethod().getName(), jvmSignature.getAsmMethod().getDescriptor(), jvmSignature.getGenericsSignature(), null);
if(v.generateCode()) {
int start = 0;
if(kind != OwnerKind.TRAIT_IMPL) {
if (needJetAnnotations) {
if (functionDescriptor instanceof PropertyAccessorDescriptor) {
PropertyCodegen.generateJetPropertyAnnotation(mv, propertyTypeSignature, jvmSignature.getKotlinTypeParameter());
} else if (functionDescriptor instanceof NamedFunctionDescriptor) {
if (propertyTypeSignature != null) {
throw new IllegalStateException();
}
AnnotationVisitor av = mv.visitAnnotation(JvmStdlibNames.JET_METHOD.getDescriptor(), true);
if(functionDescriptor.getReturnType().isNullable()) {
av.visit(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD, true);
}
if (jvmSignature.getKotlinReturnType() != null) {
av.visit(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, jvmSignature.getKotlinReturnType());
}
if (jvmSignature.getKotlinTypeParameter() != null) {
av.visit(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, jvmSignature.getKotlinTypeParameter());
}
av.visitEnd();
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
aw.writeKind(JvmStdlibNames.JET_METHOD_KIND_REGULAR);
aw.writeNullableReturnType(functionDescriptor.getReturnType().isNullable());
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
aw.writeReturnType(jvmSignature.getKotlinReturnType());
aw.visitEnd();
} else {
throw new IllegalStateException();
}
}
if(kind == OwnerKind.TRAIT_IMPL) {
AnnotationVisitor av = mv.visitParameterAnnotation(start++, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true);
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, "this$self");
av.visitEnd();
}
if(receiverParameter.exists()) {
AnnotationVisitor av = mv.visitParameterAnnotation(start++, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true);
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, "this$receiver");
if(receiverParameter.getType().isNullable()) {
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, true);
}
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, true);
av.visitEnd();
}
for (final TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
AnnotationVisitor av = mv.visitParameterAnnotation(start++, JvmStdlibNames.JET_TYPE_PARAMETER.getDescriptor(), true);
av.visit(JvmStdlibNames.JET_TYPE_PARAMETER_NAME_FIELD, typeParameterDescriptor.getName());
av.visitEnd();
}
for(int i = 0; i != paramDescrs.size(); ++i) {
AnnotationVisitor av = mv.visitParameterAnnotation(i + start, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true);
ValueParameterDescriptor parameterDescriptor = paramDescrs.get(i);
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, parameterDescriptor.getName());
if(parameterDescriptor.hasDefaultValue()) {
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, true);
if(receiverParameter.exists()) {
AnnotationVisitor av = mv.visitParameterAnnotation(start++, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true);
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, "this$receiver");
if(receiverParameter.getType().isNullable()) {
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, true);
}
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, true);
av.visitEnd();
}
if(parameterDescriptor.getOutType().isNullable()) {
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, true);
for (final TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
AnnotationVisitor av = mv.visitParameterAnnotation(start++, JvmStdlibNames.JET_TYPE_PARAMETER.getDescriptor(), true);
av.visit(JvmStdlibNames.JET_TYPE_PARAMETER_NAME_FIELD, typeParameterDescriptor.getName());
av.visitEnd();
}
if (jvmSignature.getKotlinParameterTypes() != null && jvmSignature.getKotlinParameterTypes().get(i) != null) {
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, jvmSignature.getKotlinParameterTypes().get(i + start).getKotlinSignature());
for(int i = 0; i != paramDescrs.size(); ++i) {
AnnotationVisitor av = mv.visitParameterAnnotation(i + start, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true);
ValueParameterDescriptor parameterDescriptor = paramDescrs.get(i);
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, parameterDescriptor.getName());
if(parameterDescriptor.hasDefaultValue()) {
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, true);
}
if(parameterDescriptor.getOutType().isNullable()) {
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, true);
}
if (jvmSignature.getKotlinParameterTypes() != null && jvmSignature.getKotlinParameterTypes().get(i) != null) {
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, jvmSignature.getKotlinParameterTypes().get(i + start).getKotlinSignature());
}
av.visitEnd();
}
av.visitEnd();
}
}
if (!isAbstract && v.generateCode()) {
......
......@@ -245,7 +245,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
Method originalMethod = originalSignature.getJvmMethodSignature().getAsmMethod();
MethodVisitor mv = v.newMethod(null, Opcodes.ACC_PUBLIC | Opcodes.ACC_BRIDGE | Opcodes.ACC_FINAL, method.getName(), method.getDescriptor(), null, null);
PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature.getPropertyTypeKotlinSignature(), originalSignature.getJvmMethodSignature().getKotlinTypeParameter());
mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd();
if (v.generateCode()) {
mv.visitCode();
......@@ -269,7 +268,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
Method originalMethod = originalSignature2.getJvmMethodSignature().getAsmMethod();
MethodVisitor mv = v.newMethod(null, Opcodes.ACC_PUBLIC | Opcodes.ACC_BRIDGE | Opcodes.ACC_FINAL, method.getName(), method.getDescriptor(), null, null);
PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature2.getPropertyTypeKotlinSignature(), originalSignature2.getJvmMethodSignature().getKotlinTypeParameter());
mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd();
if (v.generateCode()) {
mv.visitCode();
......
package org.jetbrains.jet.codegen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.MethodVisitor;
/**
* @author Stepan Koltsov
*/
public class JetMethodAnnotationWriter {
private final AnnotationVisitor av;
private JetMethodAnnotationWriter(AnnotationVisitor av) {
this.av = av;
}
public void writeKind(int kind) {
if (kind != JvmStdlibNames.JET_METHOD_KIND_DEFAULT) {
av.visit(JvmStdlibNames.JET_METHOD_KIND_FIELD, kind);
}
}
public void writeTypeParameters(@NotNull String typeParameters) {
if (typeParameters.length() > 0) {
av.visit(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, typeParameters);
}
}
public void writeReturnType(@NotNull String returnType) {
if (returnType.length() > 0) {
av.visit(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, returnType);
}
}
public void writePropertyType(@NotNull String propertyType) {
if (propertyType.length() > 0) {
av.visit(JvmStdlibNames.JET_METHOD_PROPERTY_TYPE_FIELD, propertyType);
}
}
public void writeNullableReturnType(boolean nullableReturnType) {
if (nullableReturnType) {
av.visit(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD, nullableReturnType);
}
}
public void visitEnd() {
av.visitEnd();
}
public static JetMethodAnnotationWriter visitAnnotation(MethodVisitor mv) {
return new JetMethodAnnotationWriter(mv.visitAnnotation(JvmStdlibNames.JET_METHOD.getDescriptor(), true));
}
}
......@@ -13,7 +13,6 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.lexer.JetTokens;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
......@@ -89,7 +88,7 @@ public class PropertyCodegen {
if (getter != null) {
if (getter.getBodyExpression() != null) {
JvmPropertyAccessorSignature signature = state.getTypeMapper().mapGetterSignature(propertyDescriptor, kind);
functionCodegen.generateMethod(getter, signature.getJvmMethodSignature(), signature.getPropertyTypeKotlinSignature(), propertyDescriptor.getGetter());
functionCodegen.generateMethod(getter, signature.getJvmMethodSignature(), true, signature.getPropertyTypeKotlinSignature(), propertyDescriptor.getGetter());
}
else if (!getter.hasModifier(JetTokens.PRIVATE_KEYWORD)) {
generateDefaultGetter(p, getter);
......@@ -111,7 +110,7 @@ public class PropertyCodegen {
final PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter();
assert setterDescriptor != null;
JvmPropertyAccessorSignature signature = state.getTypeMapper().mapSetterSignature(propertyDescriptor, kind);
functionCodegen.generateMethod(setter, signature.getJvmMethodSignature(), signature.getPropertyTypeKotlinSignature(), setterDescriptor);
functionCodegen.generateMethod(setter, signature.getJvmMethodSignature(), true, signature.getPropertyTypeKotlinSignature(), setterDescriptor);
}
else if (!p.hasModifier(JetTokens.PRIVATE_KEYWORD)) {
generateDefaultSetter(p, setter);
......@@ -170,14 +169,11 @@ public class PropertyCodegen {
}
public static void generateJetPropertyAnnotation(MethodVisitor mv, @NotNull String kotlinType, @NotNull String typeParameters) {
AnnotationVisitor annotationVisitor = mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true);
if (kotlinType.length() > 0) {
annotationVisitor.visit(JvmStdlibNames.JET_PROPERTY_TYPE_FIELD, kotlinType);
}
if (typeParameters.length() > 0) {
annotationVisitor.visit(JvmStdlibNames.JET_PROPERTY_TYPE_PARAMETERS_FIELD, typeParameters);
}
annotationVisitor.visitEnd();
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
aw.writeKind(JvmStdlibNames.JET_METHOD_KIND_PROPERTY);
aw.writeTypeParameters(typeParameters);
aw.writePropertyType(kotlinType);
aw.visitEnd();
}
private void generateDefaultSetter(JetProperty p, JetDeclaration declaration) {
......
......@@ -132,12 +132,11 @@ public class JavaDescriptorResolver {
private static abstract class ResolverScopeData {
@Nullable
private Set<VariableDescriptor> properties;
private boolean kotlin;
protected boolean kotlin;
}
private static class ResolverClassData extends ResolverScopeData {
private JavaClassDescriptor classDescriptor;
private boolean kotlin;
@NotNull
public ClassDescriptor getClassDescriptor() {
......@@ -147,7 +146,6 @@ public class JavaDescriptorResolver {
private static class ResolverNamespaceData extends ResolverScopeData {
private JavaNamespaceDescriptor namespaceDescriptor;
private boolean kotlin;
@NotNull
public NamespaceDescriptor getNamespaceDescriptor() {
......@@ -892,7 +890,7 @@ public class JavaDescriptorResolver {
if (psiMethod.getName().startsWith(JvmAbi.GETTER_PREFIX)) {
// TODO: some java properties too
if (method.getJetProperty().isDefined()) {
if (method.getJetMethod().kind() == JvmStdlibNames.JET_METHOD_KIND_PROPERTY) {
if (psiMethod.getName().equals(JvmStdlibNames.JET_OBJECT_GET_TYPEINFO_METHOD)) {
continue;
......@@ -933,7 +931,7 @@ public class JavaDescriptorResolver {
}
} else if (psiMethod.getName().startsWith(JvmAbi.SETTER_PREFIX)) {
if (method.getJetProperty().isDefined()) {
if (method.getJetMethod().kind() == JvmStdlibNames.JET_METHOD_KIND_PROPERTY) {
if (psiMethod.getParameterList().getParametersCount() == 0) {
// TODO: report error properly
throw new IllegalStateException();
......@@ -1215,7 +1213,7 @@ public class JavaDescriptorResolver {
}
// TODO: ugly
if (method.getJetProperty().isDefined()) {
if (method.getJetMethod().kind() == JvmStdlibNames.JET_METHOD_KIND_PROPERTY) {
return null;
}
......@@ -1308,9 +1306,9 @@ public class JavaDescriptorResolver {
@NotNull PsiMethodWrapper method,
@NotNull FunctionDescriptor functionDescriptor,
@NotNull TypeVariableResolver classTypeVariableResolver) {
if (method.getJetMethodOrProperty().typeParameters().length() > 0) {
if (method.getJetMethod().typeParameters().length() > 0) {
List<TypeParameterDescriptor> r = resolveMethodTypeParametersFromJetSignature(
method.getJetMethodOrProperty().typeParameters(), method.getPsiMethod(), functionDescriptor, classTypeVariableResolver);
method.getJetMethod().typeParameters(), method.getPsiMethod(), functionDescriptor, classTypeVariableResolver);
initializeTypeParameters(method.getPsiMethod());
return r;
}
......
......@@ -24,15 +24,16 @@ public class JvmStdlibNames {
public static final JvmClassName JET_METHOD = new JvmClassName("jet.runtime.typeinfo.JetMethod");
public static final String JET_METHOD_KIND_FIELD = "kind";
public static final String JET_METHOD_NULLABLE_RETURN_TYPE_FIELD = "nullableReturnType";
public static final String JET_METHOD_RETURN_TYPE_FIELD = "returnType";
public static final String JET_METHOD_TYPE_PARAMETERS_FIELD = "typeParameters";
public static final JvmClassName JET_PROPERTY = new JvmClassName("jet.runtime.typeinfo.JetProperty");
public static final String JET_PROPERTY_TYPE_FIELD = "type";
public static final String JET_PROPERTY_TYPE_PARAMETERS_FIELD = "typeParameters";
public static final String JET_METHOD_PROPERTY_TYPE_FIELD = "propertyType";
public static final int JET_METHOD_KIND_REGULAR = 0;
public static final int JET_METHOD_KIND_PROPERTY = 1;
public static final int JET_METHOD_KIND_DEFAULT = JET_METHOD_KIND_REGULAR;
public static final JvmClassName JET_CONSTRUCTOR = new JvmClassName("jet.runtime.typeinfo.JetConstructor");
/**
......
package org.jetbrains.jet.lang.resolve.java;
import com.intellij.psi.PsiMember;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.PsiParameter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.java.kt.JetConstructorAnnotation;
import org.jetbrains.jet.lang.resolve.java.kt.JetMethodAnnotation;
import org.jetbrains.jet.lang.resolve.java.kt.JetMethodOrPropertyAnnotation;
import org.jetbrains.jet.lang.resolve.java.kt.JetPropertyAnnotation;
import java.util.ArrayList;
import java.util.List;
......@@ -62,23 +59,6 @@ public class PsiMethodWrapper extends PsiMemberWrapper {
return jetConstructor;
}
private JetPropertyAnnotation jetProperty;
@NotNull
public JetPropertyAnnotation getJetProperty() {
if (jetProperty == null) {
jetProperty = JetPropertyAnnotation.get(getPsiMethod());
}
return jetProperty;
}
public JetMethodOrPropertyAnnotation getJetMethodOrProperty() {
if (getJetMethod().isDefined()) {
return getJetMethod();
} else {
return getJetProperty();
}
}
@NotNull
public PsiMethod getPsiMethod() {
return (PsiMethod) psiMember;
......
......@@ -9,11 +9,30 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
/**
* @author Stepan Koltsov
*/
public class JetMethodAnnotation extends JetMethodOrPropertyAnnotation {
public class JetMethodAnnotation extends PsiAnnotationWrapper {
public JetMethodAnnotation(@Nullable PsiAnnotation psiAnnotation) {
super(psiAnnotation);
}
private int kind;
private boolean kindInitialized;
public int kind() {
if (!kindInitialized) {
kind = getIntAttribute(JvmStdlibNames.JET_METHOD_KIND_FIELD, JvmStdlibNames.JET_METHOD_KIND_DEFAULT);
kindInitialized = true;
}
return kind;
}
private String typeParameters;
@NotNull
public String typeParameters() {
if (typeParameters == null) {
typeParameters = getStringAttribute(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, "");
}
return typeParameters;
}
private String returnType;
@NotNull
......@@ -34,7 +53,16 @@ public class JetMethodAnnotation extends JetMethodOrPropertyAnnotation {
}
return returnTypeNullable;
}
private String propertyType;
@NotNull
public String propertyType() {
if (propertyType == null) {
propertyType = getStringAttribute(JvmStdlibNames.JET_METHOD_PROPERTY_TYPE_FIELD, "");
}
return propertyType;
}
public static JetMethodAnnotation get(PsiMethod psiMethod) {
return new JetMethodAnnotation(psiMethod.getModifierList().findAnnotation(JvmStdlibNames.JET_METHOD.getFqName()));
}
......
package org.jetbrains.jet.lang.resolve.java.kt;
import com.intellij.psi.PsiAnnotation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
/**
* @author Stepan Koltsov
*/
public abstract class JetMethodOrPropertyAnnotation extends PsiAnnotationWrapper {
protected JetMethodOrPropertyAnnotation(@Nullable PsiAnnotation psiAnnotation) {
super(psiAnnotation);
}
private String typeParameters;
@NotNull
public String typeParameters() {
if (typeParameters == null) {
typeParameters = getStringAttribute(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, "");
}
return typeParameters;
}
}
package org.jetbrains.jet.lang.resolve.java.kt;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
/**
* @author Stepan Koltsov
*/
public class JetPropertyAnnotation extends JetMethodOrPropertyAnnotation {
protected JetPropertyAnnotation(@Nullable PsiAnnotation psiAnnotation) {
super(psiAnnotation);
}
@NotNull
public static JetPropertyAnnotation get(@NotNull PsiMethod psiMethod) {
return new JetPropertyAnnotation(psiMethod.getModifierList().findAnnotation(JvmStdlibNames.JET_PROPERTY.getFqName()));
}
}
......@@ -19,6 +19,11 @@ public class PsiAnnotationUtils {
return getAttribute(annotation, field, defaultValue);
}
public static int getIntAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, int defaultValue) {
return getAttribute(annotation, field, defaultValue);
}
@NotNull
private static <T> T getAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, @NotNull T defaultValue) {
if (annotation == null) {
return defaultValue;
......
......@@ -33,4 +33,9 @@ public abstract class PsiAnnotationWrapper {
protected boolean getBooleanAttribute(String name, boolean defaultValue) {
return PsiAnnotationUtils.getBooleanAttribute(psiAnnotation, name, defaultValue);
}
protected int getIntAttribute(String name, int defaultValue) {
return PsiAnnotationUtils.getIntAttribute(psiAnnotation, name, defaultValue);
}
}
......@@ -3,6 +3,8 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
/**
* ... and also a closure
*
* @author Stepan Koltsov
*/
public interface NamedFunctionDescriptor extends FunctionDescriptor {
......
......@@ -17,6 +17,11 @@ import java.lang.annotation.Target;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface JetMethod {
int KIND_REGULAR = 0;
int KIND_PROPERTY = 1;
int kind() default KIND_REGULAR;
/**
* @return type projections or empty
*/
......@@ -37,4 +42,10 @@ public @interface JetMethod {
* Return type type unless java type is correct Kotlin type.
*/
String returnType () default "";
/**
* If this is property.
* @return
*/
String propertyType() default "";
}
package jet.runtime.typeinfo;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Stepan Koltsov
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface JetProperty {
String type() default "";
String typeParameters() default "";
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册