com.sun.tools.javac.tree.JCTree.JCInstanceOf Java Examples
The following examples show how to use
com.sun.tools.javac.tree.JCTree.JCInstanceOf.
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: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 5 votes |
private InstanceOfExpression convertInstanceOf(JCInstanceOf expression) { return InstanceOfExpression.newBuilder() .setSourcePosition(getSourcePosition(expression)) .setExpression(convertExpression(expression.getExpression())) .setTestTypeDescriptor(environment.createTypeDescriptor(expression.getType().type)) .build(); }
Example #2
Source File: PrettyCommentsPrinter.java From EasyMPermission with MIT License | 5 votes |
public void visitTypeTest(JCInstanceOf tree) { try { open(prec, TreeInfo.ordPrec); printExpr(tree.expr, TreeInfo.ordPrec); print(" instanceof "); printExpr(tree.clazz, TreeInfo.ordPrec + 1); close(prec, TreeInfo.ordPrec); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #3
Source File: CRTable.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void visitTypeTest(JCInstanceOf tree) { SourceRange sr = new SourceRange(startPos(tree), endPos(tree)); sr.mergeWith(csp(tree.expr)); sr.mergeWith(csp(tree.clazz)); result = sr; }
Example #4
Source File: TransTypes.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void visitTypeTest(JCInstanceOf tree) { tree.expr = translate(tree.expr, null); tree.clazz = translate(tree.clazz, null); result = tree; }
Example #5
Source File: JavacTreeMaker.java From EasyMPermission with MIT License | 4 votes |
public JCInstanceOf TypeTest(JCExpression expr, JCTree clazz) { return invoke(TypeTest, expr, clazz); }
Example #6
Source File: UInstanceOf.java From Refaster with Apache License 2.0 | 4 votes |
@Override public JCInstanceOf inline(Inliner inliner) throws CouldNotResolveImportException { return inliner.maker().TypeTest(getExpression().inline(inliner), getType().inline(inliner)); }
Example #7
Source File: ExpressionTemplate.java From Refaster with Apache License 2.0 | 4 votes |
/** * 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; } }