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

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCThrow. 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: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitThrow(JCThrow tree) {
    scan(tree.expr);
    Symbol sym = TreeInfo.symbol(tree.expr);
    if (sym != null &&
        sym.kind == VAR &&
        (sym.flags() & (FINAL | EFFECTIVELY_FINAL)) != 0 &&
        preciseRethrowTypes.get(sym) != null &&
        allowImprovedRethrowAnalysis) {
        for (Type t : preciseRethrowTypes.get(sym)) {
            markThrown(tree, t);
        }
    }
    else {
        markThrown(tree, tree.expr.type);
    }
    markDead();
}
 
Example #2
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void visitThrow(JCThrow tree) {
	try {
		print("throw ");
		printExpr(tree.expr);
		print(";");
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
Example #3
Source File: HandleNonNull.java    From EasyMPermission with MIT License 5 votes vote down vote up
/**
 * Checks if the statement is of the form 'if (x == null) {throw WHATEVER;},
 * where the block braces are optional. If it is of this form, returns "x".
 * If it is not of this form, returns null.
 */
public String returnVarNameIfNullCheck(JCStatement stat) {
	if (!(stat instanceof JCIf)) return null;
	
	/* Check that the if's statement is a throw statement, possibly in a block. */ {
		JCStatement then = ((JCIf) stat).thenpart;
		if (then instanceof JCBlock) {
			List<JCStatement> stats = ((JCBlock) then).stats;
			if (stats.length() == 0) return null;
			then = stats.get(0);
		}
		if (!(then instanceof JCThrow)) return null;
	}
	
	/* Check that the if's conditional is like 'x == null'. Return from this method (don't generate
	   a nullcheck) if 'x' is equal to our own variable's name: There's already a nullcheck here. */ {
		JCExpression cond = ((JCIf) stat).cond;
		while (cond instanceof JCParens) cond = ((JCParens) cond).expr;
		if (!(cond instanceof JCBinary)) return null;
		JCBinary bin = (JCBinary) cond;
		if (!CTC_EQUAL.equals(treeTag(bin))) return null;
		if (!(bin.lhs instanceof JCIdent)) return null;
		if (!(bin.rhs instanceof JCLiteral)) return null;
		if (!CTC_BOT.equals(typeTag(bin.rhs))) return null;
		return ((JCIdent) bin.lhs).name.toString();
	}
}
 
Example #4
Source File: TreePruner.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void visitLambda(JCLambda tree) {
  if (tree.getBodyKind() == BodyKind.STATEMENT) {
    JCExpression ident = make.at(tree).QualIdent(symtab.assertionErrorType.tsym);
    JCThrow throwTree = make.Throw(make.NewClass(null, List.nil(), ident, List.nil(), null));
    tree.body = make.Block(0, List.of(throwTree));
  }
}
 
Example #5
Source File: CRTable.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitThrow(JCThrow tree) {
    SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
    sr.mergeWith(csp(tree.expr));
    result = sr;
}
 
Example #6
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitThrow(JCThrow tree) {
    tree.expr = translate(tree.expr, erasure(tree.expr.type));
    result = tree;
}
 
Example #7
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitThrow(JCThrow tree) {
    scan(tree.expr);
    markDead();
}
 
Example #8
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitThrow(JCThrow tree) {
    scanExpr(tree.expr);
    markDead();
}
 
Example #9
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private ThrowStatement convertThrow(JCThrow statement) {
  return new ThrowStatement(
      getSourcePosition(statement), convertExpression(statement.getExpression()));
}
 
Example #10
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private Statement convertStatement(JCStatement jcStatement) {
  switch (jcStatement.getKind()) {
    case ASSERT:
      return convertAssert((JCAssert) jcStatement);
    case BLOCK:
      return convertBlock((JCBlock) jcStatement);
    case BREAK:
      return convertBreak((JCBreak) jcStatement);
    case CLASS:
      convertClassDeclaration((JCClassDecl) jcStatement);
      return null;
    case CONTINUE:
      return convertContinue((JCContinue) jcStatement);
    case DO_WHILE_LOOP:
      return convertDoWhileLoop((JCDoWhileLoop) jcStatement);
    case EMPTY_STATEMENT:
      return new EmptyStatement(getSourcePosition(jcStatement));
    case ENHANCED_FOR_LOOP:
      return convertEnhancedForLoop((JCEnhancedForLoop) jcStatement);
    case EXPRESSION_STATEMENT:
      return convertExpressionStatement((JCExpressionStatement) jcStatement);
    case FOR_LOOP:
      return convertForLoop((JCForLoop) jcStatement);
    case IF:
      return convertIf((JCIf) jcStatement);
    case LABELED_STATEMENT:
      return convertLabeledStatement((JCLabeledStatement) jcStatement);
    case RETURN:
      return convertReturn((JCReturn) jcStatement);
    case SWITCH:
      return convertSwitch((JCSwitch) jcStatement);
    case THROW:
      return convertThrow((JCThrow) jcStatement);
    case TRY:
      return convertTry((JCTry) jcStatement);
    case VARIABLE:
      return convertVariableDeclaration((JCVariableDecl) jcStatement);
    case WHILE_LOOP:
      return convertWhileLoop((JCWhileLoop) jcStatement);
    case SYNCHRONIZED:
      return convertSynchronized((JCSynchronized) jcStatement);
    default:
      throw new AssertionError("Unknown statement node type: " + jcStatement.getKind());
  }
}
 
Example #11
Source File: JavacTreeMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCThrow Throw(JCExpression expr) {
	return invoke(Throw, expr);
}
 
Example #12
Source File: UThrow.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public JCThrow inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().Throw(getExpression().inline(inliner));
}