Source Code Cross Referenced for LocalVariableLookAhead.java in  » UML » jrefactory » org » acm » seguin » pretty » 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 » UML » jrefactory » org.acm.seguin.pretty 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Author:  Chris Seguin
003:         *
004:         *  This software has been developed under the copyleft
005:         *  rules of the GNU General Public License.  Please
006:         *  consult the GNU General Public License for more
007:         *  details about use and distribution of this software.
008:         */
009:        package org.acm.seguin.pretty;
010:
011:        import net.sourceforge.jrefactory.ast.ASTBlockStatement;
012:        import net.sourceforge.jrefactory.ast.ASTLocalVariableDeclaration;
013:        import net.sourceforge.jrefactory.ast.ASTName;
014:        import net.sourceforge.jrefactory.ast.ASTPrimitiveType;
015:        import net.sourceforge.jrefactory.ast.ASTReferenceType;
016:        import net.sourceforge.jrefactory.ast.ASTClassOrInterfaceType;
017:        import net.sourceforge.jrefactory.ast.ASTTypeArguments;
018:        import net.sourceforge.jrefactory.ast.ASTType;
019:        import net.sourceforge.jrefactory.ast.ASTVariableDeclaratorId;
020:        import net.sourceforge.jrefactory.ast.ASTAnnotation;
021:        import net.sourceforge.jrefactory.ast.SimpleNode;
022:
023:        /**
024:         *  Helps determine the size of a local variable for spacing purposes
025:         *
026:         *@author    Chris Seguin
027:         *@author    Mike Atkinson
028:         */
029:        class LocalVariableLookAhead {
030:            private FieldSize size;
031:
032:            /**
033:             *  Constructor for the LocalVariableLookAhead object
034:             */
035:            public LocalVariableLookAhead() {
036:                size = new FieldSize();
037:            }
038:
039:            /**
040:             *  Main processing method for the LocalVariableLookAhead object
041:             *
042:             *@param  body  Description of Parameter
043:             *@return       Description of the Returned Value
044:             */
045:            public FieldSize run(SimpleNode body) {
046:                int last = body.jjtGetNumChildren();
047:                for (int ndx = 0; ndx < last; ndx++) {
048:                    SimpleNode child = (SimpleNode) body.jjtGetChild(ndx);
049:                    if ((child instanceof  ASTBlockStatement)
050:                            && (child.jjtGetFirstChild() instanceof  ASTLocalVariableDeclaration)) {
051:                        ASTLocalVariableDeclaration localVariable = (ASTLocalVariableDeclaration) child
052:                                .jjtGetFirstChild();
053:                        int equalsLength = computeEqualsLength(localVariable);
054:                        size.setMinimumEquals(equalsLength);
055:                    }
056:                }
057:
058:                return size;
059:            }
060:
061:            /**
062:             *  Compute the length of the equals
063:             *
064:             *@param  localVariable  the local variable
065:             *@return                the length
066:             */
067:            public int computeEqualsLength(
068:                    ASTLocalVariableDeclaration localVariable) {
069:                int modifierLength = computeModifierLength(localVariable);
070:                int typeLength = computeTypeLength(localVariable);
071:                int nameLength = computeNameLength(localVariable);
072:                int equalsLength = modifierLength + typeLength + nameLength;
073:                return equalsLength;
074:            }
075:
076:            /**
077:             *  Compute the length of the type
078:             *
079:             *@param  localVariable  the local variable
080:             *@return                the type length
081:             */
082:            public int computeTypeLength(
083:                    ASTLocalVariableDeclaration localVariable) {
084:                int childNo = localVariable.skipAnnotations();
085:                ASTType typeNode = (ASTType) localVariable.jjtGetChild(childNo);
086:                int typeLength = 0; //2 * typeNode.getArrayCount();
087:                if (typeNode.jjtGetFirstChild() instanceof  ASTPrimitiveType) {
088:                    ASTPrimitiveType primitive = (ASTPrimitiveType) typeNode
089:                            .jjtGetFirstChild();
090:                    typeLength += primitive.getName().length();
091:                } else if (typeNode.jjtGetFirstChild() instanceof  ASTReferenceType) {
092:                    typeLength += computeReferenceTypeLength((ASTReferenceType) typeNode
093:                            .jjtGetFirstChild());
094:                } else {
095:                    ASTName name = (ASTName) typeNode.jjtGetFirstChild();
096:                    typeLength += name.getName().length();
097:                }
098:                size.setTypeLength(typeLength);
099:                return typeLength;
100:            }
101:
102:            /**
103:             *  Compute the length of the type
104:             *
105:             *@param  reference  the reference type
106:             *@return            the type length
107:             *@since             JRefactory 2.7.00
108:             */
109:            public int computeReferenceTypeLength(ASTReferenceType reference) {
110:                int typeLength = 0;
111:                if (reference.jjtGetFirstChild() instanceof  ASTPrimitiveType) {
112:                    ASTPrimitiveType primitive = (ASTPrimitiveType) reference
113:                            .jjtGetFirstChild();
114:                    typeLength += primitive.getName().length();
115:                } else if (reference.jjtGetFirstChild() instanceof  ASTClassOrInterfaceType) {
116:                    ASTClassOrInterfaceType name = (ASTClassOrInterfaceType) reference
117:                            .jjtGetFirstChild();
118:                    typeLength += name.getName().length();
119:                } else {
120:                    // FIXME: sometimes the child is a CompilationUnit which should not be a child of a ASTReferenceType
121:                    //System.out.println("LocalVariableLookAhead.computeReferenceTypeLength: Error: reference.jjtGetFirstChild()="+reference.jjtGetFirstChild());
122:                }
123:                typeLength += reference.getArrayCount() * 2;
124:                return typeLength;
125:            }
126:
127:            /**
128:             *  Compute the length of the modifier
129:             *
130:             *@param  localVariable  the local variable
131:             *@return                the length of the modifier
132:             */
133:            private int computeModifierLength(
134:                    ASTLocalVariableDeclaration localVariable) {
135:                int modifierLength = localVariable.isUsingFinal() ? 6 : 0;
136:                size.setModifierLength(modifierLength);
137:                return modifierLength;
138:            }
139:
140:            /**
141:             *  Compute the length of the name
142:             *
143:             *@param  localVariable  the local variable
144:             *@return                the length
145:             */
146:            private int computeNameLength(
147:                    ASTLocalVariableDeclaration localVariable) {
148:                int childNo = localVariable.skipAnnotations();
149:                ASTVariableDeclaratorId id = (ASTVariableDeclaratorId) localVariable
150:                        .jjtGetChild(childNo + 1).jjtGetFirstChild();
151:                int nameLength = id.getName().length();
152:                size.setNameLength(nameLength);
153:                return nameLength;
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.