Convert compile constant classes to kotlin: j2k
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
+6
-6
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -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)
|
||||
|
||||
|
||||
+1
-1
@@ -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"
|
||||
}
|
||||
|
||||
@@ -386,9 +386,9 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
private fun renderConstant(value: CompileTimeConstant<*>): String {
|
||||
return when (value) {
|
||||
is ArrayValue -> value.getValue().map { renderConstant(it) }.joinToString(", ", "{", "}")
|
||||
is AnnotationValue -> renderAnnotation(value.getValue())
|
||||
is KClassValue -> renderType(value.getValue()) + "::class"
|
||||
is ArrayValue -> value.value.map { renderConstant(it) }.joinToString(", ", "{", "}")
|
||||
is AnnotationValue -> renderAnnotation(value.value)
|
||||
is KClassValue -> renderType(value.value) + "::class"
|
||||
else -> value.toString()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,41 +14,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class AnnotationValue extends CompileTimeConstant<AnnotationDescriptor> {
|
||||
|
||||
public AnnotationValue(@NotNull AnnotationDescriptor value) {
|
||||
super(value, true, false, false);
|
||||
public class AnnotationValue(value: AnnotationDescriptor) : CompileTimeConstant<AnnotationDescriptor>(value, true, false, false) {
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return value.getType()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AnnotationDescriptor getValue() {
|
||||
AnnotationDescriptor value = super.getValue();
|
||||
assert value != null : "Guaranteed by constructor";
|
||||
return value;
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitAnnotationValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return value.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitAnnotationValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
override fun toString(): String {
|
||||
return value.toString()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,83 +14,58 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
import java.util.List;
|
||||
public class ArrayValue(value: List<CompileTimeConstant<*>>, private val type: JetType, canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant<List<CompileTimeConstant<*>>>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) {
|
||||
|
||||
public class ArrayValue extends CompileTimeConstant<List<CompileTimeConstant<?>>> {
|
||||
|
||||
private final JetType type;
|
||||
|
||||
public ArrayValue(@NotNull List<CompileTimeConstant<?>> value,
|
||||
@NotNull JetType type,
|
||||
boolean canBeUsedInAnnotations,
|
||||
boolean usesVariableAsConstant) {
|
||||
super(value, canBeUsedInAnnotations, false, usesVariableAsConstant);
|
||||
assert KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type)
|
||||
: "Type should be an array, but was " + type + ": " + value;
|
||||
this.type = type;
|
||||
init {
|
||||
assert(KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type)) { "Type should be an array, but was " + type + ": " + value }
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<CompileTimeConstant<?>> getValue() {
|
||||
List<CompileTimeConstant<?>> value = super.getValue();
|
||||
assert value != null : "Guaranteed by constructor";
|
||||
return value;
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return type
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return type;
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitArrayValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitArrayValue(this, data);
|
||||
override fun toString(): String {
|
||||
return value.toString()
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
override fun equals(o: Any?): Boolean {
|
||||
if (this === o) return true
|
||||
if (o == null || javaClass != o.javaClass) return false
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ArrayValue that = (ArrayValue) o;
|
||||
val that = o as? ArrayValue ?: return false
|
||||
|
||||
if (value == null) {
|
||||
return that.value == null;
|
||||
return that.value == null
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (Object thisObject : value) {
|
||||
if (!thisObject.equals(that.value.get(i))) {
|
||||
return false;
|
||||
var i = 0
|
||||
for (thisObject in value) {
|
||||
if (thisObject != that.value.get(i)) {
|
||||
return false
|
||||
}
|
||||
i++;
|
||||
i++
|
||||
}
|
||||
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = 0;
|
||||
if (value == null) return hashCode;
|
||||
for (Object o : value) {
|
||||
hashCode += o.hashCode();
|
||||
override fun hashCode(): Int {
|
||||
var hashCode = 0
|
||||
if (value == null) return hashCode
|
||||
for (o in value) {
|
||||
hashCode += o.hashCode()
|
||||
}
|
||||
return hashCode;
|
||||
return hashCode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,33 +14,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class BooleanValue extends CompileTimeConstant<Boolean> {
|
||||
public class BooleanValue(value: Boolean, canBeUseInAnnotation: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant<Boolean>(value, canBeUseInAnnotation, false, usesVariableAsConstant) {
|
||||
|
||||
public BooleanValue(boolean value, boolean canBeUseInAnnotation, boolean usesVariableAsConstant) {
|
||||
super(value, canBeUseInAnnotation, false, usesVariableAsConstant);
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return kotlinBuiltIns.getBooleanType()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getBooleanType();
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitBooleanValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitBooleanValue(this, data);
|
||||
override fun toString(): String {
|
||||
return "$value"
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,32 +14,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class ByteValue extends IntegerValueConstant<Byte> {
|
||||
public class ByteValue(value: Byte, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVaraiableAsConstant: Boolean) : IntegerValueConstant<Byte>(value, canBeUsedInAnnotations, pure, usesVaraiableAsConstant) {
|
||||
|
||||
public ByteValue(byte value, boolean canBeUsedInAnnotations, boolean pure, boolean usesVaraiableAsConstant) {
|
||||
super(value, canBeUsedInAnnotations, pure, usesVaraiableAsConstant);
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return kotlinBuiltIns.getByteType()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getByteType();
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitByteValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitByteValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + ".toByte()";
|
||||
override fun toString(): String {
|
||||
return "$value.toByte()"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,55 +14,44 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class CharValue extends IntegerValueConstant<Character> {
|
||||
public class CharValue(value: Char, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVariableAsConstant: Boolean) : IntegerValueConstant<Char>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) {
|
||||
|
||||
public CharValue(char value, boolean canBeUsedInAnnotations, boolean pure, boolean usesVariableAsConstant) {
|
||||
super(value, canBeUsedInAnnotations, pure, usesVariableAsConstant);
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return kotlinBuiltIns.getCharType()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getCharType();
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitCharValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitCharValue(this, data);
|
||||
}
|
||||
override fun toString() = "\\u%04X ('%s')".format(value.toInt(), getPrintablePart(value))
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("\\u%04X ('%s')", (int) value, getPrintablePart(value));
|
||||
}
|
||||
|
||||
private static String getPrintablePart(char c) {
|
||||
switch (c) {
|
||||
case '\b':
|
||||
return "\\b";
|
||||
case '\t':
|
||||
return "\\t";
|
||||
case '\n':
|
||||
return "\\n";
|
||||
case '\f':
|
||||
return "\\f";
|
||||
case '\r':
|
||||
return "\\r";
|
||||
default:
|
||||
return isPrintableUnicode(c) ? Character.toString(c) : "?";
|
||||
private fun getPrintablePart(c: Char): String {
|
||||
when (c) {
|
||||
'\b' -> return "\\b"
|
||||
'\t' -> return "\\t"
|
||||
'\n' -> return "\\n"
|
||||
//TODO_R: can't escape form feed in Kotlin
|
||||
12.toChar() -> return "\\f"
|
||||
'\r' -> return "\\r"
|
||||
else -> return if (isPrintableUnicode(c)) Character.toString(c) else "?"
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isPrintableUnicode(char c) {
|
||||
int t = Character.getType(c);
|
||||
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;
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
+32
-44
@@ -14,57 +14,45 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public abstract class CompileTimeConstant<T> {
|
||||
protected final T value;
|
||||
private final int flags;
|
||||
public abstract class CompileTimeConstant<T> protected constructor(public open val value: T, canBeUsedInAnnotations: Boolean, isPure: Boolean, usesVariableAsConstant: Boolean) {
|
||||
private val flags: Int
|
||||
|
||||
/*
|
||||
init {
|
||||
flags = (if (isPure) IS_PURE_MASK else 0) or (if (canBeUsedInAnnotations) CAN_BE_USED_IN_ANNOTATIONS_MASK else 0) or (if (usesVariableAsConstant) USES_VARIABLE_AS_CONSTANT_MASK else 0)
|
||||
}
|
||||
|
||||
public fun canBeUsedInAnnotations(): Boolean {
|
||||
return (flags and CAN_BE_USED_IN_ANNOTATIONS_MASK) != 0
|
||||
}
|
||||
|
||||
public fun isPure(): Boolean {
|
||||
return (flags and IS_PURE_MASK) != 0
|
||||
}
|
||||
|
||||
public fun usesVariableAsConstant(): Boolean {
|
||||
return (flags and USES_VARIABLE_AS_CONSTANT_MASK) != 0
|
||||
}
|
||||
|
||||
public abstract fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType
|
||||
|
||||
public abstract fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R
|
||||
|
||||
companion object {
|
||||
|
||||
/*
|
||||
* if is pure is false then constant type cannot be changed
|
||||
* ex1. val a: Long = 1.toInt() (TYPE_MISMATCH error, 1.toInt() isn't pure)
|
||||
* ex2. val b: Int = a (TYPE_MISMATCH error, a isn't pure)
|
||||
*
|
||||
*/
|
||||
private static final int IS_PURE_MASK = 1;
|
||||
private static final int CAN_BE_USED_IN_ANNOTATIONS_MASK = 1 << 1;
|
||||
private static final int USES_VARIABLE_AS_CONSTANT_MASK = 1 << 2;
|
||||
|
||||
protected CompileTimeConstant(T value,
|
||||
boolean canBeUsedInAnnotations,
|
||||
boolean isPure,
|
||||
boolean usesVariableAsConstant) {
|
||||
this.value = value;
|
||||
flags = (isPure ? IS_PURE_MASK : 0) |
|
||||
(canBeUsedInAnnotations ? CAN_BE_USED_IN_ANNOTATIONS_MASK : 0) |
|
||||
(usesVariableAsConstant ? USES_VARIABLE_AS_CONSTANT_MASK : 0);
|
||||
private val IS_PURE_MASK = 1
|
||||
private val CAN_BE_USED_IN_ANNOTATIONS_MASK = 1 shl 1
|
||||
private val USES_VARIABLE_AS_CONSTANT_MASK = 1 shl 2
|
||||
}
|
||||
|
||||
public boolean canBeUsedInAnnotations() {
|
||||
return (flags & CAN_BE_USED_IN_ANNOTATIONS_MASK) != 0;
|
||||
}
|
||||
|
||||
public boolean isPure() {
|
||||
return (flags & IS_PURE_MASK) != 0;
|
||||
}
|
||||
|
||||
public boolean usesVariableAsConstant() {
|
||||
return (flags & USES_VARIABLE_AS_CONSTANT_MASK) != 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns);
|
||||
|
||||
public abstract <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data);
|
||||
}
|
||||
|
||||
@@ -14,32 +14,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class DoubleValue extends CompileTimeConstant<Double> {
|
||||
public class DoubleValue(value: Double, canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant<Double>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) {
|
||||
|
||||
public DoubleValue(double value, boolean canBeUsedInAnnotations, boolean usesVariableAsConstant) {
|
||||
super(value, canBeUsedInAnnotations, false, usesVariableAsConstant);
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return kotlinBuiltIns.getDoubleType()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getDoubleType();
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitDoubleValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitDoubleValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + ".toDouble()";
|
||||
override fun toString(): String {
|
||||
return "$value.toDouble()"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,64 +14,43 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
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
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getClassObjectType;
|
||||
public class EnumValue(value: ClassDescriptor, usesVariableAsConstant: Boolean) : CompileTimeConstant<ClassDescriptor>(value, true, false, usesVariableAsConstant) {
|
||||
|
||||
public class EnumValue extends CompileTimeConstant<ClassDescriptor> {
|
||||
|
||||
public EnumValue(@NotNull ClassDescriptor value, boolean usesVariableAsConstant) {
|
||||
super(value, true, false, usesVariableAsConstant);
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return getType()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return getType();
|
||||
private fun getType(): JetType {
|
||||
val type = value.classObjectType
|
||||
return type.sure { "Enum entry must have a class object type: " + value }
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JetType getType() {
|
||||
JetType type = getClassObjectType(value);
|
||||
assert type != null : "Enum entry must have a class object type: " + value;
|
||||
return type;
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitEnumValue(this, data)
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassDescriptor getValue() {
|
||||
ClassDescriptor value = super.getValue();
|
||||
assert value != null : "Guaranteed by constructor";
|
||||
return value;
|
||||
override fun toString(): String {
|
||||
return "${getType()}.${value.getName()}"
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitEnumValue(this, data);
|
||||
override fun equals(o: Any?): Boolean {
|
||||
if (this === o) return true
|
||||
if (o == null || javaClass != o.javaClass) return false
|
||||
|
||||
return value == (o as? EnumValue)?.value
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getType() + "." + value.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
return value.equals(((EnumValue) o).value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return value.hashCode();
|
||||
override fun hashCode(): Int {
|
||||
return value.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,56 +14,40 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public abstract class ErrorValue extends CompileTimeConstant<Void> {
|
||||
public abstract class ErrorValue : CompileTimeConstant<Unit>(Unit, true, false, false) {
|
||||
|
||||
public ErrorValue() {
|
||||
super(null, true, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated // Should not be called, for this is not a real value, but a indication of an error
|
||||
public Void getValue() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitErrorValue(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ErrorValue create(@NotNull String message) {
|
||||
return new ErrorValueWithMessage(message);
|
||||
}
|
||||
|
||||
public static class ErrorValueWithMessage extends ErrorValue {
|
||||
private final String message;
|
||||
|
||||
public ErrorValueWithMessage(@NotNull String message) {
|
||||
this.message = message;
|
||||
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()
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitErrorValue(this, data)
|
||||
}
|
||||
|
||||
public class ErrorValueWithMessage(public val message: String) : ErrorValue() {
|
||||
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return ErrorUtils.createErrorType(message)
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return ErrorUtils.createErrorType(message);
|
||||
override fun toString(): String {
|
||||
return message
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getMessage();
|
||||
companion object {
|
||||
|
||||
public fun create(message: String): ErrorValue {
|
||||
return ErrorValueWithMessage(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,32 +14,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class FloatValue extends CompileTimeConstant<Float> {
|
||||
public class FloatValue(value: Float, canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant<Float>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) {
|
||||
|
||||
public FloatValue(float value, boolean canBeUsedInAnnotations, boolean usesVariableAsConstant) {
|
||||
super(value, canBeUsedInAnnotations, false, usesVariableAsConstant);
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return kotlinBuiltIns.getFloatType()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getFloatType();
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitFloatValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitFloatValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + ".toFloat()";
|
||||
override fun toString(): String {
|
||||
return "$value.toFloat()"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,49 +14,38 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class IntValue extends IntegerValueConstant<Integer> {
|
||||
public class IntValue(value: Int, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVariableAsConstant: Boolean) : IntegerValueConstant<Int>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) {
|
||||
|
||||
public IntValue(int value, boolean canBeUsedInAnnotations, boolean pure, boolean usesVariableAsConstant) {
|
||||
super(value, canBeUsedInAnnotations, pure, usesVariableAsConstant);
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return kotlinBuiltIns.getIntType()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getIntType();
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitIntValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitIntValue(this, data);
|
||||
override fun toString(): String {
|
||||
return value.toString()
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
override fun equals(o: Any?): Boolean {
|
||||
if (this === o) return true
|
||||
if (o == null || javaClass != o.javaClass) return false
|
||||
|
||||
val intValue = o as? IntValue ?: return false
|
||||
|
||||
if (value !== intValue.value) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
IntValue intValue = (IntValue) o;
|
||||
|
||||
if (value != intValue.value) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return value;
|
||||
override fun hashCode(): Int {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
public abstract class IntegerValueConstant<T> extends CompileTimeConstant<T> {
|
||||
|
||||
protected IntegerValueConstant(T value, boolean canBeUsedInAnnotations, boolean pure, boolean usesVariableAsConstant) {
|
||||
super(value, canBeUsedInAnnotations, pure, usesVariableAsConstant);
|
||||
}
|
||||
}
|
||||
public abstract class IntegerValueConstant<T> protected constructor(value: T, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant<T>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant)
|
||||
|
||||
+33
-48
@@ -14,74 +14,59 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.types.*
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Collections
|
||||
|
||||
public class IntegerValueTypeConstant extends IntegerValueConstant<Number> {
|
||||
public class IntegerValueTypeConstant(value: Number, canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean) : IntegerValueConstant<Number>(value, canBeUsedInAnnotations, true, usesVariableAsConstant) {
|
||||
|
||||
private final IntegerValueTypeConstructor typeConstructor;
|
||||
private val typeConstructor: IntegerValueTypeConstructor
|
||||
|
||||
public IntegerValueTypeConstant(@NotNull Number value, boolean canBeUsedInAnnotations, boolean usesVariableAsConstant) {
|
||||
super(value, canBeUsedInAnnotations, true, usesVariableAsConstant);
|
||||
this.typeConstructor = new IntegerValueTypeConstructor(value.longValue());
|
||||
init {
|
||||
this.typeConstructor = IntegerValueTypeConstructor(value.toLong())
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return new JetTypeImpl(
|
||||
Annotations.EMPTY, typeConstructor,
|
||||
false, Collections.<TypeProjection>emptyList(),
|
||||
ErrorUtils.createErrorScope("Scope for number value type (" + typeConstructor.toString() + ")", true));
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return JetTypeImpl(Annotations.EMPTY, typeConstructor, false, emptyList<TypeProjection>(), ErrorUtils.createErrorScope("Scope for number value type (" + typeConstructor.toString() + ")", true))
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@Deprecated
|
||||
public Number getValue() {
|
||||
throw new UnsupportedOperationException("Use IntegerValueTypeConstant.getValue(expectedType) instead");
|
||||
deprecated("")
|
||||
override val value: Number
|
||||
get() = throw UnsupportedOperationException("Use IntegerValueTypeConstant.getValue(expectedType) instead")
|
||||
|
||||
public fun getType(expectedType: JetType): JetType {
|
||||
return TypeUtils.getPrimitiveNumberType(typeConstructor, expectedType)
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getType(@NotNull JetType expectedType) {
|
||||
return TypeUtils.getPrimitiveNumberType(typeConstructor, expectedType);
|
||||
}
|
||||
public fun getValue(expectedType: JetType): Number {
|
||||
val numberValue = typeConstructor.getValue()
|
||||
val builtIns = KotlinBuiltIns.getInstance()
|
||||
|
||||
@NotNull
|
||||
public Number getValue(@NotNull JetType expectedType) {
|
||||
Number numberValue = typeConstructor.getValue();
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
|
||||
JetType valueType = getType(expectedType);
|
||||
if (valueType.equals(builtIns.getIntType())) {
|
||||
return numberValue.intValue();
|
||||
val valueType = getType(expectedType)
|
||||
if (valueType == builtIns.getIntType()) {
|
||||
return numberValue.toInt()
|
||||
}
|
||||
else if (valueType.equals(builtIns.getByteType())) {
|
||||
return numberValue.byteValue();
|
||||
else if (valueType == builtIns.getByteType()) {
|
||||
return numberValue.toByte()
|
||||
}
|
||||
else if (valueType.equals(builtIns.getShortType())) {
|
||||
return numberValue.shortValue();
|
||||
else if (valueType == builtIns.getShortType()) {
|
||||
return numberValue.toShort()
|
||||
}
|
||||
else {
|
||||
return numberValue.longValue();
|
||||
return numberValue.toLong()
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitNumberTypeValue(this, data);
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitNumberTypeValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return typeConstructor.toString();
|
||||
override fun toString(): String {
|
||||
return typeConstructor.toString()
|
||||
}
|
||||
}
|
||||
|
||||
+37
-55
@@ -14,83 +14,65 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.TypeConstructor;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList
|
||||
import java.util.Collections
|
||||
|
||||
public class IntegerValueTypeConstructor implements TypeConstructor {
|
||||
private final long value;
|
||||
private final Collection<JetType> supertypes = new ArrayList<JetType>(4);
|
||||
public class IntegerValueTypeConstructor(private val value: Long) : TypeConstructor {
|
||||
private val supertypes = ArrayList<JetType>(4)
|
||||
|
||||
public IntegerValueTypeConstructor(long value) {
|
||||
// order of types matters
|
||||
// 'getPrimitiveNumberType' returns first of supertypes that is a subtype of expected type
|
||||
// for expected type 'Any' result type 'Int' should be returned
|
||||
this.value = value;
|
||||
checkBoundsAndAddSuperType(value, (long) Integer.MIN_VALUE, (long) Integer.MAX_VALUE, KotlinBuiltIns.getInstance().getIntType());
|
||||
checkBoundsAndAddSuperType(value, (long) Byte.MIN_VALUE, (long) Byte.MAX_VALUE, KotlinBuiltIns.getInstance().getByteType());
|
||||
checkBoundsAndAddSuperType(value, (long) Short.MIN_VALUE, (long) Short.MAX_VALUE, KotlinBuiltIns.getInstance().getShortType());
|
||||
supertypes.add(KotlinBuiltIns.getInstance().getLongType());
|
||||
}
|
||||
init {
|
||||
checkBoundsAndAddSuperType(value, Integer.MIN_VALUE.toLong(), Integer.MAX_VALUE.toLong(), KotlinBuiltIns.getInstance().getIntType())
|
||||
checkBoundsAndAddSuperType(value, java.lang.Byte.MIN_VALUE.toLong(), java.lang.Byte.MAX_VALUE.toLong(), KotlinBuiltIns.getInstance().getByteType())
|
||||
checkBoundsAndAddSuperType(value, java.lang.Short.MIN_VALUE.toLong(), java.lang.Short.MAX_VALUE.toLong(), KotlinBuiltIns.getInstance().getShortType())
|
||||
supertypes.add(KotlinBuiltIns.getInstance().getLongType())
|
||||
}// order of types matters
|
||||
// 'getPrimitiveNumberType' returns first of supertypes that is a subtype of expected type
|
||||
// for expected type 'Any' result type 'Int' should be returned
|
||||
|
||||
private void checkBoundsAndAddSuperType(long value, long minValue, long maxValue, JetType kotlinType) {
|
||||
private fun checkBoundsAndAddSuperType(value: Long, minValue: Long, maxValue: Long, kotlinType: JetType) {
|
||||
if (value >= minValue && value <= maxValue) {
|
||||
supertypes.add(kotlinType);
|
||||
supertypes.add(kotlinType)
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetType> getSupertypes() {
|
||||
return supertypes;
|
||||
override fun getSupertypes(): Collection<JetType> {
|
||||
return supertypes
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getParameters() {
|
||||
return Collections.emptyList();
|
||||
override fun getParameters(): List<TypeParameterDescriptor> {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinal() {
|
||||
return false;
|
||||
override fun isFinal(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDenotable() {
|
||||
return false;
|
||||
override fun isDenotable(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ClassifierDescriptor getDeclarationDescriptor() {
|
||||
return null;
|
||||
override fun getDeclarationDescriptor(): ClassifierDescriptor? {
|
||||
return null
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Annotations getAnnotations() {
|
||||
return Annotations.EMPTY;
|
||||
override fun getAnnotations(): Annotations {
|
||||
return Annotations.EMPTY
|
||||
}
|
||||
|
||||
public Long getValue() {
|
||||
return value;
|
||||
public fun getValue(): Long {
|
||||
return value
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IntegerValueType(" + value + ")";
|
||||
override fun toString(): String {
|
||||
return "IntegerValueType(" + value + ")"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,10 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
|
||||
public class KClassValue(type: JetType) : CompileTimeConstant<JetType>(type, true, false, false) {
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = value
|
||||
override fun getValue(): JetType = value.getArguments().single().getType()
|
||||
public class KClassValue(private val type: JetType) : CompileTimeConstant<JetType>(type, true, false, false) {
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns) = type
|
||||
override val value: JetType
|
||||
get() = type.getArguments().single().getType()
|
||||
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitKClassValue(this, data)
|
||||
}
|
||||
|
||||
@@ -14,32 +14,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class LongValue extends IntegerValueConstant<Long> {
|
||||
public class LongValue(value: Long, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVariableAsConstant: Boolean) : IntegerValueConstant<Long>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) {
|
||||
|
||||
public LongValue(long value, boolean canBeUsedInAnnotations, boolean pure, boolean usesVariableAsConstant) {
|
||||
super(value, canBeUsedInAnnotations, pure, usesVariableAsConstant);
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return kotlinBuiltIns.getLongType()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getLongType();
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitLongValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitLongValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + ".toLong()";
|
||||
override fun toString(): String {
|
||||
return "$value.toLong()"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,34 +14,27 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class NullValue extends CompileTimeConstant<Void> {
|
||||
public class NullValue private constructor() : CompileTimeConstant<Void?>(null, false, false, false) {
|
||||
|
||||
public static final NullValue NULL = new NullValue();
|
||||
|
||||
private NullValue() {
|
||||
super(null, false, false, false);
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return kotlinBuiltIns.getNullableNothingType()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getNullableNothingType();
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitNullValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitNullValue(this, data);
|
||||
override fun toString(): String {
|
||||
return "null"
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "null";
|
||||
companion object {
|
||||
public val NULL: NullValue = NullValue()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,33 +14,24 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class ShortValue extends IntegerValueConstant<Short> {
|
||||
public class ShortValue(value: Short, canBeUsedInAnnotations: Boolean, pure: Boolean, usesVariableAsConstant: Boolean) : IntegerValueConstant<Short>(value, canBeUsedInAnnotations, pure, usesVariableAsConstant) {
|
||||
|
||||
public ShortValue(short value, boolean canBeUsedInAnnotations, boolean pure, boolean usesVariableAsConstant) {
|
||||
super(value, canBeUsedInAnnotations, pure, usesVariableAsConstant);
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return kotlinBuiltIns.getShortType()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getShortType();
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitShortValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitShortValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + ".toShort()";
|
||||
override fun toString(): String {
|
||||
return "$value.toShort()"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,49 +14,38 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.constants;
|
||||
package org.jetbrains.kotlin.resolve.constants
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
public class StringValue extends CompileTimeConstant<String> {
|
||||
public class StringValue(value: String, canBeUsedInAnnotations: Boolean, usesVariableAsConstant: Boolean) : CompileTimeConstant<String>(value, canBeUsedInAnnotations, false, usesVariableAsConstant) {
|
||||
|
||||
public StringValue(String value, boolean canBeUsedInAnnotations, boolean usesVariableAsConstant) {
|
||||
super(value, canBeUsedInAnnotations, false, usesVariableAsConstant);
|
||||
override fun getType(kotlinBuiltIns: KotlinBuiltIns): JetType {
|
||||
return kotlinBuiltIns.getStringType()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getStringType();
|
||||
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D): R {
|
||||
return visitor.visitStringValue(this, data)
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitStringValue(this, data);
|
||||
override fun toString(): String {
|
||||
return "\"" + value + "\""
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "\"" + value + "\"";
|
||||
override fun equals(o: Any?): Boolean {
|
||||
if (this === o) return true
|
||||
if (o == null || javaClass != o.javaClass) return false
|
||||
|
||||
val that = o as? StringValue ?: return false
|
||||
|
||||
if (if (value != null) value != that.value else that.value != null) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
StringValue that = (StringValue) o;
|
||||
|
||||
if (value != null ? !value.equals(that.value) : that.value != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return value != null ? value.hashCode() : 0;
|
||||
override fun hashCode(): Int {
|
||||
return if (value != null) value.hashCode() else 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class ConvertToStringTemplateIntention : JetSelfTargetingOffsetIndependen
|
||||
constant.getValue(type).toString()
|
||||
}
|
||||
else {
|
||||
constant?.getValue().toString()
|
||||
constant?.value.toString()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ public abstract class DeprecatedSymbolUsageFixBase(
|
||||
if (pattern.isEmpty()) return null
|
||||
val importValues = replaceWithValue.argumentValue("imports"/*TODO: kotlin.ReplaceWith::imports.name*/) as? List<*> ?: return null
|
||||
if (importValues.any { it !is StringValue }) return null
|
||||
val imports = importValues.map { (it as StringValue).getValue()!! }
|
||||
val imports = importValues.map { (it as StringValue).value }
|
||||
|
||||
// should not be available for descriptors with optional parameters if we cannot fetch default values for them (currently for library with no sources)
|
||||
if (descriptor is CallableDescriptor &&
|
||||
|
||||
@@ -84,7 +84,7 @@ public class JsCallChecker : CallChecker {
|
||||
return
|
||||
}
|
||||
|
||||
val code = evaluationResult.getValue() as String
|
||||
val code = evaluationResult.value as String
|
||||
val errorReporter = JsCodeErrorReporter(argument, code, context.trace)
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user