Source Code Cross Referenced for JOp.java in  » 6.0-JDK-Modules » jaxb-xjc » com » sun » codemodel » 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 » jaxb xjc » com.sun.codemodel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms
003:         * of the Common Development and Distribution License
004:         * (the "License").  You may not use this file except
005:         * in compliance with the License.
006:         * 
007:         * You can obtain a copy of the license at
008:         * https://jwsdp.dev.java.net/CDDLv1.0.html
009:         * See the License for the specific language governing
010:         * permissions and limitations under the License.
011:         * 
012:         * When distributing Covered Code, include this CDDL
013:         * HEADER in each file and include the License file at
014:         * https://jwsdp.dev.java.net/CDDLv1.0.html  If applicable,
015:         * add the following below this CDDL HEADER, with the
016:         * fields enclosed by brackets "[]" replaced with your
017:         * own identifying information: Portions Copyright [yyyy]
018:         * [name of copyright owner]
019:         */
020:
021:        package com.sun.codemodel;
022:
023:        /**
024:         * JClass for generating expressions containing operators
025:         */
026:
027:        abstract public class JOp {
028:
029:            private JOp() {
030:            }
031:
032:            /**
033:             * Determine whether the top level of an expression involves an
034:             * operator.
035:             */
036:            static boolean hasTopOp(JExpression e) {
037:                return (e instanceof  UnaryOp) || (e instanceof  BinaryOp);
038:            }
039:
040:            /* -- Unary operators -- */
041:
042:            static private class UnaryOp extends JExpressionImpl {
043:
044:                protected String op;
045:                protected JExpression e;
046:                protected boolean opFirst = true;
047:
048:                UnaryOp(String op, JExpression e) {
049:                    this .op = op;
050:                    this .e = e;
051:                }
052:
053:                UnaryOp(JExpression e, String op) {
054:                    this .op = op;
055:                    this .e = e;
056:                    opFirst = false;
057:                }
058:
059:                public void generate(JFormatter f) {
060:                    if (opFirst)
061:                        f.p('(').p(op).g(e).p(')');
062:                    else
063:                        f.p('(').g(e).p(op).p(')');
064:                }
065:
066:            }
067:
068:            public static JExpression minus(JExpression e) {
069:                return new UnaryOp("-", e);
070:            }
071:
072:            /**
073:             * Logical not <tt>'!x'</tt>.
074:             */
075:            public static JExpression not(JExpression e) {
076:                if (e == JExpr.TRUE)
077:                    return JExpr.FALSE;
078:                if (e == JExpr.FALSE)
079:                    return JExpr.TRUE;
080:                return new UnaryOp("!", e);
081:            }
082:
083:            public static JExpression complement(JExpression e) {
084:                return new UnaryOp("~", e);
085:            }
086:
087:            static private class TightUnaryOp extends UnaryOp {
088:
089:                TightUnaryOp(JExpression e, String op) {
090:                    super (e, op);
091:                }
092:
093:                public void generate(JFormatter f) {
094:                    if (opFirst)
095:                        f.p(op).g(e);
096:                    else
097:                        f.g(e).p(op);
098:                }
099:
100:            }
101:
102:            public static JExpression incr(JExpression e) {
103:                return new TightUnaryOp(e, "++");
104:            }
105:
106:            public static JExpression decr(JExpression e) {
107:                return new TightUnaryOp(e, "--");
108:            }
109:
110:            /* -- Binary operators -- */
111:
112:            static private class BinaryOp extends JExpressionImpl {
113:
114:                String op;
115:                JExpression left;
116:                JGenerable right;
117:
118:                BinaryOp(String op, JExpression left, JGenerable right) {
119:                    this .left = left;
120:                    this .op = op;
121:                    this .right = right;
122:                }
123:
124:                public void generate(JFormatter f) {
125:                    f.p('(').g(left).p(op).g(right).p(')');
126:                }
127:
128:            }
129:
130:            public static JExpression plus(JExpression left, JExpression right) {
131:                return new BinaryOp("+", left, right);
132:            }
133:
134:            public static JExpression minus(JExpression left, JExpression right) {
135:                return new BinaryOp("-", left, right);
136:            }
137:
138:            public static JExpression mul(JExpression left, JExpression right) {
139:                return new BinaryOp("*", left, right);
140:            }
141:
142:            public static JExpression div(JExpression left, JExpression right) {
143:                return new BinaryOp("/", left, right);
144:            }
145:
146:            public static JExpression mod(JExpression left, JExpression right) {
147:                return new BinaryOp("%", left, right);
148:            }
149:
150:            public static JExpression shl(JExpression left, JExpression right) {
151:                return new BinaryOp("<<", left, right);
152:            }
153:
154:            public static JExpression shr(JExpression left, JExpression right) {
155:                return new BinaryOp(">>", left, right);
156:            }
157:
158:            public static JExpression shrz(JExpression left, JExpression right) {
159:                return new BinaryOp(">>>", left, right);
160:            }
161:
162:            public static JExpression band(JExpression left, JExpression right) {
163:                return new BinaryOp("&", left, right);
164:            }
165:
166:            public static JExpression bor(JExpression left, JExpression right) {
167:                return new BinaryOp("|", left, right);
168:            }
169:
170:            public static JExpression cand(JExpression left, JExpression right) {
171:                if (left == JExpr.TRUE)
172:                    return right;
173:                if (right == JExpr.TRUE)
174:                    return left;
175:                if (left == JExpr.FALSE)
176:                    return left; // JExpr.FALSE
177:                if (right == JExpr.FALSE)
178:                    return right; // JExpr.FALSE
179:                return new BinaryOp("&&", left, right);
180:            }
181:
182:            public static JExpression cor(JExpression left, JExpression right) {
183:                if (left == JExpr.TRUE)
184:                    return left; // JExpr.TRUE
185:                if (right == JExpr.TRUE)
186:                    return right; // JExpr.FALSE
187:                if (left == JExpr.FALSE)
188:                    return right;
189:                if (right == JExpr.FALSE)
190:                    return left;
191:                return new BinaryOp("||", left, right);
192:            }
193:
194:            public static JExpression xor(JExpression left, JExpression right) {
195:                return new BinaryOp("^", left, right);
196:            }
197:
198:            public static JExpression lt(JExpression left, JExpression right) {
199:                return new BinaryOp("<", left, right);
200:            }
201:
202:            public static JExpression lte(JExpression left, JExpression right) {
203:                return new BinaryOp("<=", left, right);
204:            }
205:
206:            public static JExpression gt(JExpression left, JExpression right) {
207:                return new BinaryOp(">", left, right);
208:            }
209:
210:            public static JExpression gte(JExpression left, JExpression right) {
211:                return new BinaryOp(">=", left, right);
212:            }
213:
214:            public static JExpression eq(JExpression left, JExpression right) {
215:                return new BinaryOp("==", left, right);
216:            }
217:
218:            public static JExpression ne(JExpression left, JExpression right) {
219:                return new BinaryOp("!=", left, right);
220:            }
221:
222:            public static JExpression _instanceof (JExpression left, JType right) {
223:                return new BinaryOp("instanceof", left, right);
224:            }
225:
226:            /* -- Ternary operators -- */
227:
228:            static private class TernaryOp extends JExpressionImpl {
229:
230:                String op1;
231:                String op2;
232:                JExpression e1;
233:                JExpression e2;
234:                JExpression e3;
235:
236:                TernaryOp(String op1, String op2, JExpression e1,
237:                        JExpression e2, JExpression e3) {
238:                    this .e1 = e1;
239:                    this .op1 = op1;
240:                    this .e2 = e2;
241:                    this .op2 = op2;
242:                    this .e3 = e3;
243:                }
244:
245:                public void generate(JFormatter f) {
246:                    f.p('(').g(e1).p(op1).g(e2).p(op2).g(e3).p(')');
247:                }
248:
249:            }
250:
251:            public static JExpression cond(JExpression cond,
252:                    JExpression ifTrue, JExpression ifFalse) {
253:                return new TernaryOp("?", ":", cond, ifTrue, ifFalse);
254:            }
255:
256:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.