Ejemplo n.º 1
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a <code>switch</code> statement.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2TryStatement(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ElementType.TRY_STATEMENT,pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.TRY)
     {
         throw new ArgumentException(
                 CommonErrorMessages.getInvalidArgumentValueMessage(
                         "pTree.Type == " + pTree.Type, "pTree"));
     }
     if (pTree.ChildCount > 1)
     {
         // The next child may be an 'catch' clause list or a 'finally'
         // clause.
         AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(1);
         if (child.Type == JavaTreeParser.CATCH_CLAUSE_LIST)
         {
             if (child.ChildCount > 0)
             {
                 mCatchClauseListTree = child;
             }
             if (pTree.ChildCount == 3)
             {
                 // Switch forward to the 'finally' clause.
                 child = (AST2JSOMTree)pTree.GetChild(2);
             }
             else
             {
                 child = null;
             }
         }
         if (child != null)
         {
             mFinallyBlockScopeTree = child;
         }
     }
 }
 /**
  * Constructor.
  *
  * @param pTree  The root tree representing a class constructor call.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2ClassConstructorCall(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ExpressionType.CLASS_CONSTRUCTOR_CALL,pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.CLASS_CONSTRUCTOR_CALL) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     // Get the optional generic type argument list. If there is no such list
     // it's the identifier.
     int offset = 0;
     AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(offset);
     if (child.Type == JavaTreeParser.GENERIC_TYPE_ARG_LIST) {
     // Remember the generic type argument list.
     mGenericTypeArgumentListTree = child;
     // Switch forward to the identifier.
     offset++;
     child = (AST2JSOMTree)pTree.GetChild(offset);
     }
     if (child.Type != JavaTreeParser.IDENT) {
     // 'mIdentifierTree' must get resolved just in time.
     mQualifiedTypeIdentTree = child;
     } else {
     // 'mQualifiedTypeIdentTree' remains 'null' for inner new
     // expressions.
     mIdentifierTree = child;
     }
     // If there are arguments get and remember them.
     offset++;
     mArgumentListTree = (AST2JSOMTree)pTree.GetChild(offset);
     if (mArgumentListTree.ChildCount == 0) {
     mArgumentListTree = null;
     }
     // Get and remember optional class scope declarations.
     offset++;
     if (offset == pTree.ChildCount - 1) {
     mClassScopeDeclTree = (AST2JSOMTree)pTree.GetChild(offset);
     }
 }
Ejemplo n.º 3
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a <code>forEach</code>
  *               statement.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2ForEachStatement(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ElementType.FOR_EACH_STATEMENT,pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.FOR_EACH) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     if (pTree.GetChild(0).ChildCount > 0) {
     mHasModifier = true;
     }
     mIdentifierTree = (AST2JSOMTree)pTree.GetChild(2);
 }
 /**
  * Constructor.
  * <p>
  * If classes derived from this class should be recognized by another JSOM
  * type than <code>JSOMType.VARIABLE_DECLARATION</code> they must call
  * this constructor via the explicit super constructor call.
  *
  * @param pTree  The tree node representing a variable declaration.
  * @param pJSOMType  The JSOM type of the new instance.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 protected AST2CommonVariableDeclaration(
     AST2JSOMTree pTree, JSOMType pJSOMType,
     TokenRewriteStream pTokenRewriteStream)
     : base(pTree, pJSOMType, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.VAR_DECLARATION) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     if (pTree.GetChild(0).ChildCount == 0) {
     mHasModifier = false;
     }
 }
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a method declaration.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2AnnotationMethodDeclaration(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, JSOMType.ANNOTATION_METHOD_DECLARATION, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.ANNOTATION_METHOD_DECL) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     mModifierListTree = (AST2JSOMTree)pTree.GetChild(0);
     mIdentifierTree = (AST2JSOMTree)pTree.GetChild(2);
     if (pTree.ChildCount == 4) {
     mHasDefaultValue = true;
     }
 }
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing an interface declaration.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2InterfaceDeclaration(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, JSOMType.INTERFACE_DECLARATION, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.INTERFACE) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     int childOffset = 2;
     AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(childOffset);
     if (child.Type == JavaTreeParser.GENERIC_TYPE_PARAM_LIST) {
     mGenericTypeParamTree = child;
     childOffset++;
     child = (AST2JSOMTree)pTree.GetChild(childOffset);
     }
     if (child.Type == JavaTreeParser.EXTENDS_CLAUSE) {
     mExtendsClauseTree = child;
     childOffset++;
     child = (AST2JSOMTree)pTree.GetChild(childOffset);
     }
     mScopeTree = child;
 }
Ejemplo n.º 7
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a <code>break</code> statement.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2BreakStatement(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ElementType.BREAK_STATEMENT, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.BREAK)
     {
         throw new ArgumentException(
                 CommonErrorMessages.getInvalidArgumentValueMessage(
                         "pTree.Type == " + pTree.Type, "pTree"));
     }
     if (pTree.ChildCount == 1)
     {
         mLabelNode = (AST2JSOMTree)pTree.GetChild(0);
     }
 }
Ejemplo n.º 8
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing an annotation.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2Annotation(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, JSOMType.ANNOTATION, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.AT) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     if (   pTree.ChildCount == 2
     && pTree.GetChild(1).ChildCount == 1) {
     mHasInitializers = true;
     }
 }
Ejemplo n.º 9
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing an enumeration declaration.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2EnumDeclaration(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, JSOMType.ENUM_DECLARATION, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.ENUM) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(2);
     if (child.Type == JavaTreeParser.IMPLEMENTS_CLAUSE) {
     mImplementsClauseTree = child;
     child = (AST2JSOMTree)pTree.GetChild(3);
     }
     mScopeTree = child;
 }
Ejemplo n.º 10
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a type.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2MethodCall(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ExpressionType.METHOD_CALL, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.METHOD_CALL) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     // Check if there is a generic type argument list.
     ITree child = pTree.GetChild(1);
     if (child.Type == JavaTreeParser.GENERIC_TYPE_ARG_LIST) {
     if (child.ChildCount > 0) {
         mHasGenericTypeArgumentList = true;
     }
     }
 }
Ejemplo n.º 11
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a variable initializer, i.e.
  *               an expression or an array initializer.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2StaticArrayCreator(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ExpressionType.STATIC_ARRAY_CREATOR,pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.STATIC_ARRAY_CREATOR) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     int childOffset = 0;
     AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(childOffset);
     if (AST2PrimitiveType.isPrimitiveType(child)) {
     mIsArrayOfPrimitiveType = true;
     mPrimitiveTypeTree = child;
     childOffset++;
     child = (AST2JSOMTree)pTree.GetChild(childOffset);
     } else {
     if (child.Type == JavaTreeParser.GENERIC_TYPE_ARG_LIST) {
         mGenericTypeArgsTree = child;
         childOffset++;
         child = (AST2JSOMTree)pTree.GetChild(childOffset);
     }
     mQualifiedTypeIdentTree = child;
     childOffset++;
     child = (AST2JSOMTree)pTree.GetChild(childOffset);
     }
     if (child.Type == JavaTreeParser.EXPR) {
     int numberOfExpressions = 1;
     int childOffsetBuffer = childOffset + 1;
     while (   childOffsetBuffer < pTree.ChildCount
            &&    pTree.GetChild(childOffsetBuffer).Type
               == JavaTreeParser.EXPR) {
         numberOfExpressions++;
         childOffsetBuffer++;
     }
     mArrayDimTrees = new List<AST2JSOMTree>(numberOfExpressions);
     mArrayDimTrees.Add(child); // Add the first expressions.
     for (int offset = 1; offset < numberOfExpressions; offset++) {
         // Add rest of expressions.
         childOffset++;
         mArrayDimTrees.Add((AST2JSOMTree)pTree.GetChild(childOffset));
     }
     // Check if there is still an array declarator list.
     childOffset++;
     if (childOffset == pTree.ChildCount - 1) {
         mNumberOfArrayDeclarators =
             pTree.GetChild(childOffset).ChildCount;
     }
     } else {
     mHasExplicitInitializer = true;
     // The array creator has an explicit initializer.
     mNumberOfArrayDeclarators =
         pTree.GetChild(childOffset).ChildCount;
     // Get the initializers
     child = (AST2JSOMTree)pTree.GetChild(childOffset + 1);
     int numberOfInitializers = child.ChildCount;
     if (numberOfInitializers > 0) {
         mArrayInitializersTree = child;
     }
     }
 }
Ejemplo n.º 12
0
        /**
         * Constructor.
         *
         * @param pTree  The tree node representing a type.
         * @param pJavaSourceIdentifier  The identifier of the Java source, for
         *                               example the Java file name (without the
         *                               <i>.java</code> suffix). If the origin of
         *                               the parsed Java source isn't a file then a
         *                               name must be stated if it would be a file.
         *                               That means that the name should match the
         *                               public type declaration within the Java
         *                               source. However, this will not be checked
         *                               by this class and it's up to the caller to
         *                               pass the correct file name or at least to
         *                               interpret what's <i>correct</i>.
         * @param pTokenRewriteStream  The token stream the token of the stated
         *                             tree node belongs to.
         */
        public AST2JavaSource(
            AST2JSOMTree pTree, String pJavaSourceIdentifier, 
            TokenRewriteStream pTokenRewriteStream, int pLineCount)
            : base(pTree, JSOMType.JAVA_SOURCE, pTokenRewriteStream)
        {
            if (pTree.Type != JavaTreeParser.JAVA_SOURCE) {
            throw new ArgumentException(
                    CommonErrorMessages.getInvalidArgumentValueMessage(
                            "pTree.Type == " + pTree.Type, "pTree"));
            }
            mLineCount = pLineCount;
            mJavaSourceIdentifier = pJavaSourceIdentifier;
            AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(0);
            if (child.ChildCount > 0) {
            mAnnotationsTree = child;
            }
            int numberOfChildren = pTree.ChildCount;
            if (numberOfChildren > 1) {
            int childOffset = 1;
            child = (AST2JSOMTree)pTree.GetChild(childOffset);
            if (child.Type == JavaTreeParser.PACKAGE) {
                mPackageDeclTree = child;
                childOffset++;
            }
            int importDeclCtr = 0;
            int typeDeclCtr = 0;
            int childOffsetBuffer = childOffset;
            while (   childOffset < numberOfChildren
                   &&    pTree.GetChild(childOffset).Type
                      == JavaTreeParser.IMPORT) {
                importDeclCtr++;
                childOffset++;
            }
            typeDeclCtr = numberOfChildren - childOffset;
            if (importDeclCtr > 0) {
                mImportDeclTrees = new List<AST2JSOMTree>(importDeclCtr);
                while (importDeclCtr > 0) {
                    mImportDeclTrees.Add((AST2JSOMTree)pTree.GetChild(childOffsetBuffer));
                    childOffsetBuffer++;
                    importDeclCtr--;
                }

            }
            if (typeDeclCtr > 0) {
                mTypeDeclTrees = new List<AST2JSOMTree>(typeDeclCtr);
                while (typeDeclCtr > 0) {
                    mTypeDeclTrees.Add((AST2JSOMTree)pTree.GetChild(childOffsetBuffer));
                    childOffsetBuffer++;
                    typeDeclCtr--;
                }
            }
            }
        }
Ejemplo n.º 13
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a type.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2Type(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, JSOMType.TYPE, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.TYPE) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     if (   pTree.GetChild(0).Type
     == JavaTreeParser.QUALIFIED_TYPE_IDENT) {
     mIsComplexType = true;
     }
 }
Ejemplo n.º 14
0
 /**
  * Constructor.
  * <p>
  * This constructor is used to create a <code>JSOM</code> object
  * representing a more or less detailed method declaration. An example would
  * be a method definition, i.e. a method signature followed by a statement
  * block scope.
  *
  * @param pTree  The tree node representing a method declaration.
  * @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 AST2MethodDeclaration(
     AST2JSOMTree pTree, JSOMType pJSOMType, 
     TokenRewriteStream pTokenRewriteStream)
     : base(pTree, pJSOMType, pTokenRewriteStream)
 {
     if (pTree.Type == JavaTreeParser.FUNCTION_METHOD_DECL) {
     // Get the type child.
     int offset = 1;
     AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(offset);
     if (child.Type == JavaTreeParser.GENERIC_TYPE_PARAM_LIST) {
         offset++;
         child = (AST2JSOMTree)pTree.GetChild(offset);
     }
     mReturnTypeTree = child;
     // Get the identifier.
     offset++;
     mIdentifierTree = (AST2JSOMTree)pTree.GetChild(offset);
     // Is there an array declarator list behind the formal parameter
     // list?
     offset += 2;
     if (offset < pTree.ChildCount) {
         child = (AST2JSOMTree)pTree.GetChild(offset);
         if (child.Type == JavaTreeParser.ARRAY_DECLARATOR_LIST) {
             mNumberOfArrayDeclarators = child.ChildCount;
         }
     }
     } else if (pTree.Type == JavaTreeParser.VOID_METHOD_DECL) {
     // For void method only the identifier must be fetched.
     AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(1);
     if (child.Type == JavaTreeParser.GENERIC_TYPE_PARAM_LIST) {
         child = (AST2JSOMTree)pTree.GetChild(2);
     }
     mIdentifierTree = child;
     } else {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
 }
Ejemplo n.º 15
0
        /**
         * Resolves a generic type parameter list.
         *
         * @param pTree  The generic type parameter list's root node.
         * @param pTokenRewriteStream  The token stream the token of the stated
         *                             tree node belongs to.
         *
         * @return  A list containing the generic type parameters.
         */
        public static List<AST2GenericTypeParameter> resolveGenericTypeParameterList(
            AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
        {
            if (pTree.Type != JavaTreeParser.GENERIC_TYPE_PARAM_LIST) {
            throw new ArgumentException(
                    CommonErrorMessages.getInvalidArgumentValueMessage(
                            "pTree.Type == " + pTree.Type, "pTree"));
            }
            int size = pTree.ChildCount;
            List<AST2GenericTypeParameter> result =
            new List<AST2GenericTypeParameter>(size);
            for (int offset = 0; offset < size; offset++) {
            result.Add(new AST2GenericTypeParameter((AST2JSOMTree)
                    pTree.GetChild(offset), pTokenRewriteStream));
            }

            return result;
        }
Ejemplo n.º 16
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing an array type declarator.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2ArrayTypeDeclarator(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ExpressionType.ARRAY_TYPE_DECLARATOR, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.ARRAY_DECLARATOR) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     mTypeTree = (AST2JSOMTree)pTree.GetChild(0);
     // Count all 1+ array declarators (the first array declarator is
     // represented by the root and mustn't counted).
     while (mTypeTree.Type == JavaTreeParser.ARRAY_DECLARATOR) {
     // Walk down the sub-trees until the type has been found, i.e. the
     // current child doesn't represent an array declarator.
     mNumberOfArrayDeclarators++;
     mTypeTree = (AST2JSOMTree)mTypeTree.GetChild(0);
     }
     if (!AST2PrimitiveType.isPrimitiveType(mTypeTree)) {
     mIsArrayOfPrimitiveType = false;
     }
 }
Ejemplo n.º 17
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a labeled statement.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2LabeledStatement(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ElementType.LABELED_STATEMENT, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.LABELED_STATEMENT)
     {
         throw new ArgumentException(
                 CommonErrorMessages.getInvalidArgumentValueMessage(
                         "pTree.Type == " + pTree.Type, "pTree"));
     }
     mIdentifierTree = (AST2JSOMTree)pTree.GetChild(0);
 }
        /**
         * Resolves a qualified type identifier.
         *
         * @param pTree  The qualified type identifier's root node.
         * @param pTokenRewriteStream  The token stream the token of the stated
         *                             tree node belongs to.
         *
         * @return  A list containing the identifiers from the qualified type
         *          identifier.
         */
        public static List<AST2ComplexTypeIdentifier> resolveQualifiedTypeIdentifier(
            AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
        {
            if (pTree.Type != JavaTreeParser.QUALIFIED_TYPE_IDENT) {
            throw new ArgumentException(
                    CommonErrorMessages.getInvalidArgumentValueMessage(
                            "pTree.Type == " + pTree.Type, "pTree"));
            }
            int size = pTree.ChildCount;
            List<AST2ComplexTypeIdentifier> result =
            new List<AST2ComplexTypeIdentifier>(size);
            for (int offset = 0; offset < size; offset++) {
            result.Add(new AST2ComplexTypeIdentifier((AST2JSOMTree)
                    pTree.GetChild(offset), pTokenRewriteStream));
            }

            return result;
        }
Ejemplo n.º 19
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a <code>for</code> statement.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2ForStatement(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ElementType.FOR_STATEMENT,pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.FOR) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     ITree child = pTree.GetChild(0);
     if (child.ChildCount == 0) {
     mForInitType = ForInitType.NONE;
     } else if (   child.GetChild(0).Type
            == JavaTreeParser.VAR_DECLARATION) {
     mForInitType = ForInitType.VAR_DECL;
     } else {
     mForInitType = ForInitType.EXPRESSION;
     }
     if (pTree.GetChild(1).ChildCount == 0) {
     mHasForCondition = false;
     }
     child = pTree.GetChild(2);
     if (pTree.GetChild(2).ChildCount == 0) {
     mHasForUpdater = false;
     }
 }
Ejemplo n.º 20
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a type.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2EnumConstant(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, JSOMType.ENUM_CONSTANT, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.IDENT) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(0);
     if (child.ChildCount > 0) {
     mHasAnnotations = true;
     }
     if (pTree.ChildCount > 1) {
     // The next child may be an argument list or a class scope.
     child = (AST2JSOMTree)pTree.GetChild(1);
     if (child.Type == JavaTreeParser.ARGUMENT_LIST) {
         if (child.ChildCount > 0) {
             mArgumentsTree = child;
         }
         if (pTree.ChildCount == 3) {
             // Switch forward to the class scope.
             child = (AST2JSOMTree)pTree.GetChild(2);
         } else {
             child = null;
         }
     }
     if (child != null) {
         mClassScopeTree = child;
     }
     }
 }
Ejemplo n.º 21
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a <code>switch</code> statement.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2SwitchStatement(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ElementType.SWITCH_STATEMENT, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.SWITCH) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     if (pTree.GetChild(1).ChildCount == 0) {
     mHasSwitchLabels = false;
     }
 }
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing any type declaration, i.e. a
  *               a class declaration, for example. 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 AST2CommonTypeDeclaration(
     AST2JSOMTree pTree, JSOMType pJSOMType,
     TokenRewriteStream pTokenRewriteStream)
     : base(pTree, pJSOMType, pTokenRewriteStream)
 {
     if (pTree.GetChild(0).ChildCount == 0) {
     mHasModifier = false;
     }
     mIdentifierTree = (AST2JSOMTree)getTreeNode().GetChild(1);
 }
Ejemplo n.º 23
0
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing an enumeration top level scope.
  * @param pOwner  The enumeration declaration the new object belongs to.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2EnumTopLevelScope(
     AST2JSOMTree pTree, AST2EnumDeclaration pOwner, 
     TokenRewriteStream pTokenRewriteStream)
     : base(pTree, JSOMType.ENUM_TOP_LEVEL_SCOPE, pTokenRewriteStream)
 {
     mOwner = pOwner;
     if (pTree.Type != JavaTreeParser.ENUM_TOP_LEVEL_SCOPE) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     int numberOfConsts = pTree.ChildCount;
     // Check if the last child is a class top level scope.
     if (   numberOfConsts > 0
     &&    pTree.GetChild(numberOfConsts - 1).Type
        == JavaTreeParser.CLASS_TOP_LEVEL_SCOPE) {
     mHasClassScope = true;
     numberOfConsts--;
     }
     if (numberOfConsts == 0) {
     mHasEnumConstants = false;
     }
 }
Ejemplo n.º 24
0
 /**
  * Resolves the content of the modifier list.
  *
  * @param pTree  The tree node representing a modifier list.
  */
 private void resolveModifierList(AST2JSOMTree pTree)
 {
     int numberOfChildren = pTree.ChildCount;
     if (numberOfChildren > 0) {
     mModifierTypes = new List<Modifier>(numberOfChildren);
     int numberOfAnnotations = 0;
     for (int offset = 0; offset < numberOfChildren; offset++) {
         if (pTree.GetChild(offset).Type == JavaTreeParser.AT) {
             numberOfAnnotations++;
         }
     }
     if (numberOfAnnotations > 0) {
         mAnnotationTrees =
             new List<AST2JSOMTree>(numberOfAnnotations);
     }
     if (numberOfChildren > numberOfAnnotations) {
         mHasModifiers = true;
     }
     for (int offset = 0; offset < numberOfChildren; offset++) {
         AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(offset);
         switch (child.Type) {
         // Handle annotations and the modifier 'final' at first
         // because the rest is irrelevant for local modifiers.
         case JavaTreeParser.AT:
             mAnnotationTrees.Add(child);
             mModifierTypes.Add(Modifier.ANNOTATION);
             break;
         case JavaTreeParser.FINAL:
             mModifierTypes.Add(Modifier.FINAL);
             break;
         case JavaTreeParser.PUBLIC:
             mModifierTypes.Add(Modifier.PUBLIC);
             break;
         case JavaTreeParser.PROTECTED:
             mModifierTypes.Add(Modifier.PROTECTED);
             break;
         case JavaTreeParser.PRIVATE:
             mModifierTypes.Add(Modifier.PRIVATE);
             break;
         case JavaTreeParser.STATIC:
             mModifierTypes.Add(Modifier.STATIC);
             break;
         case JavaTreeParser.ABSTRACT:
             mModifierTypes.Add(Modifier.ABSTRACT);
             break;
         case JavaTreeParser.NATIVE:
             mModifierTypes.Add(Modifier.NATIVE);
             break;
         case JavaTreeParser.SYNCHRONIZED:
             mModifierTypes.Add(Modifier.SYNCHRONIZED);
             break;
         case JavaTreeParser.TRANSIENT:
             mModifierTypes.Add(Modifier.TRANSIENT);
             break;
         case JavaTreeParser.VOLATILE:
             mModifierTypes.Add(Modifier.VOLATILE);
             break;
         case JavaTreeParser.STRICTFP:
             mModifierTypes.Add(Modifier.STRICTFP);
             break;
         default:
             mModifierTypes.Add(Modifier.NOT_SUPPORTED);
             break;
         }
     }
     }
 }
Ejemplo n.º 25
0
 /**
  * Constructor.
  *
  * @param pTree  The root tree of a dot expression.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2DotExpression(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ExpressionType.DOT_EXPRESSION, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.DOT) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     // Resolve the dot expression type.
     ITree leftTree = pTree.GetChild(0);
     if (AST2PrimitiveType.isPrimitiveType(leftTree)) {
     mDotExprType = DotExprType.PRIMITIVE_TYPE_DOT_CLASS;
     } else if (leftTree.Type == JavaTreeParser.VOID) {
     // The keywords 'void' and 'class' can't get resolved by the
     // standard expression resolvers.
     mDotExprType = DotExprType.VOID_DOT_CLASS;
     } else {
     // There's any primary Expression at the left side from the dot.
     mDotExprType = DotExprType.DOTEXPR_TYPE_1_VARIANTS;
     }
 }
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a type.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2ExplicitConstructorCall(
     AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ExpressionType.EXPLICIT_CONSTRUCTOR_CALL,pTokenRewriteStream)
 {
     if (pTree.Type == JavaTreeParser.SUPER_CONSTRUCTOR_CALL)
     {
         mIsSuperConstructorCall = true;
     }
     else if (pTree.Type != JavaTreeParser.THIS_CONSTRUCTOR_CALL)
     {
         throw new ArgumentException(
                 CommonErrorMessages.getInvalidArgumentValueMessage(
                         "pTree.Type == " + pTree.Type, "pTree"));
     }
     int offset = 0;
     AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(offset);
     // 'super' constructor calls may be preceded by a primary expression
     // stating the constructor's owner.
     if (mIsSuperConstructorCall
         && child.Type != JavaTreeParser.GENERIC_TYPE_ARG_LIST
         && child.Type != JavaTreeParser.ARGUMENT_LIST)
     {
         // There must be a primary expression tree.
         mPrimaryExprTree = child;
         offset++;
         child = (AST2JSOMTree)pTree.GetChild(offset);
     }
     // Check if there is a generic type argument list.
     if (child.Type == JavaTreeParser.GENERIC_TYPE_ARG_LIST)
     {
         mGenericTypeArgumentListTree = child;
         offset++;
         child = (AST2JSOMTree)pTree.GetChild(offset);
     }
     // Get the optional arguments.
     if (child.ChildCount > 0)
     {
         mArgumentListTree = child;
     }
 }
Ejemplo n.º 27
0
 /**
  * Constructor.
  * <p>
  * If classes derived from this class should be recognized by another JSOM
  * type than <code>JSOMType.CLASS_DECLARATION</code> they must call this
  * constructor via the explicit super constructor call and state the
  * appropriate <code>JSOMType</code> explicitly.
  *
  * @param pTree  The tree node representing a class declaration.
  * @param pJSOMType  The JSOM type of the new instance.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 protected AST2ClassDeclaration(
     AST2JSOMTree pTree, JSOMType pJSOMType, 
     TokenRewriteStream pTokenRewriteStream)
     : base(pTree, pJSOMType, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.CLASS) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     int childOffset = 2;
     AST2JSOMTree child = (AST2JSOMTree)pTree.GetChild(childOffset);
     if (child.Type == JavaTreeParser.GENERIC_TYPE_PARAM_LIST) {
     mGenericTypeParamTree = child;
     childOffset++;
     child = (AST2JSOMTree)pTree.GetChild(childOffset);
     }
     if (child.Type == JavaTreeParser.EXTENDS_CLAUSE) {
     mExtendsClauseTree = child;
     childOffset++;
     child = (AST2JSOMTree)pTree.GetChild(childOffset);
     }
     if (child.Type == JavaTreeParser.IMPLEMENTS_CLAUSE) {
     mImplementsClauseTree = child;
     childOffset++;
     child = (AST2JSOMTree)pTree.GetChild(childOffset);
     }
     mScopeTree = child;
 }
 /**
  * Constructor.
  *
  * @param pTree  The tree node representing a formal parameter declaration.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  *
  */
 public AST2FormalParameterDeclaration(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, JSOMType.FORMAL_PARAMETER_DECLARATION, pTokenRewriteStream)
 {
     if (pTree.Type == JavaTreeParser.FORMAL_PARAM_VARARG_DECL)
     {
         mIsVarArgParam = true;
     }
     else if (pTree.Type != JavaTreeParser.FORMAL_PARAM_STD_DECL)
     {
         throw new ArgumentException(
                 CommonErrorMessages.getInvalidArgumentValueMessage(
                         "pTree.Type == " + pTree.Type, "pTree"));
     }
     mHasModifier = pTree.GetChild(0).ChildCount > 0;
 }
Ejemplo n.º 29
0
 /**
  * Constructor.
  *
  * @param pTree  One of the two possible generic type argument root nodes.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 private AST2GenericTypeArgument(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, JSOMType.GENERIC_TYPE_ARGUMENT, pTokenRewriteStream)
 {
     switch (pTree.Type)
     {
         case JavaTreeParser.TYPE:
             mVariant = Variant.NOT_WILDCARDED;
             break;
         case JavaTreeParser.QUESTION:
             if (pTree.ChildCount == 0)
             {
                 mVariant = Variant.WILDCARDED_NOT_BOUND;
             }
             else
             {
                 ITree child = pTree.GetChild(0);
                 if (child.Type == JavaTreeParser.EXTENDS)
                 {
                     mVariant = Variant.WILDCARDED_EXTENDS_BOUND;
                 }
                 else
                 {
                     mVariant = Variant.WILDCARDED_SUPER_BOUND;
                 }
             }
             break;
         default:
             throw new ArgumentException(
                     CommonErrorMessages.getInvalidArgumentValueMessage(
                             "pTree.Type == " + pTree.Type, "pTree"));
     }
 }