* additionalContext parameter.
*/
@NotNull
- Promise<EvaluateResult> evaluate(@NotNull String expression, @Nullable Map<String, EvaluateContextAdditionalParameter> additionalContext, boolean enableBreak);
+ Promise<EvaluateResult> evaluate(@NotNull String expression, @Nullable Map<String, Object> additionalContext, boolean enableBreak);
@NotNull
Promise<EvaluateResult> evaluate(@NotNull String expression);
+++ /dev/null
-package org.jetbrains.debugger;
-
-public interface EvaluateContextAdditionalParameter {
-}
\ No newline at end of file
@NotNull
@Override
- public abstract Promise<EvaluateResult> evaluate(@NotNull String expression, @Nullable Map<String, EvaluateContextAdditionalParameter> additionalContext, boolean enableBreak);
+ public abstract Promise<EvaluateResult> evaluate(@NotNull String expression, @Nullable Map<String, Object> additionalContext, boolean enableBreak);
@NotNull
public final VALUE_MANAGER getValueManager() {
* is available.
*/
public interface ObjectProperty extends Variable {
- /**
- * @return whether property described as 'writable'
- */
boolean isWritable();
- /**
- * @return property getter value (function or undefined) or null if not an accessor property
- */
@Nullable
FunctionValue getGetter();
- /**
- * @return property setter value (function or undefined) or null if not an accessor property
- */
@Nullable
FunctionValue getSetter();
- /**
- * @return whether property described as 'configurable'
- */
+
boolean isConfigurable();
- /**
- * @return whether property described as 'enumerable'
- */
boolean isEnumerable();
}
--- /dev/null
+package org.jetbrains.debugger;
+
+import com.intellij.util.BitUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.debugger.values.FunctionValue;
+import org.jetbrains.debugger.values.Value;
+
+public class ObjectPropertyImpl extends VariableImpl implements ObjectProperty {
+ public static final byte WRITABLE = 0x01;
+ public static final byte CONFIGURABLE = 0x02;
+ public static final byte ENUMERABLE = 0x04;
+
+ private final FunctionValue getter;
+ private final FunctionValue setter;
+
+ private final int flags;
+
+ public ObjectPropertyImpl(@NotNull String name,
+ @Nullable Value value,
+ @Nullable FunctionValue getter,
+ @Nullable FunctionValue setter,
+ @Nullable ValueModifier valueModifier,
+ int flags) {
+ super(name, value, valueModifier);
+
+ this.getter = getter;
+ this.setter = setter;
+
+ this.flags = flags;
+ }
+
+ @Nullable
+ @Override
+ public final FunctionValue getGetter() {
+ return getter;
+ }
+
+ @Nullable
+ @Override
+ public final FunctionValue getSetter() {
+ return setter;
+ }
+
+ @Override
+ public final boolean isWritable() {
+ return BitUtil.isSet(flags, WRITABLE);
+ }
+
+ @Override
+ public final boolean isConfigurable() {
+ return BitUtil.isSet(flags, CONFIGURABLE);
+ }
+
+ @Override
+ public final boolean isEnumerable() {
+ return BitUtil.isSet(flags, ENUMERABLE);
+ }
+}
\ No newline at end of file
@NotNull
public static Promise<Value> evaluateGet(@NotNull final Variable variable,
- @NotNull EvaluateContextAdditionalParameter host,
+ @NotNull Object host,
@NotNull EvaluateContext evaluateContext,
@NotNull String selfName) {
StringBuilder builder = new StringBuilder(selfName);
public abstract class VariablesHost<VALUE_MANAGER extends ValueManager> {
@SuppressWarnings("unchecked")
- public static final PromiseManager<VariablesHost, List<Variable>> VARIABLES_LOADER =
+ private static final PromiseManager<VariablesHost, List<Variable>> VARIABLES_LOADER =
new PromiseManager<VariablesHost, List<Variable>>(VariablesHost.class) {
@Override
public boolean isUpToDate(@NotNull VariablesHost host, @NotNull List<Variable> data) {
return VARIABLES_LOADER.get(this);
}
+ public final void set(@NotNull List<Variable> result) {
+ updateCacheStamp();
+ VARIABLES_LOADER.set(this, result);
+ }
+
@NotNull
protected abstract Promise<List<Variable>> load();
+++ /dev/null
-package org.jetbrains.debugger.values;
-
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.jetbrains.debugger.ObjectProperty;
-import org.jetbrains.debugger.ValueModifier;
-import org.jetbrains.debugger.VariableImpl;
-
-public abstract class ObjectPropertyBase extends VariableImpl implements ObjectProperty {
- private final FunctionValue getter;
- private final FunctionValue setter;
-
- protected ObjectPropertyBase(@NotNull String name, @Nullable Value value, @Nullable FunctionValue getter, @Nullable FunctionValue setter, @Nullable ValueModifier valueModifier) {
- super(name, value, valueModifier);
-
- this.getter = getter;
- this.setter = setter;
- }
-
- @Override
- public boolean isWritable() {
- return true;
- }
-
- @Nullable
- @Override
- public final FunctionValue getGetter() {
- return getter;
- }
-
- @Nullable
- @Override
- public FunctionValue getSetter() {
- return setter;
- }
-
- @Override
- public boolean isConfigurable() {
- return true;
- }
-
- @Override
- public boolean isEnumerable() {
- return true;
- }
-}
\ No newline at end of file
import org.jetbrains.annotations.Nullable;
public class PrimitiveValue extends ValueBase {
- public static final PrimitiveValue NULL_VALUE = new PrimitiveValue(ValueType.NULL, "null");
- public static final PrimitiveValue UNDEFINED_VALUE = new PrimitiveValue(ValueType.UNDEFINED, "undefined");
+ 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");
package org.jetbrains.debugger.values;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.debugger.EvaluateContextAdditionalParameter;
/**
* An object that represents a VM variable value (compound or atomic).
*/
-public interface Value extends EvaluateContextAdditionalParameter {
+public interface Value {
@NotNull
ValueType getType();
node.setPresentation(icon, null, valueString, true);
}
else {
- context.getEvaluateContext().evaluate("a.length", Collections.<String, EvaluateContextAdditionalParameter>singletonMap("a", value), false)
+ context.getEvaluateContext().evaluate("a.length", Collections.<String, Object>singletonMap("a", value), false)
.done(new Consumer<EvaluateResult>() {
@Override
public void consume(EvaluateResult result) {
}
}
+ @NotNull
private static XValuePresentation createNumberPresentation(@NotNull String value) {
- return value.equals("NaN") || value.equals("Infinity") ? new XKeywordValuePresentation(value) : new XNumericValuePresentation(value);
+ return value.equals(PrimitiveValue.NA_N_VALUE) || value.equals(PrimitiveValue.INFINITY_VALUE) ? new XKeywordValuePresentation(value) : new XNumericValuePresentation(value);
}
@Override
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
package org.jetbrains.jsonProtocol;
import java.lang.annotation.ElementType;
* Specifies JSON property name, which otherwise is derived from the method name (optional "get"
* prefix is truncated with the first letter decapitalization).
*/
- String jsonLiteralName() default "";
+ String name() default "";
// read any primitive value as String (true as true, number as string - don't try to parse)
boolean allowAnyPrimitiveValue() default false;
// Don't use Guava CaseFormat.*! ObjectWithURL must be converted to OBJECT_WITH_URL
public static String convertRawEnumName(@NotNull String enumValue) {
- StringBuilder builder = new StringBuilder(enumValue.length() + 4);
+ int n = enumValue.length();
+ StringBuilder builder = new StringBuilder(n + 4);
boolean prevIsLowerCase = false;
- for (int i = 0; i < enumValue.length(); i++) {
+ for (int i = 0; i < n; i++) {
char c = enumValue.charAt(i);
if (c == '-' || c == ' ') {
builder.append('_');
if (Character.isUpperCase(c)) {
// second check handle "CSPViolation" (transform to CSP_VIOLATION)
- if (prevIsLowerCase || (i != 0 && (i + 1) < enumValue.length() && Character.isLowerCase(enumValue.charAt(i + 1)))) {
+ if (prevIsLowerCase || (i != 0 && (i + 1) < n && Character.isLowerCase(enumValue.charAt(i + 1)))) {
builder.append('_');
}
builder.append(c);
}
@Override
- void writeReadCode(ClassScope scope, boolean subtyping, String fieldName, @NotNull TextOutput out) {
+ void writeReadCode(ClassScope scope, boolean subtyping, @NotNull TextOutput out) {
componentParser.writeArrayReadCode(scope, subtyping, out);
}
}
}
@Override
- void writeReadCode(ClassScope scope, boolean subtyping, String fieldName, @NotNull TextOutput out) {
+ void writeReadCode(ClassScope scope, boolean subtyping, @NotNull TextOutput out) {
beginReadCall("Enum", subtyping, out);
out.comma().append(enumClass.getCanonicalName()).append(".class").append(')');
}
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
package org.jetbrains.protocolReader;
+import org.jetbrains.annotations.NotNull;
+
class FieldLoader {
public static final char FIELD_PREFIX = '_';
- private final String fieldName;
+ final String name;
+ final String jsonName;
+
final ValueReader valueReader;
- FieldLoader(String fieldName, ValueReader valueReader) {
- this.fieldName = fieldName;
+ FieldLoader(@NotNull String name, @NotNull String jsonName, @NotNull ValueReader valueReader) {
+ this.name = name;
+ this.jsonName = jsonName;
this.valueReader = valueReader;
}
- public String getFieldName() {
- return fieldName;
- }
-
- public void writeFieldDeclaration(TextOutput out) {
- out.append("private ");
+ public void writeFieldDeclaration(@NotNull TextOutput out) {
+ out.append("private").space();
valueReader.appendFinishedValueTypeName(out);
- out.append(' ').append(FIELD_PREFIX).append(fieldName);
+ out.space().append(FIELD_PREFIX).append(name);
if (valueReader instanceof PrimitiveValueReader) {
String defaultValue = ((PrimitiveValueReader)valueReader).defaultValue;
if (defaultValue != null) {
import java.util.*;
final class FieldProcessor<T> {
- private final List<FieldLoader> fieldLoaders = new ArrayList<>(2);
+ private final List<FieldLoader> fieldLoaders = new ArrayList<>();
private final LinkedHashMap<Method, MethodHandler> methodHandlerMap = new LinkedHashMap<>();
- private final List<VolatileFieldBinding> volatileFields = new ArrayList<>(2);
+ private final List<VolatileFieldBinding> volatileFields = new ArrayList<>();
boolean lazyRead;
private final InterfaceReader reader;
}
});
- Package aPackage = typeClass.getPackage();
+ Package classPackage = typeClass.getPackage();
for (Method method : methods) {
Class<?> methodClass = method.getDeclaringClass();
// use method from super if super located in the same package
- if (methodClass != typeClass && methodClass.getPackage() != aPackage) {
- continue;
+ if (methodClass != typeClass) {
+ Package methodPackage = methodClass.getPackage();
+ // may be it will be useful later
+ // && !methodPackage.getName().equals("org.jetbrains.debugger.adapters")
+ if (methodPackage != classPackage) {
+ continue;
+ }
}
- if (method.getParameterTypes().length != 0) {
+ if (method.getParameterCount() != 0) {
throw new JsonProtocolModelParseException("No parameters expected in " + method);
}
try {
- String fieldName = checkAndGetJsonFieldName(method);
MethodHandler methodHandler;
-
JsonSubtypeCasting jsonSubtypeCaseAnnotation = method.getAnnotation(JsonSubtypeCasting.class);
- if (jsonSubtypeCaseAnnotation != null) {
- methodHandler = processManualSubtypeMethod(method, jsonSubtypeCaseAnnotation);
- lazyRead = true;
+ if (jsonSubtypeCaseAnnotation == null) {
+ methodHandler = processFieldGetterMethod(method);
}
else {
- methodHandler = processFieldGetterMethod(method, fieldName);
+ methodHandler = processManualSubtypeMethod(method, jsonSubtypeCaseAnnotation);
+ lazyRead = true;
}
methodHandlerMap.put(method, methodHandler);
}
}
}
- private MethodHandler processFieldGetterMethod(@NotNull Method method, @NotNull String fieldName) {
+ @NotNull
+ private MethodHandler processFieldGetterMethod(@NotNull Method method) {
+ String jsonName = method.getName();
+ JsonField fieldAnnotation = method.getAnnotation(JsonField.class);
+ if (fieldAnnotation != null && !fieldAnnotation.name().isEmpty()) {
+ jsonName = fieldAnnotation.name();
+ }
+
Type genericReturnType = method.getGenericReturnType();
boolean addNotNullAnnotation;
-
boolean isPrimitive = genericReturnType instanceof Class ? ((Class)genericReturnType).isPrimitive() : !(genericReturnType instanceof ParameterizedType);
if (isPrimitive) {
addNotNullAnnotation = false;
}
+ else if (fieldAnnotation != null) {
+ addNotNullAnnotation = !fieldAnnotation.optional() && !fieldAnnotation.allowAnyPrimitiveValue() && !fieldAnnotation.allowAnyPrimitiveValueAndMap();
+ }
else {
- JsonField jsonField = method.getAnnotation(JsonField.class);
- if (jsonField != null) {
- addNotNullAnnotation = !jsonField.optional() && !jsonField.allowAnyPrimitiveValue() && !jsonField.allowAnyPrimitiveValueAndMap();
- }
- else {
- addNotNullAnnotation = method.getAnnotation(JsonOptionalField.class) == null;
- }
+ addNotNullAnnotation = method.getAnnotation(JsonOptionalField.class) == null;
}
- ValueReader fieldTypeParser;
- try {
- fieldTypeParser = reader.getFieldTypeParser(genericReturnType, false, method);
- }
- catch (Exception e) {
- throw new RuntimeException("Cannot create field type parser for method " + method, e);
- }
+ ValueReader fieldTypeParser = reader.getFieldTypeParser(genericReturnType, false, method);
if (fieldTypeParser != InterfaceReader.VOID_PARSER) {
- fieldLoaders.add(new FieldLoader(fieldName, fieldTypeParser));
+ fieldLoaders.add(new FieldLoader(method.getName(), jsonName, fieldTypeParser));
}
- final String effectiveFieldName = fieldTypeParser == InterfaceReader.VOID_PARSER ? null : fieldName;
+ final String effectiveFieldName = fieldTypeParser == InterfaceReader.VOID_PARSER ? null : method.getName();
return new MethodHandler() {
@Override
void writeMethodImplementationJava(@NotNull ClassScope scope, @NotNull Method method, @NotNull TextOutput out) {
volatileFields.add(binding);
return binding;
}
-
- @NotNull
- private static String checkAndGetJsonFieldName(@NotNull Method method) {
- if (method.getParameterTypes().length != 0) {
- throw new JsonProtocolModelParseException("Must have 0 parameters");
- }
- JsonField fieldAnnotation = method.getAnnotation(JsonField.class);
- if (fieldAnnotation != null) {
- String jsonLiteralName = fieldAnnotation.jsonLiteralName();
- if (!jsonLiteralName.isEmpty()) {
- return jsonLiteralName;
- }
- }
- return method.getName();
- }
}
private static final PrimitiveValueReader RAW_STRING_PARSER = new PrimitiveValueReader("String", null, true);
private static final PrimitiveValueReader RAW_STRING_OR_MAP_PARSER = new PrimitiveValueReader("Object", null, true) {
@Override
- void writeReadCode(ClassScope methodScope, boolean subtyping, String fieldName, @NotNull TextOutput out) {
+ void writeReadCode(ClassScope methodScope, boolean subtyping, @NotNull TextOutput out) {
out.append("readRawStringOrMap(");
addReaderParameter(subtyping, out);
out.append(')');
}
@Override
- void writeReadCode(ClassScope scope, boolean subtyping, String fieldName, @NotNull TextOutput out) {
+ void writeReadCode(ClassScope scope, boolean subtyping, @NotNull TextOutput out) {
out.append("null");
}
};
{
fieldBinding.writeGetExpression(out);
out.append(" = ");
- parser.writeReadCode(classScope, true, null, classScope.getOutput());
+ parser.writeReadCode(classScope, true, classScope.getOutput());
out.semi();
}
if (parser.isThrowsIOException()) {
}
@Override
- void writeReadCode(ClassScope scope, boolean subtyping, String fieldName, @NotNull TextOutput out) {
+ void writeReadCode(ClassScope scope, boolean subtyping, @NotNull TextOutput out) {
beginReadCall("Map", subtyping, out);
if (componentParser == null) {
out.comma().append("null");
}
@Override
- void writeReadCode(ClassScope scope, boolean subtyping, String fieldName, @NotNull TextOutput out) {
+ void writeReadCode(ClassScope scope, boolean subtyping, @NotNull TextOutput out) {
refToType.type.writeInstantiateCode(scope.getRootClassScope(), subtyping, out);
out.append('(');
addReaderParameter(subtyping, out);
}
@Override
- void writeReadCode(ClassScope methodScope, boolean subtyping, String fieldName, @NotNull TextOutput out) {
+ void writeReadCode(ClassScope methodScope, boolean subtyping, @NotNull TextOutput out) {
if (asRawString) {
out.append("readRawString(");
addReaderParameter(subtyping, out);
else {
ValueReader.addReaderParameter(subtyping, out);
out.append(".next").append(readPostfix).append("()");
- //beginReadCall(readPostfix, subtyping, out, fieldName);
+ //beginReadCall(readPostfix, subtyping, out, name);
}
}
}
@Override
- void writeReadCode(ClassScope scope, boolean subtyping, String fieldName, @NotNull TextOutput out) {
+ void writeReadCode(ClassScope scope, boolean subtyping, @NotNull TextOutput out) {
addReaderParameter(subtyping, out);
out.append(".subReader();").newLine();
addReaderParameter(subtyping, out);
}
@Override
- void writeReadCode(ClassScope scope, boolean subtyping, String fieldName, @NotNull TextOutput out) {
+ void writeReadCode(ClassScope scope, boolean subtyping, @NotNull TextOutput out) {
}
@Override
out.newLine();
}
- String fieldName = fieldLoader.getFieldName();
out.append(operator).append(" (name");
- out.append(".equals(\"").append(fieldName).append("\"))").openBlock();
+ out.append(".equals(\"").append(fieldLoader.jsonName).append("\"))").openBlock();
{
String primitiveValueName = fieldLoader.valueReader instanceof ObjectValueReader ? ((ObjectValueReader)fieldLoader.valueReader).primitiveValueName : null;
if (primitiveValueName != null) {
out.append("if (reader.peek() == com.google.gson.stream.JsonToken.BEGIN_OBJECT)").openBlock();
}
- assignField(out, fieldName);
+ assignField(out, fieldLoader.name);
- fieldLoader.valueReader.writeReadCode(classScope, false, fieldName, out);
+ fieldLoader.valueReader.writeReadCode(classScope, false, out);
out.semi();
if (primitiveValueName != null) {
appendFinishedValueTypeName(out);
}
- abstract void writeReadCode(ClassScope methodScope, boolean subtyping, String fieldName, @NotNull TextOutput out);
+ abstract void writeReadCode(ClassScope methodScope, boolean subtyping, @NotNull TextOutput out);
void writeArrayReadCode(@NotNull ClassScope scope, boolean subtyping, @NotNull TextOutput out) {
throw new UnsupportedOperationException();