/** * @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."); } }
/** * @see com.habelitz.jsobjectizer.jsom.api.statement.base.StatementBlockElementContainer#removeStatementBlockElement(com.habelitz.jsobjectizer.jsom.api.statement.StatementBlockElement, bool) * * __TEST__ */ public void removeStatementBlockElement( StatementBlockElement pStatementBlockElement, bool pRemovingOfSurroundingHiddenTokensEnabled) { bool elementRemoved = false; if (mHasSwitchLabels) { if (mLabels == null) { resolveSwitchLabels(); } foreach (SwitchLabel label in mLabels) { if (label.hasStatementBlockElement(pStatementBlockElement)) { label.removeStatementBlockElement( pStatementBlockElement, pRemovingOfSurroundingHiddenTokensEnabled); elementRemoved = true; break; } } } if (!elementRemoved) { // The stated statement block element doesn't belong to 'this'. throw new JSourceObjectizerException( CommonJSOMMessages .getStatementBlockElementDoesNotExistMessage( pStatementBlockElement.getJSOMType().ToString() + " (" + pStatementBlockElement.getLineNumber() + ':' + pStatementBlockElement.getCharPositionInLine() + ")", getLineNumber() + ":" + getCharPositionInLine())); } }
/** * @see com.habelitz.jsobjectizer.jsom.api.statement.base.StatementBlockElementContainer#removeStatementBlockElement(com.habelitz.jsobjectizer.jsom.api.statement.StatementBlockElement, bool) * * __TEST__ */ public void removeStatementBlockElement( StatementBlockElement pStatementBlockElement, bool pRemovingOfSurroundingHiddenTokensEnabled) { AST2StatementBlockElement removedElement = null; // If the elements haven't been resolve the passed statement block // element can't belong to this. if (mElements != null) { int offset = mElements.IndexOf((AST2StatementBlockElement)pStatementBlockElement); if (offset != -1) { removedElement = mElements[offset]; mElements.RemoveAt(offset); } } if (removedElement == null) { // The stated statement block element doesn't belong to 'this'. throw new JSourceObjectizerException( CommonJSOMMessages.getStatementBlockElementDoesNotExistMessage( pStatementBlockElement.getJSOMType().ToString() + " (" + pStatementBlockElement.getLineNumber() + ':' + pStatementBlockElement.getCharPositionInLine() + ")", getLineNumber() + ":" + getCharPositionInLine())); } // If still here a matching statement block element has been found. if (pRemovingOfSurroundingHiddenTokensEnabled) { removeTreeNode( removedElement, ChangeTokenBorder.FARTHEST_NEWLINE_EXCLUDING, ChangeTokenBorder.NEXT_NEWLINE_INCLUDING); } else { removeTreeNode(removedElement); } }