diff options
Diffstat (limited to 'platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains')
8 files changed, 146 insertions, 1 deletions
diff --git a/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonField.java b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonField.java new file mode 100644 index 000000000000..3b960b8636a9 --- /dev/null +++ b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonField.java @@ -0,0 +1,32 @@ +// 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; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Describes a method that corresponds to a type field (i.e. a property of JSON object). + * Its use is optional, because all methods by default are recognized as field-reading methods. + * Should be used to specify JSON property name. + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface JsonField { + /** + * 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 ""; + + // read any primitive value as String (true as true, number as string - don't try to parse) + boolean allowAnyPrimitiveValue() default false; + + boolean allowAnyPrimitiveValueAndMap() default false; + + boolean optional() default false; +}
\ No newline at end of file diff --git a/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonNullable.java b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonNullable.java new file mode 100644 index 000000000000..8e88ab4eb2b4 --- /dev/null +++ b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonNullable.java @@ -0,0 +1,19 @@ +// 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; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * For field-reading method specifies its type as {@code nullable}; it means + * that JSON structure may have null value for a corresponding property. + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface JsonNullable { +} diff --git a/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonOptionalField.java b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonOptionalField.java new file mode 100644 index 000000000000..92c9cd978700 --- /dev/null +++ b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonOptionalField.java @@ -0,0 +1,19 @@ +// 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; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * For field-reading method specifies that the field is optional and may safely be absent in + * JSON object. By default fields are not optional. + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface JsonOptionalField { +} diff --git a/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonParseMethod.java b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonParseMethod.java new file mode 100644 index 000000000000..8016b9b59539 --- /dev/null +++ b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonParseMethod.java @@ -0,0 +1,15 @@ +// Copyright (c) 2011 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; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface JsonParseMethod { +} diff --git a/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonReaders.java b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonReaders.java index aa1d19f1bad2..056e4dc6b78f 100644 --- a/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonReaders.java +++ b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonReaders.java @@ -234,7 +234,7 @@ public final class JsonReaders { return list; } - public static List<String> readListOfPrimitive(JsonReaderEx reader) { + public static List<String> readRawStringArray(JsonReaderEx reader) { reader.beginArray(); if (!reader.hasNext()) { reader.endArray(); diff --git a/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonSubtype.java b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonSubtype.java new file mode 100644 index 000000000000..b40d4a1b7687 --- /dev/null +++ b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonSubtype.java @@ -0,0 +1,14 @@ +// 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; + +/** + * A base interface for JSON subtype interface. This inheritance serves 2 purposes: + * it declares base type (visible to human and to interface analyzer) and adds {@link #getSuper()} + * getter that may be directly used in programs. + */ +public interface JsonSubtype<BASE> { + BASE getSuper(); +} diff --git a/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonSubtypeCasting.java b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonSubtypeCasting.java new file mode 100644 index 000000000000..cc59fed74eac --- /dev/null +++ b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonSubtypeCasting.java @@ -0,0 +1,21 @@ +// 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; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks method as method casting to a subtype. Normally the method return type should be + * some other json type, which serves as subtype; the subtype interface must extend + * {@link JsonSubtype} (with correct generic parameter). + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD }) +public @interface JsonSubtypeCasting { + boolean reinterpret() default false; +} diff --git a/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonType.java b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonType.java new file mode 100644 index 000000000000..79dc453ac9fb --- /dev/null +++ b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/JsonType.java @@ -0,0 +1,25 @@ +// 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; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks an interface as interface to json type object. This way user may hold JSON object in + * form of statically typed Java interface. The interface provides methods for reading properties + * (here called fields, because we imply there are "types" in JSON) and for accessing subtypes. + * <p/> + * In this design casting to subtypes means getting a different object of the subtype interface. + * For a type interface, a set of subtypes is defined by its methods + * with {@link JsonSubtypeCasting} annotation. These methods provide access to subtype objects. + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface JsonType { + boolean allowsOtherProperties() default false; +} |