本文整理汇总了Java中org.eclipse.xtext.xbase.XIfExpression.getElse方法的典型用法代码示例。如果您正苦于以下问题:Java XIfExpression.getElse方法的具体用法?Java XIfExpression.getElse怎么用?Java XIfExpression.getElse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.xbase.XIfExpression
的用法示例。
在下文中一共展示了XIfExpression.getElse方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collectIfParts
import org.eclipse.xtext.xbase.XIfExpression; //导入方法依赖的package包/类
private List<XExpression> collectIfParts(XIfExpression expression, List<XExpression> result) {
result.add(expression.getIf());
if (expression.getElse() instanceof XIfExpression) {
collectIfParts((XIfExpression) expression.getElse(), result);
}
return result;
}
示例2: _toJavaStatement
import org.eclipse.xtext.xbase.XIfExpression; //导入方法依赖的package包/类
protected void _toJavaStatement(XIfExpression expr, ITreeAppendable b, boolean isReferenced) {
if (isReferenced)
declareSyntheticVariable(expr, b);
internalToJavaStatement(expr.getIf(), b, true);
b.newLine().append("if (");
internalToJavaExpression(expr.getIf(), b);
b.append(") {").increaseIndentation();
final boolean canBeReferenced = isReferenced && !isPrimitiveVoid(expr.getThen());
internalToJavaStatement(expr.getThen(), b, canBeReferenced);
if (canBeReferenced) {
b.newLine();
b.append(getVarName(expr, b));
b.append(" = ");
internalToConvertedExpression(expr.getThen(), b, getLightweightType(expr));
b.append(";");
}
b.decreaseIndentation().newLine().append("}");
if (expr.getElse() != null) {
b.append(" else {").increaseIndentation();
final boolean canElseBeReferenced = isReferenced && !isPrimitiveVoid(expr.getElse());
internalToJavaStatement(expr.getElse(), b, canElseBeReferenced);
if (canElseBeReferenced) {
b.newLine();
b.append(getVarName(expr, b));
b.append(" = ");
internalToConvertedExpression(expr.getElse(), b, getLightweightType(expr));
b.append(";");
}
b.decreaseIndentation().newLine().append("}");
}
}
示例3: _doEvaluate
import org.eclipse.xtext.xbase.XIfExpression; //导入方法依赖的package包/类
protected Object _doEvaluate(XIfExpression ifExpression, IEvaluationContext context, CancelIndicator indicator) {
Object conditionResult = internalEvaluate(ifExpression.getIf(), context, indicator);
if (Boolean.TRUE.equals(conditionResult)) {
return internalEvaluate(ifExpression.getThen(), context, indicator);
} else {
if (ifExpression.getElse() == null)
return getDefaultObjectValue(typeResolver.resolveTypes(ifExpression).getActualType(ifExpression));
return internalEvaluate(ifExpression.getElse(), context, indicator);
}
}
示例4: testIf_3
import org.eclipse.xtext.xbase.XIfExpression; //导入方法依赖的package包/类
@Test public void testIf_3() throws Exception {
XIfExpression ie = (XIfExpression) expression("if (foo) bar else if (baz) if (apa) bpa else cpa");
XIfExpression nestedIf = (XIfExpression) ie.getElse();
XIfExpression secondNested = (XIfExpression) nestedIf.getThen();
XFeatureCall cpa = (XFeatureCall) secondNested.getElse();
assertEquals("cpa",cpa.getConcreteSyntaxFeatureName());
}
示例5: checkInstanceOfOrder
import org.eclipse.xtext.xbase.XIfExpression; //导入方法依赖的package包/类
@Check
public void checkInstanceOfOrder(XIfExpression expression) {
if (isIgnored(IssueCodes.UNREACHABLE_IF_BLOCK)) {
return;
}
if (expression.eContainer() instanceof XIfExpression) {
XIfExpression container = (XIfExpression) expression.eContainer();
if (container.getElse() == expression) {
return;
}
}
List<XExpression> ifParts = collectIfParts(expression, new ArrayList<XExpression>());
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), expression);
Multimap<JvmIdentifiableElement, LightweightTypeReference> previousTypeReferences = HashMultimap.create();
for (XExpression ifPart : ifParts) {
if (!(ifPart instanceof XInstanceOfExpression)) {
continue;
}
XInstanceOfExpression instanceOfExpression = (XInstanceOfExpression) ifPart;
if (!(instanceOfExpression.getExpression() instanceof XAbstractFeatureCall)) {
continue;
}
XAbstractFeatureCall featureCall = (XAbstractFeatureCall) instanceOfExpression.getExpression();
JvmIdentifiableElement feature = featureCall.getFeature();
if (!(feature instanceof XVariableDeclaration)
&& !(feature instanceof JvmField)
&& !(feature instanceof JvmFormalParameter)) {
continue;
}
JvmTypeReference type = instanceOfExpression.getType();
LightweightTypeReference actualType = owner.toLightweightTypeReference(type);
if (actualType == null) {
continue;
}
if (isHandled(actualType, previousTypeReferences.get(feature))) {
addIssue("Unreachable code: The if condition can never match. It is already handled by a previous condition.", type, IssueCodes.UNREACHABLE_IF_BLOCK);
continue;
}
previousTypeReferences.put(feature, actualType);
}
}
示例6: isVariableDeclarationRequired
import org.eclipse.xtext.xbase.XIfExpression; //导入方法依赖的package包/类
@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);
}
示例7: getThen
import org.eclipse.xtext.xbase.XIfExpression; //导入方法依赖的package包/类
@Override
protected XExpression getThen(XIfExpression ifExpression) {
if (ifExpression.getElse() != null)
return ifExpression.getElse();
return super.getThen(ifExpression);
}
示例8: getElse
import org.eclipse.xtext.xbase.XIfExpression; //导入方法依赖的package包/类
@Override
protected XExpression getElse(XIfExpression ifExpression) {
if (ifExpression.getElse() != null)
return ifExpression.getThen();
return super.getElse(ifExpression);
}
示例9: testIf_2
import org.eclipse.xtext.xbase.XIfExpression; //导入方法依赖的package包/类
@Test public void testIf_2() throws Exception {
XIfExpression ie = (XIfExpression) expression("if (foo) bar else if (baz) apa else bpa");
XIfExpression nestedIf = (XIfExpression) ie.getElse();
XFeatureCall bpa = (XFeatureCall) nestedIf.getElse();
assertEquals("bpa",bpa.getConcreteSyntaxFeatureName());
}
示例10: getElse
import org.eclipse.xtext.xbase.XIfExpression; //导入方法依赖的package包/类
/**
* Only for testing purpose.
* @nooverride This method is not intended to be re-implemented or extended by clients.
* @noreference This method is not intended to be referenced by clients.
*/
/* @Nullable */
protected XExpression getElse(XIfExpression ifExpression) {
return ifExpression.getElse();
}