本文整理汇总了Java中org.eclipse.xtext.xbase.XBasicForLoopExpression类的典型用法代码示例。如果您正苦于以下问题:Java XBasicForLoopExpression类的具体用法?Java XBasicForLoopExpression怎么用?Java XBasicForLoopExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XBasicForLoopExpression类属于org.eclipse.xtext.xbase包,在下文中一共展示了XBasicForLoopExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkDeadCode
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
@Check
public void checkDeadCode(XBasicForLoopExpression loop) {
XExpression predicate = loop.getExpression();
if (!earlyExitComputer.isEarlyExit(predicate)) {
Optional<BooleanResult> result = getBooleanResult(predicate);
if (result.isPresent()) {
BooleanResult booleanResult = result.get();
markConstantBooleanCondition(predicate, booleanResult, false);
if (booleanResult.isCompileTimeConstant() && !booleanResult.getValue().or(Boolean.TRUE)) {
markAsDeadCode(loop.getEachExpression());
return;
}
}
if (earlyExitComputer.isEarlyExit(loop.getEachExpression())) {
markAsDeadCode(loop.getUpdateExpressions());
}
} else {
if (!markAsDeadCode(loop.getUpdateExpressions())) {
markAsDeadCode(loop.getEachExpression());
}
}
}
示例2: _computeTypes
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
protected void _computeTypes(final XBasicForLoopExpression object, final ITypeComputationState state) {
for(XExpression initExpression : object.getInitExpressions()) {
ITypeComputationState expressionState = state.withoutExpectation();
expressionState.computeTypes(initExpression);
addLocalToCurrentScope(initExpression, state);
}
state.withinScope(object);
XExpression expression = object.getExpression();
if (expression != null) {
LightweightTypeReference booleanType = getRawTypeForName(Boolean.TYPE, state);
ITypeComputationState conditionExpectation = state.withExpectation(booleanType);
conditionExpectation.computeTypes(expression);
}
XExpression eachExpression = object.getEachExpression();
ITypeComputationState stateWithoutExpectation = state.withoutExpectation();
ITypeComputationState eachExpressionState = reassignCheckedType(expression, eachExpression, stateWithoutExpectation);
eachExpressionState.computeTypes(eachExpression);
for (XExpression updateExpression : object.getUpdateExpressions()) {
eachExpressionState.computeTypes(updateExpression);
}
LightweightTypeReference primitiveVoid = getPrimitiveVoid(state);
state.acceptActualType(primitiveVoid);
}
示例3: _doEvaluate
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
protected Object _doEvaluate(XBasicForLoopExpression forLoop, IEvaluationContext context, CancelIndicator indicator) {
IEvaluationContext forkedContext = context.fork();
for (XExpression initExpression : forLoop.getInitExpressions()) {
internalEvaluate(initExpression, forkedContext, indicator);
}
XExpression expression = forLoop.getExpression();
Object condition = expression == null ? Boolean.TRUE : internalEvaluate(expression, forkedContext, indicator);
while (Boolean.TRUE.equals(condition)) {
internalEvaluate(forLoop.getEachExpression(), forkedContext, indicator);
for (XExpression updateExpression : forLoop.getUpdateExpressions()) {
internalEvaluate(updateExpression, forkedContext, indicator);
}
condition = expression == null ? Boolean.TRUE : internalEvaluate(expression, forkedContext, indicator);
}
return null;
}
示例4: _toJavaStatement
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
protected void _toJavaStatement(XBasicForLoopExpression expr, ITreeAppendable b, boolean isReferenced) {
if (canCompileToJavaBasicForStatement(expr, b)) {
toJavaBasicForStatement(expr, b, isReferenced);
} else {
toJavaWhileStatement(expr, b, isReferenced);
}
}
示例5: exitPoints
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
protected Collection<IEarlyExitComputer.ExitPoint> exitPoints(final XExpression expression) {
if (expression instanceof XDoWhileExpression) {
return _exitPoints((XDoWhileExpression)expression);
} else if (expression instanceof XWhileExpression) {
return _exitPoints((XWhileExpression)expression);
} else if (expression instanceof XAbstractFeatureCall) {
return _exitPoints((XAbstractFeatureCall)expression);
} else if (expression instanceof XBasicForLoopExpression) {
return _exitPoints((XBasicForLoopExpression)expression);
} else if (expression instanceof XBlockExpression) {
return _exitPoints((XBlockExpression)expression);
} else if (expression instanceof XConstructorCall) {
return _exitPoints((XConstructorCall)expression);
} else if (expression instanceof XForLoopExpression) {
return _exitPoints((XForLoopExpression)expression);
} else if (expression instanceof XIfExpression) {
return _exitPoints((XIfExpression)expression);
} else if (expression instanceof XReturnExpression) {
return _exitPoints((XReturnExpression)expression);
} else if (expression instanceof XSwitchExpression) {
return _exitPoints((XSwitchExpression)expression);
} else if (expression instanceof XSynchronizedExpression) {
return _exitPoints((XSynchronizedExpression)expression);
} else if (expression instanceof XThrowExpression) {
return _exitPoints((XThrowExpression)expression);
} else if (expression instanceof XTryCatchFinallyExpression) {
return _exitPoints((XTryCatchFinallyExpression)expression);
} else if (expression instanceof XVariableDeclaration) {
return _exitPoints((XVariableDeclaration)expression);
} else if (expression != null) {
return _exitPoints(expression);
} else {
throw new IllegalArgumentException("Unhandled parameter types: " +
Arrays.<Object>asList(expression).toString());
}
}
示例6: completeXBasicForLoopInit
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
protected void completeXBasicForLoopInit(final EObject model, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
final ICompositeNode node = NodeModelUtils.getNode(model);
int _offset = node.getOffset();
int _offset_1 = context.getOffset();
boolean _greaterEqualsThan = (_offset >= _offset_1);
if (_greaterEqualsThan) {
this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor);
return;
}
if ((model instanceof XBasicForLoopExpression)) {
final EList<XExpression> children = ((XBasicForLoopExpression)model).getInitExpressions();
for (int i = (children.size() - 1); (i >= 0); i--) {
{
final XExpression child = children.get(i);
final ICompositeNode childNode = NodeModelUtils.getNode(child);
int _endOffset = childNode.getEndOffset();
int _offset_2 = context.getOffset();
boolean _lessEqualsThan = (_endOffset <= _offset_2);
if (_lessEqualsThan) {
this.createLocalVariableAndImplicitProposals(child, IExpressionScope.Anchor.AFTER, context, acceptor);
return;
}
}
}
}
this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor);
}
示例7: testBasicForLoopExpression_0
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
@Test public void testBasicForLoopExpression_0() throws Exception {
XBasicForLoopExpression loop = (XBasicForLoopExpression) expression("for(var i = 0; i < 10; i = i + 1) {}");
for (XExpression initExpression : loop.getInitExpressions()) {
assertExpected(null, initExpression);
}
assertExpected("boolean", loop.getExpression());
for (XExpression updateExpression : loop.getUpdateExpressions()) {
assertExpected(null, updateExpression);
}
}
示例8: testBasicForLoopExpression_1
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
@Test public void testBasicForLoopExpression_1() throws Exception {
XBasicForLoopExpression loop = (XBasicForLoopExpression) expression("for(null; null; null) {}");
for (XExpression initExpression : loop.getInitExpressions()) {
assertExpected(null, initExpression);
}
assertExpected("boolean", loop.getExpression());
for (XExpression updateExpression : loop.getUpdateExpressions()) {
assertExpected(null, updateExpression);
}
}
示例9: testBasicForLoopExpression_2
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
@Test public void testBasicForLoopExpression_2() throws Exception {
XBasicForLoopExpression loop = (XBasicForLoopExpression) expression("for(;;) {}");
for (XExpression initExpression : loop.getInitExpressions()) {
assertExpected(null, initExpression);
}
assertExpected(null, loop.getExpression());
for (XExpression updateExpression : loop.getUpdateExpressions()) {
assertExpected(null, updateExpression);
}
}
示例10: sequence_XBasicForLoopExpression
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
@Deprecated
protected void sequence_XBasicForLoopExpression(EObject context, XBasicForLoopExpression semanticObject) {
sequence_XBasicForLoopExpression(createContext(context, semanticObject), semanticObject);
}
示例11: computeTypes
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
@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);
}
}
示例12: isIntentionalEarlyExit
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
/**
* 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;
}
示例13: doInternalToJavaStatement
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
@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);
}
}
示例14: toJavaBasicForStatement
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
/**
* @param isReferenced unused in this context but necessary for dispatch signature
*/
protected void toJavaBasicForStatement(XBasicForLoopExpression expr, ITreeAppendable b, boolean isReferenced) {
ITreeAppendable loopAppendable = b.trace(expr);
loopAppendable.openPseudoScope();
loopAppendable.newLine().append("for (");
EList<XExpression> initExpressions = expr.getInitExpressions();
XExpression firstInitExpression = IterableExtensions.head(initExpressions);
if (firstInitExpression instanceof XVariableDeclaration) {
XVariableDeclaration variableDeclaration = (XVariableDeclaration) firstInitExpression;
LightweightTypeReference type = appendVariableTypeAndName(variableDeclaration, loopAppendable);
loopAppendable.append(" = ");
if (variableDeclaration.getRight() != null) {
compileAsJavaExpression(variableDeclaration.getRight(), loopAppendable, type);
} else {
appendDefaultLiteral(loopAppendable, type);
}
} else {
for (int i = 0; i < initExpressions.size(); i++) {
if (i != 0) {
loopAppendable.append(", ");
}
XExpression initExpression = initExpressions.get(i);
compileAsJavaExpression(initExpression, loopAppendable, getLightweightType(initExpression));
}
}
loopAppendable.append(";");
XExpression expression = expr.getExpression();
if (expression != null) {
loopAppendable.append(" ");
internalToJavaExpression(expression, loopAppendable);
}
loopAppendable.append(";");
EList<XExpression> updateExpressions = expr.getUpdateExpressions();
for (int i = 0; i < updateExpressions.size(); i++) {
if (i != 0) {
loopAppendable.append(",");
}
loopAppendable.append(" ");
XExpression updateExpression = updateExpressions.get(i);
internalToJavaExpression(updateExpression, loopAppendable);
}
loopAppendable.append(") {").increaseIndentation();
XExpression eachExpression = expr.getEachExpression();
internalToJavaStatement(eachExpression, loopAppendable, false);
loopAppendable.decreaseIndentation().newLine().append("}");
loopAppendable.closeScope();
}
示例15: toJavaWhileStatement
import org.eclipse.xtext.xbase.XBasicForLoopExpression; //导入依赖的package包/类
protected void toJavaWhileStatement(XBasicForLoopExpression expr, ITreeAppendable b, boolean isReferenced) {
ITreeAppendable loopAppendable = b.trace(expr);
boolean needBraces = !bracesAreAddedByOuterStructure(expr);
if (needBraces) {
loopAppendable.newLine().increaseIndentation().append("{");
loopAppendable.openPseudoScope();
}
EList<XExpression> initExpressions = expr.getInitExpressions();
for (int i = 0; i < initExpressions.size(); i++) {
XExpression initExpression = initExpressions.get(i);
if (i < initExpressions.size() - 1) {
internalToJavaStatement(initExpression, loopAppendable, false);
} else {
internalToJavaStatement(initExpression, loopAppendable, isReferenced);
if (isReferenced) {
loopAppendable.newLine().append(getVarName(expr, loopAppendable)).append(" = (");
internalToConvertedExpression(initExpression, loopAppendable, getLightweightType(expr));
loopAppendable.append(");");
}
}
}
final String varName = loopAppendable.declareSyntheticVariable(expr, "_while");
XExpression expression = expr.getExpression();
if (expression != null) {
internalToJavaStatement(expression, loopAppendable, true);
loopAppendable.newLine().append("boolean ").append(varName).append(" = ");
internalToJavaExpression(expression, loopAppendable);
loopAppendable.append(";");
} else {
loopAppendable.newLine().append("boolean ").append(varName).append(" = true;");
}
loopAppendable.newLine();
loopAppendable.append("while (");
loopAppendable.append(varName);
loopAppendable.append(") {").increaseIndentation();
loopAppendable.openPseudoScope();
XExpression eachExpression = expr.getEachExpression();
internalToJavaStatement(eachExpression, loopAppendable, false);
EList<XExpression> updateExpressions = expr.getUpdateExpressions();
if (!updateExpressions.isEmpty()) {
for (XExpression updateExpression : updateExpressions) {
internalToJavaStatement(updateExpression, loopAppendable, false);
}
}
if (!isEarlyExit(eachExpression)) {
if (expression != null) {
internalToJavaStatement(expression, loopAppendable, true);
loopAppendable.newLine().append(varName).append(" = ");
internalToJavaExpression(expression, loopAppendable);
loopAppendable.append(";");
} else {
loopAppendable.newLine().append(varName).append(" = true;");
}
}
loopAppendable.closeScope();
loopAppendable.decreaseIndentation().newLine().append("}");
if (needBraces) {
loopAppendable.closeScope();
loopAppendable.decreaseIndentation().newLine().append("}");
}
}