Drop ArrayValue redundant constructor parameter

This commit is contained in:
Pavel V. Talanov
2015-07-03 14:20:39 +03:00
parent ae88dd3f1f
commit f97767e159
6 changed files with 10 additions and 8 deletions
@@ -249,7 +249,7 @@ public class AnnotationResolver {
if (parameterDescriptor.declaresDefaultValue() && constants.isEmpty()) return null; if (parameterDescriptor.declaresDefaultValue() && constants.isEmpty()) return null;
return new ArrayValue(constants, parameterDescriptor.getType(), true, usesVariableAsConstant); return new ArrayValue(constants, parameterDescriptor.getType(), usesVariableAsConstant);
} }
else { else {
// we should actually get only one element, but just in case of getting many, we take the last one // we should actually get only one element, but just in case of getting many, we take the last one
@@ -387,7 +387,7 @@ public class ConstantExpressionEvaluator private constructor(val trace: BindingT
val varargType = resultingDescriptor.getValueParameters().first().getVarargElementType()!! val varargType = resultingDescriptor.getValueParameters().first().getVarargElementType()!!
val arguments = call.getValueArguments().values().flatMap { resolveArguments(it.getArguments(), varargType) } val arguments = call.getValueArguments().values().flatMap { resolveArguments(it.getArguments(), varargType) }
return ArrayValue(arguments, resultingDescriptor.getReturnType()!!, true, arguments.any() { it.usesVariableAsConstant() }) return ArrayValue(arguments, resultingDescriptor.getReturnType()!!, arguments.any() { it.usesVariableAsConstant() })
} }
// Ann() // Ann()
@@ -125,7 +125,7 @@ class LazyJavaAnnotationDescriptor(
val values = elements.map { val values = elements.map {
argument -> resolveAnnotationArgument(argument) ?: NullValue argument -> resolveAnnotationArgument(argument) ?: NullValue
} }
return ArrayValue(values, valueParameter.getType(), true, values.any { it.usesVariableAsConstant() }) return ArrayValue(values, valueParameter.getType(), values.any { it.usesVariableAsConstant() })
} }
private fun resolveFromEnumValue(element: JavaField?): CompileTimeConstant<*>? { private fun resolveFromEnumValue(element: JavaField?): CompileTimeConstant<*>? {
@@ -107,7 +107,7 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
val parameter = DescriptorResolverUtils.getAnnotationParameterByName(name, annotationClass) val parameter = DescriptorResolverUtils.getAnnotationParameterByName(name, annotationClass)
if (parameter != null) { if (parameter != null) {
elements.trimToSize() elements.trimToSize()
arguments[parameter] = ArrayValue(elements, parameter.getType(), true, false) arguments[parameter] = ArrayValue(elements, parameter.getType(), false)
} }
} }
} }
@@ -24,8 +24,8 @@ import java.util.*
public class ArrayValue( public class ArrayValue(
value: List<CompileTimeConstant<*>>, value: List<CompileTimeConstant<*>>,
private val type: JetType, private val type: JetType,
canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean usesVariableAsConstant: Boolean
) : CompileTimeConstant<List<CompileTimeConstant<*>>>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) { ) : CompileTimeConstant<List<CompileTimeConstant<*>>>(value, true, false, usesVariableAsConstant) {
init { init {
assert(KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type)) { "Type should be an array, but was " + type + ": " + value } assert(KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type)) { "Type should be an array, but was " + type + ": " + value }
@@ -110,9 +110,11 @@ public class AnnotationDeserializer(private val module: ModuleDescriptor) {
val expectedElementType = builtIns.getArrayElementType(if (expectedIsArray) expectedType else actualArrayType) val expectedElementType = builtIns.getArrayElementType(if (expectedIsArray) expectedType else actualArrayType)
ArrayValue( ArrayValue(
arrayElements.map { resolveValue(expectedElementType, it, nameResolver) }, arrayElements.map {
resolveValue(expectedElementType, it, nameResolver)
},
actualArrayType, actualArrayType,
true, true true
) )
} }
else -> error("Unsupported annotation argument type: ${value.getType()} (expected $expectedType)") else -> error("Unsupported annotation argument type: ${value.getType()} (expected $expectedType)")