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

项目:xtext-extras    文件:XbaseCompiler.java   
/**
 * @param isReferenced unused in this context but necessary for dispatch signature  
 */
protected void _toJavaStatement(XDoWhileExpression expr, ITreeAppendable b, boolean isReferenced) {
    boolean needsStatement = !canCompileToJavaExpression(expr.getPredicate(), b);
    String variable = null;
    if (needsStatement) {
        variable = b.declareSyntheticVariable(expr, "_dowhile");
        b.newLine().append("boolean ").append(variable).append(" = false;");
    }
    b.newLine().append("do {").increaseIndentation();
    internalToJavaStatement(expr.getBody(), b, false);
    if (needsStatement && !isEarlyExit(expr.getBody())) {
        internalToJavaStatement(expr.getPredicate(), b, true);
        b.newLine();
        b.append(variable).append(" = ");
        internalToJavaExpression(expr.getPredicate(), b);
        b.append(";");
    }
    b.decreaseIndentation().newLine().append("} while(");
    if (needsStatement) {
        b.append(variable);
    } else {
        internalToJavaExpression(expr.getPredicate(), b);
    }
    b.append(");");
}
项目:xtext-extras    文件:DefaultEarlyExitComputer.java   
protected Collection<IEarlyExitComputer.ExitPoint> _exitPoints(final XDoWhileExpression expression) {
  Collection<IEarlyExitComputer.ExitPoint> exitPoints = this.getExitPoints(expression.getBody());
  boolean _isNotEmpty = this.isNotEmpty(exitPoints);
  if (_isNotEmpty) {
    return exitPoints;
  }
  exitPoints = this.getExitPoints(expression.getPredicate());
  boolean _isNotEmpty_1 = this.isNotEmpty(exitPoints);
  if (_isNotEmpty_1) {
    return exitPoints;
  }
  boolean _isBooleanConstant = this.isBooleanConstant(expression.getPredicate(), true);
  if (_isBooleanConstant) {
    IEarlyExitComputer.ExitPoint _exitPoint = new IEarlyExitComputer.ExitPoint(expression, false);
    return Collections.<IEarlyExitComputer.ExitPoint>singletonList(_exitPoint);
  }
  return Collections.<IEarlyExitComputer.ExitPoint>emptyList();
}
项目:xtext-extras    文件:EarlyExitValidator.java   
@Check
public void checkDeadCode(XDoWhileExpression loop) {
    if (earlyExitComputer.isEarlyExit(loop.getBody())) {
        markAsDeadCode(loop.getPredicate());
    } else {
        XExpression predicate = loop.getPredicate();
        if (!earlyExitComputer.isEarlyExit(predicate)) {
            validateCondition(predicate, true);
        }
    }
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
/**
 * Since we are sure that the loop body is executed at least once, the early exit information
 * of the loop body expression can be used for the outer expression.
 */
protected void _computeTypes(XDoWhileExpression object, ITypeComputationState state) {
    ITypeComputationResult loopBodyResult = computeWhileLoopBody(object, state, false);
    boolean noImplicitReturn = (loopBodyResult.getConformanceFlags() & ConformanceFlags.NO_IMPLICIT_RETURN) != 0;
    LightweightTypeReference primitiveVoid = getPrimitiveVoid(state);
    if (noImplicitReturn)
        state.acceptActualType(primitiveVoid, ConformanceFlags.NO_IMPLICIT_RETURN | ConformanceFlags.UNCHECKED);
    else
        state.acceptActualType(primitiveVoid);
}
项目:xtext-extras    文件:XbaseInterpreter.java   
protected IEvaluationResult _doEvaluate(XDoWhileExpression doWhileLoop, IEvaluationContext context, CancelIndicator indicator) {
    Object condition = null;
    do {
        internalEvaluate(doWhileLoop.getBody(), context, indicator);
        condition = internalEvaluate(doWhileLoop.getPredicate(), context, indicator);
    } while (Boolean.TRUE.equals(condition));
    return null;
}
项目: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());
  }
}
项目:dsl-devkit    文件:AbstractCheckSemanticSequencer.java   
/**
 * Constraint:
 *     (body=XExpression predicate=XExpression)
 */
protected void sequence_XDoWhileExpression(EObject context, XDoWhileExpression semanticObject) {
    if(errorAcceptor != null) {
        if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__PREDICATE) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__PREDICATE));
        if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__BODY) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__BODY));
    }
    INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
    SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
    feeder.accept(grammarAccess.getXDoWhileExpressionAccess().getBodyXExpressionParserRuleCall_2_0(), semanticObject.getBody());
    feeder.accept(grammarAccess.getXDoWhileExpressionAccess().getPredicateXExpressionParserRuleCall_5_0(), semanticObject.getPredicate());
    feeder.finish();
}
项目:dsl-devkit    文件:AbstractCheckCfgSemanticSequencer.java   
/**
 * Constraint:
 *     (body=XExpression predicate=XExpression)
 */
protected void sequence_XDoWhileExpression(EObject context, XDoWhileExpression semanticObject) {
    if(errorAcceptor != null) {
        if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__PREDICATE) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__PREDICATE));
        if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__BODY) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__BODY));
    }
    INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
    SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
    feeder.accept(grammarAccess.getXDoWhileExpressionAccess().getBodyXExpressionParserRuleCall_2_0(), semanticObject.getBody());
    feeder.accept(grammarAccess.getXDoWhileExpressionAccess().getPredicateXExpressionParserRuleCall_5_0(), semanticObject.getPredicate());
    feeder.finish();
}
项目:xtext-extras    文件:AbstractXbaseSemanticSequencer.java   
@Deprecated
protected void sequence_XDoWhileExpression(EObject context, XDoWhileExpression semanticObject) {
    sequence_XDoWhileExpression(createContext(context, semanticObject), semanticObject);
}
项目: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    文件: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    文件: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    文件:XbaseParserTest.java   
@Test public void testDoWhileExpression() throws Exception {
    XDoWhileExpression expression = (XDoWhileExpression) expression("do foo while (true)");
    assertTrue(expression.getPredicate() instanceof XBooleanLiteral);
    assertFeatureCall("foo",expression.getBody());
}
项目:xtext-extras    文件:XbaseExpectedTypeProviderTest.java   
@Test public void testWhileExpression_1() throws Exception {
    XDoWhileExpression exp = (XDoWhileExpression) expression("do null while (null)");

    assertExpected("boolean", exp.getPredicate()); // while (null) is invalid thus we expect the primitive boolean
    assertExpected(null, exp.getBody());
}
项目:xtext-extras    文件:AbstractXbaseSemanticSequencer.java   
/**
 * Contexts:
 *     XExpression returns XDoWhileExpression
 *     XAssignment returns XDoWhileExpression
 *     XAssignment.XBinaryOperation_1_1_0_0_0 returns XDoWhileExpression
 *     XOrExpression returns XDoWhileExpression
 *     XOrExpression.XBinaryOperation_1_0_0_0 returns XDoWhileExpression
 *     XAndExpression returns XDoWhileExpression
 *     XAndExpression.XBinaryOperation_1_0_0_0 returns XDoWhileExpression
 *     XEqualityExpression returns XDoWhileExpression
 *     XEqualityExpression.XBinaryOperation_1_0_0_0 returns XDoWhileExpression
 *     XRelationalExpression returns XDoWhileExpression
 *     XRelationalExpression.XInstanceOfExpression_1_0_0_0_0 returns XDoWhileExpression
 *     XRelationalExpression.XBinaryOperation_1_1_0_0_0 returns XDoWhileExpression
 *     XOtherOperatorExpression returns XDoWhileExpression
 *     XOtherOperatorExpression.XBinaryOperation_1_0_0_0 returns XDoWhileExpression
 *     XAdditiveExpression returns XDoWhileExpression
 *     XAdditiveExpression.XBinaryOperation_1_0_0_0 returns XDoWhileExpression
 *     XMultiplicativeExpression returns XDoWhileExpression
 *     XMultiplicativeExpression.XBinaryOperation_1_0_0_0 returns XDoWhileExpression
 *     XUnaryOperation returns XDoWhileExpression
 *     XCastedExpression returns XDoWhileExpression
 *     XCastedExpression.XCastedExpression_1_0_0_0 returns XDoWhileExpression
 *     XPostfixOperation returns XDoWhileExpression
 *     XPostfixOperation.XPostfixOperation_1_0_0 returns XDoWhileExpression
 *     XMemberFeatureCall returns XDoWhileExpression
 *     XMemberFeatureCall.XAssignment_1_0_0_0_0 returns XDoWhileExpression
 *     XMemberFeatureCall.XMemberFeatureCall_1_1_0_0_0 returns XDoWhileExpression
 *     XPrimaryExpression returns XDoWhileExpression
 *     XParenthesizedExpression returns XDoWhileExpression
 *     XDoWhileExpression returns XDoWhileExpression
 *     XExpressionOrVarDeclaration returns XDoWhileExpression
 *
 * Constraint:
 *     (body=XExpression predicate=XExpression)
 */
protected void sequence_XDoWhileExpression(ISerializationContext context, XDoWhileExpression semanticObject) {
    if (errorAcceptor != null) {
        if (transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__BODY) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__BODY));
        if (transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__PREDICATE) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__PREDICATE));
    }
    SequenceFeeder feeder = createSequencerFeeder(context, semanticObject);
    feeder.accept(grammarAccess.getXDoWhileExpressionAccess().getBodyXExpressionParserRuleCall_2_0(), semanticObject.getBody());
    feeder.accept(grammarAccess.getXDoWhileExpressionAccess().getPredicateXExpressionParserRuleCall_5_0(), semanticObject.getPredicate());
    feeder.finish();
}