/** * @see com.habelitz.jsobjectizer.jsom.api.statement.base.StatementBlockElementContainer#replaceStatementBlockElement(com.habelitz.jsobjectizer.jsom.api.statement.StatementBlockElement, java.lang.String) * * __TEST__ */ public void replaceStatementBlockElement( StatementBlockElement pOldElement, String pNewElement) { bool elementReplaced = false; if (mHasSwitchLabels) { if (mLabels == null) { resolveSwitchLabels(); } foreach (SwitchLabel label in mLabels) { if (label.hasStatementBlockElement(pOldElement)) { label.replaceStatementBlockElement( pOldElement, pNewElement); elementReplaced = true; break; } } } if (!elementReplaced) { // The stated statement block element doesn't belong to 'this'. // TODO After implementation of adding JSOMs to JSOMs: // Replace message by an internationalized message. throw new JSourceObjectizerException( "The old statement block element '" + pOldElement.getMarshaller().ToString() + "' passed as argument doesn't belong to the statement " + "block scope."); } }
/** * @see com.habelitz.jsobjectizer.jsom.api.statement.base.StatementBlockElementContainer#replaceStatementBlockElement(com.habelitz.jsobjectizer.jsom.api.statement.StatementBlockElement, java.lang.String) * * __TEST__ */ public void replaceStatementBlockElement( StatementBlockElement pOldElement, String pNewElement) { List<String> errorMessages = new List<String>(); AST2StatementBlockElement newElement = null; try { newElement = getUnmarshaller().unmarshalAST2StatementBlockElement( pNewElement, errorMessages); } catch (JSourceUnmarshallerException jsue) { // TODO After implementation of adding JSOMs to JSOMs: // Replace message by an internationalized message. throw new JSourceObjectizerException( "Parsing the statement block element '" + pNewElement + "' failed.", jsue); } if (pNewElement != null) { if (mElements == null) { resolveStatementBlockElements(); } int offset = mElements.IndexOf((AST2StatementBlockElement)pOldElement); if (offset >= 0) { AST2StatementBlockElement oldParamDecl = mElements[offset]; mElements[offset] = newElement; // Note that the offset of the statement block element within // the list of 'StatementBlockElement' object may not match the // offset of the root tree's child list. ITree root = getTreeNode(); ITree oldChild = oldParamDecl.getTreeNode(); int childCount = root.ChildCount; bool childFound = false; for (offset = 0; offset < childCount; offset++) { if (oldChild == root.GetChild(offset)) { root.SetChild(offset, newElement.getTreeNode()); getTokenRewriteStream().Replace( oldChild.TokenStartIndex, oldChild.TokenStopIndex, pNewElement); childFound = true; break; } } if (!childFound) { // TODO Internationalize the message. throw new JSourceObjectizerInternalException( "No tree node found for the statement block " + "element '" + pOldElement.getMarshaller().ToString() + "' at " + pOldElement.getLineNumber() + ':' + pOldElement.getCharPositionInLine() + '.'); } } else { // TODO After implementation of adding JSOMs to JSOMs: // Replace message by an internationalized message. throw new JSourceObjectizerException( "The old statement block element '" + pOldElement.getMarshaller().ToString() + "' passed as argument doesn't belong to the " + "statement block scope."); } } else { // TODO After implementation of adding JSOMs to JSOMs: // Replace message by an internationalized message. throw new JSourceObjectizerException( "Unmarshalling the new statement block element '" + pNewElement + "' failed."); } }