Source Code Cross Referenced for ExpressionTest.java in  » IDE-Netbeans » php » org » netbeans » modules » php » model » 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 » IDE Netbeans » php » org.netbeans.modules.php.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package org.netbeans.modules.php.model;
042:
043:        import java.util.List;
044:
045:        import org.netbeans.modules.php.model.resources.ResourceMarker;
046:
047:        /**
048:         *
049:         * @author ads
050:         *
051:         */
052:        public class ExpressionTest extends BaseCase {
053:
054:            public void testOrExpression() throws Exception {
055:                PhpModel model = getModel(ResourceMarker.EXPRESSION);
056:                model.sync();
057:                model.readLock();
058:                try {
059:                    Statement statement = model.getStatements().get(0);
060:                    assert statement instanceof  ExpressionStatement;
061:
062:                    ExpressionStatement expressionStatement = (ExpressionStatement) statement;
063:                    Expression expression = expressionStatement.getExpression();
064:
065:                    assert expression.getElementType().equals(
066:                            BinaryExpression.class);
067:                    BinaryExpression binaryExpression = (BinaryExpression) expression;
068:
069:                    assert binaryExpression.getOperator().equals("or") : "Expected to find"
070:                            + " 'or' operator, but found :"
071:                            + binaryExpression.getOperator();
072:
073:                    Expression left = binaryExpression.getLeftOperand();
074:                    Expression right = binaryExpression.getRightOperand();
075:
076:                    String text = binaryExpression.getText();
077:                    assert left.getElementType().equals(Literal.class) : "Expected to "
078:                            + "find literal as first operand in expression '"
079:                            + text + "' , but found :" + left.getElementType();
080:
081:                    assert right.getElementType()
082:                            .equals(BinaryExpression.class) : "Expected to "
083:                            + "find binary expression as second operand in expression '"
084:                            + text + "' , but found :" + right.getElementType();
085:
086:                    binaryExpression = (BinaryExpression) right;
087:
088:                    assert binaryExpression.getOperator().equals("or") : "Expected to find"
089:                            + " 'or' operator, but found :"
090:                            + binaryExpression.getOperator();
091:
092:                    left = binaryExpression.getLeftOperand();
093:                    right = binaryExpression.getRightOperand();
094:
095:                    assert left.getElementType().equals(Literal.class) : "Expected to find literal as second operand in complex expression :"
096:                            + text + " , but found :" + left.getElementType();
097:
098:                    assert right.getElementType().equals(Literal.class) : "Expected to find literal as third operand in complex expression :"
099:                            + text + " , but found :" + right.getElementType();
100:
101:                } finally {
102:                    model.readUnlock();
103:                }
104:            }
105:
106:            public void testSecondExpression() throws Exception {
107:                PhpModel model = getModel(ResourceMarker.EXPRESSION);
108:                model.sync();
109:                model.readLock();
110:                try {
111:                    Statement statement = model.getStatements().get(1);
112:                    assert statement instanceof  ExpressionStatement;
113:
114:                    ExpressionStatement expressionStatement = (ExpressionStatement) statement;
115:                    Expression expression = expressionStatement.getExpression();
116:
117:                    assert expression.getElementType().equals(
118:                            BinaryExpression.class);
119:                    BinaryExpression binaryExpression = (BinaryExpression) expression;
120:
121:                    assert binaryExpression.getOperator().equals("+=") : "Expected"
122:                            + " to find '+=' operator in second expression , but found :"
123:                            + binaryExpression.getOperator();
124:
125:                    Expression left = binaryExpression.getLeftOperand();
126:                    Expression right = binaryExpression.getRightOperand();
127:
128:                    assert left.getElementType().equals(Variable.class) : "Expected to "
129:                            + "find variable as left operand in second expression , but found :"
130:                            + left.getElementType();
131:                    assert right.getElementType()
132:                            .equals(BinaryExpression.class) : "Expected to find binary expression as right operand in second"
133:                            + " expression, but found :"
134:                            + right.getElementType();
135:
136:                    binaryExpression = (BinaryExpression) right;
137:                    assert binaryExpression.getOperator().equals("xor") : "Expected to "
138:                            + "find 'xor' as operator in left operand , but found :"
139:                            + binaryExpression.getOperator();
140:
141:                    left = binaryExpression.getLeftOperand();
142:                    right = binaryExpression.getRightOperand();
143:
144:                    assert left.getElementType().equals(Variable.class) : "Expected to "
145:                            + "find variable as left operand in second expression inside "
146:                            + "assignent, but found :" + left.getElementType();
147:
148:                    assert right.getElementType()
149:                            .equals(BinaryExpression.class) : "Expected to find binary expression as right operand in second"
150:                            + " expression inside assignment, but found :"
151:                            + right.getElementType();
152:
153:                    binaryExpression = (BinaryExpression) right;
154:
155:                    assert binaryExpression.getOperator().equals("&&") : "Expected to find"
156:                            + " operator '&&' after 'xor' operator, but found :"
157:                            + binaryExpression.getOperator();
158:
159:                    left = binaryExpression.getLeftOperand();
160:                    right = binaryExpression.getRightOperand();
161:
162:                    assert left.getElementType().equals(Literal.class) : "Expected to "
163:                            + "find literal expression as left operand in && operator, but "
164:                            + "found :" + left.getElementType();
165:
166:                    assert right.getElementType()
167:                            .equals(BinaryExpression.class) : "Expected to find binary expression as right operand in second"
168:                            + " expression with && operator, but found :"
169:                            + right.getElementType();
170:
171:                    binaryExpression = (BinaryExpression) right;
172:
173:                    assert binaryExpression.getOperator().equals("|") : "Expected to find"
174:                            + " operator '|' after '&&' operator, but found :"
175:                            + binaryExpression.getOperator();
176:
177:                    left = binaryExpression.getLeftOperand();
178:                    right = binaryExpression.getRightOperand();
179:
180:                    assert left.getElementType().equals(Literal.class) : "Expected to "
181:                            + "find literal expression as left operand in '|' operator, but "
182:                            + "found :" + left.getElementType();
183:
184:                    assert right.getElementType().equals(Literal.class) : "Expected to "
185:                            + "find literal expression as left operand in '|' operator, but "
186:                            + "found :" + right.getElementType();
187:                } finally {
188:                    model.readUnlock();
189:                }
190:            }
191:
192:            public void testThirdExpression() throws Exception {
193:                PhpModel model = getModel(ResourceMarker.EXPRESSION);
194:                model.sync();
195:                model.readLock();
196:                try {
197:                    Statement statement = model.getStatements().get(2);
198:                    assert statement instanceof  ExpressionStatement;
199:
200:                    ExpressionStatement expressionStatement = (ExpressionStatement) statement;
201:                    Expression expression = expressionStatement.getExpression();
202:
203:                    assert expression.getElementType().equals(
204:                            BinaryExpression.class);
205:                    BinaryExpression binaryExpression = (BinaryExpression) expression;
206:
207:                    assert binaryExpression.getOperator().equals("=") : "Expected"
208:                            + " to find '=' operator in third expression , but found :"
209:                            + binaryExpression.getOperator();
210:
211:                    Expression left = binaryExpression.getLeftOperand();
212:                    Expression right = binaryExpression.getRightOperand();
213:
214:                    assert left.getElementType().equals(Variable.class) : "Expected to "
215:                            + "find variable as left operand in third expression , but found :"
216:                            + left.getElementType();
217:                    assert right.getElementType()
218:                            .equals(BinaryExpression.class) : "Expected to find binary expression as right operand in third"
219:                            + " expression, but found :"
220:                            + right.getElementType();
221:
222:                    binaryExpression = (BinaryExpression) right;
223:                    assert binaryExpression.getOperator().equals("+") : "Expected to "
224:                            + "find '+' as operator in left operand , but found :"
225:                            + binaryExpression.getOperator();
226:
227:                    left = binaryExpression.getLeftOperand();
228:                    right = binaryExpression.getRightOperand();
229:
230:                    assert left.getElementType().equals(Variable.class) : "Expected to "
231:                            + "find variable as left operand inside assignment"
232:                            + " in third expression , but found :"
233:                            + left.getElementType();
234:                    assert right.getElementType()
235:                            .equals(BinaryExpression.class) : "Expected to find binary expression as right operand in third"
236:                            + " expression after assignment, but found :"
237:                            + right.getElementType();
238:
239:                    binaryExpression = (BinaryExpression) right;
240:                    assert binaryExpression.getOperator().equals("-") : "Expected to "
241:                            + "find '-' as operator in left operand , but found :"
242:                            + binaryExpression.getOperator();
243:
244:                    left = binaryExpression.getLeftOperand();
245:                    right = binaryExpression.getRightOperand();
246:
247:                    assert left.getElementType().equals(Literal.class) : "Expected to "
248:                            + "find literal as left operand with '-' operator "
249:                            + " in third expression , but found :"
250:                            + left.getElementType();
251:                    assert right.getElementType().equals(UnaryExpression.class) : "Expected to find unary expression as right operand in third"
252:                            + " expression after assignment, but found :"
253:                            + right.getElementType();
254:
255:                    UnaryExpression unaryExpression = (UnaryExpression) right;
256:                    assert unaryExpression.getOperator().equals("++") : "Expected"
257:                            + " to find '++' unary operator , but found :"
258:                            + unaryExpression.getOperator();
259:
260:                    assert unaryExpression.isPostfix() : "Expected to find postfix operator";
261:                    assert !unaryExpression.isPrefix() : "Unexpected prefix operator";
262:
263:                    expression = unaryExpression.getOperand();
264:                    assert expression.getElementType().equals(Variable.class) : "Expected to find variable in incremental operator '++', "
265:                            + "but found : " + expression.getElementType();
266:                } finally {
267:                    model.readUnlock();
268:                }
269:            }
270:
271:            public void testFourthExpression() throws Exception {
272:                PhpModel model = getModel(ResourceMarker.EXPRESSION);
273:                model.sync();
274:                model.readLock();
275:                try {
276:                    Statement statement = model.getStatements().get(3);
277:                    assert statement instanceof  ExpressionStatement;
278:
279:                    ExpressionStatement expressionStatement = (ExpressionStatement) statement;
280:                    Expression expression = expressionStatement.getExpression();
281:
282:                    assert expression.getElementType().equals(
283:                            BinaryExpression.class);
284:                    BinaryExpression binaryExpression = (BinaryExpression) expression;
285:
286:                    assert binaryExpression.getOperator().equals("!==") : "Expected to find '!==' operator but found : "
287:                            + binaryExpression.getOperator();
288:
289:                    Expression left = binaryExpression.getLeftOperand();
290:                    Expression right = binaryExpression.getRightOperand();
291:
292:                    assert left.getElementType().equals(Variable.class) : "Expected to "
293:                            + "find variable as left operand in fourth expression , but found :"
294:                            + left.getElementType();
295:                    assert right.getElementType()
296:                            .equals(BinaryExpression.class) : "Expected to find binary expression as right operand in fourth"
297:                            + " expression, but found :"
298:                            + right.getElementType();
299:
300:                    binaryExpression = (BinaryExpression) right;
301:                    assert binaryExpression.getOperator().equals("/") : "Expected to "
302:                            + "find '/' as operator in right operand , but found :"
303:                            + binaryExpression.getOperator();
304:
305:                    left = binaryExpression.getLeftOperand();
306:                    right = binaryExpression.getRightOperand();
307:
308:                    assert left.getElementType().equals(UnaryExpression.class) : "Expected to find unary expression as left operand with '/' operator "
309:                            + " in fourth expression , but found :"
310:                            + left.getElementType();
311:                    assert right.getElementType().equals(Literal.class) : "Expected to find literal expression as right operand in third"
312:                            + " expression after assignment, but found :"
313:                            + right.getElementType();
314:
315:                    UnaryExpression unaryExpression = (UnaryExpression) left;
316:                    assert unaryExpression.getOperator().equals(
317:                            UnaryExpression.PARENS) : "Expected to find '()' unary operator , but found :"
318:                            + unaryExpression.getOperand();
319:
320:                    assert !unaryExpression.isPostfix() : "Unexpected postfix unary expression";
321:                    assert !unaryExpression.isPrefix() : "Unexpected prefix unary expression";
322:
323:                    expression = unaryExpression.getOperand();
324:                    assert expression.getElementType().equals(
325:                            BinaryExpression.class) : "Expected to find binary expression inside () , but found :"
326:                            + expression.getElementType();
327:
328:                    binaryExpression = (BinaryExpression) expression;
329:
330:                    assert binaryExpression.getOperator().equals("<>") : "Expected to "
331:                            + "find '<>' as operator in right operand , but found :"
332:                            + binaryExpression.getOperator();
333:
334:                    left = binaryExpression.getLeftOperand();
335:                    right = binaryExpression.getRightOperand();
336:
337:                    assert left.getElementType().equals(Constant.class) : "Expected to find unary expression as left operand with '/' operator "
338:                            + " in fourth expression inside (), but found :"
339:                            + left.getElementType();
340:                    assert right.getElementType().equals(Variable.class) : "Expected to find variable expression as right operand in fourth"
341:                            + " expression inside (), but found :"
342:                            + right.getElementType();
343:
344:                    Constant conzt = (Constant) left;
345:                    // TODO : Constant interface should be extended with more methods
346:                    // and there should be set of tests for these methods. 
347:                } finally {
348:                    model.readUnlock();
349:                }
350:            }
351:
352:            public void testFifthExpression() throws Exception {
353:                PhpModel model = getModel(ResourceMarker.EXPRESSION);
354:                model.sync();
355:                model.readLock();
356:                try {
357:
358:                    Statement statement = model.getStatements().get(4);
359:                    assert statement instanceof  ExpressionStatement;
360:
361:                    ExpressionStatement expressionStatement = (ExpressionStatement) statement;
362:                    Expression expression = expressionStatement.getExpression();
363:
364:                    assert expression.getElementType().equals(
365:                            BinaryExpression.class);
366:                    BinaryExpression binaryExpression = (BinaryExpression) expression;
367:
368:                    assert binaryExpression.getOperator().equals(".=") : "Expected to find '.=' operator but found : "
369:                            + binaryExpression.getOperator();
370:
371:                    Expression left = binaryExpression.getLeftOperand();
372:                    Expression right = binaryExpression.getRightOperand();
373:
374:                    assert left.getElementType().equals(Variable.class) : "Expected to find variable as left operand in fifth expression , "
375:                            + "but found :" + left.getElementType();
376:                    assert right.getElementType()
377:                            .equals(BinaryExpression.class) : "Expected to find binary expression as right operand in fifth"
378:                            + " expression , but found :"
379:                            + right.getElementType();
380:
381:                    binaryExpression = (BinaryExpression) right;
382:
383:                    assert binaryExpression.getOperator().equals("&") : "Expected"
384:                            + " to find '&' operator as first operator in left assignment "
385:                            + "expression , but found : "
386:                            + binaryExpression.getOperator();
387:
388:                    left = binaryExpression.getLeftOperand();
389:                    right = binaryExpression.getRightOperand();
390:
391:                    assert left.getElementType().equals(CallExpression.class) : "Expected to find call expression as left operand in fifth"
392:                            + " expression after assignment with '&' operator, but found :"
393:                            + right.getElementType();
394:
395:                    assert right.getElementType()
396:                            .equals(BinaryExpression.class) : "Expected to find binary expression as right operand with '&' operator "
397:                            + " in fifth expression , but found :"
398:                            + left.getElementType();
399:
400:                    CallExpression callExpression = (CallExpression) left;
401:                    IdentifierExpression name = callExpression.getName();
402:                    assert name != null;
403:                    assert name.getElementType().equals(Constant.class) : "Expected to find"
404:                            + " constant as function name , but found :"
405:                            + name.getElementType();
406:
407:                    binaryExpression = (BinaryExpression) right;
408:
409:                    left = binaryExpression.getLeftOperand();
410:                    right = binaryExpression.getRightOperand();
411:
412:                    assert binaryExpression.getOperator().equals("+") : "Expected "
413:                            + "operator '+' as lst operator in right expression, but found :"
414:                            + binaryExpression.getOperator();
415:
416:                    assert left.getElementType().equals(UnaryExpression.class) : "Expected to find unary expression as left expression with '+'"
417:                            + " operator, but found : " + left.getElementType();
418:
419:                    assert right.getElementType().equals(CallExpression.class) : "Expected to find call expression as last expression in "
420:                            + "right operand of assignment expression, but found: "
421:                            + right.getElementType();
422:
423:                    UnaryExpression unaryExpression = (UnaryExpression) left;
424:                    assert unaryExpression.isPrefix() : "Expected prefix unary expression";
425:                    assert !unaryExpression.isPostfix() : "Unexpected postfix unary expression";
426:
427:                    assert unaryExpression.getOperator().equals("!") : "Expected to find "
428:                            + "unary operand '!', but found :"
429:                            + unaryExpression.getOperand();
430:
431:                    callExpression = (CallExpression) right;
432:
433:                    assert callExpression.getArguments() != null;
434:                    Arguments args = callExpression.getArguments();
435:                    assert args.getArgumentsList().size() == 2 : "Expected to find two arguments,"
436:                            + " but found :" + args.getArgumentsList();
437:                    name = callExpression.getName();
438:                    assert name != null;
439:                    assert name.getElementType().equals(
440:                            ClassMemberExpression.class) : "Expected to find class memeber expression in last call expression,"
441:                            + "but found :" + name.getElementType();
442:
443:                    ClassMemberExpression memberExpression = (ClassMemberExpression) name;
444:                    IdentifierExpression identifierExpression = memberExpression
445:                            .getOwnerIdentifier();
446:                    assert identifierExpression != null;
447:                    assert identifierExpression.getElementType().equals(
448:                            Variable.class) : "Expected to find variable as identifier expression for class"
449:                            + " in last method call expression, but found :"
450:                            + identifierExpression.getElementType();
451:
452:                    assert identifierExpression.getText().equals("$clazz") : "Expected text '$clazz' for identifier expression , but found :"
453:                            + identifierExpression.getText();
454:
455:                    /*
456:                     * unary expression is !$arr[ ++$i ]
457:                     */
458:                    expression = unaryExpression.getOperand();
459:
460:                    assert expression.getElementType().equals(
461:                            ArrayMemberExpression.class) : "Expected to find array member access in unary expression ,"
462:                            + "but found : " + expression.getElementType();
463:
464:                    ArrayMemberExpression arrayMember = (ArrayMemberExpression) expression;
465:                    assert arrayMember.getCallExpression() == null;
466:
467:                    expression = arrayMember.getExpression();
468:                    assert expression != null : "Expression in '[]' should be not null";
469:                    assert expression.getElementType().equals(
470:                            UnaryExpression.class) : "Expected to find unary expression in '[]', but found :"
471:                            + expression.getElementType();
472:                    assert ((UnaryExpression) expression).getOperator().equals(
473:                            "++") : "Expected to find unary operator '++' in '[]', but found :"
474:                            + ((UnaryExpression) expression).getOperator();
475:
476:                    identifierExpression = arrayMember.getOwnerIdentifier();
477:                    assert identifierExpression != null;
478:                    assert identifierExpression.getElementType().equals(
479:                            Variable.class) : "Expected to find variable identifier for array , but found :"
480:                            + identifierExpression.getElementType();
481:                } finally {
482:                    model.readUnlock();
483:                }
484:            }
485:
486:            public void testSixthExpression() throws Exception {
487:                PhpModel model = getModel(ResourceMarker.EXPRESSION);
488:                model.sync();
489:                model.readLock();
490:                try {
491:                    Statement statement = model.getStatements().get(5);
492:                    assert statement instanceof  ExpressionStatement;
493:
494:                    ExpressionStatement expressionStatement = (ExpressionStatement) statement;
495:                    Expression expression = expressionStatement.getExpression();
496:
497:                    assert expression.getElementType().equals(
498:                            ArrayExpression.class) : "Expected to find array expression in sixth expression, but "
499:                            + "found :" + expression.getElementType();
500:
501:                    ArrayExpression arrayExpr = (ArrayExpression) expression;
502:                    List<ArrayDefElement> elements = arrayExpr.getElements();
503:
504:                    assert elements.size() > 1 : "Expected to find at least two "
505:                            + "array def elements, but found : "
506:                            + elements.size();
507:                    ArrayDefElement element = elements.get(0);
508:                    assert element != null;
509:                    assert element.getElementType().equals(
510:                            UnaryExpression.class) : "Expected to find unary expression as first array element,"
511:                            + "but found :" + element.getElementType();
512:
513:                    UnaryExpression unary = (UnaryExpression) element;
514:                    assert unary.getOperator().equals("--") : "Expected to find unary"
515:                            + " operator '--' , but found :"
516:                            + unary.getOperator();
517:
518:                    assert unary.getOperand().getElementType().equals(
519:                            Variable.class) : "Expected to find variable type for operand in unary expression,"
520:                            + "but found : " + unary.getOperand();
521:
522:                    element = elements.get(1);
523:                    assert element.getElementType().equals(
524:                            AssociativeArrayElement.class) : "Expected to find associative element as second element in "
525:                            + "array definition, but found : "
526:                            + element.getElementType();
527:                    AssociativeArrayElement assoc = (AssociativeArrayElement) element;
528:                    assert assoc != null;
529:                    Expression key = assoc.getKey();
530:                    Expression value = assoc.getValue();
531:
532:                    assert key != null : "Expected to find key element in associative "
533:                            + "array element";
534:                    assert value != null : "Expected to find value element in associative "
535:                            + "array element";
536:
537:                    assert key.getElementType().equals(UnaryExpression.class) : "Expected to find unary expression '()' as key , but found :"
538:                            + key.getElementType();
539:                    assert value.getElementType().equals(Variable.class) : "Expected "
540:                            + "to find variable as value , but found :"
541:                            + value.getElementType();
542:
543:                    unary = (UnaryExpression) key;
544:                    assert unary.getOperator().equals(UnaryExpression.PARENS) : "Expected"
545:                            + " '()' operator in unary expression , but found : "
546:                            + unary.getOperator();
547:                    expression = unary.getOperand();
548:
549:                    assert expression.getElementType().equals(
550:                            BinaryExpression.class) : "Expected to find binary expression inside '()' , but found :"
551:                            + expression.getElementType();
552:                    BinaryExpression binaryExpression = (BinaryExpression) expression;
553:
554:                    assert binaryExpression.getOperator().equals("+") : "Expected to find '+' operator as operator inside '()' , but found :"
555:                            + binaryExpression.getOperator();
556:
557:                    assert binaryExpression.getLeftOperand().getElementType()
558:                            .equals(Variable.class) : "Expected variable type for left operand"
559:                            + " in additive expression,"
560:                            + " but found :"
561:                            + binaryExpression.getLeftOperand()
562:                                    .getElementType();
563:                    assert binaryExpression.getRightOperand().getElementType()
564:                            .equals(Variable.class) : "Expected variable type for right operand "
565:                            + "in additive expression,"
566:                            + " but found :"
567:                            + binaryExpression.getLeftOperand()
568:                                    .getElementType();
569:                } finally {
570:                    model.readUnlock();
571:                }
572:            }
573:
574:            public void testSeventhExpression() throws Exception {
575:                PhpModel model = getModel(ResourceMarker.EXPRESSION);
576:                model.sync();
577:                model.readLock();
578:                try {
579:                    Statement statement = model.getStatements().get(6);
580:                    assert statement instanceof  ExpressionStatement;
581:
582:                    Expression expression = ((ExpressionStatement) statement)
583:                            .getExpression();
584:                    assert expression.getElementType().equals(
585:                            CallExpression.class) : "Expected to find call expression , but found : "
586:                            + expression.getElementType();
587:
588:                    CallExpression callExpression = (CallExpression) expression;
589:                    Arguments args = callExpression.getArguments();
590:                    assert args != null;
591:                    List<Expression> argums = args.getArgumentsList();
592:                    assert argums.size() > 0 : "Expected to find at least one arument";
593:                    expression = argums.get(0);
594:                    assert expression.getElementType().equals(
595:                            UnaryExpression.class) : "Expected to find unary expression as argument for include"
596:                            + " function, but found  :"
597:                            + expression.getElementType();
598:
599:                    assert callExpression.getName().getElementType().equals(
600:                            Constant.class) : "Expected to find constant name for include function , but found :"
601:                            + callExpression.getName().getElementType();
602:
603:                    assert callExpression.getName().getText().equals("include") : "Expected to find 'include' as text for function , but found :"
604:                            + callExpression.getName().getText();
605:
606:                    UnaryExpression unary = (UnaryExpression) expression;
607:                    assert unary.getOperator().equals(UnaryExpression.PARENS) : "Expected"
608:                            + " '()' unary operator, but found :"
609:                            + unary.getOperator();
610:
611:                    expression = unary.getOperand();
612:                    assert expression.getElementType().equals(Literal.class) : "Expected"
613:                            + " literal element as argument for include, but found :"
614:                            + expression.getElementType();
615:                } finally {
616:                    model.readUnlock();
617:                }
618:            }
619:
620:            public void testEighthExpression() throws Exception {
621:                PhpModel model = getModel(ResourceMarker.EXPRESSION);
622:                model.sync();
623:                model.readLock();
624:                try {
625:                    Statement statement = model.getStatements().get(7);
626:                    assert statement instanceof  ExpressionStatement;
627:
628:                    Expression expression = ((ExpressionStatement) statement)
629:                            .getExpression();
630:                    assert expression.getElementType().equals(
631:                            CallExpression.class) : "Expected to find call expression , but found : "
632:                            + expression.getElementType();
633:
634:                    CallExpression callExpression = (CallExpression) expression;
635:                    Arguments args = callExpression.getArguments();
636:                    assert args != null;
637:                    assert args.getArgumentsList().size() > 0 : "Expected to find at least"
638:                            + " one argument";
639:
640:                    assert args.getArgumentsList().get(0).getElementType()
641:                            .equals(Variable.class) : "Expected to find variable as argument,"
642:                            + " but found : "
643:                            + args.getArgumentsList().get(0).getElementType();
644:
645:                    IdentifierExpression identifierExpression = callExpression
646:                            .getName();
647:                    assert identifierExpression != null;
648:                    assert identifierExpression.getElementType().equals(
649:                            Constant.class) : "Expected to find constant function name, but found :"
650:                            + identifierExpression.getElementType();
651:
652:                    assert identifierExpression.getText().equals("unset") : "Expected to find 'unset' as text for function name , but found :"
653:                            + identifierExpression.getText();
654:                } finally {
655:                    model.readUnlock();
656:                }
657:            }
658:
659:            public void testNinthExpression() throws Exception {
660:                PhpModel model = getModel(ResourceMarker.EXPRESSION);
661:                model.sync();
662:                model.readLock();
663:                try {
664:                    Statement statement = model.getStatements().get(8);
665:                    assert statement instanceof  ExpressionStatement;
666:
667:                    Expression expression = ((ExpressionStatement) statement)
668:                            .getExpression();
669:                    assert expression.getElementType().equals(
670:                            BinaryExpression.class) : "Expected to find binary expression , but found : "
671:                            + expression.getElementType();
672:
673:                    BinaryExpression binaryExpression = (BinaryExpression) expression;
674:                    Expression left = binaryExpression.getLeftOperand();
675:                    Expression right = binaryExpression.getRightOperand();
676:
677:                    assert left != null;
678:                    assert left.getElementType().equals(Variable.class) : "Expected to find variable in left operand of assignment"
679:                            + " expression , but found :"
680:                            + left.getElementType();
681:
682:                    assert right != null;
683:                    assert right.getElementType().equals(NewExpression.class) : "Expected to find new expression in right operand of"
684:                            + " assignment expression , but found :"
685:                            + right.getElementType();
686:
687:                    NewExpression newExpression = (NewExpression) right;
688:                    assert !newExpression.isByReference() : "Unexpexted reference in new"
689:                            + " expression";
690:                    Arguments args = newExpression.getArguments();
691:                    assert args != null;
692:                    assert args.getElementType().equals(Arguments.class) : "Expected"
693:                            + " arguments type in new expression , but found : "
694:                            + args.getElementType();
695:                    List<Expression> argums = args.getArgumentsList();
696:                    assert argums.size() > 0 : "Expected at least one argument in new "
697:                            + "expression";
698:                    expression = argums.get(0);
699:                    assert expression != null;
700:                    assert expression.getElementType().equals(Variable.class) : "Expected to fund variable as argument in new expression, "
701:                            + "but found : " + expression.getElementType();
702:
703:                    Reference<ClassDefinition> ref = newExpression
704:                            .getClassName();
705:                    assert ref != null;
706:                    assert ref.getIdentifier().equals("Class") : "Expected 'Class' "
707:                            + "identifier for class name in new expression, but found :"
708:                            + ref.getIdentifier();
709:                } finally {
710:                    model.readUnlock();
711:                }
712:            }
713:
714:            public void testTenthExpression() throws Exception {
715:                PhpModel model = getModel(ResourceMarker.EXPRESSION);
716:                model.sync();
717:                model.readLock();
718:                try {
719:                    Statement statement = model.getStatements().get(9);
720:                    assert statement instanceof  ExpressionStatement;
721:
722:                    Expression expression = ((ExpressionStatement) statement)
723:                            .getExpression();
724:
725:                    assert expression.getElementType().equals(
726:                            BinaryExpression.class) : "Expected to find binary expression , but found : "
727:                            + expression.getElementType();
728:
729:                    BinaryExpression binaryExpression = (BinaryExpression) expression;
730:                    Expression left = binaryExpression.getLeftOperand();
731:                    Expression right = binaryExpression.getRightOperand();
732:
733:                    assert binaryExpression.getOperator().equals("instanceof") : "Expected instanceof operator but found :"
734:                            + binaryExpression.getOperator();
735:
736:                    assert left.getElementType().equals(Variable.class) : "Expected "
737:                            + "variable as left expression in instanceof operator, but found:"
738:                            + left.getElementType();
739:                    assert right.getElementType().equals(Variable.class) : "Expected "
740:                            + "variable as right expression in instanceof operator, but found:"
741:                            + left.getElementType();
742:
743:                } finally {
744:                    model.readUnlock();
745:                }
746:            }
747:
748:            public void testEleventhExpression() throws Exception {
749:                PhpModel model = getModel(ResourceMarker.EXPRESSION);
750:                model.sync();
751:                model.readLock();
752:                try {
753:                    Statement statement = model.getStatements().get(10);
754:                    assert statement instanceof  ExpressionStatement;
755:
756:                    Expression expression = ((ExpressionStatement) statement)
757:                            .getExpression();
758:
759:                    assert expression.getElementType().equals(
760:                            BinaryExpression.class) : "Expected to find binary expression , but found : "
761:                            + expression.getElementType();
762:
763:                    BinaryExpression binaryExpression = (BinaryExpression) expression;
764:                    Expression left = binaryExpression.getLeftOperand();
765:                    Expression right = binaryExpression.getRightOperand();
766:
767:                    assert binaryExpression.getOperator().equals("instanceof") : "Expected instanceof operator but found :"
768:                            + binaryExpression.getOperator();
769:
770:                    assert left.getElementType().equals(Variable.class) : "Expected "
771:                            + "variable as left expression in instanceof operator, but found:"
772:                            + left.getElementType();
773:                    assert right.getElementType().equals(Constant.class) : "Expected "
774:                            + "constant as right expression in instanceof operator, but found:"
775:                            + left.getElementType();
776:
777:                } finally {
778:                    model.readUnlock();
779:                }
780:            }
781:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.