public MemberSelectTree buildIteratorMethodAccess(ExpressionTree iterableExpr){
  DeclaredType exprType=(DeclaredType)TypesUtils.upperBound(InternalUtils.typeOf(iterableExpr));
  assert exprType != null : "expression must be of declared type Iterable<>";
  TypeElement exprElement=(TypeElement)exprType.asElement();
  Symbol.MethodSymbol iteratorMethod=null;
  for (  ExecutableElement method : ElementFilter.methodsIn(elements.getAllMembers(exprElement))) {
    Name methodName=method.getSimpleName();
    if (method.getParameters().size() == 0) {
      if (methodName.contentEquals("iterator")) {
        iteratorMethod=(Symbol.MethodSymbol)method;
      }
    }
  }
  assert iteratorMethod != null : "no iterator method declared for expression type";
  Type.MethodType methodType=(Type.MethodType)iteratorMethod.asType();
  Symbol.TypeSymbol methodClass=methodType.asElement();
  DeclaredType iteratorType=(DeclaredType)methodType.getReturnType();
  TypeMirror elementType;
  if (iteratorType.getTypeArguments().size() > 0) {
    elementType=iteratorType.getTypeArguments().get(0);
    if (elementType instanceof Type.CapturedType) {
      elementType=((Type.CapturedType)elementType).wildcard;
    }
    iteratorType=modelTypes.getDeclaredType((TypeElement)modelTypes.asElement(iteratorType),elementType);
  }
  Type.MethodType updatedMethodType=new Type.MethodType(com.sun.tools.javac.util.List.<Type>nil(),(Type)iteratorType,com.sun.tools.javac.util.List.<Type>nil(),methodClass);
  JCTree.JCFieldAccess iteratorAccess=(JCTree.JCFieldAccess)maker.Select((JCTree.JCExpression)iterableExpr,iteratorMethod);
  iteratorAccess.setType(updatedMethodType);
  return iteratorAccess;
}

public MemberSelectTree buildIteratorMethodAccess ( ExpressionTree iterableExpr ) { DeclaredType exprType = ( DeclaredType ) TypesUtils . upperBound ( InternalUtils . typeOf ( iterableExpr ) ) ; assert exprType != null : "expression must be of declared type Iterable<>" ; TypeElement exprElement = ( TypeElement ) exprType . asElement ( ) ; Symbol . MethodSymbol iteratorMethod = null ; for ( ExecutableElement method : ElementFilter . methodsIn ( elements . getAllMembers ( exprElement ) ) ) { Name methodName = method . getSimpleName ( ) ; if ( method . getParameters ( ) . size ( ) == 0 ) { if ( methodName . contentEquals ( "iterator" ) ) { iteratorMethod = ( Symbol . MethodSymbol ) method ; } } } assert iteratorMethod != null : "no iterator method declared for expression type" ; Type . MethodType methodType = ( Type . MethodType ) iteratorMethod . asType ( ) ; Symbol . TypeSymbol methodClass = methodType . asElement ( ) ; DeclaredType iteratorType = ( DeclaredType ) methodType . getReturnType ( ) ; TypeMirror elementType ; if ( iteratorType . getTypeArguments ( ) . size ( ) > 0 ) { elementType = iteratorType . getTypeArguments ( ) . get ( 0 ) ; if ( elementType instanceof Type . CapturedType ) { elementType = ( ( Type . CapturedType ) elementType ) . wildcard ; } iteratorType = modelTypes . getDeclaredType ( ( TypeElement ) modelTypes . asElement ( iteratorType ) , elementType ) ; } Type . MethodType updatedMethodType = new Type . MethodType ( com . sun . tools . javac . util . List . < Type > nil ( ) , ( Type ) iteratorType , com . sun . tools . javac . util . List . < Type > nil ( ) , methodClass ) ; JCTree . JCFieldAccess iteratorAccess = ( JCTree . JCFieldAccess ) maker . Select ( ( JCTree . JCExpression ) iterableExpr , iteratorMethod ) ; iteratorAccess . setType ( updatedMethodType ) ; return iteratorAccess ; }
builds an ast tree to access the iterator ( ) method of some iterable expression .
