项目:xtext-extras
文件:EarlyExitValidator.java
@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.",IssueCodes.INVALID_EARLY_EXIT);
}
}
}
}
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,-1,new String[] {
}));
}
}
项目:xtext-extras
文件:EarlyExitValidator.java
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);
}
}
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(),XbasePackage.Literals.XTHROW_EXPRESSION__EXPRESSION,new String[] {
EcoreUtil.getURI(exceptionType).toString(),EcoreUtil.getURI(object).toString()
}));
}
}
}
}
项目:xtext-extras
文件:XbaseCompiler.java
@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);
}
}
项目:xtext-extras
文件:XbaseCompiler.java
/**
* @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(),null);
b.append(";");
}
项目:xtext-extras
文件:XbaseInterpreter.java
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);
}
项目:xtext-extras
文件:XbaseFormatter.java
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());
}
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());
}
}
项目:xtext-extras
文件:XbaseFormatter2.java
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);
}
项目:xtext-extras
文件:AbstractBatchReturnTypeTest.java
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;
}
项目:xtext-extras
文件:ValidationTests.java
@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);
}
项目:xtext-extras
文件:XbaseParserTest.java
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());
}
项目:dsl-devkit
文件:AbstractCheckSemanticSequencer.java
/**
* 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();
}
/**
* Constraint:
* expression=XExpression
*/
protected void sequence_XThrowExpression(EObject context,semanticObject.getExpression());
Feeder.finish();
}
项目:xtext-extras
文件:AbstractXbaseSemanticSequencer.java
@Deprecated
protected void sequence_XThrowExpression(EObject context,XThrowExpression semanticObject) {
sequence_XThrowExpression(createContext(context,semanticObject),semanticObject);
}
项目:xtext-extras
文件:XbaseValidator.java
protected boolean isValueExpectedRecursive(XExpression expr) {
EStructuralFeature feature = expr.eContainingFeature();
EObject container = expr.eContainer();
// is part of block
if (container instanceof XBlockExpression) {
XBlockExpression blockExpression = (XBlockExpression) container;
final List<XExpression> expressions = blockExpression.getExpressions();
if (expressions.get(expressions.size()-1) != expr) {
return false;
}
}
// no expectation cases
if (feature == XbasePackage.Literals.XTRY_CATCH_FINALLY_EXPRESSION__FINALLY_EXPRESSION
|| feature == XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__BODY
|| feature == XbasePackage.Literals.XFOR_LOOP_EXPRESSION__EACH_EXPRESSION) {
return false;
}
// is value expected
if (container instanceof XAbstractFeatureCall
|| container instanceof XConstructorCall
|| container instanceof XAssignment
|| container instanceof XVariableDeclaration
|| container instanceof XReturnExpression
|| container instanceof XThrowExpression
|| feature == XbasePackage.Literals.XFOR_LOOP_EXPRESSION__FOR_EXPRESSION
|| feature == XbasePackage.Literals.XSWITCH_EXPRESSION__SWITCH
|| feature == XbasePackage.Literals.XCASE_PART__CASE
|| feature == XbasePackage.Literals.XIF_EXPRESSION__IF
|| feature == XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__PREDICATE
|| feature == XbasePackage.Literals.XBASIC_FOR_LOOP_EXPRESSION__EXPRESSION
|| feature == XbasePackage.Literals.XSYNCHRONIZED_EXPRESSION__ParaM) {
return true;
}
if (isLocalClassSemantics(container) || logicalContainerProvider.getLogicalContainer(expr) != null) {
LightweightTypeReference expectedReturnType = typeResolver.resolveTypes(expr).getExpectedReturnType(expr);
return expectedReturnType == null || !expectedReturnType.isPrimitiveVoid();
}
if (container instanceof XCasePart || container instanceof XCatchClause) {
container = container.eContainer();
}
if (container instanceof XExpression) {
return isValueExpectedRecursive((XExpression) container);
}
return true;
}
@Override
public void computeTypes(XExpression expression,ITypecomputationState state) {
if (expression instanceof XAssignment) {
_computeTypes((XAssignment)expression,state);
} else if (expression instanceof XAbstractFeatureCall) {
_computeTypes((XAbstractFeatureCall)expression,state);
} else if (expression instanceof XDoWhileExpression) {
_computeTypes((XDoWhileExpression)expression,state);
} else if (expression instanceof XWhileExpression) {
_computeTypes((XWhileExpression)expression,state);
} else if (expression instanceof XBlockExpression) {
_computeTypes((XBlockExpression)expression,state);
} else if (expression instanceof XBooleanLiteral) {
_computeTypes((XBooleanLiteral)expression,state);
} else if (expression instanceof XCastedExpression) {
_computeTypes((XCastedExpression)expression,state);
} else if (expression instanceof XClosure) {
_computeTypes((XClosure)expression,state);
} else if (expression instanceof XConstructorCall) {
_computeTypes((XConstructorCall)expression,state);
} else if (expression instanceof XForLoopExpression) {
_computeTypes((XForLoopExpression)expression,state);
} else if (expression instanceof XBasicForLoopExpression) {
_computeTypes((XBasicForLoopExpression)expression,state);
} else if (expression instanceof XIfExpression) {
_computeTypes((XIfExpression)expression,state);
} else if (expression instanceof XInstanceOfExpression) {
_computeTypes((XInstanceOfExpression)expression,state);
} else if (expression instanceof xnumberLiteral) {
_computeTypes((xnumberLiteral)expression,state);
} else if (expression instanceof xnullLiteral) {
_computeTypes((xnullLiteral)expression,state);
} else if (expression instanceof XReturnExpression) {
_computeTypes((XReturnExpression)expression,state);
} else if (expression instanceof XStringLiteral) {
_computeTypes((XStringLiteral)expression,state);
} else if (expression instanceof XSwitchExpression) {
_computeTypes((XSwitchExpression)expression,state);
} else if (expression instanceof XThrowExpression) {
_computeTypes((XThrowExpression)expression,state);
} else if (expression instanceof XTryCatchFinallyExpression) {
_computeTypes((XTryCatchFinallyExpression)expression,state);
} else if (expression instanceof XTypeLiteral) {
_computeTypes((XTypeLiteral)expression,state);
} else if (expression instanceof XVariableDeclaration) {
_computeTypes((XVariableDeclaration)expression,state);
} else if (expression instanceof XListLiteral) {
_computeTypes((XListLiteral)expression,state);
} else if (expression instanceof XSetLiteral) {
_computeTypes((XSetLiteral)expression,state);
} else if (expression instanceof XSynchronizedExpression) {
_computeTypes((XSynchronizedExpression)expression,state);
} else {
throw new UnsupportedOperationException("Missing type computation for expression type: " + expression.eClass().getName() + " / " + state);
}
}
项目:xtext-extras
文件:ThrownExceptionSwitch.java
@Override
public Boolean caseXThrowExpression(XThrowExpression object) {
accept(getType(object.getExpression()));
return Boolean.TRUE;
}
/**
* 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;
}
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;
}
项目:xtext-extras
文件:XbaseCompiler.java
@Override
protected void doInternalToJavaStatement(XExpression obj,ITreeAppendable appendable,boolean isReferenced) {
if (obj instanceof XBlockExpression) {
_toJavaStatement((XBlockExpression) obj,appendable,isReferenced);
} else if (obj instanceof XCastedExpression) {
_toJavaStatement((XCastedExpression) obj,isReferenced);
} else if (obj instanceof XClosure) {
_toJavaStatement((XClosure) obj,isReferenced);
} else if (obj instanceof XConstructorCall) {
_toJavaStatement((XConstructorCall) obj,isReferenced);
} else if (obj instanceof XDoWhileExpression) {
_toJavaStatement((XDoWhileExpression) obj,isReferenced);
} else if (obj instanceof XForLoopExpression) {
_toJavaStatement((XForLoopExpression) obj,isReferenced);
} else if (obj instanceof XBasicForLoopExpression) {
_toJavaStatement((XBasicForLoopExpression) obj,isReferenced);
} else if (obj instanceof XIfExpression) {
_toJavaStatement((XIfExpression) obj,isReferenced);
} else if (obj instanceof XInstanceOfExpression) {
_toJavaStatement((XInstanceOfExpression) obj,isReferenced);
} else if (obj instanceof XReturnExpression) {
_toJavaStatement((XReturnExpression) obj,isReferenced);
} else if (obj instanceof XSwitchExpression) {
_toJavaStatement((XSwitchExpression) obj,isReferenced);
} else if (obj instanceof XThrowExpression) {
_toJavaStatement((XThrowExpression) obj,isReferenced);
} else if (obj instanceof XTryCatchFinallyExpression) {
_toJavaStatement((XTryCatchFinallyExpression) obj,isReferenced);
} else if (obj instanceof XVariableDeclaration) {
_toJavaStatement((XVariableDeclaration) obj,isReferenced);
} else if (obj instanceof XWhileExpression) {
_toJavaStatement((XWhileExpression) obj,isReferenced);
} else if (obj instanceof XListLiteral) {
_toJavaStatement((XListLiteral) obj,isReferenced);
} else if (obj instanceof XSetLiteral) {
_toJavaStatement((XSetLiteral) obj,isReferenced);
} else if (obj instanceof XSynchronizedExpression) {
_toJavaStatement((XSynchronizedExpression) obj,isReferenced);
} else {
super.doInternalToJavaStatement(obj,isReferenced);
}
}
项目:xtext-extras
文件:XbaseCompiler.java
protected void _toJavaExpression(XThrowExpression throwExpression,ITreeAppendable b) {
b.append("/* error - Couldn't compile invalid throw */");
}
项目:xtext-extras
文件:XbaseCompiler.java
@Override
protected boolean isVariableDeclarationrequired(XExpression expr,boolean recursive) {
if (expr instanceof XAnnotation) {
return false;
}
if (expr instanceof XListLiteral) {
return false;
}
if (expr instanceof XSetLiteral) {
return false;
}
if (expr instanceof XCastedExpression) {
return false;
}
if (expr instanceof XInstanceOfExpression) {
return false;
}
if (expr instanceof XMemberFeatureCall && isVariableDeclarationrequired((XMemberFeatureCall) expr,b))
return true;
EObject container = expr.eContainer();
if ((container instanceof XVariableDeclaration)
|| (container instanceof XReturnExpression)
|| (container instanceof XThrowExpression)) {
return false;
}
if (container instanceof XIfExpression) {
XIfExpression ifExpression = (XIfExpression) container;
if (ifExpression.getThen() == expr || ifExpression.getElse() == expr) {
return false;
}
}
if (container instanceof XCasePart) {
XCasePart casePart = (XCasePart) container;
if (casePart.getThen() == expr) {
return false;
}
}
if (container instanceof XSwitchExpression) {
XSwitchExpression switchExpression = (XSwitchExpression) container;
if (switchExpression.getDefault() == expr) {
return false;
}
}
if (container instanceof XBlockExpression) {
List<XExpression> siblings = ((XBlockExpression) container).getExpressions();
if (siblings.get(siblings.size() - 1) == expr) {
return isVariableDeclarationrequired(getFeatureCall(expr),b);
}
}
if (container instanceof XClosure) {
if (((XClosure) container).getExpression() == expr) {
return false;
}
}
if (expr instanceof XAssignment) {
XAssignment a = (XAssignment) expr;
for (XExpression arg : getActualArguments(a)) {
if (isVariableDeclarationrequired(arg,recursive)) {
return true;
}
}
}
return super.isVariableDeclarationrequired(expr,recursive);
}
项目:xtext-extras
文件:XbaseInterpreter.java
/**
* don't call this directly. Always call evaluate() internalEvaluate()
*/
protected Object doEvaluate(XExpression expression,CancelIndicator indicator) {
if (expression instanceof XAssignment) {
return _doEvaluate((XAssignment)expression,indicator);
} else if (expression instanceof XDoWhileExpression) {
return _doEvaluate((XDoWhileExpression)expression,indicator);
} else if (expression instanceof XMemberFeatureCall) {
return _doEvaluate((XMemberFeatureCall)expression,indicator);
} else if (expression instanceof XWhileExpression) {
return _doEvaluate((XWhileExpression)expression,indicator);
} else if (expression instanceof XFeatureCall) {
return _doEvaluate((XFeatureCall)expression,indicator);
} else if (expression instanceof XAbstractFeatureCall) {
return _doEvaluate((XAbstractFeatureCall)expression,indicator);
} else if (expression instanceof XBlockExpression) {
return _doEvaluate((XBlockExpression)expression,indicator);
} else if (expression instanceof XSynchronizedExpression) {
return _doEvaluate((XSynchronizedExpression)expression,indicator);
} else if (expression instanceof XBooleanLiteral) {
return _doEvaluate((XBooleanLiteral)expression,indicator);
} else if (expression instanceof XCastedExpression) {
return _doEvaluate((XCastedExpression)expression,indicator);
} else if (expression instanceof XClosure) {
return _doEvaluate((XClosure)expression,indicator);
} else if (expression instanceof XConstructorCall) {
return _doEvaluate((XConstructorCall)expression,indicator);
} else if (expression instanceof XForLoopExpression) {
return _doEvaluate((XForLoopExpression)expression,indicator);
} else if (expression instanceof XBasicForLoopExpression) {
return _doEvaluate((XBasicForLoopExpression)expression,indicator);
} else if (expression instanceof XIfExpression) {
return _doEvaluate((XIfExpression)expression,indicator);
} else if (expression instanceof XInstanceOfExpression) {
return _doEvaluate((XInstanceOfExpression)expression,indicator);
} else if (expression instanceof xnullLiteral) {
return _doEvaluate((xnullLiteral)expression,indicator);
} else if (expression instanceof xnumberLiteral) {
return _doEvaluate((xnumberLiteral)expression,indicator);
} else if (expression instanceof XReturnExpression) {
return _doEvaluate((XReturnExpression)expression,indicator);
} else if (expression instanceof XStringLiteral) {
return _doEvaluate((XStringLiteral)expression,indicator);
} else if (expression instanceof XSwitchExpression) {
return _doEvaluate((XSwitchExpression)expression,indicator);
} else if (expression instanceof XThrowExpression) {
return _doEvaluate((XThrowExpression)expression,indicator);
} else if (expression instanceof XTryCatchFinallyExpression) {
return _doEvaluate((XTryCatchFinallyExpression)expression,indicator);
} else if (expression instanceof XTypeLiteral) {
return _doEvaluate((XTypeLiteral)expression,indicator);
} else if (expression instanceof XVariableDeclaration) {
return _doEvaluate((XVariableDeclaration)expression,indicator);
} else if (expression instanceof XListLiteral) {
return _doEvaluate((XListLiteral)expression,indicator);
} else if (expression instanceof XSetLiteral) {
return _doEvaluate((XSetLiteral)expression,indicator);
} else {
throw new IllegalArgumentException("Unhandled parameter types: " +
Arrays.<Object>asList(expression,indicator).toString());
}
}
项目:xtext-extras
文件:XbaseParserTest.java
@Test public void testThrowExpression() throws Exception {
XThrowExpression throwEx = (XThrowExpression) expression("throw foo");
assertFeatureCall("foo",throwEx.getExpression());
}
项目:xtext-extras
文件:XbaseExpectedTypeProviderTest.java
@Test public void testThrowExpression() throws Exception {
XThrowExpression exp = (XThrowExpression) expression("throw null");
assertExpected("java.lang.Throwable",exp.getExpression());
}
项目:xtext-extras
文件:AbstractXbaseSemanticSequencer.java
/**
* Contexts:
* XExpression returns XThrowExpression
* XAssignment returns XThrowExpression
* XAssignment.XBinaryOperation_1_1_0_0_0 returns XThrowExpression
* XOrExpression returns XThrowExpression
* XOrExpression.XBinaryOperation_1_0_0_0 returns XThrowExpression
* XAndExpression returns XThrowExpression
* XAndExpression.XBinaryOperation_1_0_0_0 returns XThrowExpression
* XEqualityExpression returns XThrowExpression
* XEqualityExpression.XBinaryOperation_1_0_0_0 returns XThrowExpression
* XRelationalExpression returns XThrowExpression
* XRelationalExpression.XInstanceOfExpression_1_0_0_0_0 returns XThrowExpression
* XRelationalExpression.XBinaryOperation_1_1_0_0_0 returns XThrowExpression
* XOtherOperatorExpression returns XThrowExpression
* XOtherOperatorExpression.XBinaryOperation_1_0_0_0 returns XThrowExpression
* XAdditiveExpression returns XThrowExpression
* XAdditiveExpression.XBinaryOperation_1_0_0_0 returns XThrowExpression
* XMultiplicativeExpression returns XThrowExpression
* XMultiplicativeExpression.XBinaryOperation_1_0_0_0 returns XThrowExpression
* XUnaryOperation returns XThrowExpression
* XCastedExpression returns XThrowExpression
* XCastedExpression.XCastedExpression_1_0_0_0 returns XThrowExpression
* XPostfixOperation returns XThrowExpression
* XPostfixOperation.XPostfixOperation_1_0_0 returns XThrowExpression
* XMemberFeatureCall returns XThrowExpression
* XMemberFeatureCall.XAssignment_1_0_0_0_0 returns XThrowExpression
* XMemberFeatureCall.XMemberFeatureCall_1_1_0_0_0 returns XThrowExpression
* XPrimaryExpression returns XThrowExpression
* XParenthesizedExpression returns XThrowExpression
* XExpressionorVarDeclaration returns XThrowExpression
* XThrowExpression returns XThrowExpression
*
* Constraint:
* expression=XExpression
*/
protected void sequence_XThrowExpression(ISerializationContext context,XThrowExpression semanticObject) {
if (errorAcceptor != null) {
if (transientValues.isValueTransient(semanticObject,XbasePackage.Literals.XTHROW_EXPRESSION__EXPRESSION));
}
SequenceFeeder Feeder = createSequencerFeeder(context,semanticObject);
Feeder.accept(grammaraccess.getXThrowExpressionAccess().getExpressionXExpressionParserRuleCall_2_0(),semanticObject.getExpression());
Feeder.finish();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。