1 /** 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. 5 * Portions Copyright 2013-2015 Philip Helger 6 * 7 * The contents of this file are subject to the terms of either the GNU 8 * General Public License Version 2 only ("GPL") or the Common Development 9 * and Distribution License("CDDL") (collectively, the "License"). You 10 * may not use this file except in compliance with the License. You can 11 * obtain a copy of the License at 12 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html 13 * or packager/legal/LICENSE.txt. See the License for the specific 14 * language governing permissions and limitations under the License. 15 * 16 * When distributing the software, include this License Header Notice in each 17 * file and include the License file at packager/legal/LICENSE.txt. 18 * 19 * GPL Classpath Exception: 20 * Oracle designates this particular file as subject to the "Classpath" 21 * exception as provided by Oracle in the GPL Version 2 section of the License 22 * file that accompanied this code. 23 * 24 * Modifications: 25 * If applicable, add the following below the License Header, with the fields 26 * enclosed by brackets [] replaced by your own identifying information: 27 * "Portions Copyright [year] [name of copyright owner]" 28 * 29 * Contributor(s): 30 * If you wish your version of this file to be governed by only the CDDL or 31 * only the GPL Version 2, indicate your decision by adding "[Contributor] 32 * elects to include this software in this distribution under the [CDDL or GPL 33 * Version 2] license." If you don't indicate a single choice of license, a 34 * recipient has the option to distribute your version of this file under 35 * either the CDDL, the GPL Version 2 or to extend the choice of license to 36 * its licensees as provided above. However, if you add GPL Version 2 code 37 * and therefore, elected the GPL Version 2 license, then the option applies 38 * only if the new code is made subject to such option by the copyright 39 * holder. 40 */ 41 package com.helger.jcodemodel; 42 43 import javax.annotation.Nonnull; 44 45 /** 46 * A Java expression. 47 * <p> 48 * Unlike most of CodeModel, JExpressions are built bottom-up ( meaning you 49 * start from leaves and then gradually build complicated expressions by 50 * combining them.) 51 * <p> 52 * {@link IJExpression} defines a series of composer methods, which returns a 53 * complicated expression (by often taking other {@link IJExpression}s as 54 * parameters. For example, you can build "5+2" by 55 * <tt>JExpr.lit(5).add(JExpr.lit(2))</tt> 56 */ 57 public interface IJExpression extends IJGenerable 58 { 59 /** 60 * @return <code>-[this]" from "[this]</code>. 61 */ 62 @Nonnull 63 IJExpression minus (); 64 65 /** 66 * @return <code>![this]" from "[this]</code>. 67 */ 68 @Nonnull 69 IJExpression not (); 70 71 /** 72 * @return <code>~[this]" from "[this]</code>. 73 */ 74 @Nonnull 75 IJExpression complement (); 76 77 /** 78 * @return <code>[this]++" from "[this]</code>. 79 */ 80 @Nonnull 81 IJExpression incr (); 82 83 /** 84 * @return <code>++[this]" from "[this]</code>. 85 */ 86 @Nonnull 87 IJExpression preincr (); 88 89 /** 90 * @return <code>[this]--" from "[this]</code>. 91 */ 92 @Nonnull 93 IJExpression decr (); 94 95 /** 96 * @return <code>--[this]" from "[this]</code>. 97 */ 98 @Nonnull 99 IJExpression predecr (); 100 101 /** 102 * @param right 103 * value to add 104 * @return <code>[this]+[right]</code>. 105 */ 106 @Nonnull 107 IJExpression plus (@Nonnull IJExpression right); 108 109 /** 110 * @param right 111 * value to add 112 * @return <code>[this]+[right]</code>. 113 */ 114 @Nonnull 115 IJExpression plus (double right); 116 117 /** 118 * @param right 119 * value to add 120 * @return <code>[this]+[right]</code>. 121 */ 122 @Nonnull 123 IJExpression plus (float right); 124 125 /** 126 * @param right 127 * value to add 128 * @return <code>[this]+[right]</code>. 129 */ 130 @Nonnull 131 IJExpression plus (int right); 132 133 /** 134 * @param right 135 * value to add 136 * @return <code>[this]+[right]</code>. 137 */ 138 @Nonnull 139 IJExpression plus (long right); 140 141 /** 142 * @param right 143 * value to add 144 * @return <code>[this]+[right]</code>. 145 */ 146 @Nonnull 147 IJExpression plus (@Nonnull String right); 148 149 /** 150 * @param right 151 * value to add 152 * @return <code>[this]-[right]</code>. 153 */ 154 @Nonnull 155 IJExpression minus (@Nonnull IJExpression right); 156 157 /** 158 * @param right 159 * value to subtract 160 * @return <code>[this]-[right]</code>. 161 */ 162 @Nonnull 163 IJExpression minus (double right); 164 165 /** 166 * @param right 167 * value to subtract 168 * @return <code>[this]-[right]</code>. 169 */ 170 @Nonnull 171 IJExpression minus (float right); 172 173 /** 174 * @param right 175 * value to subtract 176 * @return <code>[this]-[right]</code>. 177 */ 178 @Nonnull 179 IJExpression minus (int right); 180 181 /** 182 * @param right 183 * value to subtract 184 * @return <code>[this]-[right]</code>. 185 */ 186 @Nonnull 187 IJExpression minus (long right); 188 189 /** 190 * @param right 191 * value to multiply 192 * @return <code>[this]*[right]</code>. 193 */ 194 @Nonnull 195 IJExpression mul (@Nonnull IJExpression right); 196 197 /** 198 * @param right 199 * value to multiply 200 * @return <code>[this]*[right]</code>. 201 */ 202 @Nonnull 203 IJExpression mul (double right); 204 205 /** 206 * @param right 207 * value to multiply 208 * @return <code>[this]*[right]</code>. 209 */ 210 @Nonnull 211 IJExpression mul (float right); 212 213 /** 214 * @param right 215 * value to multiply 216 * @return <code>[this]*[right]</code>. 217 */ 218 @Nonnull 219 IJExpression mul (int right); 220 221 /** 222 * @param right 223 * value to multiply 224 * @return <code>[this]*[right]</code>. 225 */ 226 @Nonnull 227 IJExpression mul (long right); 228 229 /** 230 * @param right 231 * value to divide through 232 * @return <code>[this]/[right]</code>. 233 */ 234 @Nonnull 235 IJExpression div (@Nonnull IJExpression right); 236 237 /** 238 * @param right 239 * value to divide through 240 * @return <code>[this]/[right]</code>. 241 */ 242 @Nonnull 243 IJExpression div (double right); 244 245 /** 246 * @param right 247 * value to divide through 248 * @return <code>[this]/[right]</code>. 249 */ 250 @Nonnull 251 IJExpression div (float right); 252 253 /** 254 * @param right 255 * value to divide through 256 * @return <code>[this]/[right]</code>. 257 */ 258 @Nonnull 259 IJExpression div (int right); 260 261 /** 262 * @param right 263 * value to divide through 264 * @return <code>[this]/[right]</code>. 265 */ 266 @Nonnull 267 IJExpression div (long right); 268 269 /** 270 * @param right 271 * value to mod with 272 * @return <code>[this]%[right]</code>. 273 */ 274 @Nonnull 275 IJExpression mod (@Nonnull IJExpression right); 276 277 /** 278 * @param right 279 * number of bits to shift 280 * @return <code>[this]<<[right]</code>. 281 */ 282 @Nonnull 283 IJExpression shl (@Nonnull IJExpression right); 284 285 /** 286 * @param right 287 * number of bits to shift 288 * @return <code>[this]<<[right]</code>. 289 */ 290 @Nonnull 291 IJExpression shl (int right); 292 293 /** 294 * @param right 295 * number of bits to shift 296 * @return <code>[this] >> [right]</code>. 297 */ 298 @Nonnull 299 IJExpression shr (@Nonnull IJExpression right); 300 301 /** 302 * @param right 303 * number of bits to shift 304 * @return <code>[this] >> [right]</code>. 305 */ 306 @Nonnull 307 IJExpression shr (int right); 308 309 /** 310 * @param right 311 * number of bits to shift 312 * @return <code>[this] >>> [right]</code>. 313 */ 314 @Nonnull 315 IJExpression shrz (@Nonnull IJExpression right); 316 317 /** 318 * @param right 319 * number of bits to shift 320 * @return <code>[this] >>> [right]</code>. 321 */ 322 @Nonnull 323 IJExpression shrz (int right); 324 325 /** 326 * Bit-wise AND '&'. 327 * 328 * @param right 329 * value to combine with 330 * @return <code>[this] & [right]</code>. 331 */ 332 @Nonnull 333 IJExpression band (@Nonnull IJExpression right); 334 335 /** 336 * Bit-wise OR '|'. 337 * 338 * @param right 339 * value to combine with 340 * @return <code>[this] | [right]</code>. 341 */ 342 @Nonnull 343 IJExpression bor (@Nonnull IJExpression right); 344 345 /** 346 * Logical AND '&&'. 347 * 348 * @param right 349 * value to combine with 350 * @return <code>[this] && [right]</code>. 351 */ 352 @Nonnull 353 IJExpression cand (@Nonnull IJExpression right); 354 355 /** 356 * Logical OR '||'. 357 * 358 * @param right 359 * value to combine with 360 * @return <code>[this] || [right]</code>. 361 */ 362 @Nonnull 363 IJExpression cor (@Nonnull IJExpression right); 364 365 /** 366 * @param right 367 * value to combine with 368 * @return <code>[this] ^ [right]</code>. 369 */ 370 @Nonnull 371 IJExpression xor (@Nonnull IJExpression right); 372 373 /** 374 * @param right 375 * value to compare to 376 * @return <code>[this] < [right]</code>. 377 */ 378 @Nonnull 379 IJExpression lt (@Nonnull IJExpression right); 380 381 /** 382 * @return <code>[this] < 0</code>. 383 */ 384 @Nonnull 385 IJExpression lt0 (); 386 387 /** 388 * @param right 389 * value to compare to 390 * @return <code>[this] <= [right]</code>. 391 */ 392 @Nonnull 393 IJExpression lte (@Nonnull IJExpression right); 394 395 /** 396 * @return <code>[this] <= 0</code>. 397 */ 398 @Nonnull 399 IJExpression lte0 (); 400 401 /** 402 * @param right 403 * value to compare to 404 * @return <code>[this] > [right]</code>. 405 */ 406 @Nonnull 407 IJExpression gt (@Nonnull IJExpression right); 408 409 /** 410 * @return <code>[this] > 0</code>. 411 */ 412 @Nonnull 413 IJExpression gt0 (); 414 415 /** 416 * @param right 417 * value to compare to 418 * @return <code>[this] >= [right]</code>. 419 */ 420 @Nonnull 421 IJExpression gte (@Nonnull IJExpression right); 422 423 /** 424 * @return <code>[this] >= 0</code>. 425 */ 426 @Nonnull 427 IJExpression gte0 (); 428 429 /** 430 * Equals 431 * 432 * @param right 433 * expression to compare to 434 * @return <code><em>expr</em> == <em>right</em></code> 435 */ 436 @Nonnull 437 IJExpression eq (@Nonnull IJExpression right); 438 439 /** 440 * Shortcut for <code>eq (JExpr._null ())</code> 441 * 442 * @return <code><em>expr</em> == null</code> 443 */ 444 @Nonnull 445 IJExpression eqNull (); 446 447 /** 448 * Shortcut for <code>eq (JExpr.lit (0))</code> 449 * 450 * @return <code><em>expr</em> == 0</code> 451 */ 452 @Nonnull 453 IJExpression eq0 (); 454 455 /** 456 * Not equals 457 * 458 * @param right 459 * expression to compare to 460 * @return <code><em>expr</em> != <em>right</em></code> 461 */ 462 @Nonnull 463 IJExpression ne (@Nonnull IJExpression right); 464 465 /** 466 * Shortcut for <code>ne (JExpr._null ())</code> 467 * 468 * @return Never <code><em>expr</em> != null</code> 469 */ 470 @Nonnull 471 IJExpression neNull (); 472 473 /** 474 * Shortcut for <code>ne (JExpr.lit (0))</code> 475 * 476 * @return Never <code><em>expr</em> != 0</code> 477 */ 478 @Nonnull 479 IJExpression ne0 (); 480 481 /** 482 * @param right 483 * type to check 484 * @return <code>[this] instanceof [right]</code>. 485 */ 486 @Nonnull 487 IJExpression _instanceof (@Nonnull AbstractJType right); 488 489 /** 490 * @param method 491 * Method to be invoked 492 * @return <code>[this].[method]</code>. Arguments shall be added to the 493 * returned {@link JInvocation} object. 494 */ 495 @Nonnull 496 JInvocation invoke (@Nonnull JMethod method); 497 498 /** 499 * @param method 500 * name of the method to invoke 501 * @return <code>[this].[method]</code>. Arguments shall be added to the 502 * returned {@link JInvocation} object. 503 */ 504 @Nonnull 505 JInvocation invoke (@Nonnull String method); 506 507 @Nonnull 508 JFieldRef ref (@Nonnull JVar field); 509 510 @Nonnull 511 JFieldRef ref (@Nonnull String field); 512 513 /** 514 * @param index 515 * array index 516 * @return <code>[this] [ [index] ]</code> 517 */ 518 @Nonnull 519 JArrayCompRef component (@Nonnull IJExpression index); 520 521 /** 522 * @param index 523 * array index 524 * @return <code>[this] [ [index] ]</code> 525 */ 526 @Nonnull 527 JArrayCompRef component (int index); 528 529 /** 530 * @return <code>[this] [0]</code> 531 */ 532 @Nonnull 533 JArrayCompRef component0 (); 534 }