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


Java TryStatement.resources方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: handleResourceDeclarations

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
private void handleResourceDeclarations(TryStatement tryStatement) {
	List<VariableDeclarationExpression> resources= tryStatement.resources();
	for (Iterator<VariableDeclarationExpression> iterator= resources.iterator(); iterator.hasNext();) {
		iterator.next().accept(this);
	}

	//check if the exception is thrown as a result of resource#close()
	boolean exitMarked= false;
	for (VariableDeclarationExpression variable : resources) {
		Type type= variable.getType();
		IMethodBinding methodBinding= Bindings.findMethodInHierarchy(type.resolveBinding(), "close", new ITypeBinding[0]); //$NON-NLS-1$
		if (methodBinding != null) {
			ITypeBinding[] exceptionTypes= methodBinding.getExceptionTypes();
			for (int j= 0; j < exceptionTypes.length; j++) {
				if (matches(exceptionTypes[j])) { // a close() throws the caught exception
					// mark name of resource
					for (VariableDeclarationFragment fragment : (List<VariableDeclarationFragment>) variable.fragments()) {
						SimpleName name= fragment.getName();
						fResult.add(new OccurrenceLocation(name.getStartPosition(), name.getLength(), 0, fDescription));
					}
					if (!exitMarked) {
						// mark exit position
						exitMarked= true;
						Block body= tryStatement.getBody();
						int offset= body.getStartPosition() + body.getLength() - 1; // closing bracket of try block
						fResult.add(new OccurrenceLocation(offset, 1, 0, Messages.format(SearchMessages.ExceptionOccurrencesFinder_occurrence_implicit_close_description,
								BasicElementLabels.getJavaElementName(fException.getName()))));
					}
				}
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:34,代码来源:ExceptionOccurrencesFinder.java

示例5: 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

示例6: handleResourceDeclarations

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
private void handleResourceDeclarations(TryStatement tryStatement) {
	if (tryStatement.getAST().apiLevel() >= AST.JLS4) {
		List<VariableDeclarationExpression> resources= tryStatement.resources();
		for (Iterator<VariableDeclarationExpression> iterator= resources.iterator(); iterator.hasNext();) {
			iterator.next().accept(this);
		}

		//check if the exception is thrown as a result of resource#close()
		boolean exitMarked= false;
		for (VariableDeclarationExpression variable : resources) {
			Type type= variable.getType();
			IMethodBinding methodBinding= Bindings.findMethodInHierarchy(type.resolveBinding(), "close", new ITypeBinding[0]); //$NON-NLS-1$
			if (methodBinding != null) {
				ITypeBinding[] exceptionTypes= methodBinding.getExceptionTypes();
				for (int j= 0; j < exceptionTypes.length; j++) {
					if (matches(exceptionTypes[j])) { // a close() throws the caught exception
						// mark name of resource
						for (VariableDeclarationFragment fragment : (List<VariableDeclarationFragment>) variable.fragments()) {
							SimpleName name= fragment.getName();
							fResult.add(new OccurrenceLocation(name.getStartPosition(), name.getLength(), 0, fDescription));
						}
						if (!exitMarked) {
							// mark exit position
							exitMarked= true;
							Block body= tryStatement.getBody();
							int offset= body.getStartPosition() + body.getLength() - 1; // closing bracket of try block
							fResult.add(new OccurrenceLocation(offset, 1, 0, Messages.format(SearchMessages.ExceptionOccurrencesFinder_occurrence_implicit_close_description,
									BasicElementLabels.getJavaElementName(fException.getName()))));
						}
					}
				}
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:36,代码来源:ExceptionOccurrencesFinder.java

示例7: visit

import org.eclipse.jdt.core.dom.TryStatement; //导入方法依赖的package包/类
public boolean visit(TryStatement node) {
	printIndent();
	this.buffer.append("try ");//$NON-NLS-1$
	if (node.getAST().apiLevel() >= AST.JLS4) {
		List resources = node.resources();
		if (!resources.isEmpty()) {
			this.buffer.append('(');
			for (Iterator it = resources.iterator(); it.hasNext(); ) {
				VariableDeclarationExpression variable = (VariableDeclarationExpression) it.next();
				variable.accept(this);
				if (it.hasNext()) {
					this.buffer.append(';');
				}
			}
			this.buffer.append(')');
		}
	}
	node.getBody().accept(this);
	this.buffer.append(" ");//$NON-NLS-1$
	for (Iterator it = node.catchClauses().iterator(); it.hasNext(); ) {
		CatchClause cc = (CatchClause) it.next();
		cc.accept(this);
	}
	if (node.getFinally() != null) {
		this.buffer.append(" finally ");//$NON-NLS-1$
		node.getFinally().accept(this);
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:30,代码来源:NaiveASTFlattener.java


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