Java 类org.eclipse.xtext.xbase.XReturnExpression 实例源码

项目: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.", expr, null, IssueCodes.INVALID_EARLY_EXIT);
            }
        }
    }
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
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[] { 
                }));
    }
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
protected void checkValidReturnExpression(XExpression returnValue, ITypeComputationState expressionState) {
    ITypeComputationResult result = expressionState.computeTypes(returnValue);
    LightweightTypeReference actualType = result.getActualExpressionType();
    int conformanceFlags = result.getConformanceFlags();
    if (actualType.isPrimitiveVoid() && (conformanceFlags & ConformanceFlags.NO_IMPLICIT_RETURN) != 0) {
        String message = "Invalid return's expression.";
        if (returnValue instanceof XReturnExpression) {
            // when the return's expression is directory a return
            // we provide a more detailed error
            message = "Return cannot be nested.";
        }
        expressionState.addDiagnostic(new EObjectDiagnosticImpl(
                Severity.ERROR,
                IssueCodes.INVALID_RETURN,
                message,
                returnValue,
                null,
                -1,
                new String[] { 
                }));
    }
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
public void checkReturn(XReturnExpression expr) {
    XExpression returnedExpression = expr.getExpression();
    IResolvedTypes resolvedTypes = typeResolver.resolveTypes(expr);
    LightweightTypeReference expectedReturnType = resolvedTypes.getExpectedReturnType(expr);
    if (expectedReturnType == null) {
        return;
    }
    if (expectedReturnType.isPrimitiveVoid()) {
        if (returnedExpression != null)
            error("Void functions cannot return a value.", expr, null,
                    ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_RETURN);
    } else {
        if (returnedExpression == null)
            error("The function must return a result of type " + expectedReturnType.getHumanReadableName() + ".", expr, null,
                    ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_RETURN);
        else {
            LightweightTypeReference expressionType = getActualType(returnedExpression);
            if (expressionType.isPrimitiveVoid()) {
                error("Incompatible types. Expected " + getNameOfTypes(expectedReturnType) + " but was "
                        + canonicalName(expressionType), returnedExpression, null,
                        ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_TYPES);
            }
        }

    }
}
项目: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);
    }
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
protected void _computeTypes(XReturnExpression object, ITypeComputationState state) {
    XExpression returnValue = object.getExpression();
    ITypeComputationState expressionState = state.withReturnExpectation();

    checkValidReturn(object, state);

    LightweightTypeReference primitiveVoid = getPrimitiveVoid(state);
    if (returnValue != null) {
        checkValidReturnExpression(returnValue, expressionState);
        state.acceptActualType(primitiveVoid, ConformanceFlags.NO_IMPLICIT_RETURN);
    } else {
        state.acceptActualType(primitiveVoid, ConformanceFlags.EXPLICIT_VOID_RETURN);
        state.acceptActualType(primitiveVoid, ConformanceFlags.NO_IMPLICIT_RETURN);
    }
}
项目: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(XReturnExpression expr, ITreeAppendable b, boolean isReferenced) {
    if (expr.getExpression()!=null) {
        internalToJavaStatement(expr.getExpression(), b, true);
        b.newLine().append("return ");
        LightweightTypeReference returnTypeToCompile = findRealReturnType(expr);
        internalToConvertedExpression(expr.getExpression(), b, returnTypeToCompile);
        b.append(";");
    } else {
        b.newLine().append("return;");
    }
}
项目:xtext-extras    文件:XbaseFormatter.java   
protected void _format(final XReturnExpression expr, @Extension final IFormattableDocument format) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.<XExpression>prepend(expr.getExpression(), _function);
  format.<XExpression>format(expr.getExpression());
}
项目:xtext-extras    文件:DefaultEarlyExitComputer.java   
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 XReturnExpression 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    文件:XbaseParserTest.java   
@Test public void testReturnExpressionInBlock_1() throws Exception {
    XBlockExpression block = (XBlockExpression) expression(
        "{ return 1 2 }");
    assertEquals(2, block.getExpressions().size());
    assertTrue(block.getExpressions().get(0) instanceof XReturnExpression);
    XReturnExpression returnExpression = (XReturnExpression) block.getExpressions().get(0);
    assertTrue(returnExpression.getExpression() instanceof XNumberLiteral);
}
项目:xtext-extras    文件:XbaseParserTest.java   
@Test public void testReturnExpressionInBlock_2() throws Exception {
    XBlockExpression block = (XBlockExpression) expression(
        "{ return }");
    assertEquals(1, block.getExpressions().size());
    assertTrue(block.getExpressions().get(0) instanceof XReturnExpression);
    XReturnExpression returnExpression = (XReturnExpression) block.getExpressions().get(0);
    assertNull(returnExpression.getExpression());
}
项目:xtext-extras    文件:XbaseParserTest.java   
@Test public void testReturnExpressionInBlock_3() throws Exception {
    XBlockExpression block = (XBlockExpression) expression(
        "{ return; 1 2 }");
    assertEquals(3, block.getExpressions().size());
    assertTrue(block.getExpressions().get(0) instanceof XReturnExpression);
    XReturnExpression returnExpression = (XReturnExpression) block.getExpressions().get(0);
    assertNull(returnExpression.getExpression());
}
项目:xtext-extras    文件:AbstractExpectationTest.java   
@Test
public void testFeatureCallVarArgument_04() {
  ExpectationTestingTypeComputer _typeComputer = this.getTypeComputer();
  final Function1<XExpression, Boolean> _function = (XExpression it) -> {
    return Boolean.valueOf((it instanceof XReturnExpression));
  };
  _typeComputer.setPredicate(_function);
  this.expects("new foo.ClassWithGenericMethod().genericMethod(return null)").types("Unbound[T]").finalizedAs("Object");
}
项目:dsl-devkit    文件:CheckJavaValidator.java   
/**
 * Checks that return expressions do not occur in check implementations.
 *
 * @param expression
 *          the expression
 */
@Check
public void checkReturnExpressions(final XReturnExpression expression) {
  if (expression.getExpression() != null) {
    error(Messages.CheckJavaValidator_NO_RETURN_IN_CHECK_IMPL, XbasePackage.Literals.XRETURN_EXPRESSION__EXPRESSION, IssueCodes.RETURN_IN_IMPL);
  }
}
项目:xtext-extras    文件:AbstractXbaseSemanticSequencer.java   
@Deprecated
protected void sequence_XReturnExpression(EObject context, XReturnExpression semanticObject) {
    sequence_XReturnExpression(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;
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
@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    文件:ExtendedEarlyExitComputer.java   
/**
 * 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;
}
项目:xtext-extras    文件:ExtendedEarlyExitComputer.java   
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, 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);
    }
}
项目:xtext-extras    文件:XbaseCompiler.java   
protected void _toJavaExpression(XReturnExpression returnExpression, ITreeAppendable b) {
    b.append("/* error - couldn't compile nested return */");
}
项目:xtext-extras    文件:XbaseCompiler.java   
@Override
protected boolean isVariableDeclarationRequired(XExpression expr, ITreeAppendable b, 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), 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, b, recursive)) {
                return true;
            }
        }
    }
    return super.isVariableDeclarationRequired(expr, b, recursive);
}
项目:xtext-extras    文件:XbaseInterpreter.java   
/**
 * 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());
    }
}
项目:xtext-extras    文件:XbaseInterpreter.java   
protected Object _doEvaluate(XReturnExpression returnExpr, IEvaluationContext context, CancelIndicator indicator) {
    Object returnValue = internalEvaluate(returnExpr.getExpression(), context, indicator);
    throw new ReturnValue(returnValue);
}
项目:xtext-extras    文件:DefaultEarlyExitComputer.java   
protected Collection<IEarlyExitComputer.ExitPoint> _exitPoints(final XReturnExpression expression) {
  IEarlyExitComputer.ExitPoint _exitPoint = new IEarlyExitComputer.ExitPoint(expression, false);
  return Collections.<IEarlyExitComputer.ExitPoint>singletonList(_exitPoint);
}
项目:xtext-extras    文件:AbstractXbaseSemanticSequencer.java   
/**
 * Contexts:
 *     XExpression returns XReturnExpression
 *     XAssignment returns XReturnExpression
 *     XAssignment.XBinaryOperation_1_1_0_0_0 returns XReturnExpression
 *     XOrExpression returns XReturnExpression
 *     XOrExpression.XBinaryOperation_1_0_0_0 returns XReturnExpression
 *     XAndExpression returns XReturnExpression
 *     XAndExpression.XBinaryOperation_1_0_0_0 returns XReturnExpression
 *     XEqualityExpression returns XReturnExpression
 *     XEqualityExpression.XBinaryOperation_1_0_0_0 returns XReturnExpression
 *     XRelationalExpression returns XReturnExpression
 *     XRelationalExpression.XInstanceOfExpression_1_0_0_0_0 returns XReturnExpression
 *     XRelationalExpression.XBinaryOperation_1_1_0_0_0 returns XReturnExpression
 *     XOtherOperatorExpression returns XReturnExpression
 *     XOtherOperatorExpression.XBinaryOperation_1_0_0_0 returns XReturnExpression
 *     XAdditiveExpression returns XReturnExpression
 *     XAdditiveExpression.XBinaryOperation_1_0_0_0 returns XReturnExpression
 *     XMultiplicativeExpression returns XReturnExpression
 *     XMultiplicativeExpression.XBinaryOperation_1_0_0_0 returns XReturnExpression
 *     XUnaryOperation returns XReturnExpression
 *     XCastedExpression returns XReturnExpression
 *     XCastedExpression.XCastedExpression_1_0_0_0 returns XReturnExpression
 *     XPostfixOperation returns XReturnExpression
 *     XPostfixOperation.XPostfixOperation_1_0_0 returns XReturnExpression
 *     XMemberFeatureCall returns XReturnExpression
 *     XMemberFeatureCall.XAssignment_1_0_0_0_0 returns XReturnExpression
 *     XMemberFeatureCall.XMemberFeatureCall_1_1_0_0_0 returns XReturnExpression
 *     XPrimaryExpression returns XReturnExpression
 *     XParenthesizedExpression returns XReturnExpression
 *     XExpressionOrVarDeclaration returns XReturnExpression
 *     XReturnExpression returns XReturnExpression
 *
 * Constraint:
 *     expression=XExpression?
 */
protected void sequence_XReturnExpression(ISerializationContext context, XReturnExpression semanticObject) {
    genericSequencer.createSequence(context, semanticObject);
}
项目:dsl-devkit    文件:AbstractCheckSemanticSequencer.java   
/**
 * Constraint:
 *     (expression=XExpression?)
 */
protected void sequence_XReturnExpression(EObject context, XReturnExpression semanticObject) {
    genericSequencer.createSequence(context, semanticObject);
}
项目:dsl-devkit    文件:AbstractCheckCfgSemanticSequencer.java   
/**
 * Constraint:
 *     (expression=XExpression?)
 */
protected void sequence_XReturnExpression(EObject context, XReturnExpression semanticObject) {
    genericSequencer.createSequence(context, semanticObject);
}