Minor. Extract method

This commit is contained in:
Andrey Breslav
2014-03-21 15:43:46 +04:00
parent cbb24a7d4e
commit 3560a9da73
@@ -220,26 +220,37 @@ public class AnnotationResolver {
) { ) {
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> descriptorToArgument : resolvedCall.getValueArguments().entrySet()) { for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> descriptorToArgument : resolvedCall.getValueArguments().entrySet()) {
ValueParameterDescriptor parameterDescriptor = descriptorToArgument.getKey(); ValueParameterDescriptor parameterDescriptor = descriptorToArgument.getKey();
ResolvedValueArgument resolvedArgument = descriptorToArgument.getValue();
JetType varargElementType = parameterDescriptor.getVarargElementType(); CompileTimeConstant<?> value = getAnnotationArgumentValue(trace, parameterDescriptor, resolvedArgument);
boolean argumentsAsVararg = varargElementType != null && !hasSpread(descriptorToArgument.getValue()); if (value != null) {
List<CompileTimeConstant<?>> constants = resolveValueArguments(descriptorToArgument.getValue(), annotationDescriptor.setValueArgument(parameterDescriptor, value);
argumentsAsVararg ? varargElementType : parameterDescriptor.getType(), }
trace); }
}
if (argumentsAsVararg) { @Nullable
JetType arrayType = KotlinBuiltIns.getInstance().getPrimitiveArrayJetTypeByPrimitiveJetType(varargElementType); private static CompileTimeConstant<?> getAnnotationArgumentValue(
if (arrayType == null) { BindingTrace trace,
arrayType = KotlinBuiltIns.getInstance().getArrayType(varargElementType); ValueParameterDescriptor parameterDescriptor,
} ResolvedValueArgument resolvedArgument
annotationDescriptor.setValueArgument(parameterDescriptor, new ArrayValue(constants, arrayType, true)); ) {
} JetType varargElementType = parameterDescriptor.getVarargElementType();
else { boolean argumentsAsVararg = varargElementType != null && !hasSpread(resolvedArgument);
// we should actually get only one element, but just in case of getting many, we take the last one List<CompileTimeConstant<?>> constants = resolveValueArguments(resolvedArgument,
if (!constants.isEmpty()) { argumentsAsVararg ? varargElementType : parameterDescriptor.getType(),
annotationDescriptor.setValueArgument(parameterDescriptor, KotlinPackage.last(constants)); 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;
} }
} }