Convert compile constant classes to kotlin: j2k

This commit is contained in:
Pavel V. Talanov
2015-06-30 15:57:54 +03:00
parent a6180611f4
commit 0369de86c7
29 changed files with 377 additions and 602 deletions
@@ -63,7 +63,6 @@ import java.util.List;
import java.util.Map;
import static org.jetbrains.kotlin.diagnostics.Errors.NOT_AN_ANNOTATION_CLASS;
import static org.jetbrains.kotlin.resolve.BindingContext.ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT;
import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
public class AnnotationResolver {
@@ -99,7 +99,7 @@ public object AnnotationTargetChecker {
?: return DEFAULT_TARGET_LIST
val valueArguments = targetEntryDescriptor.getAllValueArguments()
val valueArgument = valueArguments.entrySet().firstOrNull()?.getValue() as? ArrayValue ?: return DEFAULT_TARGET_LIST
return valueArgument.getValue().filterIsInstance<EnumValue>().map { it.getValue().getName().asString() }
return valueArgument.value.filterIsInstance<EnumValue>().map { it.value.getName().asString() }
}
private fun checkAnnotationEntry(entry: JetAnnotationEntry, actualTargets: List<Target>, trace: BindingTrace) {
@@ -59,5 +59,5 @@ private fun CallableDescriptor.isPlatformStaticIn(predicate: (DeclarationDescrip
public fun AnnotationDescriptor.argumentValue(parameterName: String): Any? {
return getAllValueArguments().entrySet()
.singleOrNull { it.key.getName().asString() == parameterName }
?.value?.getValue()
?.value?.value
}
@@ -151,7 +151,7 @@ public class ConstantExpressionEvaluator private constructor(val trace: BindingT
else {
if (!constant.canBeUsedInAnnotations()) canBeUsedInAnnotation = false
if (constant.usesVariableAsConstant()) usesVariableAsConstant = true
sb.append(constant.getValue())
sb.append(constant.value)
}
}
return if (!interupted)
@@ -180,8 +180,8 @@ public class ConstantExpressionEvaluator private constructor(val trace: BindingT
val rightConstant = evaluate(rightExpression, booleanType)
if (rightConstant == null) return null
val leftValue = leftConstant.getValue()
val rightValue = rightConstant.getValue()
val leftValue = leftConstant.value
val rightValue = rightConstant.value
if (leftValue !is Boolean || rightValue !is Boolean) return null
val result = when(operationToken) {
@@ -341,7 +341,7 @@ public class ConstantExpressionEvaluator private constructor(val trace: BindingT
if (compileTimeConstant is IntegerValueTypeConstant)
compileTimeConstant.getValue(expectedType ?: TypeUtils.NO_EXPECTED_TYPE)
else
compileTimeConstant.getValue()
compileTimeConstant.value
return createCompileTimeConstant(value, expectedType, isPure = false,
canBeUsedInAnnotation = isPropertyCompileTimeConstant(callableDescriptor),
usesVariableAsConstant = true)
@@ -462,7 +462,7 @@ public class ConstantExpressionEvaluator private constructor(val trace: BindingT
return OperationArgument(evaluationResultWithNewType, compileTimeType, expression)
}
val evaluationResult = evaluatedConstant.getValue()
val evaluationResult = evaluatedConstant.value
if (evaluationResult == null) return null
return OperationArgument(evaluationResult, compileTimeType, expression)
@@ -580,7 +580,7 @@ private fun createStringConstant(value: CompileTimeConstant<*>?): StringValue? {
is CharValue,
is DoubleValue, is FloatValue,
is BooleanValue,
is NullValue -> StringValue("${value.getValue()}", value.canBeUsedInAnnotations(), value.usesVariableAsConstant())
is NullValue -> StringValue("${value.value}", value.canBeUsedInAnnotations(), value.usesVariableAsConstant())
else -> null
}
}
@@ -52,39 +52,39 @@ public object AnnotationSerializer {
constant.accept(object : AnnotationArgumentVisitor<Unit, Unit> {
override fun visitAnnotationValue(value: AnnotationValue, data: Unit) {
setType(Type.ANNOTATION)
setAnnotation(serializeAnnotation(value.getValue(), nameTable))
setAnnotation(serializeAnnotation(value.value, nameTable))
}
override fun visitArrayValue(value: ArrayValue, data: Unit) {
setType(Type.ARRAY)
for (element in value.getValue()) {
for (element in value.value) {
addArrayElement(valueProto(element, KotlinBuiltIns.getInstance().getArrayElementType(type), nameTable).build())
}
}
override fun visitBooleanValue(value: BooleanValue, data: Unit) {
setType(Type.BOOLEAN)
setIntValue(if (value.getValue()!!) 1 else 0)
setIntValue(if (value.value) 1 else 0)
}
override fun visitByteValue(value: ByteValue, data: Unit) {
setType(Type.BYTE)
setIntValue(value.getValue()!!.toLong())
setIntValue(value.value.toLong())
}
override fun visitCharValue(value: CharValue, data: Unit) {
setType(Type.CHAR)
setIntValue(value.getValue()!!.toLong())
setIntValue(value.value.toLong())
}
override fun visitDoubleValue(value: DoubleValue, data: Unit) {
setType(Type.DOUBLE)
setDoubleValue(value.getValue()!!)
setDoubleValue(value.value)
}
override fun visitEnumValue(value: EnumValue, data: Unit) {
setType(Type.ENUM)
val enumEntry = value.getValue()
val enumEntry = value.value
setClassId(nameTable.getFqNameIndex(enumEntry.getContainingDeclaration() as ClassDescriptor))
setEnumValueId(nameTable.getSimpleNameIndex(enumEntry.getName()))
}
@@ -95,12 +95,12 @@ public object AnnotationSerializer {
override fun visitFloatValue(value: FloatValue, data: Unit) {
setType(Type.FLOAT)
setFloatValue(value.getValue()!!)
setFloatValue(value.value)
}
override fun visitIntValue(value: IntValue, data: Unit) {
setType(Type.INT)
setIntValue(value.getValue()!!.toLong())
setIntValue(value.value.toLong())
}
override fun visitKClassValue(value: KClassValue?, data: Unit?) {
@@ -110,7 +110,7 @@ public object AnnotationSerializer {
override fun visitLongValue(value: LongValue, data: Unit) {
setType(Type.LONG)
setIntValue(value.getValue()!!)
setIntValue(value.value)
}
override fun visitNullValue(value: NullValue, data: Unit) {
@@ -135,12 +135,12 @@ public object AnnotationSerializer {
override fun visitShortValue(value: ShortValue, data: Unit) {
setType(Type.SHORT)
setIntValue(value.getValue()!!.toLong())
setIntValue(value.value.toLong())
}
override fun visitStringValue(value: StringValue, data: Unit) {
setType(Type.STRING)
setStringValue(nameTable.getStringIndex(value.getValue()!!))
setStringValue(nameTable.getStringIndex(value.value))
}
}, Unit)
@@ -36,7 +36,7 @@ public abstract class AbstractEvaluateExpressionTest : AbstractAnnotationDescrip
property, context ->
val compileTimeConstant = property.getCompileTimeInitializer()
if (compileTimeConstant is StringValue) {
"\\\"${compileTimeConstant.getValue()}\\\""
"\\\"${compileTimeConstant.value}\\\""
} else {
"$compileTimeConstant"
}