Resolve annotations on type parameters of functions and properties

This commit is contained in:
Svetlana Isakova
2015-10-16 15:14:16 +03:00
parent 9b440345a1
commit 082469aee4
10 changed files with 118 additions and 19 deletions
@@ -35,13 +35,16 @@ import org.jetbrains.kotlin.resolve.inline.InlineUtil
public class AnnotationChecker(private val additionalCheckers: Iterable<AdditionalAnnotationChecker>) {
public fun check(annotated: JetAnnotated, trace: BindingTrace, descriptor: DeclarationDescriptor? = null) {
if (annotated is JetTypeParameter) return // TODO: support type parameter annotations
val actualTargets = getActualTargetList(annotated, descriptor)
checkEntries(annotated.annotationEntries, actualTargets, trace)
if (annotated is JetCallableDeclaration) {
annotated.typeReference?.let { check(it, trace) }
annotated.receiverTypeReference?.let { check(it, trace) }
}
if (annotated is JetTypeParameterListOwner && annotated is JetCallableDeclaration) {
// TODO: support type parameter annotations for type parameters on classes and properties
annotated.typeParameters.forEach { check(it, trace) }
}
if (annotated is JetTypeReference) {
annotated.typeElement?.typeArgumentsAsTypes?.filterNotNull()?.forEach { check(it, trace) }
}
@@ -353,7 +353,6 @@ public class DeclarationsChecker {
if (typeParameter != null) {
DescriptorResolver.checkConflictingUpperBounds(trace, typeParameter, jetTypeParameter);
}
annotationChecker.check(jetTypeParameter, trace, null);
}
}
@@ -386,13 +386,15 @@ public class DescriptorResolver {
public List<TypeParameterDescriptorImpl> resolveTypeParametersForCallableDescriptor(
DeclarationDescriptor containingDescriptor,
LexicalWritableScope extensibleScope,
LexicalScope scopeForAnnotationsResolve,
List<JetTypeParameter> typeParameters,
BindingTrace trace
) {
List<TypeParameterDescriptorImpl> result = new ArrayList<TypeParameterDescriptorImpl>();
for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) {
JetTypeParameter typeParameter = typeParameters.get(i);
result.add(resolveTypeParameterForCallableDescriptor(containingDescriptor, extensibleScope, typeParameter, i, trace));
result.add(resolveTypeParameterForCallableDescriptor(
containingDescriptor, extensibleScope, scopeForAnnotationsResolve, typeParameter, i, trace));
}
return result;
}
@@ -400,6 +402,7 @@ public class DescriptorResolver {
private TypeParameterDescriptorImpl resolveTypeParameterForCallableDescriptor(
DeclarationDescriptor containingDescriptor,
LexicalWritableScope extensibleScope,
LexicalScope scopeForAnnotationsResolve,
JetTypeParameter typeParameter,
int index,
BindingTrace trace
@@ -409,12 +412,12 @@ public class DescriptorResolver {
trace.report(VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY.on(typeParameter));
}
// TODO: Support annotation for type parameters
AnnotationResolver.reportUnsupportedAnnotationForTypeParameter(typeParameter, trace);
Annotations annotations =
annotationResolver.resolveAnnotationsWithArguments(scopeForAnnotationsResolve, typeParameter.getModifierList(), trace);
TypeParameterDescriptorImpl typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification(
containingDescriptor,
Annotations.Companion.getEMPTY(),
annotations,
typeParameter.hasModifier(JetTokens.REIFIED_KEYWORD),
typeParameter.getVariance(),
JetPsiUtil.safeName(typeParameter.getName()),
@@ -771,8 +774,8 @@ public class DescriptorResolver {
LexicalWritableScope writableScope = new LexicalWritableScope(
scope, containingDeclaration, false, null, new TraceBasedRedeclarationHandler(trace),
"Scope with type parameters of a property");
typeParameterDescriptors = resolveTypeParametersForCallableDescriptor(propertyDescriptor, writableScope, typeParameters,
trace);
typeParameterDescriptors = resolveTypeParametersForCallableDescriptor(
propertyDescriptor, writableScope, scope, typeParameters, trace);
writableScope.changeLockLevel(WritableScope.LockLevel.READING);
resolveGenericBounds(property, propertyDescriptor, writableScope, typeParameterDescriptors, trace);
scopeWithTypeParameters = writableScope;
@@ -147,7 +147,7 @@ class FunctionDescriptorResolver(
TraceBasedRedeclarationHandler(trace), "Function descriptor header scope")
val typeParameterDescriptors = descriptorResolver.
resolveTypeParametersForCallableDescriptor(functionDescriptor, innerScope, function.getTypeParameters(), trace)
resolveTypeParametersForCallableDescriptor(functionDescriptor, innerScope, scope, function.getTypeParameters(), trace)
innerScope.changeLockLevel(WritableScope.LockLevel.BOTH)
descriptorResolver.resolveGenericBounds(function, functionDescriptor, innerScope, typeParameterDescriptors, trace)
@@ -128,10 +128,6 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
context.trace.report(LOCAL_VARIABLE_WITH_DELEGATE.on(property.getDelegate()));
}
for (JetTypeParameter typeParameter : property.getTypeParameters()) {
AnnotationResolver.reportUnsupportedAnnotationForTypeParameter(typeParameter, context.trace);
}
VariableDescriptor propertyDescriptor = components.descriptorResolver.
resolveLocalVariableDescriptor(scope, property, context.dataFlowInfo, context.trace);
JetExpression initializer = property.getInitializer();