@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); } }
@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; }
/** * Syntax: '('* */ @Override protected void emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a(EObject semanticObject, ISynNavigable transition, List<INode> nodes) { Keyword kw = grammarAccess.getXParenthesizedExpressionAccess().getLeftParenthesisKeyword_0(); if (nodes == null) { if (semanticObject instanceof XIfExpression || semanticObject instanceof XTryCatchFinallyExpression) { EObject cnt = semanticObject.eContainer(); if (cnt instanceof XExpression && !(cnt instanceof XBlockExpression) && !(cnt instanceof XForLoopExpression)) acceptUnassignedKeyword(kw, kw.getValue(), null); } if (semanticObject instanceof XConstructorCall) { XConstructorCall call = (XConstructorCall) semanticObject; if (!call.isExplicitConstructorCall() && call.getArguments().isEmpty()) { acceptUnassignedKeyword(kw, kw.getValue(), null); } } } acceptNodes(transition, nodes); }
protected boolean bracesAreAddedByOuterStructure(XExpression expression) { EObject container = expression.eContainer(); if (container instanceof XTryCatchFinallyExpression || container instanceof XIfExpression || container instanceof XClosure || container instanceof XSynchronizedExpression) { return true; } if (container instanceof XBlockExpression) { XBlockExpression blockExpression = (XBlockExpression) container; EList<XExpression> expressions = blockExpression.getExpressions(); if (expressions.size() == 1 && expressions.get(0) == expression) { return bracesAreAddedByOuterStructure(blockExpression); } } if (!(container instanceof XExpression)) { return true; } return false; }
protected void _toJavaStatement(XTryCatchFinallyExpression expr, ITreeAppendable outerAppendable, boolean isReferenced) { ITreeAppendable b = outerAppendable.trace(expr, false); if (isReferenced && !isPrimitiveVoid(expr)) { declareSyntheticVariable(expr, b); } b.newLine().append("try {").increaseIndentation(); final boolean canBeReferenced = isReferenced && !isPrimitiveVoid(expr.getExpression()); internalToJavaStatement(expr.getExpression(), b, canBeReferenced); if (canBeReferenced) { b.newLine().append(getVarName(expr, b)).append(" = "); internalToConvertedExpression(expr.getExpression(), b, getLightweightType(expr)); b.append(";"); } b.decreaseIndentation().newLine().append("}"); appendCatchAndFinally(expr, b, isReferenced); }
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()); }
@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); } }
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("}"); } }
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); }
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()); } }
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()); }
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()); }
/** * see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=356722 */ @Test public void testTryCatchExpression_3() throws Exception { XTryCatchFinallyExpression tryEx = (XTryCatchFinallyExpression) expression( "try foo catch (java.lang.Exception) {}"); Iterator<INode> iterator = ((XtextResource)tryEx.eResource()).getParseResult().getSyntaxErrors().iterator(); final INode errorNode = iterator.next(); assertEquals(")",errorNode.getText()); assertEquals("missing RULE_ID at ')'",errorNode.getSyntaxErrorMessage().getMessage()); }
@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()); }
@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); } }
@Deprecated protected void sequence_XTryCatchFinallyExpression(EObject context, XTryCatchFinallyExpression semanticObject) { sequence_XTryCatchFinallyExpression(createContext(context, semanticObject), semanticObject); }
@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); } }
/** * 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; }
@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, appendable, isReferenced); } else if (obj instanceof XClosure) { _toJavaStatement((XClosure) obj, appendable, isReferenced); } else if (obj instanceof XConstructorCall) { _toJavaStatement((XConstructorCall) obj, appendable, isReferenced); } else if (obj instanceof XDoWhileExpression) { _toJavaStatement((XDoWhileExpression) obj, appendable, isReferenced); } else if (obj instanceof XForLoopExpression) { _toJavaStatement((XForLoopExpression) obj, appendable, isReferenced); } else if (obj instanceof XBasicForLoopExpression) { _toJavaStatement((XBasicForLoopExpression) obj, appendable, isReferenced); } else if (obj instanceof XIfExpression) { _toJavaStatement((XIfExpression) obj, appendable, isReferenced); } else if (obj instanceof XInstanceOfExpression) { _toJavaStatement((XInstanceOfExpression) obj, appendable, isReferenced); } else if (obj instanceof XReturnExpression) { _toJavaStatement((XReturnExpression) obj, appendable, isReferenced); } else if (obj instanceof XSwitchExpression) { _toJavaStatement((XSwitchExpression) obj, appendable, isReferenced); } else if (obj instanceof XThrowExpression) { _toJavaStatement((XThrowExpression) obj, appendable, isReferenced); } else if (obj instanceof XTryCatchFinallyExpression) { _toJavaStatement((XTryCatchFinallyExpression) obj, appendable, isReferenced); } else if (obj instanceof XVariableDeclaration) { _toJavaStatement((XVariableDeclaration) obj, appendable, isReferenced); } else if (obj instanceof XWhileExpression) { _toJavaStatement((XWhileExpression) obj, appendable, isReferenced); } else if (obj instanceof XListLiteral) { _toJavaStatement((XListLiteral) obj, appendable, isReferenced); } else if (obj instanceof XSetLiteral) { _toJavaStatement((XSetLiteral) obj, appendable, isReferenced); } else if (obj instanceof XSynchronizedExpression) { _toJavaStatement((XSynchronizedExpression) obj, appendable, isReferenced); } else { super.doInternalToJavaStatement(obj, appendable, isReferenced); } }
protected void _toJavaExpression(XTryCatchFinallyExpression expr, ITreeAppendable b) { b.trace(expr, false).append(getVarName(expr, b)); }
/** * don't call this directly. Always call evaluate() internalEvaluate() */ protected Object doEvaluate(XExpression expression, IEvaluationContext context, CancelIndicator indicator) { if (expression instanceof XAssignment) { return _doEvaluate((XAssignment)expression, context, indicator); } else if (expression instanceof XDoWhileExpression) { return _doEvaluate((XDoWhileExpression)expression, context, indicator); } else if (expression instanceof XMemberFeatureCall) { return _doEvaluate((XMemberFeatureCall)expression, context, indicator); } else if (expression instanceof XWhileExpression) { return _doEvaluate((XWhileExpression)expression, context, indicator); } else if (expression instanceof XFeatureCall) { return _doEvaluate((XFeatureCall)expression, context, indicator); } else if (expression instanceof XAbstractFeatureCall) { return _doEvaluate((XAbstractFeatureCall)expression, context, indicator); } else if (expression instanceof XBlockExpression) { return _doEvaluate((XBlockExpression)expression, context, indicator); } else if (expression instanceof XSynchronizedExpression) { return _doEvaluate((XSynchronizedExpression)expression, context, indicator); } else if (expression instanceof XBooleanLiteral) { return _doEvaluate((XBooleanLiteral)expression, context, indicator); } else if (expression instanceof XCastedExpression) { return _doEvaluate((XCastedExpression)expression, context, indicator); } else if (expression instanceof XClosure) { return _doEvaluate((XClosure)expression, context, indicator); } else if (expression instanceof XConstructorCall) { return _doEvaluate((XConstructorCall)expression, context, indicator); } else if (expression instanceof XForLoopExpression) { return _doEvaluate((XForLoopExpression)expression, context, indicator); } else if (expression instanceof XBasicForLoopExpression) { return _doEvaluate((XBasicForLoopExpression)expression, context, indicator); } else if (expression instanceof XIfExpression) { return _doEvaluate((XIfExpression)expression, context, indicator); } else if (expression instanceof XInstanceOfExpression) { return _doEvaluate((XInstanceOfExpression)expression, context, indicator); } else if (expression instanceof XNullLiteral) { return _doEvaluate((XNullLiteral)expression, context, indicator); } else if (expression instanceof XNumberLiteral) { return _doEvaluate((XNumberLiteral)expression, context, indicator); } else if (expression instanceof XReturnExpression) { return _doEvaluate((XReturnExpression)expression, context, indicator); } else if (expression instanceof XStringLiteral) { return _doEvaluate((XStringLiteral)expression, context, indicator); } else if (expression instanceof XSwitchExpression) { return _doEvaluate((XSwitchExpression)expression, context, indicator); } else if (expression instanceof XThrowExpression) { return _doEvaluate((XThrowExpression)expression, context, indicator); } else if (expression instanceof XTryCatchFinallyExpression) { return _doEvaluate((XTryCatchFinallyExpression)expression, context, indicator); } else if (expression instanceof XTypeLiteral) { return _doEvaluate((XTypeLiteral)expression, context, indicator); } else if (expression instanceof XVariableDeclaration) { return _doEvaluate((XVariableDeclaration)expression, context, indicator); } else if (expression instanceof XListLiteral) { return _doEvaluate((XListLiteral)expression, context, indicator); } else if (expression instanceof XSetLiteral) { return _doEvaluate((XSetLiteral)expression, context, indicator); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(expression, context, indicator).toString()); } }
public void findImplicitReturns(final XExpression expression, final ImplicitReturnFinder.Acceptor acceptor) { if (expression instanceof XAbstractFeatureCall) { _findImplicitReturns((XAbstractFeatureCall)expression, acceptor); return; } else if (expression instanceof XBlockExpression) { _findImplicitReturns((XBlockExpression)expression, acceptor); return; } else if (expression instanceof XBooleanLiteral) { _findImplicitReturns((XBooleanLiteral)expression, acceptor); return; } else if (expression instanceof XCastedExpression) { _findImplicitReturns((XCastedExpression)expression, acceptor); return; } else if (expression instanceof XClosure) { _findImplicitReturns((XClosure)expression, acceptor); return; } else if (expression instanceof XCollectionLiteral) { _findImplicitReturns((XCollectionLiteral)expression, acceptor); return; } else if (expression instanceof XConstructorCall) { _findImplicitReturns((XConstructorCall)expression, acceptor); return; } else if (expression instanceof XIfExpression) { _findImplicitReturns((XIfExpression)expression, acceptor); return; } else if (expression instanceof XInstanceOfExpression) { _findImplicitReturns((XInstanceOfExpression)expression, acceptor); return; } else if (expression instanceof XNullLiteral) { _findImplicitReturns((XNullLiteral)expression, acceptor); return; } else if (expression instanceof XNumberLiteral) { _findImplicitReturns((XNumberLiteral)expression, acceptor); return; } else if (expression instanceof XStringLiteral) { _findImplicitReturns((XStringLiteral)expression, acceptor); return; } else if (expression instanceof XSwitchExpression) { _findImplicitReturns((XSwitchExpression)expression, acceptor); return; } else if (expression instanceof XSynchronizedExpression) { _findImplicitReturns((XSynchronizedExpression)expression, acceptor); return; } else if (expression instanceof XTryCatchFinallyExpression) { _findImplicitReturns((XTryCatchFinallyExpression)expression, acceptor); return; } else if (expression instanceof XTypeLiteral) { _findImplicitReturns((XTypeLiteral)expression, acceptor); return; } else if (expression != null) { _findImplicitReturns(expression, acceptor); return; } else if (expression == null) { _findImplicitReturns((Void)null, acceptor); return; } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(expression, acceptor).toString()); } }
@Test public void testTryCatchExpression() throws Exception { XTryCatchFinallyExpression tryEx = (XTryCatchFinallyExpression) expression( "try throw foo catch (Exception e) bar finally baz"); doTestTryCatchExpression(tryEx); }
@Test public void testTryCatchExpression_1() throws Exception { XTryCatchFinallyExpression tryEx = (XTryCatchFinallyExpression) expression( "try foo finally bar"); assertFeatureCall("foo", tryEx.getExpression()); assertFeatureCall("bar", tryEx.getFinallyExpression()); }
@Test public void testTryCatchExpression_2() throws Exception { XTryCatchFinallyExpression tryEx = (XTryCatchFinallyExpression) expression( "try foo catch (java.lang.Exception e) bar"); doTestTryCatchExpression_2(tryEx); }
@Test public void testTryCatch_0() throws Exception { XTryCatchFinallyExpression exp = (XTryCatchFinallyExpression) expression("try 'foo' catch (Exception e) e",true); XCatchClause xCatchClause = exp.getCatchClauses().get(0); assertSame(xCatchClause.getDeclaredParam(), ((XFeatureCall)xCatchClause.getExpression()).getFeature()); }
/** * Contexts: * XExpression returns XTryCatchFinallyExpression * XAssignment returns XTryCatchFinallyExpression * XAssignment.XBinaryOperation_1_1_0_0_0 returns XTryCatchFinallyExpression * XOrExpression returns XTryCatchFinallyExpression * XOrExpression.XBinaryOperation_1_0_0_0 returns XTryCatchFinallyExpression * XAndExpression returns XTryCatchFinallyExpression * XAndExpression.XBinaryOperation_1_0_0_0 returns XTryCatchFinallyExpression * XEqualityExpression returns XTryCatchFinallyExpression * XEqualityExpression.XBinaryOperation_1_0_0_0 returns XTryCatchFinallyExpression * XRelationalExpression returns XTryCatchFinallyExpression * XRelationalExpression.XInstanceOfExpression_1_0_0_0_0 returns XTryCatchFinallyExpression * XRelationalExpression.XBinaryOperation_1_1_0_0_0 returns XTryCatchFinallyExpression * XOtherOperatorExpression returns XTryCatchFinallyExpression * XOtherOperatorExpression.XBinaryOperation_1_0_0_0 returns XTryCatchFinallyExpression * XAdditiveExpression returns XTryCatchFinallyExpression * XAdditiveExpression.XBinaryOperation_1_0_0_0 returns XTryCatchFinallyExpression * XMultiplicativeExpression returns XTryCatchFinallyExpression * XMultiplicativeExpression.XBinaryOperation_1_0_0_0 returns XTryCatchFinallyExpression * XUnaryOperation returns XTryCatchFinallyExpression * XCastedExpression returns XTryCatchFinallyExpression * XCastedExpression.XCastedExpression_1_0_0_0 returns XTryCatchFinallyExpression * XPostfixOperation returns XTryCatchFinallyExpression * XPostfixOperation.XPostfixOperation_1_0_0 returns XTryCatchFinallyExpression * XMemberFeatureCall returns XTryCatchFinallyExpression * XMemberFeatureCall.XAssignment_1_0_0_0_0 returns XTryCatchFinallyExpression * XMemberFeatureCall.XMemberFeatureCall_1_1_0_0_0 returns XTryCatchFinallyExpression * XPrimaryExpression returns XTryCatchFinallyExpression * XParenthesizedExpression returns XTryCatchFinallyExpression * XExpressionOrVarDeclaration returns XTryCatchFinallyExpression * XTryCatchFinallyExpression returns XTryCatchFinallyExpression * * Constraint: * (expression=XExpression ((catchClauses+=XCatchClause+ finallyExpression=XExpression?) | finallyExpression=XExpression)) */ protected void sequence_XTryCatchFinallyExpression(ISerializationContext context, XTryCatchFinallyExpression semanticObject) { genericSequencer.createSequence(context, semanticObject); }
/** * Constraint: * (expression=XExpression ((catchClauses+=XCatchClause+ finallyExpression=XExpression?) | finallyExpression=XExpression)) */ protected void sequence_XTryCatchFinallyExpression(EObject context, XTryCatchFinallyExpression semanticObject) { genericSequencer.createSequence(context, semanticObject); }