当前位置: 首页>>代码示例>>Java>>正文


Java TryStatement.catchClauses方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.TryStatement.catchClauses方法的典型用法代码示例。如果您正苦于以下问题:Java TryStatement.catchClauses方法的具体用法?Java TryStatement.catchClauses怎么用?Java TryStatement.catchClauses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.TryStatement的用法示例。


在下文中一共展示了TryStatement.catchClauses方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:21,代码来源:FlowAnalyzer.java

示例2: endVisit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:21,代码来源:StatementAnalyzer.java

示例3: endVisit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:StatementAnalyzer.java

示例4: visit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:FlowAnalyzer.java

示例5: endVisit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:StatementAnalyzer.java

示例6: visit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
public boolean visit(TryStatement node) {
	if (mtbStack.isEmpty()) // not part of a method
		return true;

	String bodyStr = node.getBody() != null ? node.getBody().toString()
			: "";
	bodyStr = edit_str(bodyStr);
	StringBuilder catchClauses = new StringBuilder();
	for (Object o : node.catchClauses()) {
		if (catchClauses.length() > 0)
			catchClauses.append(",");
		CatchClause c = (CatchClause) o;
		catchClauses.append(getQualifiedName(c.getException().getType()
				.resolveBinding()));
		catchClauses.append(":");
		if (c.getBody() != null)
			catchClauses.append(edit_str(c.getBody().toString()));
	}
	String finallyStr = node.getFinally() != null ? node.getFinally()
			.toString() : "";
	finallyStr = edit_str(finallyStr);

	IMethodBinding mtb = mtbStack.peek();
	String methodStr = getQualifiedName(mtb);

	facts.add(Fact.makeTryCatchFact(bodyStr, catchClauses.toString(),
			finallyStr, methodStr));

	return true;
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:31,代码来源:ASTVisitorAtomicChange.java

示例7: pushExcptions

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
void pushExcptions(TryStatement node) {
	List<CatchClause> catchClauses= node.catchClauses();
	if (catchClauses == null) {
		catchClauses= EMPTY_CATCH_CLAUSE;
	}
	fExceptionStack.add(catchClauses);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:8,代码来源:FlowContext.java

示例8: visit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
@Override
public boolean visit(TryStatement node) {
	fCurrentExceptions = new ArrayList<>(1);
	fTryStack.push(fCurrentExceptions);

	// visit try block
	node.getBody().accept(this);

	List<VariableDeclarationExpression> resources = node.resources();
	for (Iterator<VariableDeclarationExpression> iterator = resources.iterator(); iterator.hasNext();) {
		iterator.next().accept(this);
	}

	// Remove those exceptions that get catch by following catch blocks
	List<CatchClause> catchClauses = node.catchClauses();
	if (!catchClauses.isEmpty()) {
		handleCatchArguments(catchClauses);
	}
	List<ITypeBinding> current = fTryStack.pop();
	fCurrentExceptions = fTryStack.peek();
	for (Iterator<ITypeBinding> iter = current.iterator(); iter.hasNext();) {
		addException(iter.next(), node.getAST());
	}

	// visit catch and finally
	for (Iterator<CatchClause> iter = catchClauses.iterator(); iter.hasNext();) {
		iter.next().accept(this);
	}
	if (node.getFinally() != null) {
		node.getFinally().accept(this);
	}

	// return false. We have visited the body by ourselves.
	return false;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:36,代码来源:AbstractExceptionAnalyzer.java

示例9: visit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
public boolean visit(TryStatement node)
{
  if (this.mtbStack.isEmpty()) {
    return true;
  }
  String bodyStr = node.getBody() != null ? node.getBody().toString() : 
    "";
  bodyStr = edit_str(bodyStr);
  StringBuilder catchClauses = new StringBuilder();
  for (Object o : node.catchClauses())
  {
    if (catchClauses.length() > 0) {
      catchClauses.append(",");
    }
    CatchClause c = (CatchClause)o;
    catchClauses.append(getQualifiedName(c.getException().getType()
      .resolveBinding()));
    catchClauses.append(":");
    if (c.getBody() != null) {
      catchClauses.append(edit_str(c.getBody().toString()));
    }
  }
  String finallyStr = node.getFinally() != null ? node.getFinally()
    .toString() : "";
  finallyStr = edit_str(finallyStr);
  
  IMethodBinding mtb = (IMethodBinding)this.mtbStack.peek();
  String methodStr = getQualifiedName(mtb);
  
  this.facts.add(Fact.makeTryCatchFact(bodyStr, catchClauses.toString(), 
    finallyStr, methodStr));
  
  return true;
}
 
开发者ID:SEAL-UCLA,项目名称:Ref-Finder,代码行数:35,代码来源:ASTVisitorAtomicChange.java

示例10: visit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
@Override
public boolean visit(TryStatement node) {
  fCurrentExceptions = new ArrayList<ITypeBinding>(1);
  fTryStack.push(fCurrentExceptions);

  // visit try block
  node.getBody().accept(this);

  List<VariableDeclarationExpression> resources = node.resources();
  for (Iterator<VariableDeclarationExpression> iterator = resources.iterator();
      iterator.hasNext(); ) {
    iterator.next().accept(this);
  }

  // Remove those exceptions that get catch by following catch blocks
  List<CatchClause> catchClauses = node.catchClauses();
  if (!catchClauses.isEmpty()) handleCatchArguments(catchClauses);
  List<ITypeBinding> current = fTryStack.pop();
  fCurrentExceptions = fTryStack.peek();
  for (Iterator<ITypeBinding> iter = current.iterator(); iter.hasNext(); ) {
    addException(iter.next(), node.getAST());
  }

  // visit catch and finally
  for (Iterator<CatchClause> iter = catchClauses.iterator(); iter.hasNext(); ) {
    iter.next().accept(this);
  }
  if (node.getFinally() != null) node.getFinally().accept(this);

  // return false. We have visited the body by ourselves.
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:33,代码来源:AbstractExceptionAnalyzer.java

示例11: handleException

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
/**
 * @param nodeContaingException
 *            The node that throws an exception.
 * @param exceptionTypes
 *            The list of exceptions being thrown.
 * @throws JavaModelException
 */
private void handleException(ASTNode nodeContaingException, ITypeBinding... exceptionTypes)
		throws JavaModelException {
	Set<ITypeBinding> thrownExceptionTypeSet = new HashSet<ITypeBinding>(Arrays.asList(exceptionTypes));

	// getting the parent node to check if it's an instance of tryStatement
	ASTNode tryStatementParent = (nodeContaingException.getParent()).getParent();
	ASTNode throwStatementParent = tryStatementParent.getParent();

	if (throwStatementParent instanceof TryStatement) {
		System.out.println("this is throwStatementParent");
		this.encounteredThrownCheckedException = false;
	}

	// findTryStatmaent if there is any catch block
	else if (tryStatementParent instanceof TryStatement) {

		TryStatement tryStatement = (TryStatement) tryStatementParent;
		@SuppressWarnings("unchecked")
		List<CatchClause> catchClauses = tryStatement.catchClauses();

		Stream<SingleVariableDeclaration> catchVarDeclStream = catchClauses.stream().map(CatchClause::getException);
		Stream<Type> caughtExceptionTypeNodeStream = catchVarDeclStream.map(SingleVariableDeclaration::getType);
		Stream<ITypeBinding> caughtExceptionTypeBindingStream = caughtExceptionTypeNodeStream
				.map(Type::resolveBinding);
		Stream<IJavaElement> caughtExceptionTypeJavaStream = caughtExceptionTypeBindingStream
				.map(ITypeBinding::getJavaElement);

		// for each thrown exception type, check if it is a sub-type of the
		// caught exceptions types.
		for (ITypeBinding te : thrownExceptionTypeSet) {
			IType javaType = (IType) te.getJavaElement();
			ITypeHierarchy supertypeHierarchy = javaType.newSupertypeHierarchy(monitor);
			this.encounteredThrownCheckedException = !caughtExceptionTypeJavaStream
					.anyMatch(t -> supertypeHierarchy.contains((IType) t));
		}
	} else {
		this.encounteredThrownCheckedException = true;
	}
}
 
开发者ID:mdarefin,项目名称:Convert-For-Each-Loop-to-Lambda-Expression-Eclipse-Plugin,代码行数:47,代码来源:EnhancedForStatementVisitor.java

示例12: visit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
@Override
public boolean visit(TryStatement node) {
	fCurrentExceptions= new ArrayList<ITypeBinding>(1);
	fTryStack.push(fCurrentExceptions);

	// visit try block
	node.getBody().accept(this);

	List<VariableDeclarationExpression> resources= node.resources();
	for (Iterator<VariableDeclarationExpression> iterator= resources.iterator(); iterator.hasNext();) {
		iterator.next().accept(this);
	}

	// Remove those exceptions that get catch by following catch blocks
	List<CatchClause> catchClauses= node.catchClauses();
	if (!catchClauses.isEmpty())
		handleCatchArguments(catchClauses);
	List<ITypeBinding> current= fTryStack.pop();
	fCurrentExceptions= fTryStack.peek();
	for (Iterator<ITypeBinding> iter= current.iterator(); iter.hasNext();) {
		addException(iter.next(), node.getAST());
	}

	// visit catch and finally
	for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext(); ) {
		iter.next().accept(this);
	}
	if (node.getFinally() != null)
		node.getFinally().accept(this);

	// return false. We have visited the body by ourselves.
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:34,代码来源:AbstractExceptionAnalyzer.java

示例13: visit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
@Override
public boolean visit(TryStatement node) {
	int currentSize= fCaughtExceptions.size();
	List<CatchClause> catchClauses= node.catchClauses();
	for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext();) {
		Type type= iter.next().getException().getType();
		if (type instanceof UnionType) {
			List<Type> types= ((UnionType) type).types();
			for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) {
				addCaughtException(iterator.next());
			}
		} else {
			addCaughtException(type);
		}
	}

	node.getBody().accept(this);

	handleResourceDeclarations(node);

	int toRemove= fCaughtExceptions.size() - currentSize;
	for (int i= toRemove; i > 0; i--) {
		fCaughtExceptions.remove(currentSize);
	}

	// visit catch and finally
	for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext();) {
		iter.next().accept(this);
	}
	if (node.getFinally() != null)
		node.getFinally().accept(this);

	// return false. We have visited the body by ourselves.
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:36,代码来源:ExceptionOccurrencesFinder.java

示例14: visit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
@Override
public boolean visit(TryStatement node) {
	fCurrentExceptions= new ArrayList<ITypeBinding>(1);
	fTryStack.push(fCurrentExceptions);

	// visit try block
	node.getBody().accept(this);

	if (node.getAST().apiLevel() >= AST.JLS4) {
		List<VariableDeclarationExpression> resources= node.resources();
		for (Iterator<VariableDeclarationExpression> iterator= resources.iterator(); iterator.hasNext();) {
			iterator.next().accept(this);
		}
	}

	// Remove those exceptions that get catch by following catch blocks
	List<CatchClause> catchClauses= node.catchClauses();
	if (!catchClauses.isEmpty())
		handleCatchArguments(catchClauses);
	List<ITypeBinding> current= fTryStack.pop();
	fCurrentExceptions= fTryStack.peek();
	for (Iterator<ITypeBinding> iter= current.iterator(); iter.hasNext();) {
		addException(iter.next());
	}

	// visit catch and finally
	for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext(); ) {
		iter.next().accept(this);
	}
	if (node.getFinally() != null)
		node.getFinally().accept(this);

	// return false. We have visited the body by ourselves.
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:36,代码来源:AbstractExceptionAnalyzer.java

示例15: pushExcptions

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
void pushExcptions(TryStatement node) {
  List<CatchClause> catchClauses = node.catchClauses();
  if (catchClauses == null) catchClauses = EMPTY_CATCH_CLAUSE;
  fExceptionStack.add(catchClauses);
}
 
开发者ID:eclipse,项目名称:che,代码行数:6,代码来源:FlowContext.java


注:本文中的org.eclipse.jdt.core.dom.TryStatement.catchClauses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。