Source Code Cross Referenced for ArrayAllocationExpression.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » compiler » ast » 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 Eclipse » jdt » org.eclipse.jdt.internal.compiler.ast 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.internal.compiler.ast;
011:
012:        import org.eclipse.jdt.internal.compiler.ASTVisitor;
013:        import org.eclipse.jdt.internal.compiler.impl.*;
014:        import org.eclipse.jdt.internal.compiler.codegen.*;
015:        import org.eclipse.jdt.internal.compiler.flow.*;
016:        import org.eclipse.jdt.internal.compiler.lookup.*;
017:
018:        public class ArrayAllocationExpression extends Expression {
019:
020:            public TypeReference type;
021:
022:            //dimensions.length gives the number of dimensions, but the
023:            // last ones may be nulled as in new int[4][5][][]
024:            public Expression[] dimensions;
025:            public ArrayInitializer initializer;
026:
027:            public FlowInfo analyseCode(BlockScope currentScope,
028:                    FlowContext flowContext, FlowInfo flowInfo) {
029:                for (int i = 0, max = this .dimensions.length; i < max; i++) {
030:                    Expression dim;
031:                    if ((dim = this .dimensions[i]) != null) {
032:                        flowInfo = dim.analyseCode(currentScope, flowContext,
033:                                flowInfo);
034:                    }
035:                }
036:                if (this .initializer != null) {
037:                    return this .initializer.analyseCode(currentScope,
038:                            flowContext, flowInfo);
039:                }
040:                return flowInfo;
041:            }
042:
043:            /**
044:             * Code generation for a array allocation expression
045:             */
046:            public void generateCode(BlockScope currentScope,
047:                    CodeStream codeStream, boolean valueRequired) {
048:
049:                int pc = codeStream.position;
050:
051:                if (this .initializer != null) {
052:                    this .initializer.generateCode(currentScope, codeStream,
053:                            valueRequired);
054:                    return;
055:                }
056:
057:                int explicitDimCount = 0;
058:                for (int i = 0, max = this .dimensions.length; i < max; i++) {
059:                    Expression dimExpression;
060:                    if ((dimExpression = this .dimensions[i]) == null)
061:                        break; // implicit dim, no further explict after this point
062:                    dimExpression.generateCode(currentScope, codeStream, true);
063:                    explicitDimCount++;
064:                }
065:
066:                // array allocation
067:                if (explicitDimCount == 1) {
068:                    // Mono-dimensional array
069:                    codeStream.newArray((ArrayBinding) this .resolvedType);
070:                } else {
071:                    // Multi-dimensional array
072:                    codeStream.multianewarray(this .resolvedType,
073:                            explicitDimCount);
074:                }
075:                if (valueRequired) {
076:                    codeStream
077:                            .generateImplicitConversion(this .implicitConversion);
078:                } else {
079:                    codeStream.pop();
080:                }
081:                codeStream.recordPositionsFrom(pc, this .sourceStart);
082:            }
083:
084:            public StringBuffer printExpression(int indent, StringBuffer output) {
085:                output.append("new "); //$NON-NLS-1$
086:                this .type.print(0, output);
087:                for (int i = 0; i < this .dimensions.length; i++) {
088:                    if (this .dimensions[i] == null)
089:                        output.append("[]"); //$NON-NLS-1$
090:                    else {
091:                        output.append('[');
092:                        this .dimensions[i].printExpression(0, output);
093:                        output.append(']');
094:                    }
095:                }
096:                if (this .initializer != null)
097:                    this .initializer.printExpression(0, output);
098:                return output;
099:            }
100:
101:            public TypeBinding resolveType(BlockScope scope) {
102:                // Build an array type reference using the current dimensions
103:                // The parser does not check for the fact that dimension may be null
104:                // only at the -end- like new int [4][][]. The parser allows new int[][4][]
105:                // so this must be checked here......(this comes from a reduction to LL1 grammar)
106:
107:                TypeBinding referenceType = this .type
108:                        .resolveType(scope, true /* check bounds*/);
109:
110:                // will check for null after dimensions are checked
111:                this .constant = Constant.NotAConstant;
112:                if (referenceType == TypeBinding.VOID) {
113:                    scope.problemReporter().cannotAllocateVoidArray(this );
114:                    referenceType = null;
115:                }
116:
117:                // check the validity of the dimension syntax (and test for all null dimensions)
118:                int explicitDimIndex = -1;
119:                loop: for (int i = this .dimensions.length; --i >= 0;) {
120:                    if (this .dimensions[i] != null) {
121:                        if (explicitDimIndex < 0)
122:                            explicitDimIndex = i;
123:                    } else if (explicitDimIndex > 0) {
124:                        // should not have an empty dimension before an non-empty one
125:                        scope.problemReporter()
126:                                .incorrectLocationForNonEmptyDimension(this ,
127:                                        explicitDimIndex);
128:                        break loop;
129:                    }
130:                }
131:
132:                // explicitDimIndex < 0 says if all dimensions are nulled
133:                // when an initializer is given, no dimension must be specified
134:                if (this .initializer == null) {
135:                    if (explicitDimIndex < 0) {
136:                        scope.problemReporter()
137:                                .mustDefineDimensionsOrInitializer(this );
138:                    }
139:                    // allow new List<?>[5] - only check for generic array when no initializer, since also checked inside initializer resolution
140:                    if (referenceType != null && !referenceType.isReifiable()) {
141:                        scope.problemReporter().illegalGenericArray(
142:                                referenceType, this );
143:                    }
144:                } else if (explicitDimIndex >= 0) {
145:                    scope.problemReporter()
146:                            .cannotDefineDimensionsAndInitializer(this );
147:                }
148:
149:                // dimensions resolution 
150:                for (int i = 0; i <= explicitDimIndex; i++) {
151:                    Expression dimExpression;
152:                    if ((dimExpression = this .dimensions[i]) != null) {
153:                        TypeBinding dimensionType = dimExpression
154:                                .resolveTypeExpecting(scope, TypeBinding.INT);
155:                        if (dimensionType != null) {
156:                            this .dimensions[i].computeConversion(scope,
157:                                    TypeBinding.INT, dimensionType);
158:                        }
159:                    }
160:                }
161:
162:                // building the array binding
163:                if (referenceType != null) {
164:                    if (this .dimensions.length > 255) {
165:                        scope.problemReporter().tooManyDimensions(this );
166:                    }
167:                    this .resolvedType = scope.createArrayType(referenceType,
168:                            this .dimensions.length);
169:
170:                    // check the initializer
171:                    if (this .initializer != null) {
172:                        if ((this .initializer.resolveTypeExpecting(scope,
173:                                this .resolvedType)) != null)
174:                            this .initializer.binding = (ArrayBinding) this .resolvedType;
175:                    }
176:                }
177:                return this .resolvedType;
178:            }
179:
180:            public void traverse(ASTVisitor visitor, BlockScope scope) {
181:                if (visitor.visit(this , scope)) {
182:                    int dimensionsLength = this .dimensions.length;
183:                    this .type.traverse(visitor, scope);
184:                    for (int i = 0; i < dimensionsLength; i++) {
185:                        if (this.dimensions[i] != null)
186:                            this.dimensions[i].traverse(visitor, scope);
187:                    }
188:                    if (this.initializer != null)
189:                        this.initializer.traverse(visitor, scope);
190:                }
191:                visitor.endVisit(this, scope);
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.