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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package Torello.Browser;

import Torello.Browser.CDPTypes;
import Torello.Browser.NestedDescriptor;
import Torello.Browser.TypeBuilder;
import Torello.Java.WrongMethodException;

/**
 * Thrown by {@link AbstractBuilder} when a programmer attempts to assign a value
 * using a Java type that is incompatible with the builder property's expected
 * type.
 * 
 * <BR /><BR /><DIV CLASS=JDHint>
 * 👉 This exception provides several "convenience fields" intended to assist
 * with detailed error reporting and debugging diagnostics.
 * </DIV>
 * 
 * @see AbstractBuilder
 */
public class TypeAssignmentException extends WrongMethodException
{
    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUIDEX>  */
    public static final long serialVersionUID = 1;

    /**
     * The name of the builder property being assigned when this exception was thrown.
     * 
     * <BR /><BR /><DIV CLASS=JDHint>
     * 💡 For a {@link TypeBuilder}, this name identifies a field in the CDP type being built.  For
     * a {@link CommandBuilder}, it identifies one of the command's input parameters.
     * </DIV>
     */
    public final String name;

    /**
     * The {@link CDPTypes} byte constant describing the type implied by the accept method that was
     * invoked.
     * 
     * <BR /><BR /><DIV CLASS=JDHint>
     * 📎 This value identifies the Java/CDP type that the programmer attempted to assign.
     * </DIV>
     * 
     * @see CDPTypes
     */
    public final byte providedType;

    /**
     * The {@link CDPTypes} byte constant describing the type expected by the builder.
     * 
     * <BR /><BR /><DIV CLASS=JDHint>
     * 📎 This value will be equal to one of the constants listed in {@link CDPTypes}.
     * </DIV>
     * 
     * @see CDPTypes
     */
    public final byte expectedType;

    /**
     * The descriptor whose builder property was being assigned when this exception was thrown.
     * 
     * <BR /><BR /><DIV CLASS=JDHint>
     * 👉 This field is provided as a programmer convenience, to make debugging and error investigation
     * easier.
     * </DIV>
     */
    public final AbstractDescriptor descriptor;

    /**
     * Constructs a {@code TypeAssignmentException} with the default error message.
     * 
     * @param providedType the byte constant describing the type supplied by the programmer.
     * @param expectedType the byte constant describing the type expected by the descriptor.
     * @param name the name of the builder property being assigned.
     * @param descriptor the descriptor used by the builder.
     * 
     * @see CDPTypes
     */
    public TypeAssignmentException(
            final byte                  providedType,
            final byte                  expectedType,
            final String                name,
            final AbstractDescriptor    descriptor
        )
    {
        super(
            "An attempt has been made to assign an inappropriate value to the builder " +
            "property named '" + name + "'." + '\n' +
            "The programmer provided a value of type: " + CDPTypes.names.get(providedType) + '\n' +
            "The descriptor indicates that the expected type is: " +
            CDPTypes.names.get(expectedType) + '\n' +
            "The descriptor was: " + descriptor
        );

        this.providedType   = providedType;
        this.expectedType   = expectedType;
        this.name           = name;
        this.descriptor     = descriptor;
    }
 
    /**
     * Constructs a {@code TypeAssignmentException} with the specified detail message.
     * 
     * @param message the detail message.
     * @param providedType the byte constant describing the type supplied by the programmer.
     * @param expectedType the byte constant describing the type expected by the descriptor.
     * @param name the name of the builder property being assigned.
     * @param descriptor the descriptor used by the builder.
     */
    public TypeAssignmentException(
            final String                message, 
            final byte                  providedType,
            final byte                  expectedType,
            final String                name,
            final AbstractDescriptor    descriptor
        )
    {
        super(message);

        this.expectedType   = expectedType;
        this.providedType   = providedType;
        this.name           = name;
        this.descriptor     = descriptor;
    }

}