本文整理汇总了Java中org.eclipse.xtext.xbase.XCatchClause类的典型用法代码示例。如果您正苦于以下问题:Java XCatchClause类的具体用法?Java XCatchClause怎么用?Java XCatchClause使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XCatchClause类属于org.eclipse.xtext.xbase包,在下文中一共展示了XCatchClause类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkCatchClausesOrder
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的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);
}
}
示例2: caseXTryCatchFinallyExpression
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的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;
}
示例3: appendCatchClause
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的package包/类
protected void appendCatchClause(XCatchClause catchClause, boolean parentIsReferenced, String parentVariable,
ITreeAppendable appendable) {
JvmTypeReference type = catchClause.getDeclaredParam().getParameterType();
final String declaredParamName = makeJavaIdentifier(catchClause.getDeclaredParam().getName());
final String name = appendable.declareVariable(catchClause.getDeclaredParam(), declaredParamName);
appendable.append("if (").append(parentVariable).append(" instanceof ");
serialize(type, catchClause, appendable);
appendable.append(") ").append("{");
appendable.increaseIndentation();
ITreeAppendable withDebugging = appendable.trace(catchClause, true);
if (!XbaseUsageCrossReferencer.find(catchClause.getDeclaredParam(), catchClause.getExpression()).isEmpty()) {
ITreeAppendable parameterAppendable = withDebugging.trace(catchClause.getDeclaredParam());
appendCatchClauseParameter(catchClause, type, name, parameterAppendable.newLine());
withDebugging.append(" = (");
serialize(type, catchClause, withDebugging);
withDebugging.append(")").append(parentVariable).append(";");
}
final boolean canBeReferenced = parentIsReferenced && ! isPrimitiveVoid(catchClause.getExpression());
internalToJavaStatement(catchClause.getExpression(), withDebugging, canBeReferenced);
if (canBeReferenced) {
appendable.newLine().append(getVarName(catchClause.eContainer(), appendable)).append(" = ");
internalToConvertedExpression(catchClause.getExpression(), appendable, getLightweightType((XExpression) catchClause.eContainer()));
appendable.append(";");
}
closeBlock(appendable);
}
示例4: eSet
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的package包/类
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
switch (featureID)
{
case XbasePackage.XTRY_CATCH_FINALLY_EXPRESSION__EXPRESSION:
setExpression((XExpression)newValue);
return;
case XbasePackage.XTRY_CATCH_FINALLY_EXPRESSION__FINALLY_EXPRESSION:
setFinallyExpression((XExpression)newValue);
return;
case XbasePackage.XTRY_CATCH_FINALLY_EXPRESSION__CATCH_CLAUSES:
getCatchClauses().clear();
getCatchClauses().addAll((Collection<? extends XCatchClause>)newValue);
return;
}
super.eSet(featureID, newValue);
}
示例5: _exitPoints
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的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());
}
示例6: sequence_XCatchClause
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的package包/类
/**
* Contexts:
* XCatchClause returns XCatchClause
*
* Constraint:
* (declaredParam=FullJvmFormalParameter expression=XExpression)
*/
protected void sequence_XCatchClause(ISerializationContext context, XCatchClause semanticObject) {
if (errorAcceptor != null) {
if (transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XCATCH_CLAUSE__DECLARED_PARAM) == ValueTransient.YES)
errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XCATCH_CLAUSE__DECLARED_PARAM));
if (transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XCATCH_CLAUSE__EXPRESSION) == ValueTransient.YES)
errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XCATCH_CLAUSE__EXPRESSION));
}
SequenceFeeder feeder = createSequencerFeeder(context, semanticObject);
feeder.accept(grammarAccess.getXCatchClauseAccess().getDeclaredParamFullJvmFormalParameterParserRuleCall_2_0(), semanticObject.getDeclaredParam());
feeder.accept(grammarAccess.getXCatchClauseAccess().getExpressionXExpressionParserRuleCall_4_0(), semanticObject.getExpression());
feeder.finish();
}
示例7: checkTypes
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的package包/类
@Check
public void checkTypes(XCatchClause catchClause) {
LightweightTypeReference parameterType = getActualType(catchClause, catchClause.getDeclaredParam());
if (parameterType != null && !parameterType.isSubtypeOf(Throwable.class)) {
error("No exception of type " + parameterType.getHumanReadableName()
+ " can be thrown; an exception type must be a subclass of Throwable",
catchClause.getDeclaredParam(), TypesPackage.Literals.JVM_FORMAL_PARAMETER__PARAMETER_TYPE,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_TYPES);
}
}
示例8: appendCatchAndFinally
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的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("}");
}
}
示例9: getCatchClauses
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的package包/类
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EList<XCatchClause> getCatchClauses()
{
if (catchClauses == null)
{
catchClauses = new EObjectContainmentEList<XCatchClause>(XCatchClause.class, this, XbasePackage.XTRY_CATCH_FINALLY_EXPRESSION__CATCH_CLAUSES);
}
return catchClauses;
}
示例10: _findImplicitReturns
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的package包/类
protected void _findImplicitReturns(final XTryCatchFinallyExpression expression, final ImplicitReturnFinder.Acceptor acceptor) {
this.findImplicitReturns(expression.getExpression(), acceptor);
final Consumer<XCatchClause> _function = (XCatchClause it) -> {
this.findImplicitReturns(it.getExpression(), acceptor);
};
expression.getCatchClauses().forEach(_function);
}
示例11: doTestTryCatchExpression
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的package包/类
protected void doTestTryCatchExpression(XTryCatchFinallyExpression tryEx) {
assertFeatureCall("foo", ((XThrowExpression)tryEx.getExpression()).getExpression());
assertFeatureCall("baz", tryEx.getFinallyExpression());
assertEquals(1,tryEx.getCatchClauses().size());
XCatchClause clause = tryEx.getCatchClauses().get(0);
assertFeatureCall("bar", clause.getExpression());
assertEquals("java.lang.Exception", clause.getDeclaredParam().getParameterType().getIdentifier());
assertEquals("e", clause.getDeclaredParam().getName());
}
示例12: doTestTryCatchExpression_2
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的package包/类
protected void doTestTryCatchExpression_2(XTryCatchFinallyExpression tryEx) {
assertFeatureCall("foo", tryEx.getExpression());
assertNull(tryEx.getFinallyExpression());
assertEquals(1,tryEx.getCatchClauses().size());
XCatchClause clause = tryEx.getCatchClauses().get(0);
assertFeatureCall("bar", clause.getExpression());
assertEquals("java.lang.Exception", clause.getDeclaredParam().getParameterType().getIdentifier());
assertEquals("e", clause.getDeclaredParam().getName());
}
示例13: testTryCatchExpression
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的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());
}
示例14: testTryCatch
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的package包/类
@Test
public void testTryCatch() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("try 1 catch(Exception e) 2");
XExpression _expression = this.expression(_builder);
final XTryCatchFinallyExpression expr = ((XTryCatchFinallyExpression) _expression);
this.hasImplicitReturns(expr, expr.getExpression(), IterableExtensions.<XCatchClause>head(expr.getCatchClauses()).getExpression());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例15: sequence_XCatchClause
import org.eclipse.xtext.xbase.XCatchClause; //导入依赖的package包/类
/**
* Constraint:
* (declaredParam=FullJvmFormalParameter expression=XExpression)
*/
protected void sequence_XCatchClause(EObject context, XCatchClause semanticObject) {
if(errorAcceptor != null) {
if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XCATCH_CLAUSE__EXPRESSION) == ValueTransient.YES)
errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XCATCH_CLAUSE__EXPRESSION));
if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XCATCH_CLAUSE__DECLARED_PARAM) == ValueTransient.YES)
errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XCATCH_CLAUSE__DECLARED_PARAM));
}
INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
feeder.accept(grammarAccess.getXCatchClauseAccess().getDeclaredParamFullJvmFormalParameterParserRuleCall_2_0(), semanticObject.getDeclaredParam());
feeder.accept(grammarAccess.getXCatchClauseAccess().getExpressionXExpressionParserRuleCall_4_0(), semanticObject.getExpression());
feeder.finish();
}