本文整理汇总了Java中com.sun.source.tree.CatchTree.getParameter方法的典型用法代码示例。如果您正苦于以下问题:Java CatchTree.getParameter方法的具体用法?Java CatchTree.getParameter怎么用?Java CatchTree.getParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.CatchTree
的用法示例。
在下文中一共展示了CatchTree.getParameter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitCatchClause
import com.sun.source.tree.CatchTree; //导入方法依赖的package包/类
/**
* Helper method for {@link CatchTree}s.
*/
private void visitCatchClause(CatchTree node, AllowTrailingBlankLine allowTrailingBlankLine) {
sync(node);
builder.space();
token("catch");
builder.space();
token("(");
builder.open(plusFour);
VariableTree ex = node.getParameter();
if (ex.getType().getKind() == UNION_TYPE) {
builder.open(ZERO);
visitUnionType(ex);
builder.close();
} else {
// TODO(cushon): don't break after here for consistency with for, while, etc.
builder.breakToFill();
builder.open(ZERO);
scan(ex, null);
builder.close();
}
builder.close();
token(")");
builder.space();
visitBlock(
node.getBlock(), CollapseEmptyOrNot.NO, AllowLeadingBlankLine.YES, allowTrailingBlankLine);
}
示例2: visitCatch
import com.sun.source.tree.CatchTree; //导入方法依赖的package包/类
@Override
public Void visitCatch(CatchTree node, Void p) {
TreePath param = new TreePath(getCurrentPath(), node.getParameter());
Element ex = trees.getElement(param);
validateUnionTypeInfo(ex);
if (ex.getSimpleName().contentEquals("ex")) {
assertTrue(ex.getKind() == ElementKind.EXCEPTION_PARAMETER, "Expected EXCEPTION_PARAMETER - found " + ex.getKind());
for (Element e : types.asElement(trees.getLub(node)).getEnclosedElements()) {
Member m = e.getAnnotation(Member.class);
if (m != null) {
assertTrue(e.getKind() == m.value(), "Expected " + m.value() + " - found " + e.getKind());
}
}
assertTrue(assertionCount == 9, "Expected 9 assertions - found " + assertionCount);
}
return super.visitCatch(node, p);
}
示例3: IsInTry
import com.sun.source.tree.CatchTree; //导入方法依赖的package包/类
private boolean IsInTry(TryTreeImpl tryTree, Tree parent) {
boolean result = false;
result |= IsInBlock((BlockTreeImpl) tryTree.getFinallyBlock(), parent);
result |= IsInBlock((BlockTreeImpl) tryTree.getBlock(), parent);
List<? extends CatchTree> catches = tryTree.getCatches();
for (CatchTree catchTree : catches) {
VariableTree parameter = catchTree.getParameter();
result |= IsInVariableDeclaration((VariableTreeImpl) parameter, parent);
BlockTree block = catchTree.getBlock();
result |= IsInBlock((BlockTreeImpl) block, parent);
}
return result;
}
示例4: IsInTry
import com.sun.source.tree.CatchTree; //导入方法依赖的package包/类
private boolean IsInTry(TryTreeImpl tryTree, Tree parent, String className) {
boolean result = false;
result |= IsInBlock((BlockTreeImpl) tryTree.getFinallyBlock(), parent, className);
result |= IsInBlock((BlockTreeImpl) tryTree.getBlock(), parent, className);
List<? extends CatchTree> catches = tryTree.getCatches();
for (CatchTree catchTree : catches) {
VariableTree parameter = catchTree.getParameter();
result |= IsInVariableDeclaration((VariableTreeImpl) parameter, parent, className);
BlockTree block = catchTree.getBlock();
result |= IsInBlock((BlockTreeImpl) block, parent, className);
}
return result;
}
示例5: matchTry
import com.sun.source.tree.CatchTree; //导入方法依赖的package包/类
@Override
public Description matchTry(TryTree tree, VisitorState state) {
if (tryTreeMatches(tree, state)) {
CatchTree firstCatch = tree.getCatches().get(0);
VariableTree catchParameter = firstCatch.getParameter();
return describeMatch(firstCatch,
new SuggestedFix().replace(catchParameter, "Exception " + catchParameter.getName()));
} else {
return Description.NO_MATCH;
}
}
示例6: findUncaughtExceptions
import com.sun.source.tree.CatchTree; //导入方法依赖的package包/类
private List<? extends TypeMirror> findUncaughtExceptions(CompilationInfo info, TreePath path, List<? extends TypeMirror> exceptions) {
List<TypeMirror> result = new ArrayList<TypeMirror>();
result.addAll(exceptions);
Tree lastTree = null;
while (path != null) {
Tree currentTree = path.getLeaf();
if (currentTree.getKind() == Tree.Kind.METHOD) {
TypeMirror tm = info.getTrees().getTypeMirror(path);
if (tm != null && tm.getKind() == TypeKind.EXECUTABLE) {
for (TypeMirror mirr : ((ExecutableType) tm).getThrownTypes()) {
for (Iterator<TypeMirror> it = result.iterator(); it.hasNext();)
if (info.getTypes().isSameType(it.next(), mirr))
it.remove();
}
break;
}
}
if (currentTree.getKind() == Tree.Kind.LAMBDA_EXPRESSION) {
// no checked exceptions can be thrown out of Lambda, #243106
break;
}
if (currentTree.getKind() == Kind.TRY) {
TryTree tt = (TryTree) currentTree;
if (tt.getBlock() == lastTree) {
for (CatchTree c : tt.getCatches()) {
TreePath catchPath = new TreePath(new TreePath(path, c), c.getParameter());
VariableElement variable = (VariableElement) info.getTrees().getElement(catchPath);
if (variable == null) {
continue;
}
TypeMirror variableType = variable.asType();
if (variableType.getKind() == TypeKind.UNION) {
result.removeAll(((UnionType)variableType).getAlternatives());
} else {
result.remove(variableType);
}
}
}
}
lastTree = path.getLeaf();
path = path.getParentPath();
}
List<TypeMirror> filtered = new ArrayList<>();
OUTER: for (Iterator<TypeMirror> sourceIt = result.iterator(); sourceIt.hasNext(); ) {
TypeMirror sourceType = sourceIt.next();
for (Iterator<TypeMirror> filteredIt = filtered.iterator(); filteredIt.hasNext(); ) {
TypeMirror filteredType = filteredIt.next();
if (info.getTypes().isSubtype(sourceType, filteredType)) {
sourceIt.remove();
continue OUTER;
}
if (info.getTypes().isSubtype(filteredType, sourceType)) {
filteredIt.remove();
break;
}
}
filtered.add(sourceType);
}
return filtered;
}
示例7: tryTreeMatches
import com.sun.source.tree.CatchTree; //导入方法依赖的package包/类
private static MatchResult tryTreeMatches(TryTree tryTree, VisitorState state) {
BlockTree tryBlock = tryTree.getBlock();
List<? extends StatementTree> statements = tryBlock.getStatements();
if (statements.isEmpty()) {
return doesNotMatch();
}
// Check if any of the statements is a fail or assert* method (i.e. any
// method that can throw an AssertionFailedError)
StatementTree failStatement = null;
for (StatementTree statement : statements) {
if (!(statement instanceof ExpressionStatementTree)) {
continue;
}
if (failOrAssert.matches(((ExpressionStatementTree) statement).getExpression(), state)) {
failStatement = statement;
break;
}
}
if (failStatement == null) {
return doesNotMatch();
}
// Verify that the only catch clause catches Throwable
List<? extends CatchTree> catches = tryTree.getCatches();
if (catches.size() != 1) {
// TODO(adamwos): this could be supported - only the last catch would need
// to be checked - it would either be Throwable or Error.
return doesNotMatch();
}
CatchTree catchTree = catches.get(0);
VariableTree catchType = catchTree.getParameter();
boolean catchesThrowable = javaLangThrowable.matches(catchType, state);
boolean catchesError = javaLangError.matches(catchType, state);
boolean catchesOtherError = someAssertionFailure.matches(catchType, state);
if (!catchesThrowable && !catchesError && !catchesOtherError) {
return doesNotMatch();
}
// Verify that the catch block is empty or contains only comments.
List<? extends StatementTree> catchStatements = catchTree.getBlock().getStatements();
for (StatementTree catchStatement : catchStatements) {
// Comments are not a part of the AST. Therefore, we should either get
// an empty list of statements (regardless of the number of comments),
// or a list of empty statements.
if (!Matchers.<Tree>kindIs(EMPTY_STATEMENT).matches(catchStatement, state)) {
return doesNotMatch();
}
}
return matches(
failStatement,
catchesThrowable
? JAVA_LANG_THROWABLE
: catchesError ? JAVA_LANG_ERROR : SOME_ASSERTION_FAILURE);
}
示例8: tryTreeMatches
import com.sun.source.tree.CatchTree; //导入方法依赖的package包/类
private boolean tryTreeMatches(TryTree tryTree, VisitorState state) {
BlockTree tryBlock = tryTree.getBlock();
List<? extends StatementTree> statements = tryBlock.getStatements();
if (statements.isEmpty()) {
return false;
}
// Check if any of the statements is a fail or assert* method (i.e. any
// method that can throw an AssertionFailedError)
boolean foundFailOrAssert = false;
for (StatementTree statement : statements) {
if (!(statement instanceof ExpressionStatementTree)) {
continue;
}
if (failOrAssert.matches(
((ExpressionStatementTree) statement).getExpression(), state)) {
foundFailOrAssert = true;
break;
}
}
if (!foundFailOrAssert) {
return false;
}
// Verify that the only catch clause catches Throwable
List<? extends CatchTree> catches = tryTree.getCatches();
if (catches.size() != 1) {
// TODO(adamwos): this could be supported - only the last catch would need
// to be checked - it would either be Throwable or Error.
return false;
}
CatchTree catchTree = catches.get(0);
VariableTree catchType = catchTree.getParameter();
if (!javaLangThrowable.matches(catchType, state)) {
// TODO(adamwos): Error could be supported
return false;
}
// Verify that the catch block is empty or contains only comments.
List<? extends StatementTree> catchStatements = catchTree.getBlock().getStatements();
for (StatementTree catchStatement : catchStatements) {
// Comments are not a part of the AST. Therefore, we should either get
// an empty list of statements (regardless of the number of comments),
// or a list of empty statements.
if (!Matchers.<Tree>kindIs(EMPTY_STATEMENT).matches(catchStatement, state)) {
return false;
}
}
return true;
}
示例9: getUnionExceptions
import com.sun.source.tree.CatchTree; //导入方法依赖的package包/类
/**
* Helper that retrieves all caught exception from a conventional catch
* clause or from catch clause that contain alternatives. Empty collection
* is returned in the case of an error.
*
* @param ct catch clause
* @return exception list, never null.
*/
public static List<? extends TypeMirror> getUnionExceptions(CompilationInfo info, TreePath cP, CatchTree ct) {
if (ct.getParameter() == null) {
return Collections.emptyList();
}
TypeMirror exT = info.getTrees().getTypeMirror(new TreePath(cP, ct.getParameter()));
return getCaughtExceptions(exT);
}