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


Java XTryCatchFinallyExpression.getCatchClauses方法代码示例

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


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

示例1: checkCatchClausesOrder

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入方法依赖的package包/类
@Check
public void checkCatchClausesOrder(XTryCatchFinallyExpression expression) {
	ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), expression);
	List<LightweightTypeReference> previousTypeReferences = new ArrayList<LightweightTypeReference>();
	for (XCatchClause catchClause : expression.getCatchClauses()) {
		LightweightTypeReference actualTypeReference = owner.toLightweightTypeReference(catchClause.getDeclaredParam().getParameterType());
		if (actualTypeReference == null) {
			continue;
		}
		if (isHandled(actualTypeReference, previousTypeReferences)) {
			error("Unreachable code: The catch block can never match. It is already handled by a previous condition.", catchClause.getDeclaredParam().getParameterType(), null, IssueCodes.UNREACHABLE_CATCH_BLOCK);
			continue;
		}
		previousTypeReferences.add(actualTypeReference);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:XbaseValidator.java

示例2: caseXTryCatchFinallyExpression

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入方法依赖的package包/类
@Override
public Boolean caseXTryCatchFinallyExpression(XTryCatchFinallyExpression object) {
	List<XCatchClause> clauses = object.getCatchClauses();
	if (clauses.isEmpty()) {
		return Boolean.TRUE;
	}
	final List<LightweightTypeReference> caughtExceptions = Lists.newArrayList();
	boolean wasThrowable = false;
	for(XCatchClause clause: clauses) {
		JvmTypeReference caught = clause.getDeclaredParam().getParameterType();
		if (caught != null) {
			LightweightTypeReference caughtException = delegate.toLightweightReference(caught).getRawTypeReference();
			if (caughtException.isType(Throwable.class)) {
				wasThrowable = true;
			}
			caughtExceptions.add(caughtException);
		}
		delegate.collectThrownExceptions(clause.getExpression());
	}
	delegate.collectThrownExceptions(object.getFinallyExpression());
	if (wasThrowable) {
		return Boolean.FALSE;
	}
	delegate.catchExceptions(caughtExceptions).collectThrownExceptions(object.getExpression());
	return Boolean.FALSE;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:27,代码来源:ThrownExceptionSwitch.java

示例3: _exitPoints

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入方法依赖的package包/类
protected Collection<IEarlyExitComputer.ExitPoint> _exitPoints(final XTryCatchFinallyExpression expression) {
  Collection<IEarlyExitComputer.ExitPoint> tryExitPoints = this.getExitPoints(expression.getExpression());
  boolean _isNotEmpty = this.isNotEmpty(tryExitPoints);
  if (_isNotEmpty) {
    Collection<IEarlyExitComputer.ExitPoint> result = Lists.<IEarlyExitComputer.ExitPoint>newArrayList(tryExitPoints);
    EList<XCatchClause> _catchClauses = expression.getCatchClauses();
    for (final XCatchClause catchClause : _catchClauses) {
      {
        Collection<IEarlyExitComputer.ExitPoint> catchExitPoints = this.getExitPoints(catchClause.getExpression());
        boolean _isNotEmpty_1 = this.isNotEmpty(catchExitPoints);
        if (_isNotEmpty_1) {
          result.addAll(catchExitPoints);
        } else {
          return this.getExitPoints(expression.getFinallyExpression());
        }
      }
    }
    return result;
  }
  return this.getExitPoints(expression.getFinallyExpression());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:22,代码来源:DefaultEarlyExitComputer.java

示例4: appendCatchAndFinally

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入方法依赖的package包/类
protected void appendCatchAndFinally(XTryCatchFinallyExpression expr, ITreeAppendable b, boolean isReferenced) {
	final EList<XCatchClause> catchClauses = expr.getCatchClauses();
	if (!catchClauses.isEmpty()) {
		String variable = b.declareSyntheticVariable(Tuples.pair(expr, "_catchedThrowable"), "_t");
		b.append(" catch (final Throwable ").append(variable).append(") ");
		b.append("{").increaseIndentation();
		b.newLine();
		Iterator<XCatchClause> iterator = catchClauses.iterator();
		while (iterator.hasNext()) {
			XCatchClause catchClause = iterator.next();
			ITreeAppendable catchClauseAppendable = b.trace(catchClause);
			appendCatchClause(catchClause, isReferenced, variable, catchClauseAppendable);
			if (iterator.hasNext()) {
				b.append(" else ");
			}
		}
		b.append(" else {");
		b.increaseIndentation();
		final JvmType sneakyThrowType = findKnownTopLevelType(Exceptions.class, expr);
		if (sneakyThrowType == null) {
			b.append("COMPILE ERROR : '"+Exceptions.class.getCanonicalName()+"' could not be found on the classpath!");
		} else {
			b.newLine().append("throw ");
			b.append(sneakyThrowType);
			b.append(".sneakyThrow(");
			b.append(variable);
			b.append(");");
		}
		closeBlock(b);
		closeBlock(b);
	}
	final XExpression finallyExp = expr.getFinallyExpression();
	if (finallyExp != null) {
		b.append(" finally {").increaseIndentation();
		internalToJavaStatement(finallyExp, b, false);
		b.decreaseIndentation().newLine().append("}");
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:39,代码来源:XbaseCompiler.java

示例5: testTryCatchExpression

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入方法依赖的package包/类
@Test public void testTryCatchExpression() throws Exception {
	XTryCatchFinallyExpression exp = (XTryCatchFinallyExpression)  
			expressionWithExpectedType("try null catch (java.lang.Throwable t) null finally null", "String");

	assertExpected("java.lang.String", exp.getExpression());
	for (XCatchClause cc : exp.getCatchClauses()) {
		assertExpected("java.lang.String", cc.getExpression());
	}
	assertExpected(null, exp.getFinallyExpression());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:11,代码来源:XbaseExpectedTypeProviderTest.java

示例6: isIntentionalEarlyExit

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入方法依赖的package包/类
/**
 * Returns <code>true</code> for expressions that seem to be early exit expressions, e.g.
 * <pre>
 *   while(condition) {
 *     if (anotherCondition)
 *       return value
 *     changeResultOfFirstCondition
 *   }
 * </pre>
 */
public boolean isIntentionalEarlyExit(/* @Nullable */ XExpression expression) {
	if (expression == null) {
		return true;
	}
	if (expression instanceof XBlockExpression) {
		XBlockExpression block = (XBlockExpression) expression;
		List<XExpression> children = block.getExpressions();
		for(XExpression child: children) {
			if (isIntentionalEarlyExit(child)) {
				return true;
			}
		}
	} else if (expression instanceof XIfExpression) {
		return isIntentionalEarlyExit(((XIfExpression) expression).getThen()) 
				|| isIntentionalEarlyExit(((XIfExpression) expression).getElse());
	} else if (expression instanceof XSwitchExpression) {
		XSwitchExpression switchExpression = (XSwitchExpression) expression;
		for(XCasePart caseExpression: switchExpression.getCases()) {
			if (isIntentionalEarlyExit(caseExpression.getThen())) {
				return true;
			}
		}
		if (isIntentionalEarlyExit(switchExpression.getDefault())) {
			return true;
		}
	} else if (expression instanceof XTryCatchFinallyExpression) {
		XTryCatchFinallyExpression tryCatchFinally = (XTryCatchFinallyExpression) expression;
		if (isIntentionalEarlyExit(tryCatchFinally.getExpression())) {
			for(XCatchClause catchClause: tryCatchFinally.getCatchClauses()) {
				if (!isIntentionalEarlyExit(catchClause.getExpression()))
					return false;
			}
			return true;
		}
		return false;
	} else if (expression instanceof XAbstractWhileExpression) {
		return isIntentionalEarlyExit(((XAbstractWhileExpression) expression).getBody());
	} else if (expression instanceof XForLoopExpression) {
		return isIntentionalEarlyExit(((XForLoopExpression) expression).getEachExpression());
	} else if (expression instanceof XBasicForLoopExpression) {
		return isIntentionalEarlyExit(((XBasicForLoopExpression) expression).getEachExpression());
	} else if (expression instanceof XSynchronizedExpression) {
		return isIntentionalEarlyExit(((XSynchronizedExpression) expression).getExpression());
	}
	return expression instanceof XReturnExpression || expression instanceof XThrowExpression;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:57,代码来源:ExtendedEarlyExitComputer.java

示例7: isDefiniteEarlyExit

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入方法依赖的package包/类
public boolean isDefiniteEarlyExit(XExpression expression) {
	// TODO further improvements
	if (expression instanceof XIfExpression) {
		XIfExpression ifExpression = (XIfExpression) expression;
		return isDefiniteEarlyExit(ifExpression.getThen()) && isDefiniteEarlyExit(ifExpression.getElse());
	} else if (expression instanceof XSwitchExpression) {
		XSwitchExpression switchExpression = (XSwitchExpression) expression;
		if (isDefiniteEarlyExit(switchExpression.getDefault())) {
			for(XCasePart caseExpression: switchExpression.getCases()) {
				if (!isDefiniteEarlyExit(caseExpression.getThen())) {
					return false;
				}
			}
			return true;
		}
		return false;
	} else if (expression instanceof XTryCatchFinallyExpression) {
		XTryCatchFinallyExpression tryExpression = (XTryCatchFinallyExpression) expression;
		if (isDefiniteEarlyExit(tryExpression.getFinallyExpression())) {
			return true;
		}
		if (isDefiniteEarlyExit(tryExpression.getExpression())) {
			for(XCatchClause catchClause: tryExpression.getCatchClauses()) {
				if (!isDefiniteEarlyExit(catchClause.getExpression())) {
					return false;
				}
			}
			return true;
		}
		return false;
	} else if (expression instanceof XBlockExpression) {
		List<XExpression> expressions = ((XBlockExpression) expression).getExpressions();
		for(int i = expressions.size() - 1; i >= 0; i--) {
			if (isDefiniteEarlyExit(expressions.get(i))) {
				return true;
			}
		}
	} else if (expression instanceof XSynchronizedExpression) {
		return isDefiniteEarlyExit(((XSynchronizedExpression) expression).getExpression());
	}
	return expression instanceof XReturnExpression || expression instanceof XThrowExpression;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:43,代码来源:ExtendedEarlyExitComputer.java


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