Esempio n. 1
0
 /**
  * Copy constructor.
  *
  * @param pTree  The object that should be cloned.
  *
  * __TEST__
  */
 public AST2JSOMTree(AST2JSOMTree pTree)
     : base(pTree)
 {
     //base(pTree);
 }
        /**
         * Removes the formal parameter list.
         * <p>
         * If <code>this</code> has no formal parameters an implementation of this
         * method is expected to do nothing than return <code>null</code>.
         *
         * @return  The removed formal parameter list or <code>null</code> if <code>
         *          this hasn't formal parameters.
         */
        public FormalParameterList removeFormalParameters()
        {
            FormalParameterList paramList = getFormalParameters();
            if (paramList == null) {
            return null;
            }
            mParameters = null;
            AST2JSOMTree rootTree = (AST2JSOMTree)getTreeNode();
            int childCount = rootTree.ChildCount;
            for (int offset = 0; offset < childCount; offset++) {
            if (rootTree.GetChild(offset) == mParamsTree) {
                rootTree.DeleteChild(offset);
                break;
            }
            }
            // Update the token stream.
            // For that remove all tokens between the opening and closing brackets
            // but excluding the brackets, of course.
            TokenRewriteStream stream = getTokenRewriteStream();
            stream.Delete(mParamsTree.TokenStartIndex + 1,
                      mParamsTree.TokenStopIndex - 1);
            mParamsTree = null;

            return paramList;
        }
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing any method or constructor
  *               declaration. Note that it's up to derived classes to check
  *               that the given tree node is of a valid type.
  * @param pJSOMType  One of the <code>JSOMType.???</code> constants defined
  *                   by the interface <code>JSOM</code>.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 protected AST2CommonMethodOrConstructorDeclaration(AST2JSOMTree pTree, JSOMType pJSOMType, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, pJSOMType, pTokenRewriteStream)
 {
     // All types of method or constructor declarations start with a modifier
     // list (that may be empty).
     mModifierListTree = (AST2JSOMTree)pTree.GetChild(0);
     // Then there may follow a generic type parameter list.
     int childOffset = 1;
     AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(childOffset);
     if (child.Type == JavaTreeParser.GENERIC_TYPE_PARAM_LIST) {
     mGenericTypeParamTree = child;
     childOffset++;
     child = (AST2JSOMTree)pTree.GetChild(childOffset);
     }
     // Get the formal parameter list.
     while (child.Type != JavaTreeParser.FORMAL_PARAM_LIST) {
     childOffset++;
     child = (AST2JSOMTree)pTree.GetChild(childOffset);
     }
     if (child.ChildCount > 0) {
     mParamsTree = child;
     }
     // Finally check if there is a 'throws' clause
     childOffset++;
     int numberOfChildren = pTree.ChildCount;
     while (childOffset < numberOfChildren) {
     child = (AST2JSOMTree)pTree.GetChild(childOffset);
     if (child.Type == JavaTreeParser.THROWS_CLAUSE) {
         mThrowsClauseTree = child;
         break;
     }
     childOffset++;
     }
 }
 public void addAnnotation(Char[] pAnnotationIdentifier)
 {
     StringBuilder sbModifierList =
                 new StringBuilder('@').Append(pAnnotationIdentifier);
     ModifierList oldModifierList = getModifiers();
     if (oldModifierList != null) {
     sbModifierList.Append(' ')
                   .Append(oldModifierList.getMarshaller().ToString());
     }
     List<String> errorMessages = new List<String>();
     try {
     AST2ModifierList modifierList =
         getUnmarshaller().unmarshalAST2ModifierList(
                 sbModifierList.ToString(), errorMessages);
     if (modifierList != null) {
         // TODO  After implementation of adding JSOMs to JSOMs:
         //       Check if error messages have been emitted by the parser.
         mModifierListTree = (AST2JSOMTree)modifierList.getTreeNode();
         mModifierList = modifierList;
         getTreeNode().SetChild(0, mModifierListTree);
     }
     } catch (JSourceUnmarshallerException e) {
     // TODO  After implementation of adding JSOMs to JSOMs:
     //       Replace message by an internationalized message.
     throw new JSourceObjectizerException(
             "Parsing the annotation '" + pAnnotationIdentifier +
             "' failed.");
     }
     // Update the token stream.
     // TODO  After implementation of adding JSOMs to JSOMs:
     //       Move this stuff to 'AST2JSOM'.
     TokenRewriteStream stream = getTokenRewriteStream();
     int rightOffset = getTreeNode().TokenStartIndex;
     int leftOffset = rightOffset - 1;
     List<IToken> indentationTokens = new List<IToken>();
     while (   leftOffset > 0
        && !Constants.NL.Equals(stream.Get(leftOffset).Text)) {
     indentationTokens.Add(stream.Get(leftOffset));
     leftOffset--;
     }
     sbModifierList.Remove(0, sbModifierList.Length);
     for (int offset = indentationTokens.Count - 1; offset >= 0; offset--) {
     stream.InsertBefore(rightOffset, indentationTokens[offset].Text);
     }
     sbModifierList.Append('@').Append(pAnnotationIdentifier)
               .Append(Constants.NL);
     stream.InsertBefore(rightOffset, sbModifierList.ToString());
 }
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing an interface or class type top
  *               level scope. Note that it's up to derived classes to check
  *               that the given tree node is of a valid type.
  * @param pJSOMType  One of the <code>JSOMType.???</code> constants defined
  *                   by the interface <code>JSOM</code>.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 protected AST2AbstractTypeTopLevelScope(
     AST2JSOMTree pTree, JSOMType pJSOMType, 
     TokenRewriteStream pTokenRewriteStream)
     : base(pTree, pJSOMType, pTokenRewriteStream)
 {
     //base(pTree, pJSOMType, pTokenRewriteStream);
 }