diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/AnnotationValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/AnnotationValue.kt deleted file mode 100644 index 793ae285248..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/AnnotationValue.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor -import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor -import org.jetbrains.kotlin.types.JetType - -public class AnnotationValue(value: AnnotationDescriptor) : ConstantValue(value) { - override val type: JetType - get() = value.getType() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitAnnotationValue(this, data) - - override fun toString() = value.toString() -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ArrayValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ArrayValue.kt deleted file mode 100644 index 6a69ae3e742..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ArrayValue.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor -import org.jetbrains.kotlin.types.JetType - -public class ArrayValue( - value: List>, - override val type: JetType -) : ConstantValue>>(value) { - init { - assert(KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type)) { "Type should be an array, but was " + type + ": " + value } - } - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitArrayValue(this, data) - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - return value == (other as ArrayValue).value - } - - override fun hashCode() = value.hashCode() -} - diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/BooleanValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/BooleanValue.kt deleted file mode 100644 index 1b97566bb30..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/BooleanValue.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor - -public class BooleanValue( - value: Boolean, - builtIns: KotlinBuiltIns -) : ConstantValue(value) { - override val type = builtIns.getBooleanType() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitBooleanValue(this, data) -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ByteValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ByteValue.kt deleted file mode 100644 index 45017963172..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ByteValue.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor - -public class ByteValue( - value: Byte, - builtIns: KotlinBuiltIns -) : IntegerValueConstant(value) { - - override val type = builtIns.getByteType() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitByteValue(this, data) - - override fun toString(): String = "$value.toByte()" -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CharValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CharValue.kt deleted file mode 100644 index 58f52a4ebe8..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/CharValue.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor - -public class CharValue( - value: Char, - builtIns: KotlinBuiltIns -) : IntegerValueConstant(value) { - - override val type = builtIns.getCharType() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitCharValue(this, data) - - override fun toString() = "\\u%04X ('%s')".format(value.toInt(), getPrintablePart(value)) - - private fun getPrintablePart(c: Char): String { - when (c) { - '\b' -> return "\\b" - '\t' -> return "\\t" - '\n' -> return "\\n" - //TODO: KT-8507 - 12.toChar() -> return "\\f" - '\r' -> return "\\r" - else -> return if (isPrintableUnicode(c)) Character.toString(c) else "?" - } - } - - private fun isPrintableUnicode(c: Char): Boolean { - val t = Character.getType(c).toByte() - return t != Character.UNASSIGNED && - t != Character.LINE_SEPARATOR && - t != Character.PARAGRAPH_SEPARATOR && - t != Character.CONTROL && - t != Character.FORMAT && - t != Character.PRIVATE_USE && - t != Character.SURROGATE - } -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ConstantValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ConstantValue.kt deleted file mode 100644 index fe9a61cfc6b..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ConstantValue.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor -import org.jetbrains.kotlin.types.JetType - -public abstract class ConstantValue(public open val value: T) { - public abstract val type: JetType - - public abstract fun accept(visitor: AnnotationArgumentVisitor, data: D): R - - override fun toString() = value.toString() - -} \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/DoubleValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/DoubleValue.kt deleted file mode 100644 index 60483c806e6..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/DoubleValue.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor - -public class DoubleValue( - value: Double, - builtIns: KotlinBuiltIns -) : ConstantValue(value) { - override val type = builtIns.getDoubleType() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitDoubleValue(this, data) - - override fun toString() = "$value.toDouble()" -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/EnumValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/EnumValue.kt deleted file mode 100644 index c943df89c3e..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/EnumValue.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor -import org.jetbrains.kotlin.resolve.descriptorUtil.classObjectType -import org.jetbrains.kotlin.types.JetType -import org.jetbrains.kotlin.utils.sure - -public class EnumValue( - value: ClassDescriptor -) : ConstantValue(value) { - - override val type: JetType - get() = value.classObjectType.sure { "Enum entry must have a class object type: " + value } - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitEnumValue(this, data) - - override fun toString() = "$type.${value.getName()}" - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - return value == (other as EnumValue).value - } - - override fun hashCode() = value.hashCode() -} - diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ErrorValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ErrorValue.kt deleted file mode 100644 index 22ec21ffdc5..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ErrorValue.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor -import org.jetbrains.kotlin.types.ErrorUtils - -public abstract class ErrorValue : ConstantValue(Unit) { - - deprecated("Should not be called, for this is not a real value, but a indication of an error") - override val value: Unit - get() = throw UnsupportedOperationException() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitErrorValue(this, data) - - public class ErrorValueWithMessage(public val message: String) : ErrorValue() { - - override val type = ErrorUtils.createErrorType(message) - - override fun toString() = message - } - - companion object { - public fun create(message: String): ErrorValue { - return ErrorValueWithMessage(message) - } - } -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/FloatValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/FloatValue.kt deleted file mode 100644 index a8b5e702e73..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/FloatValue.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor - -public class FloatValue( - value: Float, - builtIns: KotlinBuiltIns -) : ConstantValue(value) { - override val type = builtIns.getFloatType() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitFloatValue(this, data) - - override fun toString() = "$value.toFloat()" -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntValue.kt deleted file mode 100644 index aea685df995..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntValue.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor - -public class IntValue( - value: Int, - builtIns: KotlinBuiltIns -) : IntegerValueConstant(value) { - - override val type = builtIns.getIntType() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitIntValue(this, data) - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - val intValue = other as IntValue - - return value == intValue.value - } - - override fun hashCode() = value -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueConstant.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueConstant.kt deleted file mode 100644 index b23941722db..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueConstant.kt +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -public abstract class IntegerValueConstant protected constructor(value: T) : ConstantValue(value) diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/KClassValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/KClassValue.kt deleted file mode 100644 index b31f7491743..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/KClassValue.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor -import org.jetbrains.kotlin.types.JetType - -public class KClassValue(override val type: JetType) : - ConstantValue(type) { - override val value: JetType - get() = type.getArguments().single().getType() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitKClassValue(this, data) -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/LongValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/LongValue.kt deleted file mode 100644 index 74eb173a3ce..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/LongValue.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor - -public class LongValue( - value: Long, - builtIns: KotlinBuiltIns -) : IntegerValueConstant(value) { - - override val type = builtIns.getLongType() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitLongValue(this, data) - - override fun toString() = "$value.toLong()" -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/NullValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/NullValue.kt deleted file mode 100644 index b8f25749dc5..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/NullValue.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor - -public class NullValue( - builtIns: KotlinBuiltIns -) : ConstantValue(null) { - - override val type = builtIns.getNullableNothingType() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitNullValue(this, data) - - override fun toString() = "null" -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ShortValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ShortValue.kt deleted file mode 100644 index 04f0236d4c3..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ShortValue.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor - -public class ShortValue( - value: Short, - builtIns: KotlinBuiltIns -) : IntegerValueConstant(value) { - - override val type = builtIns.getShortType() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitShortValue(this, data) - - override fun toString() = "$value.toShort()" -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/StringValue.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/StringValue.kt deleted file mode 100644 index ccda72185ce..00000000000 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/StringValue.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.constants - -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor - -public class StringValue( - value: String, - builtIns: KotlinBuiltIns -) : ConstantValue(value) { - override val type = builtIns.getStringType() - - override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitStringValue(this, data) - - override fun toString() = "\"$value\"" - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || javaClass != other.javaClass) return false - - return value != (other as StringValue).value - } - - override fun hashCode() = value.hashCode() -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt new file mode 100644 index 00000000000..aa46776f23f --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt @@ -0,0 +1,271 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.resolve.constants + +import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor +import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor +import org.jetbrains.kotlin.resolve.descriptorUtil.classObjectType +import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.JetType +import org.jetbrains.kotlin.utils.sure + +public abstract class ConstantValue(public open val value: T) { + public abstract val type: JetType + + public abstract fun accept(visitor: AnnotationArgumentVisitor, data: D): R + + override fun toString() = value.toString() +} + +public abstract class IntegerValueConstant protected constructor(value: T) : ConstantValue(value) + +public class AnnotationValue(value: AnnotationDescriptor) : ConstantValue(value) { + + override val type: JetType + get() = value.getType() + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitAnnotationValue(this, data) + override fun toString() = value.toString() +} + +public class ArrayValue( + value: List>, + override val type: JetType +) : ConstantValue>>(value) { + + init { + assert(KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type)) { "Type should be an array, but was " + type + ": " + value } + } + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitArrayValue(this, data) + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + return value == (other as ArrayValue).value + } + + override fun hashCode() = value.hashCode() +} + +public class BooleanValue( + value: Boolean, + builtIns: KotlinBuiltIns +) : ConstantValue(value) { + + override val type = builtIns.getBooleanType() + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitBooleanValue(this, data) + +} + +public class ByteValue( + value: Byte, + builtIns: KotlinBuiltIns +) : IntegerValueConstant(value) { + + override val type = builtIns.getByteType() + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitByteValue(this, data) + override fun toString(): String = "$value.toByte()" +} + +public class CharValue( + value: Char, + builtIns: KotlinBuiltIns +) : IntegerValueConstant(value) { + + override val type = builtIns.getCharType() + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitCharValue(this, data) + + override fun toString() = "\\u%04X ('%s')".format(value.toInt(), getPrintablePart(value)) + + private fun getPrintablePart(c: Char): String { + when (c) { + '\b' -> return "\\b" + '\t' -> return "\\t" + '\n' -> return "\\n" + //TODO: KT-8507 + 12.toChar() -> return "\\f" + '\r' -> return "\\r" + else -> return if (isPrintableUnicode(c)) Character.toString(c) else "?" + } + } + + private fun isPrintableUnicode(c: Char): Boolean { + val t = Character.getType(c).toByte() + return t != Character.UNASSIGNED && + t != Character.LINE_SEPARATOR && + t != Character.PARAGRAPH_SEPARATOR && + t != Character.CONTROL && + t != Character.FORMAT && + t != Character.PRIVATE_USE && + t != Character.SURROGATE + } +} + +public class DoubleValue( + value: Double, + builtIns: KotlinBuiltIns +) : ConstantValue(value) { + override val type = builtIns.getDoubleType() + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitDoubleValue(this, data) + + override fun toString() = "$value.toDouble()" +} + +public class EnumValue( + value: ClassDescriptor +) : ConstantValue(value) { + + override val type: JetType + get() = value.classObjectType.sure { "Enum entry must have a class object type: " + value } + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitEnumValue(this, data) + + override fun toString() = "$type.${value.getName()}" + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + return value == (other as EnumValue).value + } + + override fun hashCode() = value.hashCode() +} + +public abstract class ErrorValue : ConstantValue(Unit) { + + deprecated("Should not be called, for this is not a real value, but a indication of an error") + override val value: Unit + get() = throw UnsupportedOperationException() + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitErrorValue(this, data) + + public class ErrorValueWithMessage(public val message: String) : ErrorValue() { + + override val type = ErrorUtils.createErrorType(message) + + override fun toString() = message + } + + companion object { + public fun create(message: String): ErrorValue { + return ErrorValueWithMessage(message) + } + } +} + +public class FloatValue( + value: Float, + builtIns: KotlinBuiltIns +) : ConstantValue(value) { + override val type = builtIns.getFloatType() + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitFloatValue(this, data) + + override fun toString() = "$value.toFloat()" +} + +public class IntValue( + value: Int, + builtIns: KotlinBuiltIns +) : IntegerValueConstant(value) { + + override val type = builtIns.getIntType() + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitIntValue(this, data) + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + val intValue = other as IntValue + + return value == intValue.value + } + + override fun hashCode() = value +} + +public class KClassValue(override val type: JetType) : + ConstantValue(type) { + override val value: JetType + get() = type.getArguments().single().getType() + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitKClassValue(this, data) +} + +public class LongValue( + value: Long, + builtIns: KotlinBuiltIns +) : IntegerValueConstant(value) { + + override val type = builtIns.getLongType() + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitLongValue(this, data) + + override fun toString() = "$value.toLong()" +} + +public class NullValue( + builtIns: KotlinBuiltIns +) : ConstantValue(null) { + + override val type = builtIns.getNullableNothingType() + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitNullValue(this, data) + + override fun toString() = "null" +} + +public class ShortValue( + value: Short, + builtIns: KotlinBuiltIns +) : IntegerValueConstant(value) { + + override val type = builtIns.getShortType() + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitShortValue(this, data) + + override fun toString() = "$value.toShort()" +} + +public class StringValue( + value: String, + builtIns: KotlinBuiltIns +) : ConstantValue(value) { + override val type = builtIns.getStringType() + + override fun accept(visitor: AnnotationArgumentVisitor, data: D) = visitor.visitStringValue(this, data) + + override fun toString() = "\"$value\"" + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || javaClass != other.javaClass) return false + + return value != (other as StringValue).value + } + + override fun hashCode() = value.hashCode() +} \ No newline at end of file