From 240c0b2d33d8cf1ea94e47c681e98e294cbfbe74 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 9 Nov 2016 14:41:22 +0100 Subject: [PATCH] convert IndexedVariablesConsumer, FunctionValue, ValueType, PrimitiveValue to kotlin --- .../debugger/values/FunctionValue.java | 31 +++++------ .../values/IndexedVariablesConsumer.java | 19 +++---- .../debugger/values/PrimitiveValue.java | 55 +++++++------------ .../jetbrains/debugger/values/ValueType.java | 29 +++++----- 4 files changed, 53 insertions(+), 81 deletions(-) diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/values/FunctionValue.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/values/FunctionValue.java index 4fe430089778..c12e8a0de1d7 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/values/FunctionValue.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/values/FunctionValue.java @@ -1,35 +1,30 @@ -package org.jetbrains.debugger.values; +package org.jetbrains.debugger.values -import com.intellij.util.ThreeState; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.concurrency.Promise; -import org.jetbrains.debugger.Scope; +import com.intellij.util.ThreeState +import org.jetbrains.concurrency.Promise +import org.jetbrains.debugger.Scope -public interface FunctionValue extends ObjectValue { +interface FunctionValue : ObjectValue { /** - * You must invoke {@link #resolve} to use any function value methods + * You must invoke [.resolve] to use any function value methods */ - @NotNull - Promise resolve(); + fun resolve(): Promise /** * Returns position of opening parenthesis of function arguments. Position is absolute * within resource (not relative to script start position). - * + * @return position or null if position is not available */ - int getOpenParenLine(); + val openParenLine: Int - int getOpenParenColumn(); + val openParenColumn: Int - @Nullable - Scope[] getScopes(); + val scopes: Array? /** * Method could be called (it is normal and expected) for unresolved function. - * It must return quickly. Return {@link com.intellij.util.ThreeState#UNSURE} otherwise. + * It must return quickly. Return [com.intellij.util.ThreeState.UNSURE] otherwise. */ - @NotNull - ThreeState hasScopes(); + fun hasScopes() = ThreeState.UNSURE } diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/values/IndexedVariablesConsumer.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/values/IndexedVariablesConsumer.java index 7f4bcac8da93..22e481a47c22 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/values/IndexedVariablesConsumer.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/values/IndexedVariablesConsumer.java @@ -1,18 +1,13 @@ -package org.jetbrains.debugger.values; +package org.jetbrains.debugger.values -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.debugger.Variable; +import org.jetbrains.debugger.Variable -import java.util.List; - -public abstract class IndexedVariablesConsumer { +abstract class IndexedVariablesConsumer { // null if array is not sparse - public abstract void consumeRanges(@Nullable int[] ranges); + abstract fun consumeRanges(ranges: IntArray?) - public abstract void consumeVariables(@NotNull List variables); + abstract fun consumeVariables(variables: List) - public boolean isObsolete() { - return false; - } + open val isObsolete: Boolean + get() = false } \ No newline at end of file diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/values/PrimitiveValue.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/values/PrimitiveValue.java index a9e31ab24be7..513ef2ae6c47 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/values/PrimitiveValue.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/values/PrimitiveValue.java @@ -1,45 +1,30 @@ -package org.jetbrains.debugger.values; +package org.jetbrains.debugger.values -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +open class PrimitiveValue(type: ValueType, override val valueString: String) : ValueBase(type) { -public class PrimitiveValue extends ValueBase { - public static final String NA_N_VALUE = "NaN"; - public static final String INFINITY_VALUE = "Infinity"; - - public static final PrimitiveValue NULL = new PrimitiveValue(ValueType.NULL, "null"); - public static final PrimitiveValue UNDEFINED = new PrimitiveValue(ValueType.UNDEFINED, "undefined"); - - public static final PrimitiveValue NAN = new PrimitiveValue(ValueType.NUMBER, NA_N_VALUE); - public static final PrimitiveValue INFINITY = new PrimitiveValue(ValueType.NUMBER, INFINITY_VALUE); - - private static final PrimitiveValue TRUE = new PrimitiveValue(ValueType.BOOLEAN, "true"); - private static final PrimitiveValue FALSE = new PrimitiveValue(ValueType.BOOLEAN, "false"); - - private final String valueString; - - public PrimitiveValue(@NotNull ValueType type, @NotNull String valueString) { - super(type); - - this.valueString = valueString; + constructor(type: ValueType, value: Int) : this(type, Integer.toString(value)) { } - @NotNull - public static PrimitiveValue bool(@NotNull String value) { - return value.equals("true") ? TRUE : FALSE; + constructor(type: ValueType, value: Long) : this(type, java.lang.Long.toString(value)) { } - public PrimitiveValue(ValueType type, int value) { - this(type, Integer.toString(value)); - } + companion object { + val NA_N_VALUE = "NaN" + val INFINITY_VALUE = "Infinity" - public PrimitiveValue(ValueType type, long value) { - this(type, Long.toString(value)); - } + @JvmField + val NULL = PrimitiveValue(ValueType.NULL, "null") + @JvmField + val UNDEFINED = PrimitiveValue(ValueType.UNDEFINED, "undefined") - @Nullable - @Override - public final String getValueString() { - return valueString; + val NAN = PrimitiveValue(ValueType.NUMBER, NA_N_VALUE) + val INFINITY = PrimitiveValue(ValueType.NUMBER, INFINITY_VALUE) + + private val TRUE = PrimitiveValue(ValueType.BOOLEAN, "true") + private val FALSE = PrimitiveValue(ValueType.BOOLEAN, "false") + + fun bool(value: String): PrimitiveValue { + return if (value == "true") TRUE else FALSE + } } } \ No newline at end of file diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/values/ValueType.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/values/ValueType.java index 06da6c1fdc5e..6430606690d5 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/values/ValueType.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/values/ValueType.java @@ -1,11 +1,11 @@ -package org.jetbrains.debugger.values; +package org.jetbrains.debugger.values -import org.jetbrains.annotations.NotNull; +private val VALUE_TYPES = ValueType.values() /** * Don't forget to update NashornDebuggerSupport.ValueType and DebuggerSupport.ts respectively also */ -public enum ValueType { +enum class ValueType { OBJECT, NUMBER, STRING, @@ -16,21 +16,18 @@ public enum ValueType { NODE, UNDEFINED, - NULL; - - private static final ValueType[] VALUE_TYPES = ValueType.values(); - - @NotNull - public static ValueType fromIndex(int index) { - return VALUE_TYPES[index]; - } + NULL, + SYMBOL; /** - * Returns whether {@code type} corresponds to a JsObject. Note that while 'null' is an object - * in JavaScript world, here for API consistency it has bogus type {@link #NULL} and is - * not a {@link ObjectValue} + * Returns whether `type` corresponds to a JsObject. Note that while 'null' is an object + * in JavaScript world, here for API consistency it has bogus type [.NULL] and is + * not a [ObjectValue] */ - public boolean isObjectType() { - return this == OBJECT || this == ARRAY || this == FUNCTION || this == NODE; + val isObjectType: Boolean + get() = this == OBJECT || this == ARRAY || this == FUNCTION || this == NODE + + companion object { + fun fromIndex(index: Int) = VALUE_TYPES.get(index) } } \ No newline at end of file