Support @receiver annotations
This commit is contained in:
@@ -254,6 +254,14 @@ public class FunctionCodegen {
|
||||
v.getSerializationBindings().put(INDEX_FOR_VALUE_PARAMETER, parameter, i);
|
||||
AnnotationCodegen.forParameter(i, mv, typeMapper).genAnnotations(parameter, parameterSignature.getAsmType());
|
||||
}
|
||||
else if (kind == JvmMethodParameterKind.RECEIVER) {
|
||||
Annotated annotationHolder = (functionDescriptor instanceof PropertyAccessorDescriptor)
|
||||
? ((PropertyAccessorDescriptor) functionDescriptor).getCorrespondingProperty()
|
||||
: functionDescriptor;
|
||||
AnnotationCodegen annotationCodegen = AnnotationCodegen.forParameter(i, mv, typeMapper);
|
||||
Annotated targetedAnnotations = new AnnotatedWithAdditionalAnnotations(null, annotationHolder);
|
||||
annotationCodegen.genAnnotations(targetedAnnotations, parameterSignature.getAsmType(), RECEIVER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,6 +137,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_GET_TARGET = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_SET_TARGET = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_RECEIVER_TARGET = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Classes and traits
|
||||
|
||||
|
||||
+1
@@ -130,6 +130,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(INAPPLICABLE_GET_TARGET, "''@get:'' annotations could be applied only to property declarations");
|
||||
MAP.put(INAPPLICABLE_SET_TARGET, "''@set:'' annotations could be applied only to property declarations");
|
||||
MAP.put(INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE, "Property must be mutable");
|
||||
MAP.put(INAPPLICABLE_RECEIVER_TARGET, "''@receiver:'' annotations could be applied only to extension function or extension property declarations");
|
||||
|
||||
MAP.put(REDUNDANT_MODIFIER, "Modifier ''{0}'' is redundant because ''{1}'' is present", TO_STRING, TO_STRING);
|
||||
MAP.put(ABSTRACT_MODIFIER_IN_TRAIT, "Modifier ''abstract'' is redundant in interface");
|
||||
|
||||
@@ -41,6 +41,7 @@ public class JetAnnotationUseSiteTarget : JetElementImplStub<KotlinPlaceHolderSt
|
||||
JetTokens.PROPERTY_KEYWORD -> AnnotationUseSiteTarget.PROPERTY
|
||||
JetTokens.GET_KEYWORD -> AnnotationUseSiteTarget.PROPERTY_GETTER
|
||||
JetTokens.SET_KEYWORD -> AnnotationUseSiteTarget.PROPERTY_SETTER
|
||||
JetTokens.RECEIVER_KEYWORD -> AnnotationUseSiteTarget.RECEIVER
|
||||
else -> throw IllegalStateException("Unknown annotation target " + node.getText())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,6 +244,17 @@ public class ModifiersChecker {
|
||||
reportIfNotMutableProperty(descriptor, annotation, INAPPLICABLE_SET_TARGET);
|
||||
break;
|
||||
}
|
||||
case RECEIVER: {
|
||||
if (!(descriptor instanceof FunctionDescriptor) && !(descriptor instanceof PropertyDescriptor)) {
|
||||
reportAnnotationTargetNotApplicable(annotation, INAPPLICABLE_RECEIVER_TARGET);
|
||||
break;
|
||||
}
|
||||
|
||||
if (((CallableMemberDescriptor) descriptor).getExtensionReceiverParameter() == null) {
|
||||
reportAnnotationTargetNotApplicable(annotation, INAPPLICABLE_RECEIVER_TARGET);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -21,7 +21,8 @@ public enum class AnnotationUseSiteTarget(renderName: String? = null) {
|
||||
FILE(),
|
||||
PROPERTY(),
|
||||
PROPERTY_GETTER("get"),
|
||||
PROPERTY_SETTER("set");
|
||||
PROPERTY_SETTER("set"),
|
||||
RECEIVER();
|
||||
|
||||
public val renderName: String = renderName ?: name().toLowerCase()
|
||||
}
|
||||
Reference in New Issue
Block a user