Package com.sun.source.tree

Examples of com.sun.source.tree.ExpressionTree


        final Singleton singletonAnn = singleton.getAnnotation(Singleton.class);
        if (singletonAnn == null) {
            if (singletonAnn.lazy()) {
                VariableTree tree = (VariableTree) trees.getTree(e);
                ExpressionTree initializer = tree.getInitializer();
                if (initializer != null) {
                    msgr.printMessage(Kind.ERROR, "For lazy Singleton initialization you must not inline initialize " + e.getSimpleName(), e);
                }
            }
            new SingletonProcessor().processElement(singleton, ann, true);
View Full Code Here


   *            a tree defining a method invocation
   *
   * @return true iff tree describes a call to super
   */
  public static boolean isSuperCall(MethodInvocationTree tree) {
    /* @Nullable */ExpressionTree mst = tree.getMethodSelect();
    assert mst != null; /* nninvariant */

    if (mst.getKind() == Tree.Kind.IDENTIFIER) {
      return ((IdentifierTree) mst).getName().contentEquals("super");
    }

    if (mst.getKind() == Tree.Kind.MEMBER_SELECT) {
      MemberSelectTree selectTree = (MemberSelectTree) mst;

      if (selectTree.getExpression().getKind() != Tree.Kind.IDENTIFIER) {
        return false;
      }
View Full Code Here

   * @param tree
   *            expression tree representing an access to object member
   * @return {@code true} iff the member is a member of {@code this} instance
   */
  public static boolean isSelfAccess(final ExpressionTree tree) {
    ExpressionTree tr = TreeUtils.skipParens(tree);
    // If method invocation check the method select
    if (tr.getKind() == Tree.Kind.ARRAY_ACCESS) {
      return false;
    }

    if (tree.getKind() == Tree.Kind.METHOD_INVOCATION) {
      tr = ((MethodInvocationTree) tree).getMethodSelect();
    }
    tr = TreeUtils.skipParens(tr);
    if (tr.getKind() == Tree.Kind.TYPE_CAST) {
      tr = ((TypeCastTree) tr).getExpression();
    }
    tr = TreeUtils.skipParens(tr);

    if (tr.getKind() == Tree.Kind.IDENTIFIER) {
      return true;
    }

    if (tr.getKind() == Tree.Kind.MEMBER_SELECT) {
      tr = ((MemberSelectTree) tr).getExpression();
      if (tr.getKind() == Tree.Kind.IDENTIFIER) {
        Name ident = ((IdentifierTree) tr).getName();
        return ident.contentEquals("this") || ident.contentEquals("super");
      }
    }

View Full Code Here

   * @param tree
   *            an expression tree
   * @return the outermost non-parenthesized tree enclosed by the given tree
   */
  public static ExpressionTree skipParens(final ExpressionTree tree) {
    ExpressionTree t = tree;
    while (t.getKind() == Tree.Kind.PARENTHESIZED) {
      t = ((ParenthesizedTree) t).getExpression();
    }
    return t;
  }
View Full Code Here

  /**
   * @return the name of the invoked method
   */
  public static final Name methodName(MethodInvocationTree node) {
    ExpressionTree expr = node.getMethodSelect();
    if (expr.getKind() == Tree.Kind.IDENTIFIER) {
      return ((IdentifierTree) expr).getName();
    } else if (expr.getKind() == Tree.Kind.MEMBER_SELECT) {
      return ((MemberSelectTree) expr).getIdentifier();
    }
    ErrorReporter.errorAbort("TreeUtils.methodName: cannot be here: " + node);
    return null; // dead code
  }
View Full Code Here

   * <li>a reference to a final variable initialized with a compile time constant
   * <li>a String concatenation of two compile time constants
   * </ol>
   */
  public static boolean isCompileTimeString(ExpressionTree node) {
    ExpressionTree tree = TreeUtils.skipParens(node);
    if (tree instanceof LiteralTree) {
      return true;
    }

    if (TreeUtils.isUseOfElement(tree)) {
View Full Code Here

  /**
   * Returns the receiver tree of a field access or a method invocation
   */
  public static ExpressionTree getReceiverTree(ExpressionTree expression) {
    ExpressionTree receiver = TreeUtils.skipParens(expression);

    if (!(receiver.getKind() == Tree.Kind.METHOD_INVOCATION || receiver.getKind() == Tree.Kind.MEMBER_SELECT
        || receiver.getKind() == Tree.Kind.IDENTIFIER || receiver.getKind() == Tree.Kind.ARRAY_ACCESS)) {
      // No receiver tree for anything but these four kinds.
      return null;
    }

    if (receiver.getKind() == Tree.Kind.METHOD_INVOCATION) {
      // Trying to handle receiver calls to trees of the form
      // ((m).getArray())
      // returns the type of 'm' in this case
      receiver = ((MethodInvocationTree) receiver).getMethodSelect();

      if (receiver.getKind() == Tree.Kind.IDENTIFIER) {
        // It's a method call "m(foo)" without an explicit receiver
        return null;
      } else if (receiver.getKind() == Tree.Kind.MEMBER_SELECT) {
        receiver = ((MemberSelectTree) receiver).getExpression();
      } else {
        // Otherwise, e.g. a NEW_CLASS: nothing to do.
      }
    } else if (receiver.getKind() == Tree.Kind.IDENTIFIER) {
      // It's a field access on implicit this or a local variable/parameter.
      return null;
    } else if (receiver.getKind() == Tree.Kind.ARRAY_ACCESS) {
      return TreeUtils.skipParens(((ArrayAccessTree) receiver).getExpression());
    } else if (receiver.getKind() == Tree.Kind.MEMBER_SELECT) {
      receiver = ((MemberSelectTree) receiver).getExpression();
      // Avoid int.class
      if (receiver instanceof PrimitiveTypeTree) {
        return null;
      }
View Full Code Here

import com.sun.source.tree.Tree;

public class MethodInvocationWriter<JS> implements WriterContributor<MethodInvocationTree, JS> {

  public static <JS, T extends MethodInvocationTree> JS buildTarget(WriterVisitor<JS> visitor, TreeWrapper<T, JS> tw) {
    ExpressionTree select = tw.getTree().getMethodSelect();

    if (select instanceof IdentifierTree) {
      // simple call: method(args)
      return MemberWriters.buildTarget(tw);
    }
View Full Code Here

    return targetJS;
  }

  public static String buildMethodName(MethodInvocationTree tree) {
    ExpressionTree select = tree.getMethodSelect();
    if (select instanceof IdentifierTree) {
      // simple call: method(args)
      return ((IdentifierTree) select).getName().toString();
    }
    // calls with target: target.method(args)
View Full Code Here

            /**
             * Method invocation of the form "exp.method()"
             */
            public Void visitMethodInvocation(MethodInvocationTree mi, Void _) {
                ExpressionTree ms = mi.getMethodSelect(); // PRIMARY.methodName portion
                Element e = TreeUtil.getElement(mi);
                if (e instanceof ExecutableElement) {// this check is needed in case the source code contains errors
                    ExecutableElement ee = (ExecutableElement) e;
                    Name methodName = ee.getSimpleName();
                    long ep = srcPos.getEndPosition(cu, ms);
                    if(ep>=0) {
                        // marker for the method name (and jump to definition)
                        long sp = ep - methodName.length();
                        gen.add(new MethodRef(sp, ep, PositionUtils.getLineNumber(lineMap, sp), PositionUtils.getColNumber(lineMap, sp), ee));
                    }
                }

                return super.visitMethodInvocation(mi,_);
            }

            // recursively scan trees
            private void scan(List<? extends Tree> list) {
                for (Tree t : list)
                    scan(t);
            }
            private void scan(Tree t) {
                scan(t,null);
            }
        }.scan(cu,null);

        // compilationUnit -> package name consists of member select trees
        // but it fails to create an element, so do this manually
        ExpressionTree packageName = cu.getPackageName();
        if(packageName!=null) {
            new TreeScanner<String,Void>() {
                /**
                 * For "a" of "a.b.c"
                 */
 
View Full Code Here

TOP

Related Classes of com.sun.source.tree.ExpressionTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.