private Map < String , Object > bindBlocks ( PrepareSignatureContext sig , PrepareInvocationContext inv ) { if ( inv == null ) { return Collections . emptyMap ( ) ; } BlockDeclContext allDecl = null ; BlockDeclContext unnamedDecl = null ; List < NamedOutputBlockContext > namedBlocks = new ArrayList <> ( inv . namedBlocks ) ; Map < String , Object > blocks = new HashMap <> ( ) ; for ( BlockDeclContext blockDecl : sig . blockDecls ) { if ( blockDecl . flag != null ) { if ( blockDecl . flag . getText ( ) . equals ( "*" ) ) { if ( allDecl != null ) { throw new ExecutionException ( "only a single parameter can be marked with '*'" , getLocation ( blockDecl ) ) ; } allDecl = blockDecl ; } else if ( blockDecl . flag . getText ( ) . equals ( "+" ) ) { if ( unnamedDecl != null ) { throw new ExecutionException ( "only a single parameter can be marked with '+'" , getLocation ( blockDecl ) ) ; } unnamedDecl = blockDecl ; } else { throw new ExecutionException ( "unknown block declaration flag" , getLocation ( blockDecl ) ) ; } continue ; } //Find the block ParserRuleContext paramBlock = findAndRemoveBlock ( namedBlocks , name ( blockDecl ) ) ; //Bind the block BoundParamOutputBlock boundBlock = bindBlock ( paramBlock ) ; blocks . put ( name ( blockDecl ) , boundBlock ) ; } // // Bind unnamed block (if requested) // if ( unnamedDecl != null ) { UnnamedOutputBlockContext unnamedBlock = inv . unnamedBlock ; BoundParamOutputBlock boundUnnamedBlock = bindBlock ( unnamedBlock ) ; blocks . put ( unnamedDecl . id . getText ( ) , boundUnnamedBlock ) ; } // // Bind rest of blocks (if requested) // if ( allDecl != null ) { Map < String , Block > otherBlocks = new HashMap <> ( ) ; // Add unnamed block if it wasn't bound explicitly if ( inv . unnamedBlock != null && unnamedDecl == null ) { UnnamedOutputBlockContext unnamedBlock = inv . unnamedBlock ; BoundParamOutputBlock boundUnnamedBlock = new BoundParamOutputBlock ( unnamedBlock , mode ( unnamedBlock ) , currentScope ) ; otherBlocks . put ( "" , boundUnnamedBlock ) ; } // Add all other unbound blocks for ( NamedOutputBlockContext namedBlock : namedBlocks ) { String blockName = nullToEmpty ( name ( namedBlock ) ) ; BoundParamOutputBlock boundNamedBlock = new BoundParamOutputBlock ( namedBlock , mode ( namedBlock ) , currentScope ) ; otherBlocks . put ( blockName , boundNamedBlock ) ; } blocks . put ( allDecl . id . getText ( ) , otherBlocks ) ; } return blocks ; }
Bind block values to names based on prepare signature