summaryrefslogtreecommitdiff
path: root/platform/script-debugger/protocol/protocol-reader/src/org/jetbrains/protocolReader/ValueReader.java
blob: 7ef6b3e0fc8272250c1da18cbe60d0ebe63c6668 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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.Nullable;

/**
 * A parser that accepts value of JSON field and outputs value in another form (e.g. string
 * is converted to enum constant) to serve field getters in JsonType interfaces.
 */
abstract class ValueReader {
  private final boolean nullable;

  protected ValueReader(boolean nullable) {
    this.nullable = nullable;
  }

  public ObjectValueReader asJsonTypeParser() {
    return null;
  }

  abstract void appendFinishedValueTypeName(TextOutput out);

  void appendInternalValueTypeName(FileScope scope, TextOutput out) {
    appendFinishedValueTypeName(out);
  }

  abstract void writeReadCode(ClassScope methodScope, boolean subtyping, String fieldName, TextOutput out);

  public boolean isNullable() {
    return nullable;
  }

  abstract void writeArrayReadCode(ClassScope scope, boolean subtyping, boolean nullable, String fieldName, TextOutput out);

  protected void beginReadCall(String readPostfix, boolean subtyping, TextOutput out, @Nullable String fieldName) {
    out.append("read");
    if (isNullable()) {
      out.append("Nullable");
    }
    out.append(readPostfix).append('(');
    addReaderParameter(subtyping, out);
    if (!isNullable()) {
      out.comma();
      if (subtyping) {
        out.append("null");
      }
      else if (fieldName == null) {
        out.append("name");
      }
      else {
        out.quoute(fieldName);
      }
    }
  }

  protected static void addReaderParameter(boolean subtyping, TextOutput out) {
    out.append(subtyping ? Util.PENDING_INPUT_READER_NAME : Util.READER_NAME);
  }

  public boolean isThrowsIOException() {
    return false;
  }
}