Source Code Cross Referenced for BSHEnhancedForStatement.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » bsh » 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 » Swing Library » jEdit » org.gjt.sp.jedit.bsh 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.gjt.sp.jedit.bsh;
002:
003:        // Just testing...
004:
005:        /**
006:         Implementation of the enhanced for(:) statement.  
007:         This statement uses BshIterable to support iteration over a wide variety
008:         of iterable types.  Under JDK 1.1 this statement supports primitive and 
009:         Object arrays, Vectors, and enumerations.  Under JDK 1.2 and later it 
010:         additionally supports collections.
011:
012:         @author Daniel Leuck 
013:         @author Pat Niemeyer
014:         */
015:        class BSHEnhancedForStatement extends SimpleNode implements 
016:                ParserConstants {
017:            String varName;
018:
019:            BSHEnhancedForStatement(int id) {
020:                super (id);
021:            }
022:
023:            public Object eval(CallStack callstack, Interpreter interpreter)
024:                    throws EvalError {
025:                Class elementType = null;
026:                SimpleNode expression, statement = null;
027:
028:                NameSpace enclosingNameSpace = callstack.top();
029:                SimpleNode firstNode = ((SimpleNode) jjtGetChild(0));
030:                int nodeCount = jjtGetNumChildren();
031:
032:                if (firstNode instanceof  BSHType) {
033:                    elementType = ((BSHType) firstNode).getType(callstack,
034:                            interpreter);
035:                    expression = ((SimpleNode) jjtGetChild(1));
036:                    if (nodeCount > 2)
037:                        statement = ((SimpleNode) jjtGetChild(2));
038:                } else {
039:                    expression = firstNode;
040:                    if (nodeCount > 1)
041:                        statement = ((SimpleNode) jjtGetChild(1));
042:                }
043:
044:                BlockNameSpace eachNameSpace = new BlockNameSpace(
045:                        enclosingNameSpace);
046:                callstack.swap(eachNameSpace);
047:
048:                final Object iteratee = expression.eval(callstack, interpreter);
049:
050:                if (iteratee == Primitive.NULL)
051:                    throw new EvalError(
052:                            "The collection, array, map, iterator, or "
053:                                    + "enumeration portion of a for statement cannot be null.",
054:                            this , callstack);
055:
056:                CollectionManager cm = CollectionManager.getCollectionManager();
057:                if (!cm.isBshIterable(iteratee))
058:                    throw new EvalError("Can't iterate over type: "
059:                            + iteratee.getClass(), this , callstack);
060:                BshIterator iterator = cm.getBshIterator(iteratee);
061:
062:                Object returnControl = Primitive.VOID;
063:                while (iterator.hasNext()) {
064:                    try {
065:                        if (elementType != null)
066:                            eachNameSpace
067:                                    .setTypedVariable(varName/*name*/,
068:                                            elementType/*type*/, iterator
069:                                                    .next()/*value*/,
070:                                            new Modifiers()/*none*/);
071:                        else
072:                            eachNameSpace.setVariable(varName, iterator.next(),
073:                                    false);
074:                    } catch (UtilEvalError e) {
075:                        throw e.toEvalError("for loop iterator variable:"
076:                                + varName, this , callstack);
077:                    }
078:
079:                    boolean breakout = false; // switch eats a multi-level break here?
080:                    if (statement != null) // not empty statement
081:                    {
082:                        Object ret = statement.eval(callstack, interpreter);
083:
084:                        if (ret instanceof  ReturnControl) {
085:                            switch (((ReturnControl) ret).kind) {
086:                            case RETURN:
087:                                returnControl = ret;
088:                                breakout = true;
089:                                break;
090:
091:                            case CONTINUE:
092:                                break;
093:
094:                            case BREAK:
095:                                breakout = true;
096:                                break;
097:                            }
098:                        }
099:                    }
100:
101:                    if (breakout)
102:                        break;
103:                }
104:
105:                callstack.swap(enclosingNameSpace);
106:                return returnControl;
107:            }
108:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.