コード例 #1
0
  /*
   * Generates the initializers (AST) for all values that are shared between states (e.g. all instance factories
   * shared by AddItems overrides).
   */
  private StatementListNode genSharedFactoriesAST(
      StatesModel model, NodeFactory nodeFactory, StatementListNode statementList) {
    Map<String, SharedObject> shared = model.sharedObjects;

    StatementListNode result = statementList;

    for (Iterator<String> iter = shared.keySet().iterator(); iter.hasNext(); ) {
      SharedObject symbol = shared.get(iter.next());

      String varName = ((String) symbol.name + _FACTORY).intern();
      String typeName = NameFormatter.retrieveClassName(DEFERREDINSTANCEFROMFUNCTION);
      String factory = symbol.name + (symbol.model.isDeclared() ? _I : _C);
      String resetFunc = symbol.name + _R;

      MemberExpressionNode memberExpression =
          AbstractSyntaxTreeUtil.generateGetterSelector(nodeFactory, factory, true);

      ArgumentListNode callExpressionArgumentList =
          nodeFactory.argumentList(null, memberExpression);

      if (symbol.model.getIsTransient()) {
        memberExpression =
            AbstractSyntaxTreeUtil.generateGetterSelector(nodeFactory, resetFunc, true);
        callExpressionArgumentList =
            nodeFactory.argumentList(callExpressionArgumentList, memberExpression);
      }

      QualifiedIdentifierNode qualifiedIdentifier =
          AbstractSyntaxTreeUtil.generateQualifiedIdentifier(
              nodeFactory, standardDefs.getCorePackage(), typeName, false);

      CallExpressionNode callExpression =
          (CallExpressionNode)
              nodeFactory.callExpression(qualifiedIdentifier, callExpressionArgumentList);
      callExpression.is_new = true;
      callExpression.setRValue(false);

      MemberExpressionNode ad = nodeFactory.memberExpression(null, callExpression);

      VariableDefinitionNode variableDefinition =
          AbstractSyntaxTreeUtil.generateVariable(nodeFactory, varName, typeName, false, ad);
      result = nodeFactory.statementList(result, variableDefinition);
    }
    return result;
  }