View Javadoc
1   /*
2    * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.  Oracle designates this
8    * particular file as subject to the "Classpath" exception as provided
9    * by Oracle in the LICENSE file that accompanied this code.
10   *
11   * This code is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   * version 2 for more details (a copy is included in the LICENSE file that
15   * accompanied this code).
16   *
17   * You should have received a copy of the GNU General Public License version
18   * 2 along with this work; if not, write to the Free Software Foundation,
19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20   *
21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22   * or visit www.oracle.com if you need additional information or have any
23   * questions.
24   */
25  
26  package com.sun.codemodel.internal;
27  
28  
29  /**
30   * A Java expression.
31   *
32   * <p>
33   * Unlike most of CodeModel, JExpressions are built bottom-up (
34   * meaning you start from leaves and then gradually build compliated expressions
35   * by combining them.)
36   *
37   * <p>
38   * {@link JExpression} defines a series of composer methods,
39   * which returns a complicated expression (by often taking other {@link JExpression}s
40   * as parameters.
41   * For example, you can build "5+2" by
42   * <tt>JExpr.lit(5).add(JExpr.lit(2))</tt>
43   */
44  public interface JExpression extends JGenerable {
45      /**
46       * Returns "-[this]" from "[this]".
47       */
48      JExpression minus();
49  
50      /**
51       * Returns "![this]" from "[this]".
52       */
53      JExpression not();
54      /**
55       * Returns "~[this]" from "[this]".
56       */
57      JExpression complement();
58  
59      /**
60       * Returns "[this]++" from "[this]".
61       */
62      JExpression incr();
63  
64      /**
65       * Returns "[this]--" from "[this]".
66       */
67      JExpression decr();
68  
69      /**
70       * Returns "[this]+[right]"
71       */
72      JExpression plus(JExpression right);
73  
74      /**
75       * Returns "[this]-[right]"
76       */
77      JExpression minus(JExpression right);
78  
79      /**
80       * Returns "[this]*[right]"
81       */
82      JExpression mul(JExpression right);
83  
84      /**
85       * Returns "[this]/[right]"
86       */
87      JExpression div(JExpression right);
88  
89      /**
90       * Returns "[this]%[right]"
91       */
92      JExpression mod(JExpression right);
93  
94      /**
95       * Returns "[this]&lt;&lt;[right]"
96       */
97      JExpression shl(JExpression right);
98  
99      /**
100      * Returns "[this]>>[right]"
101      */
102     JExpression shr(JExpression right);
103 
104     /**
105      * Returns "[this]>>>[right]"
106      */
107     JExpression shrz(JExpression right);
108 
109     /** Bit-wise AND '&amp;'. */
110     JExpression band(JExpression right);
111 
112     /** Bit-wise OR '|'. */
113     JExpression bor(JExpression right);
114 
115     /** Logical AND '&amp;&amp;'. */
116     JExpression cand(JExpression right);
117 
118     /** Logical OR '||'. */
119     JExpression cor(JExpression right);
120 
121     JExpression xor(JExpression right);
122     JExpression lt(JExpression right);
123     JExpression lte(JExpression right);
124     JExpression gt(JExpression right);
125     JExpression gte(JExpression right);
126     JExpression eq(JExpression right);
127     JExpression ne(JExpression right);
128 
129     /**
130      * Returns "[this] instanceof [right]"
131      */
132     JExpression _instanceof(JType right);
133 
134     /**
135      * Returns "[this].[method]".
136      *
137      * Arguments shall be added to the returned {@link JInvocation} object.
138      */
139     JInvocation invoke(JMethod method);
140 
141     /**
142      * Returns "[this].[method]".
143      *
144      * Arguments shall be added to the returned {@link JInvocation} object.
145      */
146     JInvocation invoke(String method);
147     JFieldRef ref(JVar field);
148     JFieldRef ref(String field);
149     JArrayCompRef component(JExpression index);
150 }