Refactor compile constants to reduce boolean parameter hell
This commit is contained in:
+3
-3
@@ -100,7 +100,7 @@ class LazyJavaAnnotationDescriptor(
|
||||
|
||||
private fun resolveAnnotationArgument(argument: JavaAnnotationArgument?): CompileTimeConstant<*>? {
|
||||
return when (argument) {
|
||||
is JavaLiteralAnnotationArgument -> createCompileTimeConstant(argument.value, true, false, false, null)
|
||||
is JavaLiteralAnnotationArgument -> createCompileTimeConstant(argument.value, CompileTimeConstant.Parameters.Impl(true, false, false))
|
||||
is JavaEnumValueAnnotationArgument -> resolveFromEnumValue(argument.resolve())
|
||||
is JavaArrayAnnotationArgument -> resolveFromArray(argument.name ?: DEFAULT_ANNOTATION_MEMBER_NAME, argument.getElements())
|
||||
is JavaAnnotationAsAnnotationArgument -> resolveFromAnnotation(argument.getAnnotation())
|
||||
@@ -125,7 +125,7 @@ class LazyJavaAnnotationDescriptor(
|
||||
val values = elements.map {
|
||||
argument -> resolveAnnotationArgument(argument) ?: NullValue
|
||||
}
|
||||
return ArrayValue(values, valueParameter.getType(), values.any { it.usesVariableAsConstant() })
|
||||
return ArrayValue(values, valueParameter.getType(), CompileTimeConstant.Parameters.Impl(true, false, values.any { it.usesVariableAsConstant() }))
|
||||
}
|
||||
|
||||
private fun resolveFromEnumValue(element: JavaField?): CompileTimeConstant<*>? {
|
||||
@@ -140,7 +140,7 @@ class LazyJavaAnnotationDescriptor(
|
||||
val classifier = enumClass.getUnsubstitutedInnerClassesScope().getClassifier(element.getName())
|
||||
if (classifier !is ClassDescriptor) return null
|
||||
|
||||
return EnumValue(classifier, false)
|
||||
return EnumValue(classifier)
|
||||
}
|
||||
|
||||
private fun resolveFromJavaClassObjectType(javaType: JavaType): CompileTimeConstant<*>? {
|
||||
|
||||
+7
-7
@@ -66,8 +66,7 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
}
|
||||
|
||||
val compileTimeConstant = createCompileTimeConstant(
|
||||
normalizedValue, canBeUsedInAnnotation = true, isPureIntConstant = true,
|
||||
usesVariableAsConstant = true, expectedType = null
|
||||
normalizedValue, CompileTimeConstant.Parameters.ThrowException
|
||||
)
|
||||
return compileTimeConstant
|
||||
}
|
||||
@@ -107,7 +106,7 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
val parameter = DescriptorResolverUtils.getAnnotationParameterByName(name, annotationClass)
|
||||
if (parameter != null) {
|
||||
elements.trimToSize()
|
||||
arguments[parameter] = ArrayValue(elements, parameter.getType(), false)
|
||||
arguments[parameter] = ArrayValue(elements, parameter.getType(), CompileTimeConstant.Parameters.ThrowException)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,7 +129,7 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
if (enumClass.getKind() == ClassKind.ENUM_CLASS) {
|
||||
val classifier = enumClass.getUnsubstitutedInnerClassesScope().getClassifier(name)
|
||||
if (classifier is ClassDescriptor) {
|
||||
return EnumValue(classifier, false)
|
||||
return EnumValue(classifier)
|
||||
}
|
||||
}
|
||||
return ErrorValue.create("Unresolved enum entry: $enumClassId.$name")
|
||||
@@ -141,9 +140,10 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
}
|
||||
|
||||
private fun createConstant(name: Name?, value: Any?): CompileTimeConstant<*> {
|
||||
return createCompileTimeConstant(value, canBeUsedInAnnotation = true, isPureIntConstant = false,
|
||||
usesVariableAsConstant = false, expectedType = null)
|
||||
?: ErrorValue.create("Unsupported annotation argument: $name")
|
||||
return createCompileTimeConstant(
|
||||
value,
|
||||
CompileTimeConstant.Parameters.ThrowException
|
||||
) ?: ErrorValue.create("Unsupported annotation argument: $name")
|
||||
}
|
||||
|
||||
private fun setArgumentValueByName(name: Name, argumentValue: CompileTimeConstant<*>) {
|
||||
|
||||
Reference in New Issue
Block a user