com.sun.tools.javac.tree.JCTree.JCArrayAccess Java Examples

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCArrayAccess. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
JCExpression abstractLval(JCExpression lval, final TreeBuilder builder) {
    lval = TreeInfo.skipParens(lval);
    switch (lval.getTag()) {
    case IDENT:
        return builder.build(lval);
    case SELECT: {
        final JCFieldAccess s = (JCFieldAccess)lval;
        Symbol lid = TreeInfo.symbol(s.selected);
        if (lid != null && lid.kind == TYP) return builder.build(lval);
        return abstractRval(s.selected, selected -> builder.build(make.Select(selected, s.sym)));
    }
    case INDEXED: {
        final JCArrayAccess i = (JCArrayAccess)lval;
        return abstractRval(i.indexed, indexed -> abstractRval(i.index, syms.intType, index -> {
            JCExpression newLval = make.Indexed(indexed, index);
            newLval.setType(i.type);
            return builder.build(newLval);
        }));
    }
    case TYPECAST: {
        return abstractLval(((JCTypeCast)lval).expr, builder);
    }
    }
    throw new AssertionError(lval);
}
 
Example #2
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void visitIndexed(JCArrayAccess tree) {
    tree.indexed = translate(tree.indexed, erasure(tree.indexed.type));
    tree.index = translate(tree.index, syms.intType);

    // Insert casts of indexed expressions as needed.
    result = retype(tree, types.elemtype(tree.indexed.type), pt);
}
 
Example #3
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void visitIndexed(JCArrayAccess tree) {
	try {
		printExpr(tree.indexed, TreeInfo.postfixPrec);
		print("[");
		printExpr(tree.index);
		print("]");
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
Example #4
Source File: CRTable.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitIndexed(JCArrayAccess tree) {
    SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
    sr.mergeWith(csp(tree.indexed));
    sr.mergeWith(csp(tree.index));
    result = sr;
}
 
Example #5
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitIndexed(JCArrayAccess tree) {
    tree.indexed = translate(tree.indexed);
    tree.index = translate(tree.index, syms.intType);
    result = tree;
}
 
Example #6
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private ArrayAccess convertArrayAccess(JCArrayAccess expression) {
  return ArrayAccess.newBuilder()
      .setArrayExpression(convertExpression(expression.getExpression()))
      .setIndexExpression(convertExpression(expression.getIndex()))
      .build();
}
 
Example #7
Source File: JavacTreeMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCArrayAccess Indexed(JCExpression indexed, JCExpression index) {
	return invoke(Indexed, indexed, index);
}
 
Example #8
Source File: ExpressionTemplate.java    From Refaster with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the precedence level appropriate for unambiguously printing
 * leaf as a subexpression of its parent.
 */
private static int getPrecedence(JCTree leaf, Context context) {
  JCCompilationUnit comp = context.get(JCCompilationUnit.class);
  JCTree parent = TreeInfo.pathFor(leaf, comp).get(1);

  // In general, this should match the logic in com.sun.tools.javac.tree.Pretty.
  //
  // TODO(mdempsky): There are probably cases where we could omit parentheses
  // by tweaking the returned precedence, but they need careful review.
  // For example, consider a template to replace "add(a, b)" with "a + b",
  // which applied to "x + add(y, z)" would result in "x + (y + z)".
  // In most cases, we'd likely prefer "x + y + z" instead, but those aren't
  // always equivalent: "0L + (Integer.MIN_VALUE + Integer.MIN_VALUE)" yields
  // a different value than "0L + Integer.MIN_VALUE + Integer.MIN_VALUE" due
  // to integer promotion rules.

  if (parent instanceof JCConditional) {
    // This intentionally differs from Pretty, because Pretty appears buggy:
    // http://mail.openjdk.java.net/pipermail/compiler-dev/2013-September/007303.html
    JCConditional conditional = (JCConditional) parent;
    return TreeInfo.condPrec + ((conditional.cond == leaf) ? 1 : 0);
  } else if (parent instanceof JCAssign) {
    JCAssign assign = (JCAssign) parent;
    return TreeInfo.assignPrec + ((assign.lhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCAssignOp) {
    JCAssignOp assignOp = (JCAssignOp) parent;
    return TreeInfo.assignopPrec + ((assignOp.lhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCUnary) {
    return TreeInfo.opPrec(parent.getTag());
  } else if (parent instanceof JCBinary) {
    JCBinary binary = (JCBinary) parent;
    return TreeInfo.opPrec(parent.getTag()) + ((binary.rhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCTypeCast) {
    JCTypeCast typeCast = (JCTypeCast) parent;
    return (typeCast.expr == leaf) ? TreeInfo.prefixPrec : TreeInfo.noPrec;
  } else if (parent instanceof JCInstanceOf) {
    JCInstanceOf instanceOf = (JCInstanceOf) parent;
    return TreeInfo.ordPrec + ((instanceOf.clazz == leaf) ? 1 : 0);
  } else if (parent instanceof JCArrayAccess) {
    JCArrayAccess arrayAccess = (JCArrayAccess) parent;
    return (arrayAccess.indexed == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
  } else if (parent instanceof JCFieldAccess) {
    JCFieldAccess fieldAccess = (JCFieldAccess) parent;
    return (fieldAccess.selected == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
  } else {
    return TreeInfo.noPrec;
  }
}
 
Example #9
Source File: UArrayAccess.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public JCArrayAccess inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().Indexed(getExpression().inline(inliner), getIndex().inline(inliner));
}