本文整理汇总了Java中org.eclipse.jdt.core.dom.CatchClause类的典型用法代码示例。如果您正苦于以下问题:Java CatchClause类的具体用法?Java CatchClause怎么用?Java CatchClause使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CatchClause类属于org.eclipse.jdt.core.dom包,在下文中一共展示了CatchClause类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStatementType
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
/**
* Method that check statement type.
* @author Mariana Azevedo
* @since 13/07/2014
* @param itStatement
*/
private void getStatementType(Object itStatement) {
if (itStatement instanceof CatchClause){
this.visitor.visit((CatchClause)itStatement);
}else if (itStatement instanceof ForStatement){
this.visitor.visit((ForStatement)itStatement);
}else if (itStatement instanceof IfStatement){
this.visitor.visit((IfStatement)itStatement);
}else if (itStatement instanceof WhileStatement){
this.visitor.visit((WhileStatement)itStatement);
}else if (itStatement instanceof TryStatement){
this.visitor.visit((TryStatement)itStatement);
}else if (itStatement instanceof ConditionalExpression){
this.visitor.visit((ConditionalExpression)itStatement);
}else if (itStatement instanceof SwitchCase){
this.visitor.visit((SwitchCase)itStatement);
}else if (itStatement instanceof DoStatement){
this.visitor.visit((DoStatement)itStatement);
}else if (itStatement instanceof ExpressionStatement){
this.visitor.visit((ExpressionStatement)itStatement);
}
}
示例2: isExceptionCaught
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
boolean isExceptionCaught(ITypeBinding excpetionType) {
for (Iterator<List<CatchClause>> exceptions= fExceptionStack.iterator(); exceptions.hasNext(); ) {
for (Iterator<CatchClause> catchClauses= exceptions.next().iterator(); catchClauses.hasNext(); ) {
SingleVariableDeclaration caughtException= catchClauses.next().getException();
IVariableBinding binding= caughtException.resolveBinding();
if (binding == null) {
continue;
}
ITypeBinding caughtype= binding.getType();
while (caughtype != null) {
if (caughtype == excpetionType) {
return true;
}
caughtype= caughtype.getSuperclass();
}
}
}
return false;
}
示例3: visit
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
@Override
public boolean visit(TryStatement node) {
if (traverseNode(node)) {
fFlowContext.pushExcptions(node);
for (Iterator<VariableDeclarationExpression> iterator = node.resources().iterator(); iterator.hasNext();) {
iterator.next().accept(this);
}
node.getBody().accept(this);
fFlowContext.popExceptions();
List<CatchClause> catchClauses = node.catchClauses();
for (Iterator<CatchClause> iter = catchClauses.iterator(); iter.hasNext();) {
iter.next().accept(this);
}
Block finallyBlock = node.getFinally();
if (finallyBlock != null) {
finallyBlock.accept(this);
}
}
return false;
}
示例4: endVisit
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
@Override
public void endVisit(TryStatement node) {
if (skipNode(node)) {
return;
}
TryFlowInfo info = createTry();
setFlowInfo(node, info);
for (Iterator<VariableDeclarationExpression> iterator = node.resources().iterator(); iterator.hasNext();) {
info.mergeResources(getFlowInfo(iterator.next()), fFlowContext);
}
info.mergeTry(getFlowInfo(node.getBody()), fFlowContext);
for (Iterator<CatchClause> iter = node.catchClauses().iterator(); iter.hasNext();) {
CatchClause element = iter.next();
info.mergeCatch(getFlowInfo(element), fFlowContext);
}
info.mergeFinally(getFlowInfo(node.getFinally()), fFlowContext);
}
示例5: endVisit
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
@Override
public void endVisit(TryStatement node) {
ASTNode firstSelectedNode = getFirstSelectedNode();
if (getSelection().getEndVisitSelectionMode(node) == Selection.AFTER) {
if (firstSelectedNode == node.getBody() || firstSelectedNode == node.getFinally()) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_try_statement);
} else {
List<CatchClause> catchClauses = node.catchClauses();
for (Iterator<CatchClause> iterator = catchClauses.iterator(); iterator.hasNext();) {
CatchClause element = iterator.next();
if (element == firstSelectedNode || element.getBody() == firstSelectedNode) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_try_statement);
} else if (element.getException() == firstSelectedNode) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_catch_argument);
}
}
}
}
super.endVisit(node);
}
示例6: isExceptionCaught
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
boolean isExceptionCaught(ITypeBinding excpetionType) {
for (Iterator<List<CatchClause>> exceptions = fExceptionStack.iterator();
exceptions.hasNext(); ) {
for (Iterator<CatchClause> catchClauses = exceptions.next().iterator();
catchClauses.hasNext(); ) {
SingleVariableDeclaration caughtException = catchClauses.next().getException();
IVariableBinding binding = caughtException.resolveBinding();
if (binding == null) continue;
ITypeBinding caughtype = binding.getType();
while (caughtype != null) {
if (caughtype == excpetionType) return true;
caughtype = caughtype.getSuperclass();
}
}
}
return false;
}
示例7: create
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
@Override
public ITypeConstraint[] create(CatchClause node) {
SingleVariableDeclaration exception = node.getException();
ConstraintVariable nameVariable =
fConstraintVariableFactory.makeExpressionOrTypeVariable(exception.getName(), getContext());
ITypeConstraint[] defines =
fTypeConstraintFactory.createDefinesConstraint(
nameVariable, fConstraintVariableFactory.makeTypeVariable(exception.getType()));
ITypeBinding throwable =
node.getAST().resolveWellKnownType("java.lang.Throwable"); // $NON-NLS-1$
ITypeConstraint[] catchBound =
fTypeConstraintFactory.createSubtypeConstraint(
nameVariable, fConstraintVariableFactory.makeRawBindingVariable(throwable));
ArrayList<ITypeConstraint> result = new ArrayList<ITypeConstraint>();
result.addAll(Arrays.asList(defines));
result.addAll(Arrays.asList(catchBound));
return result.toArray(new ITypeConstraint[result.size()]);
}
示例8: endVisit
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
@Override
public void endVisit(TryStatement node) {
ASTNode firstSelectedNode = getFirstSelectedNode();
if (getSelection().getEndVisitSelectionMode(node) == Selection.AFTER) {
if (firstSelectedNode == node.getBody() || firstSelectedNode == node.getFinally()) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_try_statement);
} else {
List<CatchClause> catchClauses = node.catchClauses();
for (Iterator<CatchClause> iterator = catchClauses.iterator(); iterator.hasNext(); ) {
CatchClause element = iterator.next();
if (element == firstSelectedNode || element.getBody() == firstSelectedNode) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_try_statement);
} else if (element.getException() == firstSelectedNode) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_catch_argument);
}
}
}
}
super.endVisit(node);
}
示例9: checkSelection
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
private RefactoringStatus checkSelection(VariableDeclaration decl) {
ASTNode parent= decl.getParent();
if (parent instanceof MethodDeclaration) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_method_parameter);
}
if (parent instanceof CatchClause) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_exceptions_declared);
}
if (parent instanceof VariableDeclarationExpression && parent.getLocationInParent() == ForStatement.INITIALIZERS_PROPERTY) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_for_initializers);
}
if (parent instanceof VariableDeclarationExpression && parent.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_resource_in_try_with_resources);
}
if (decl.getInitializer() == null) {
String message= Messages.format(RefactoringCoreMessages.InlineTempRefactoring_not_initialized, BasicElementLabels.getJavaElementName(decl.getName().getIdentifier()));
return RefactoringStatus.createFatalErrorStatus(message);
}
return checkAssignments(decl);
}
示例10: isExceptionCaught
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
boolean isExceptionCaught(ITypeBinding excpetionType) {
for (Iterator<List<CatchClause>> exceptions= fExceptionStack.iterator(); exceptions.hasNext(); ) {
for (Iterator<CatchClause> catchClauses= exceptions.next().iterator(); catchClauses.hasNext(); ) {
SingleVariableDeclaration caughtException= catchClauses.next().getException();
IVariableBinding binding= caughtException.resolveBinding();
if (binding == null)
continue;
ITypeBinding caughtype= binding.getType();
while (caughtype != null) {
if (caughtype == excpetionType)
return true;
caughtype= caughtype.getSuperclass();
}
}
}
return false;
}
示例11: visit
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
@Override
public boolean visit(TryStatement node) {
if (traverseNode(node)) {
fFlowContext.pushExcptions(node);
node.getBody().accept(this);
fFlowContext.popExceptions();
List<CatchClause> catchClauses= node.catchClauses();
for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext();) {
iter.next().accept(this);
}
Block finallyBlock= node.getFinally();
if (finallyBlock != null) {
finallyBlock.accept(this);
}
}
return false;
}
示例12: create
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
@Override
public ITypeConstraint[] create(CatchClause node) {
SingleVariableDeclaration exception= node.getException();
ConstraintVariable nameVariable= fConstraintVariableFactory.makeExpressionOrTypeVariable(exception.getName(), getContext());
ITypeConstraint[] defines= fTypeConstraintFactory.createDefinesConstraint(
nameVariable,
fConstraintVariableFactory.makeTypeVariable(exception.getType()));
ITypeBinding throwable= node.getAST().resolveWellKnownType("java.lang.Throwable"); //$NON-NLS-1$
ITypeConstraint[] catchBound= fTypeConstraintFactory.createSubtypeConstraint(
nameVariable,
fConstraintVariableFactory.makeRawBindingVariable(throwable));
ArrayList<ITypeConstraint> result= new ArrayList<ITypeConstraint>();
result.addAll(Arrays.asList(defines));
result.addAll(Arrays.asList(catchBound));
return result.toArray(new ITypeConstraint[result.size()]);
}
示例13: endVisit
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
@Override
public void endVisit(TryStatement node) {
ASTNode firstSelectedNode= getFirstSelectedNode();
if (getSelection().getEndVisitSelectionMode(node) == Selection.AFTER) {
if (firstSelectedNode == node.getBody() || firstSelectedNode == node.getFinally()) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_try_statement);
} else {
List<CatchClause> catchClauses= node.catchClauses();
for (Iterator<CatchClause> iterator= catchClauses.iterator(); iterator.hasNext();) {
CatchClause element= iterator.next();
if (element == firstSelectedNode || element.getBody() == firstSelectedNode) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_try_statement);
} else if (element.getException() == firstSelectedNode) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_catch_argument);
}
}
}
}
super.endVisit(node);
}
示例14: visit
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
/**
* 'catch(' exception ')' '{' body '}'
*/
@Override
public boolean visit(final CatchClause node)
{
final int lineNo = lineStart(node);
// new dependence
final IResolvedLine rd = createDependence(LK_CATCH, lineNo, mdg.parent());
// control node parent
final ASTNode controlNode = ASTTools.enclosingControlScope(node);
// last line of the control scope
final int lineEnd = lineEnd(controlNode);
// the catch dependence must be propagated to all lines in the method's body
jumpDependences.put(lineEnd, rd);
// new variable use
final IResolvedData rv = factory.resolveExpression(node.getException().getName(), node, null,
false, true);
// map this definition
rd.definitions().add(rv);
// append the control dependence
rd.uses().add(rv);
// recursively append dependences
appendRecursive(lineNo, rd, node.getBody());
// do not visit children
return false;
}
示例15: handle
import org.eclipse.jdt.core.dom.CatchClause; //导入依赖的package包/类
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
// restriction: considering only the first catch clause
DSubTree Ttry = new DOMBlock(statement.getBody()).handle();
DSubTree Tcatch;
if (! statement.catchClauses().isEmpty())
Tcatch = new DOMCatchClause((CatchClause) statement.catchClauses().get(0)).handle();
else
Tcatch = new DSubTree();
DSubTree Tfinally = new DOMBlock(statement.getFinally()).handle();
boolean except = Ttry.isValid() && Tcatch.isValid();
if (except)
tree.addNode(new DExcept(Ttry.getNodes(), Tcatch.getNodes()));
else {
// only one of these will add nodes
tree.addNodes(Ttry.getNodes());
tree.addNodes(Tcatch.getNodes());
}
tree.addNodes(Tfinally.getNodes());
return tree;
}