Source Code Cross Referenced for JOp.java in  » 6.0-JDK-Modules-com.sun » codemodel » com » sun » codemodel » internal » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules com.sun » codemodel » com.sun.codemodel.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package com.sun.codemodel.internal;
027:
028:        /**
029:         * JClass for generating expressions containing operators
030:         */
031:
032:        abstract public class JOp {
033:
034:            private JOp() {
035:            }
036:
037:            /**
038:             * Determine whether the top level of an expression involves an
039:             * operator.
040:             */
041:            static boolean hasTopOp(JExpression e) {
042:                return (e instanceof  UnaryOp) || (e instanceof  BinaryOp);
043:            }
044:
045:            /* -- Unary operators -- */
046:
047:            static private class UnaryOp extends JExpressionImpl {
048:
049:                protected String op;
050:                protected JExpression e;
051:                protected boolean opFirst = true;
052:
053:                UnaryOp(String op, JExpression e) {
054:                    this .op = op;
055:                    this .e = e;
056:                }
057:
058:                UnaryOp(JExpression e, String op) {
059:                    this .op = op;
060:                    this .e = e;
061:                    opFirst = false;
062:                }
063:
064:                public void generate(JFormatter f) {
065:                    if (opFirst)
066:                        f.p('(').p(op).g(e).p(')');
067:                    else
068:                        f.p('(').g(e).p(op).p(')');
069:                }
070:
071:            }
072:
073:            public static JExpression minus(JExpression e) {
074:                return new UnaryOp("-", e);
075:            }
076:
077:            /**
078:             * Logical not <tt>'!x'</tt>.
079:             */
080:            public static JExpression not(JExpression e) {
081:                if (e == JExpr.TRUE)
082:                    return JExpr.FALSE;
083:                if (e == JExpr.FALSE)
084:                    return JExpr.TRUE;
085:                return new UnaryOp("!", e);
086:            }
087:
088:            public static JExpression complement(JExpression e) {
089:                return new UnaryOp("~", e);
090:            }
091:
092:            static private class TightUnaryOp extends UnaryOp {
093:
094:                TightUnaryOp(JExpression e, String op) {
095:                    super (e, op);
096:                }
097:
098:                public void generate(JFormatter f) {
099:                    if (opFirst)
100:                        f.p(op).g(e);
101:                    else
102:                        f.g(e).p(op);
103:                }
104:
105:            }
106:
107:            public static JExpression incr(JExpression e) {
108:                return new TightUnaryOp(e, "++");
109:            }
110:
111:            public static JExpression decr(JExpression e) {
112:                return new TightUnaryOp(e, "--");
113:            }
114:
115:            /* -- Binary operators -- */
116:
117:            static private class BinaryOp extends JExpressionImpl {
118:
119:                String op;
120:                JExpression left;
121:                JGenerable right;
122:
123:                BinaryOp(String op, JExpression left, JGenerable right) {
124:                    this .left = left;
125:                    this .op = op;
126:                    this .right = right;
127:                }
128:
129:                public void generate(JFormatter f) {
130:                    f.p('(').g(left).p(op).g(right).p(')');
131:                }
132:
133:            }
134:
135:            public static JExpression plus(JExpression left, JExpression right) {
136:                return new BinaryOp("+", left, right);
137:            }
138:
139:            public static JExpression minus(JExpression left, JExpression right) {
140:                return new BinaryOp("-", left, right);
141:            }
142:
143:            public static JExpression mul(JExpression left, JExpression right) {
144:                return new BinaryOp("*", left, right);
145:            }
146:
147:            public static JExpression div(JExpression left, JExpression right) {
148:                return new BinaryOp("/", left, right);
149:            }
150:
151:            public static JExpression mod(JExpression left, JExpression right) {
152:                return new BinaryOp("%", left, right);
153:            }
154:
155:            public static JExpression shl(JExpression left, JExpression right) {
156:                return new BinaryOp("<<", left, right);
157:            }
158:
159:            public static JExpression shr(JExpression left, JExpression right) {
160:                return new BinaryOp(">>", left, right);
161:            }
162:
163:            public static JExpression shrz(JExpression left, JExpression right) {
164:                return new BinaryOp(">>>", left, right);
165:            }
166:
167:            public static JExpression band(JExpression left, JExpression right) {
168:                return new BinaryOp("&", left, right);
169:            }
170:
171:            public static JExpression bor(JExpression left, JExpression right) {
172:                return new BinaryOp("|", left, right);
173:            }
174:
175:            public static JExpression cand(JExpression left, JExpression right) {
176:                if (left == JExpr.TRUE)
177:                    return right;
178:                if (right == JExpr.TRUE)
179:                    return left;
180:                if (left == JExpr.FALSE)
181:                    return left; // JExpr.FALSE
182:                if (right == JExpr.FALSE)
183:                    return right; // JExpr.FALSE
184:                return new BinaryOp("&&", left, right);
185:            }
186:
187:            public static JExpression cor(JExpression left, JExpression right) {
188:                if (left == JExpr.TRUE)
189:                    return left; // JExpr.TRUE
190:                if (right == JExpr.TRUE)
191:                    return right; // JExpr.FALSE
192:                if (left == JExpr.FALSE)
193:                    return right;
194:                if (right == JExpr.FALSE)
195:                    return left;
196:                return new BinaryOp("||", left, right);
197:            }
198:
199:            public static JExpression xor(JExpression left, JExpression right) {
200:                return new BinaryOp("^", left, right);
201:            }
202:
203:            public static JExpression lt(JExpression left, JExpression right) {
204:                return new BinaryOp("<", left, right);
205:            }
206:
207:            public static JExpression lte(JExpression left, JExpression right) {
208:                return new BinaryOp("<=", left, right);
209:            }
210:
211:            public static JExpression gt(JExpression left, JExpression right) {
212:                return new BinaryOp(">", left, right);
213:            }
214:
215:            public static JExpression gte(JExpression left, JExpression right) {
216:                return new BinaryOp(">=", left, right);
217:            }
218:
219:            public static JExpression eq(JExpression left, JExpression right) {
220:                return new BinaryOp("==", left, right);
221:            }
222:
223:            public static JExpression ne(JExpression left, JExpression right) {
224:                return new BinaryOp("!=", left, right);
225:            }
226:
227:            public static JExpression _instanceof (JExpression left, JType right) {
228:                return new BinaryOp("instanceof", left, right);
229:            }
230:
231:            /* -- Ternary operators -- */
232:
233:            static private class TernaryOp extends JExpressionImpl {
234:
235:                String op1;
236:                String op2;
237:                JExpression e1;
238:                JExpression e2;
239:                JExpression e3;
240:
241:                TernaryOp(String op1, String op2, JExpression e1,
242:                        JExpression e2, JExpression e3) {
243:                    this .e1 = e1;
244:                    this .op1 = op1;
245:                    this .e2 = e2;
246:                    this .op2 = op2;
247:                    this .e3 = e3;
248:                }
249:
250:                public void generate(JFormatter f) {
251:                    f.p('(').g(e1).p(op1).g(e2).p(op2).g(e3).p(')');
252:                }
253:
254:            }
255:
256:            public static JExpression cond(JExpression cond,
257:                    JExpression ifTrue, JExpression ifFalse) {
258:                return new TernaryOp("?", ":", cond, ifTrue, ifFalse);
259:            }
260:
261:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.