/** * Add a new statement block element validator to <code>this</code>. * * If not all children of the root tree node represented by <code>this * </code> are statement block elements the <i>invalid</i> children must be * filtered, otherwise resolving the statement block elements from the * children will fail. * <p> * Note that the validator (i.e. the filter) must be set before the * statement block elements get resolved. To ensure this it's best practice * to set the validator immediately after <code>this</code> has been * created. Alternatively the constructor * {@link #AST2StatementBlockElementContainerImpl(AST2JSOMTree, TreeNodeValidator, com.habelitz.jsobjectizer.jsom.JSOM.JSOMType, TokenRewriteStream)} * could be used, of course. * * @see #AST2StatementBlockElementContainerImpl(AST2JSOMTree, TreeNodeValidator, com.habelitz.jsobjectizer.jsom.JSOM.JSOMType, TokenRewriteStream) * * @param pTreeNodeValidator The validator that should be used the filter * the child nodes or <code>null</code> to * remove/deactivate a set validator. */ public void setChildTreeNodeValidator( TreeNodeValidator pTreeNodeValidator) { mTreeNodeValidator = pTreeNodeValidator; }
//private TreeNodeValidator mChildValidator = new TreeNodeValidator() { // /** // * Checks if the given tree node belongs to the statement list // * instead of representing a case label's expression. // * // * @param pTree The tree node that should be checked. // * // * @return <code>true</code> if the given tree node belongs to a // * default label or to the statement list of a case label. // * // * @throws ArgumentException if the passed tree isn't a // * child of <code> // * SwitchLabelImpl.this.getTreeNode()</code>. // */ // public bool isValidTreeNode(ITree pTree) // { // ITree labelRoot = AST2SwitchLabel.this.getTreeNode(); // if (pTree.Parent != labelRoot) { // // TODO Internationalize the message. // throw new ArgumentException( // "The passed tree (position " + // pTree.Line + ':' + // pTree.CharPositionInLine + ") isn't a child " + // "of the switch label root node (position " + // labelRoot.Line + ':' + // labelRoot.CharPositionInLine + ")."); // } // // The tree node isn't valid if it's the first child of a case // // label root node. // if ( !AST2SwitchLabel.this.isDefaultClause() // && labelRoot.GetChild(0) == pTree) { // return false; // } // return true; // } //}; /** * Constructor. * * @param pTree The tree node representing a <code>case</code> or * <code>default<code> switch label. * @param pTokenRewriteStream The token stream the token of the stated * tree node belongs to. */ public AST2SwitchLabel(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream) : base(pTree, JSOMType.STATEMENT_BLOCK_ELEMENT_HELPER, pTokenRewriteStream) { mChildValidator = new SwitchLabelTreeNodeValidator(this); setChildTreeNodeValidator(mChildValidator); if (pTree.Type == JavaTreeParser.CASE) { mIsDefaultClause = false; } else if (pTree.Type != JavaTreeParser.DEFAULT) { throw new ArgumentException( CommonErrorMessages.getInvalidArgumentValueMessage( "pTree.Type == " + pTree.Type, "pTree")); } }
/** * Constructor. * <p> * A new object assumes that all children of the stated tree node represent * statement block elements. This constructor calls the method * {@link #setChildTreeNodeValidator(TreeNodeValidator)} automatically with * the passed validator as parameter. * * @param pTree The root node of the statement block elements. * @param pTreeNodeValidator The validator the method * {@link #setChildTreeNodeValidator(TreeNodeValidator)} * should be called with. * @param pJSOMType If a class : this class the JSOM type of the * extending class should be passed for this argument * which will be passed forward to the implementation of * the type <code>JSOM</code>. Otherwise this argument * should be <code>null</code> - in this case the constant * <code>JSOM.JSOMType.XTRA</code> will be passed to the * <code>JSOM</code> super type. * @param pTokenRewriteStream The token stream the token of the stated * tree node belongs to. */ public AST2StatementBlockElementContainerImpl( AST2JSOMTree pTree, TreeNodeValidator pTreeNodeValidator, JSOMType pJSOMType, TokenRewriteStream pTokenRewriteStream) : this(pTree, pJSOMType, pTokenRewriteStream) { setChildTreeNodeValidator(pTreeNodeValidator); }