99 * Licensed under the Apache License, Version 2.0 (the "License");
1010 * you may not use this file except in compliance with the License.
1111 * You may obtain a copy of the License at
12- *
12+ *
1313 * http://www.apache.org/licenses/LICENSE-2.0
14- *
14+ *
1515 * Unless required by applicable law or agreed to in writing, software
1616 * distributed under the License is distributed on an "AS IS" BASIS,
1717 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3131import build .codemodel .expression .Expression ;
3232import build .codemodel .foundation .CodeModel ;
3333import build .codemodel .foundation .descriptor .Trait ;
34+ import build .codemodel .foundation .usage .TypeUsage ;
3435
3536import java .lang .invoke .MethodHandles ;
3637import java .util .Objects ;
@@ -52,21 +53,21 @@ public final class InstanceOf
5253 private final Expression expression ;
5354
5455 /**
55- * The type expression on the right-hand side of {@code instanceof}.
56+ * The resolved type on the right-hand side of {@code instanceof}.
5657 */
57- private final Expression typeExpression ;
58+ private final TypeUsage type ;
5859
5960 /**
6061 * The optional pattern-binding variable name (Java 16+ pattern matching).
6162 */
6263 private final Optional <String > bindingVariable ;
6364
6465 private InstanceOf (final Expression expression ,
65- final Expression typeExpression ,
66+ final TypeUsage type ,
6667 final Optional <String > bindingVariable ) {
6768 super (Objects .requireNonNull (expression , "expression must not be null" ).codeModel ());
6869 this .expression = expression ;
69- this .typeExpression = Objects .requireNonNull (typeExpression , "typeExpression must not be null" );
70+ this .type = Objects .requireNonNull (type , "type must not be null" );
7071 this .bindingVariable = bindingVariable == null ? Optional .empty () : bindingVariable ;
7172 }
7273
@@ -75,23 +76,23 @@ public InstanceOf(@Bound final CodeModel codeModel,
7576 final Marshaller marshaller ,
7677 final Stream <Marshalled <Trait >> traits ,
7778 final Marshalled <Expression > expression ,
78- final Marshalled <Expression > typeExpression ,
79+ final Marshalled <TypeUsage > type ,
7980 final Optional <String > bindingVariable ) {
8081 super (codeModel , marshaller , traits );
8182 this .expression = marshaller .unmarshal (expression );
82- this .typeExpression = marshaller .unmarshal (typeExpression );
83+ this .type = marshaller .unmarshal (type );
8384 this .bindingVariable = bindingVariable == null ? Optional .empty () : bindingVariable ;
8485 }
8586
8687 @ Marshal
8788 public void destructor (final Marshaller marshaller ,
8889 final Out <Stream <Marshalled <Trait >>> traits ,
8990 final Out <Marshalled <Expression >> expression ,
90- final Out <Marshalled <Expression >> typeExpression ,
91+ final Out <Marshalled <TypeUsage >> type ,
9192 final Out <Optional <String >> bindingVariable ) {
9293 super .destructor (marshaller , traits );
9394 expression .set (marshaller .marshal (this .expression ));
94- typeExpression .set (marshaller .marshal (this .typeExpression ));
95+ type .set (marshaller .marshal (this .type ));
9596 bindingVariable .set (this .bindingVariable );
9697 }
9798
@@ -105,12 +106,12 @@ public Expression expression() {
105106 }
106107
107108 /**
108- * Obtains the type expression on the right-hand side of {@code instanceof}.
109+ * Obtains the resolved type on the right-hand side of {@code instanceof}.
109110 *
110- * @return the type {@link Expression }
111+ * @return the {@link TypeUsage }
111112 */
112- public Expression typeExpression () {
113- return this .typeExpression ;
113+ public TypeUsage checkedType () {
114+ return this .type ;
114115 }
115116
116117 /**
@@ -126,7 +127,7 @@ public Optional<String> bindingVariable() {
126127 public boolean equals (final Object object ) {
127128 return object instanceof InstanceOf other
128129 && Objects .equals (this .expression , other .expression )
129- && Objects .equals (this .typeExpression , other .typeExpression )
130+ && Objects .equals (this .type , other .type )
130131 && Objects .equals (this .bindingVariable , other .bindingVariable )
131132 && super .equals (other );
132133 }
@@ -135,25 +136,25 @@ public boolean equals(final Object object) {
135136 * Creates an {@link InstanceOf} expression.
136137 *
137138 * @param expression the expression being tested
138- * @param typeExpression the type expression on the right-hand side
139+ * @param type the resolved {@link TypeUsage} on the right-hand side
139140 * @param bindingVariable the optional pattern-binding variable name
140141 * @return a new {@link InstanceOf}
141142 */
142143 public static InstanceOf of (final Expression expression ,
143- final Expression typeExpression ,
144+ final TypeUsage type ,
144145 final Optional <String > bindingVariable ) {
145- return new InstanceOf (expression , typeExpression , bindingVariable );
146+ return new InstanceOf (expression , type , bindingVariable );
146147 }
147148
148149 /**
149150 * Creates a classic (non-pattern) {@link InstanceOf} expression.
150151 *
151- * @param expression the expression being tested
152- * @param typeExpression the type expression on the right-hand side
152+ * @param expression the expression being tested
153+ * @param type the resolved {@link TypeUsage} on the right-hand side
153154 * @return a new {@link InstanceOf}
154155 */
155- public static InstanceOf of (final Expression expression , final Expression typeExpression ) {
156- return new InstanceOf (expression , typeExpression , Optional .empty ());
156+ public static InstanceOf of (final Expression expression , final TypeUsage type ) {
157+ return new InstanceOf (expression , type , Optional .empty ());
157158 }
158159
159160 static {
0 commit comments