1 Reply Latest reply: Aug 11, 2010 2:34 AM by 843810 RSS

    Compiler Tree API question

    843810
      How can I get a DeclaredType for a parameterized type when walking the ast using the CompilerTree API. My approach looks like this:
      @Override
           public Object visitVariable(VariableTree node, Trees trees)
           {
                VariableElement varElement = (VariableElement)trees.getElement(trees.getPath(this.cu,node));
                TypeMirror mirror = varElement.asType();
                
                //Get TypeMirror for type parameters
                //How is this done?
                Tree type = node.getType();
                if(type instanceof ParameterizedTypeTree)
                {
                     ParameterizedTypeTree ptt = (ParameterizedTypeTree)type;
                     List<? extends Tree> args = ptt.getTypeArguments();
                     
                     TypeMirror [] typeArgs = ... ;//??????
                     
                     TypeElement te=(TypeElement) varElement.asType();
                     DeclaredType typeParamsSubstituted = types.getDeclaredType(te, typeArgs);
                }
           }
      Unfortunately I don't know how to get the TypeMirrors for the type args and therefore I am not able to construct the DeclaredType.