Esempio n. 1
0
 /**
  * @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()));
     }
 }
Esempio n. 2
0
 /**
  * @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.");
     }
 }
Esempio n. 3
0
        /**
         * @see com.habelitz.jsobjectizer.jsom.api.statement.base.StatementBlockElementContainer#hasStatementBlockElement(com.habelitz.jsobjectizer.jsom.api.statement.StatementBlockElement)
         */
        public bool hasStatementBlockElement(
            StatementBlockElement pStatementBlockElement)
        {
            if (!mHasSwitchLabels) {
            return false; // No switch labels available.
            }
            if (mLabels == null) {
            resolveSwitchLabels();
            }
            foreach (SwitchLabel label in mLabels) {
            if (label.hasStatementBlockElement(pStatementBlockElement)) {
                return true;
            }
            }

            return false;
        }
Esempio n. 4
0
 /**
  * @see com.habelitz.jsobjectizer.jsom.api.statement.base.StatementBlockElementContainer#removeStatementBlockElement(com.habelitz.jsobjectizer.jsom.api.statement.StatementBlockElement)
  *
  * __TEST__
  */
 public void removeStatementBlockElement(
     StatementBlockElement pStatementBlockElement)
 {
     removeStatementBlockElement(pStatementBlockElement, false);
 }
        /**
         * @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);
            }
        }
 /**
  * @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#hasStatementBlockElement(com.habelitz.jsobjectizer.jsom.api.statement.StatementBlockElement)
         */
        public bool hasStatementBlockElement(
            StatementBlockElement pStatementBlockElement)
        {
            if (mElements == null) {
            resolveStatementBlockElements();
            }
            foreach (StatementBlockElement element in mElements) {
            if (element == pStatementBlockElement) {
                return true;
            }
            }

            return false;
        }
 /**
  * @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)
 {
     mElementContainer.replaceStatementBlockElement(
         pOldElement, pNewElement);
 }
 /**
  * @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)
 {
     mElementContainer.removeStatementBlockElement(
         pStatementBlockElement,
         pRemovingOfSurroundingHiddenTokensEnabled);
 }
 /**
  * @see com.habelitz.jsobjectizer.jsom.api.statement.base.StatementBlockElementContainer#removeStatementBlockElement(com.habelitz.jsobjectizer.jsom.api.statement.StatementBlockElement)
  *
  * __TEST__
  */
 public void removeStatementBlockElement(
     StatementBlockElement pStatementBlockElement)
 {
     mElementContainer.removeStatementBlockElement(
         pStatementBlockElement, false);
 }
 /**
  * @see com.habelitz.jsobjectizer.jsom.api.statement.base.StatementBlockElementContainer#hasStatementBlockElement(com.habelitz.jsobjectizer.jsom.api.statement.StatementBlockElement)
  */
 public bool hasStatementBlockElement(
     StatementBlockElement pStatementBlockElement)
 {
     return mElementContainer.hasStatementBlockElement(
         pStatementBlockElement);
 }