Package com.sun.source.util

Examples of com.sun.source.util.TreePath


   * if the block is an anonymous initializer, then return the outer class
   * @param element
   * @return
   */
  public static ClassTree enclosingClassSkipAnonymousInitializer(TreePath path) {
    TreePath enclosingClassTreePath = TreeUtils.enclosingPathOfType(path, ClassTree.class);
    if (isInsideInizializerBlock(path)) {
      //get the outer class
      TreePath outerClassTreePath = TreeUtils.enclosingPathOfType(enclosingClassTreePath.getParentPath(), ClassTree.class);
      if (outerClassTreePath != null) {
        enclosingClassTreePath = outerClassTreePath;
      }
    }
    return (ClassTree) enclosingClassTreePath.getLeaf();
View Full Code Here


public class TypeCastWriter<JS> implements WriterContributor<TypeCastTree, JS> {

  @Override
  public JS visit(WriterVisitor<JS> visitor, TypeCastTree tree, GenerationContext<JS> context) {
    TypeMirror type = context.getTrees().getTypeMirror(new TreePath(context.getCurrentPath(), tree.getType()));
    JS expr = visitor.scan(tree.getExpression(), context);
    if (TypesUtils.isIntegral(type)) {
      // add explicit cast in this case
      JS target = context.js().property(context.js().name("stjs"), "trunc");
      expr = context.js().functionCall(target, Collections.singleton(expr));
View Full Code Here

  @Override
  public R scan(Tree tree, P p) {
    if (tree == null) {
      return null;
    }
    TreePath prev = p.getCurrentPath();
    p.setCurrentPath(new TreePath(prev, tree));
    try {
      return visit(tree, p, null);
    }
    finally {
      p.setCurrentPath(prev);
View Full Code Here

    assert op != null : "Unknow operator:" + tree.getKind();

    @SuppressWarnings("unchecked")
    JS expr = context.js().binary(op, Arrays.asList(left, right));

    TypeMirror leftType = context.getTrees().getTypeMirror(new TreePath(context.getCurrentPath(), tree.getLeftOperand()));
    TypeMirror rightType = context.getTrees().getTypeMirror(new TreePath(context.getCurrentPath(), tree.getRightOperand()));
    boolean integerDivision = tree.getKind() == Kind.DIVIDE && TypesUtils.isIntegral(leftType) && TypesUtils.isIntegral(rightType);

    if (integerDivision) {
      // force a cast for integer division to have the expected behavior in JavaScript too
      JS target = context.js().property(context.js().name("stjs"), "trunc");
View Full Code Here

  public JS visit(WriterVisitor<JS> visitor, InstanceOfTree tree, GenerationContext<JS> context) {

    // build stjs.isInstanceOf(expr.constructor, type);
    // TODO do I need a check or parenthesis around !?

    TypeMirror type = context.getTrees().getTypeMirror(new TreePath(context.getCurrentPath(), tree.getType()));
    JS getConstructor = context.js().property(visitor.scan(tree.getExpression(), context), JavascriptKeywords.CONSTRUCTOR);
    JS targetInst = context.js().property(context.js().name("stjs"), "isInstanceOf");
    JS typeName = context.js().name(context.getNames().getTypeName(context, type));
    return context.js().functionCall(targetInst, Arrays.asList(getConstructor, typeName));
  }
View Full Code Here

  /**
   * handle the case a /= b, where a and b are integers. it generates: a = stjs.trunc(a/(b));
   */
  public static <JS> JS rightSide(JS left, JS right, CompoundAssignmentTree tree, GenerationContext<JS> context) {
    TypeMirror leftType = context.getTrees().getTypeMirror(new TreePath(context.getCurrentPath(), tree.getVariable()));
    TypeMirror rightType = context.getTrees().getTypeMirror(new TreePath(context.getCurrentPath(), tree.getExpression()));
    JavaScriptBuilder<JS> js = context.js();
    boolean integerDivision =
        tree.getKind() == Kind.DIVIDE_ASSIGNMENT && TypesUtils.isIntegral(leftType) && TypesUtils.isIntegral(rightType);

    if (integerDivision) {
View Full Code Here

    }
    return right;
  }

  public static <JS> AssignOperator getAssignOperator(CompoundAssignmentTree tree, GenerationContext<JS> context) {
    TypeMirror leftType = context.getTrees().getTypeMirror(new TreePath(context.getCurrentPath(), tree.getVariable()));
    TypeMirror rightType = context.getTrees().getTypeMirror(new TreePath(context.getCurrentPath(), tree.getExpression()));
    boolean integerDivision =
        tree.getKind() == Kind.DIVIDE_ASSIGNMENT && TypesUtils.isIntegral(leftType) && TypesUtils.isIntegral(rightType);
    return integerDivision ? AssignOperator.ASSIGN : AssignOperator.valueOf(tree.getKind());
  }
View Full Code Here

        Env<AttrContext> env = null;
        JCMethodDecl method = null;
        JCVariableDecl field = null;
       
        List<Tree> l = List.nil();
        TreePath p = path;
        while (p != null) {
            l = l.prepend(p.getLeaf());
            p = p.getParentPath();
        }
       
        for ( ; l.nonEmpty(); l = l.tail) {
            Tree tree = l.head;
            switch (tree.getKind()) {
View Full Code Here

        Env<AttrContext> env = null;
        JCMethodDecl method = null;
        JCVariableDecl field = null;

        List<Tree> l = List.nil();
        TreePath p = path;
        while (p != null) {
            l = l.prepend(p.getLeaf());
            p = p.getParentPath();
        }

        for ( ; l.nonEmpty(); l = l.tail) {
            Tree tree = l.head;
            switch (tree.getKind()) {
View Full Code Here

        Trees trees = Trees.instance(processingEnv);

        TypeElement testAnno = elements.getTypeElement("Check");
        for (Element elem: roundEnv.getElementsAnnotatedWith(testAnno)) {
            TreePath p = trees.getPath(elem);
            new MulticatchParamTester(trees).scan(p, null);
        }
        return true;
    }
View Full Code Here

TOP

Related Classes of com.sun.source.util.TreePath

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.