本文整理汇总了Java中org.eclipse.xtext.xbase.XThrowExpression类的典型用法代码示例。如果您正苦于以下问题:Java XThrowExpression类的具体用法?Java XThrowExpression怎么用?Java XThrowExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XThrowExpression类属于org.eclipse.xtext.xbase包,在下文中一共展示了XThrowExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkInvalidReturnExpression
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
@Check
public void checkInvalidReturnExpression(XExpression expression) {
final EReference contFeature = (EReference) expression.eContainingFeature();
final Map<EReference, EarlyExitKind> map = getDisallowedEarlyExitReferences();
if (map.containsKey(contFeature)) {
EarlyExitKind exitKind = map.get(contFeature);
List<XExpression> returns = newArrayList();
collectExits(expression, returns);
for (XExpression expr : returns) {
if (expr instanceof XReturnExpression && (exitKind == EarlyExitKind.RETURN || exitKind == EarlyExitKind.BOTH)) {
error("A return expression is not allowed in this context.", expr, null, IssueCodes.INVALID_EARLY_EXIT);
}
if (expr instanceof XThrowExpression && (exitKind == EarlyExitKind.THROW || exitKind == EarlyExitKind.BOTH)) {
error("A throw expression is not allowed in this context.", expr, null, IssueCodes.INVALID_EARLY_EXIT);
}
}
}
}
示例2: checkValidReturn
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
protected void checkValidReturn(XReturnExpression object, ITypeComputationState state) {
// if the expectation comes from a method's return type
// then it is legal, thus we must check if the return is
// contained in a throw expression
if (hasThrowableExpectation(state) &&
EcoreUtil2.getContainerOfType(object, XThrowExpression.class) != null) {
state.addDiagnostic(new EObjectDiagnosticImpl(
Severity.ERROR,
IssueCodes.INVALID_RETURN,
"Invalid return inside throw.",
object,
null,
-1,
new String[] {
}));
}
}
示例3: collectExits
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
protected void collectExits(EObject expr, List<XExpression> found) {
if (expr instanceof XReturnExpression) {
found.add((XExpression) expr);
} else if (expr instanceof XThrowExpression) {
found.add((XExpression) expr);
} else if (expr instanceof XClosure) {
return;
}
for (EObject child : expr.eContents()) {
collectExits(child, found);
}
}
示例4: _computeTypes
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
protected void _computeTypes(XThrowExpression object, ITypeComputationState state) {
LightweightTypeReference throwable = getRawTypeForName(Throwable.class, state);
ITypeComputationState expressionState = state.withExpectation(throwable);
ITypeComputationResult types = expressionState.computeTypes(object.getExpression());
LightweightTypeReference thrownException = types.getActualExpressionType();
state.acceptActualType(getPrimitiveVoid(state), ConformanceFlags.NO_IMPLICIT_RETURN | ConformanceFlags.THROWN_EXCEPTION);
if (thrownException != null && !thrownException.isUnknown()) {
if (!state.isIgnored(IssueCodes.UNHANDLED_EXCEPTION) && thrownException.isSubtypeOf(Throwable.class)
&& !thrownException.isSubtypeOf(RuntimeException.class) && !thrownException.isSubtypeOf(Error.class)) {
boolean declarationFound = false;
for (LightweightTypeReference declaredException : state.getExpectedExceptions())
if (declaredException.isAssignableFrom(thrownException)) {
declarationFound = true;
break;
}
if (!declarationFound) {
JvmType exceptionType = thrownException.getNamedType().getType();
state.addDiagnostic(new EObjectDiagnosticImpl(
expressionState.getSeverity(IssueCodes.UNHANDLED_EXCEPTION),
IssueCodes.UNHANDLED_EXCEPTION,
"Unhandled exception type " + exceptionType.getSimpleName(),
object,
XbasePackage.Literals.XTHROW_EXPRESSION__EXPRESSION,
-1,
new String[] {
EcoreUtil.getURI(exceptionType).toString(),
EcoreUtil.getURI(object).toString()
}));
}
}
}
}
示例5: internalToConvertedExpression
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
@Override
protected void internalToConvertedExpression(XExpression obj, ITreeAppendable appendable) {
if (obj instanceof XBlockExpression) {
_toJavaExpression((XBlockExpression) obj, appendable);
} else if (obj instanceof XCastedExpression) {
_toJavaExpression((XCastedExpression) obj, appendable);
} else if (obj instanceof XClosure) {
_toJavaExpression((XClosure) obj, appendable);
} else if (obj instanceof XAnnotation) {
_toJavaExpression((XAnnotation) obj, appendable);
} else if (obj instanceof XConstructorCall) {
_toJavaExpression((XConstructorCall) obj, appendable);
} else if (obj instanceof XIfExpression) {
_toJavaExpression((XIfExpression) obj, appendable);
} else if (obj instanceof XInstanceOfExpression) {
_toJavaExpression((XInstanceOfExpression) obj, appendable);
} else if (obj instanceof XSwitchExpression) {
_toJavaExpression((XSwitchExpression) obj, appendable);
} else if (obj instanceof XTryCatchFinallyExpression) {
_toJavaExpression((XTryCatchFinallyExpression) obj, appendable);
} else if (obj instanceof XListLiteral) {
_toJavaExpression((XListLiteral) obj, appendable);
} else if (obj instanceof XSetLiteral) {
_toJavaExpression((XSetLiteral) obj, appendable);
} else if (obj instanceof XSynchronizedExpression) {
_toJavaExpression((XSynchronizedExpression) obj, appendable);
} else if (obj instanceof XReturnExpression) {
_toJavaExpression((XReturnExpression) obj, appendable);
} else if (obj instanceof XThrowExpression) {
_toJavaExpression((XThrowExpression) obj, appendable);
} else {
super.internalToConvertedExpression(obj, appendable);
}
}
示例6: _toJavaStatement
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
/**
* @param isReferenced unused in this context but necessary for dispatch signature
*/
protected void _toJavaStatement(XThrowExpression expr, ITreeAppendable b, boolean isReferenced) {
internalToJavaStatement(expr.getExpression(), b, true);
b.newLine().append("throw ");
internalToConvertedExpression(expr.getExpression(), b, null);
b.append(";");
}
示例7: _doEvaluate
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
protected Object _doEvaluate(XThrowExpression throwExpression, IEvaluationContext context, CancelIndicator indicator) {
Object thrown = internalEvaluate(throwExpression.getExpression(), context, indicator);
if (thrown == null) {
return throwNullPointerException(throwExpression, "throwable expression evaluated to 'null'");
}
if (!(thrown instanceof Throwable)) {
return throwClassCastException(throwExpression.getExpression(), thrown, Throwable.class);
}
throw new EvaluationException((Throwable) thrown);
}
示例8: _format
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
protected void _format(final XThrowExpression expr, @Extension final IFormattableDocument format) {
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
format.<XExpression>prepend(expr.getExpression(), _function);
format.<XExpression>format(expr.getExpression());
}
示例9: exitPoints
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
protected Collection<IEarlyExitComputer.ExitPoint> exitPoints(final XExpression expression) {
if (expression instanceof XDoWhileExpression) {
return _exitPoints((XDoWhileExpression)expression);
} else if (expression instanceof XWhileExpression) {
return _exitPoints((XWhileExpression)expression);
} else if (expression instanceof XAbstractFeatureCall) {
return _exitPoints((XAbstractFeatureCall)expression);
} else if (expression instanceof XBasicForLoopExpression) {
return _exitPoints((XBasicForLoopExpression)expression);
} else if (expression instanceof XBlockExpression) {
return _exitPoints((XBlockExpression)expression);
} else if (expression instanceof XConstructorCall) {
return _exitPoints((XConstructorCall)expression);
} else if (expression instanceof XForLoopExpression) {
return _exitPoints((XForLoopExpression)expression);
} else if (expression instanceof XIfExpression) {
return _exitPoints((XIfExpression)expression);
} else if (expression instanceof XReturnExpression) {
return _exitPoints((XReturnExpression)expression);
} else if (expression instanceof XSwitchExpression) {
return _exitPoints((XSwitchExpression)expression);
} else if (expression instanceof XSynchronizedExpression) {
return _exitPoints((XSynchronizedExpression)expression);
} else if (expression instanceof XThrowExpression) {
return _exitPoints((XThrowExpression)expression);
} else if (expression instanceof XTryCatchFinallyExpression) {
return _exitPoints((XTryCatchFinallyExpression)expression);
} else if (expression instanceof XVariableDeclaration) {
return _exitPoints((XVariableDeclaration)expression);
} else if (expression != null) {
return _exitPoints(expression);
} else {
throw new IllegalArgumentException("Unhandled parameter types: " +
Arrays.<Object>asList(expression).toString());
}
}
示例10: _format
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
protected void _format(final XThrowExpression expr, final FormattableDocument format) {
final Procedure1<FormattingDataInit> _function = (FormattingDataInit it) -> {
it.oneSpace();
};
Function1<? super FormattableDocument, ? extends Iterable<FormattingData>> _prepend = this._formattingDataFactory.prepend(this._nodeModelAccess.nodeForEObject(expr.getExpression()), _function);
format.operator_add(_prepend);
this.format(expr.getExpression(), format);
}
示例11: hasReturnExpression
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
public boolean hasReturnExpression(final XExpression expression) {
boolean _switchResult = false;
boolean _matched = false;
if (expression instanceof XReturnExpression) {
_matched=true;
_switchResult = true;
}
if (!_matched) {
if (expression instanceof XThrowExpression) {
_matched=true;
_switchResult = true;
}
}
if (!_matched) {
if (expression instanceof XClosure) {
_matched=true;
_switchResult = false;
}
}
if (!_matched) {
final Function1<EObject, Boolean> _function = (EObject content) -> {
boolean _switchResult_1 = false;
boolean _matched_1 = false;
if (content instanceof XExpression) {
_matched_1=true;
_switchResult_1 = this.hasReturnExpression(((XExpression)content));
}
if (!_matched_1) {
_switchResult_1 = false;
}
return Boolean.valueOf(_switchResult_1);
};
_switchResult = IterableExtensions.<EObject>exists(expression.eContents(), _function);
}
return _switchResult;
}
示例12: testUnreachableCode_01
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
@Test public void testUnreachableCode_01() throws Exception {
XBlockExpression expression = (XBlockExpression) expression(
"{" +
" while (false) {" +
" throw new Exception() " +
" }" +
" null" +
"}");
XWhileExpression whileLoop = (XWhileExpression) expression.getExpressions().get(0);
XThrowExpression throwExpression = (XThrowExpression) ((XBlockExpression) whileLoop.getBody()).getExpressions().get(0);
helper.assertError(throwExpression, XbasePackage.Literals.XTHROW_EXPRESSION, UNREACHABLE_CODE);
}
示例13: doTestTryCatchExpression
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的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());
}
示例14: sequence_XThrowExpression
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
/**
* Constraint:
* expression=XExpression
*/
protected void sequence_XThrowExpression(EObject context, XThrowExpression semanticObject) {
if(errorAcceptor != null) {
if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XTHROW_EXPRESSION__EXPRESSION) == ValueTransient.YES)
errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XTHROW_EXPRESSION__EXPRESSION));
}
INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
feeder.accept(grammarAccess.getXThrowExpressionAccess().getExpressionXExpressionParserRuleCall_2_0(), semanticObject.getExpression());
feeder.finish();
}
示例15: sequence_XThrowExpression
import org.eclipse.xtext.xbase.XThrowExpression; //导入依赖的package包/类
@Deprecated
protected void sequence_XThrowExpression(EObject context, XThrowExpression semanticObject) {
sequence_XThrowExpression(createContext(context, semanticObject), semanticObject);
}