当前位置: 首页>>代码示例>>Java>>正文


Java XBasicForLoopExpression.getExpression方法代码示例

本文整理汇总了Java中org.eclipse.xtext.xbase.XBasicForLoopExpression.getExpression方法的典型用法代码示例。如果您正苦于以下问题:Java XBasicForLoopExpression.getExpression方法的具体用法?Java XBasicForLoopExpression.getExpression怎么用?Java XBasicForLoopExpression.getExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.xtext.xbase.XBasicForLoopExpression的用法示例。


在下文中一共展示了XBasicForLoopExpression.getExpression方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:23,代码来源:EarlyExitValidator.java

示例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);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:27,代码来源:XbaseTypeComputer.java

示例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;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:XbaseInterpreter.java

示例4: 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();
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:56,代码来源:XbaseCompiler.java

示例5: 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("}");
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:71,代码来源:XbaseCompiler.java


注:本文中的org.eclipse.xtext.xbase.XBasicForLoopExpression.getExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。