<s> package org . eclipse . jdt . internal . compiler . ast ; import org . eclipse . jdt . internal . compiler . ASTVisitor ; import org . eclipse . jdt . internal . compiler . impl . * ; import org . eclipse . jdt . internal . compiler . codegen . * ; import org . eclipse . jdt . internal . compiler . flow . * ; import org . eclipse . jdt . internal . compiler . lookup . * ; public class ArrayAllocationExpression extends Expression { public TypeReference type ; public Expression [ ] dimensions ; public ArrayInitializer initializer ; public FlowInfo analyseCode ( BlockScope currentScope , FlowContext flowContext , FlowInfo flowInfo ) { for ( int i = 0 , max = this . dimensions . length ; i < max ; i ++ ) { Expression dim ; if ( ( dim = this . dimensions [ i ] ) != null ) { flowInfo = dim . analyseCode ( currentScope , flowContext , flowInfo ) ; if ( ( dim . implicitConversion & TypeIds . UNBOXING ) != 0 ) { dim . checkNPE ( currentScope , flowContext , flowInfo ) ; } } } if ( this . initializer != null ) { return this . initializer . analyseCode ( currentScope , flowContext , flowInfo ) ; } return flowInfo ; } public void generateCode ( BlockScope currentScope , CodeStream codeStream , boolean valueRequired ) { int pc = codeStream . position ; if ( this . initializer != null ) { this . initializer . generateCode ( currentScope , codeStream , valueRequired ) ; return ; } int explicitDimCount = 0 ; for ( int i = 0 , max = this . dimensions . length ; i < max ; i ++ ) { Expression dimExpression ; if ( ( dimExpression = this . dimensions [ i ] ) == null ) break ; dimExpression . generateCode ( currentScope , codeStream , true ) ; explicitDimCount ++ ; } if ( explicitDimCount == 1 ) { codeStream . newArray ( ( ArrayBinding ) this . resolvedType ) ; } else { codeStream . multianewarray ( this . resolvedType , explicitDimCount ) ; } if ( valueRequired ) { codeStream . generateImplicitConversion ( this . implicitConversion ) ; } else { codeStream . pop ( ) ; } codeStream . recordPositionsFrom ( pc , this . sourceStart ) ; } public StringBuffer printExpression ( int indent , StringBuffer output ) { output . append ( "new " ) ; this . type . print ( 0 , output ) ; for ( int i = 0 ; i < this . dimensions . length ; i ++ ) { if ( this . dimensions [ i ] == null ) output . append ( "[]" ) ; else { output . append ( '[' ) ; this . dimensions [ i ] . printExpression ( 0 , output ) ; output . append ( ']' ) ; } } if ( this . initializer != null ) this . initializer . printExpression ( 0 , output ) ; return output ; } public TypeBinding resolveType ( BlockScope scope ) { TypeBinding referenceType = this . type . resolveType ( scope , true ) ; this . constant = Constant . NotAConstant ; if ( referenceType == TypeBinding . VOID ) { scope . problemReporter ( ) . cannotAllocateVoidArray ( this ) ; referenceType = null ; } int explicitDimIndex = - 1 ; loop : for ( int i = this . dimensions . length ; -- i >= 0 ; ) { if ( this . dimensions [ i ] != null ) { if ( explicitDimIndex < 0 ) explicitDimIndex = i ; } else if ( explicitDimIndex > 0 ) { scope . problemReporter ( ) . incorrectLocationForNonEmptyDimension ( this , explicitDimIndex ) ; break loop ; } } if ( this . initializer == null ) { if ( explicitDimIndex < 0 ) { scope . problemReporter ( ) . mustDefineDimensionsOrInitializer ( this ) ; } if ( referenceType != null && ! referenceType . isReifiable ( ) ) { scope . problemReporter ( ) . illegalGenericArray ( referenceType , this ) ; } } else if ( explicitDimIndex >= 0 ) { scope . problemReporter ( ) . cannotDefineDimensionsAndInitializer ( this ) ; } for ( int i = 0 ; i <= explicitDimIndex ; i ++ ) { Expression dimExpression ; if ( ( dimExpression = this . dimensions [ i ] ) != null ) { TypeBinding dimensionType = dimExpression . resolveTypeExpecting ( scope , TypeBinding . INT ) ; if ( dimensionType != null ) { this . dimensions [ i ] . computeConversion ( scope , TypeBinding . INT , dimensionType ) ; } } } if ( referenceType != null ) { if ( this . dimensions . length > 255 ) { scope . problemReporter ( ) . tooManyDimensions ( this ) ; } this . resolvedType = scope . createArrayType ( referenceType , this . dimensions . length ) ; if ( this . initializer != null ) { if ( ( this . initializer . resolveTypeExpecting ( scope , this . resolvedType ) ) != null ) this . initializer . binding = ( ArrayBinding ) this . resolvedType ; } if ( ( referenceType . tagBits & TagBits . HasMissingType ) != 0 ) { return null ; } } return this . resolvedType ; } public void traverse ( ASTVisitor visitor , BlockScope scope ) { if ( visitor . visit ( this , scope ) ) { int dimensionsLength = this . dimensions . length ; this . type . traverse ( visitor , scope ) ; for ( int i = 0 ; i < dimensionsLength ; i ++ ) { if ( this . dimensions [ i ] != null ) this . dimensions [ i ] . traverse ( visitor , scope ) ; } if ( this . initializer != null ) this . initializer . traverse ( visitor , scope ) ; } visitor . endVisit ( this , scope ) ; } } </s>