From 3560a9da731ec1ac40fbad9ff19228c136c02254 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 21 Mar 2014 15:43:46 +0400 Subject: [PATCH] Minor. Extract method --- .../jet/lang/resolve/AnnotationResolver.java | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java index bc9869c5ef3..8b303d10852 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java @@ -220,26 +220,37 @@ public class AnnotationResolver { ) { for (Map.Entry descriptorToArgument : resolvedCall.getValueArguments().entrySet()) { ValueParameterDescriptor parameterDescriptor = descriptorToArgument.getKey(); + ResolvedValueArgument resolvedArgument = descriptorToArgument.getValue(); - JetType varargElementType = parameterDescriptor.getVarargElementType(); - boolean argumentsAsVararg = varargElementType != null && !hasSpread(descriptorToArgument.getValue()); - List> constants = resolveValueArguments(descriptorToArgument.getValue(), - argumentsAsVararg ? varargElementType : parameterDescriptor.getType(), - trace); + CompileTimeConstant value = getAnnotationArgumentValue(trace, parameterDescriptor, resolvedArgument); + if (value != null) { + annotationDescriptor.setValueArgument(parameterDescriptor, value); + } + } + } - if (argumentsAsVararg) { - JetType arrayType = KotlinBuiltIns.getInstance().getPrimitiveArrayJetTypeByPrimitiveJetType(varargElementType); - if (arrayType == null) { - arrayType = KotlinBuiltIns.getInstance().getArrayType(varargElementType); - } - annotationDescriptor.setValueArgument(parameterDescriptor, new ArrayValue(constants, arrayType, true)); - } - else { - // we should actually get only one element, but just in case of getting many, we take the last one - if (!constants.isEmpty()) { - annotationDescriptor.setValueArgument(parameterDescriptor, KotlinPackage.last(constants)); - } + @Nullable + private static CompileTimeConstant getAnnotationArgumentValue( + BindingTrace trace, + ValueParameterDescriptor parameterDescriptor, + ResolvedValueArgument resolvedArgument + ) { + JetType varargElementType = parameterDescriptor.getVarargElementType(); + boolean argumentsAsVararg = varargElementType != null && !hasSpread(resolvedArgument); + List> constants = resolveValueArguments(resolvedArgument, + argumentsAsVararg ? varargElementType : parameterDescriptor.getType(), + trace); + + if (argumentsAsVararg) { + JetType arrayType = KotlinBuiltIns.getInstance().getPrimitiveArrayJetTypeByPrimitiveJetType(varargElementType); + if (arrayType == null) { + arrayType = KotlinBuiltIns.getInstance().getArrayType(varargElementType); } + return new ArrayValue(constants, arrayType, true); + } + else { + // we should actually get only one element, but just in case of getting many, we take the last one + return !constants.isEmpty() ? KotlinPackage.last(constants) : null; } }