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


Java XIfExpression类代码示例

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


XIfExpression类属于org.eclipse.xtext.xbase包,在下文中一共展示了XIfExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: _computeTypes

import org.eclipse.xtext.xbase.XIfExpression; //导入依赖的package包/类
protected void _computeTypes(XIfExpression object, ITypeComputationState state) {
	ITypeComputationState conditionExpectation = state.withExpectation(getRawTypeForName(Boolean.TYPE, state));
	XExpression condition = object.getIf();
	conditionExpectation.computeTypes(condition);
	
	// TODO then expression may influence the expected type of else and vice versa
	XExpression thenExpression = getThen(object);
	ITypeComputationState thenState = reassignCheckedType(condition, thenExpression, state);
	ITypeComputationResult thenResult = thenState.computeTypes(thenExpression);
	XExpression elseExpression = getElse(object);
	if (elseExpression != null) {
		state.computeTypes(elseExpression);
	} else {
		BranchExpressionProcessor processor = new BranchExpressionProcessor(state, object) {
			@Override
			protected String getMessage() {
				return "Missing else branch for conditional expression with primitive type";
			}
		};
		processor.process(thenResult);
		processor.commit();
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:24,代码来源:XbaseTypeComputer.java

示例2: emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a

import org.eclipse.xtext.xbase.XIfExpression; //导入依赖的package包/类
/**
 * Syntax: '('*
 */
@Override
protected void emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a(EObject semanticObject,
		ISynNavigable transition, List<INode> nodes) {

	Keyword kw = grammarAccess.getXParenthesizedExpressionAccess().getLeftParenthesisKeyword_0();

	if (nodes == null) {
		if (semanticObject instanceof XIfExpression || semanticObject instanceof XTryCatchFinallyExpression) {
			EObject cnt = semanticObject.eContainer();
			if (cnt instanceof XExpression && !(cnt instanceof XBlockExpression)
					&& !(cnt instanceof XForLoopExpression))
				acceptUnassignedKeyword(kw, kw.getValue(), null);
		}
		if (semanticObject instanceof XConstructorCall) {
			XConstructorCall call = (XConstructorCall) semanticObject;
			if (!call.isExplicitConstructorCall() && call.getArguments().isEmpty()) {
				acceptUnassignedKeyword(kw, kw.getValue(), null);
			}
		}
	}
	acceptNodes(transition, nodes);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:26,代码来源:XbaseSyntacticSequencer.java

示例3: bracesAreAddedByOuterStructure

import org.eclipse.xtext.xbase.XIfExpression; //导入依赖的package包/类
protected boolean bracesAreAddedByOuterStructure(XExpression expression) {
	EObject container = expression.eContainer();
	if (container instanceof XTryCatchFinallyExpression 
			|| container instanceof XIfExpression
			|| container instanceof XClosure
			|| container instanceof XSynchronizedExpression) {
		return true;
	}
	if (container instanceof XBlockExpression) {
		XBlockExpression blockExpression = (XBlockExpression) container;
		EList<XExpression> expressions = blockExpression.getExpressions();
		if (expressions.size() == 1 && expressions.get(0) == expression) {
			return bracesAreAddedByOuterStructure(blockExpression);
		}
	}
	if (!(container instanceof XExpression)) {
		return true;
	}
	return false;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:21,代码来源:XbaseCompiler.java

示例4: testSerialize_02

import org.eclipse.xtext.xbase.XIfExpression; //导入依赖的package包/类
@Test public void testSerialize_02() throws Exception {
	Resource resource = newResource("'foo' as String");
	XCastedExpression casted = (XCastedExpression) resource.getContents().get(0);
	
	XbaseFactory factory = XbaseFactory.eINSTANCE;
	XIfExpression ifExpression = factory.createXIfExpression();
	ifExpression.setIf(factory.createXBooleanLiteral());
	XStringLiteral stringLiteral = factory.createXStringLiteral();
	stringLiteral.setValue("value");
	ifExpression.setThen(stringLiteral);
	XInstanceOfExpression instanceOfExpression = factory.createXInstanceOfExpression();
	instanceOfExpression.setExpression(ifExpression);
	instanceOfExpression.setType(EcoreUtil.copy(casted.getType()));
	resource.getContents().clear();
	resource.getContents().add(instanceOfExpression);
	ISerializer serializer = get(ISerializer.class);
	String string = serializer.serialize(instanceOfExpression);
	// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=464846
	assertEquals("( if(false) \"value\" ) instanceof String", string);
	
	XInstanceOfExpression parsedExpression = parseHelper.parse(string);
	assertTrue(EcoreUtil.equals(instanceOfExpression, parsedExpression));
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:24,代码来源:SerializerTest.java

示例5: testReassignedType_01

import org.eclipse.xtext.xbase.XIfExpression; //导入依赖的package包/类
@Test
public void testReassignedType_01() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("{ var it = new Object() if (it instanceof String) {} }");
    XExpression _expression = this.expression(_builder, false);
    XExpression _last = IterableExtensions.<XExpression>last(((XBlockExpression) _expression).getExpressions());
    final XIfExpression ifExpr = ((XIfExpression) _last);
    XExpression _then = ifExpr.getThen();
    final XBlockExpression block = ((XBlockExpression) _then);
    final IExpressionScope expressionScope = this._iBatchTypeResolver.resolveTypes(block).getExpressionScope(block, IExpressionScope.Anchor.BEFORE);
    this.contains(expressionScope, "charAt");
    this.contains(expressionScope, "it");
    this.contains(expressionScope, "operator_lessThan");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:19,代码来源:ExpressionScopeTest.java

示例6: testReassignedType_02

import org.eclipse.xtext.xbase.XIfExpression; //导入依赖的package包/类
@Test
public void testReassignedType_02() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("{ var it = new Object() if (it instanceof String) { it = new Object() } }");
    XExpression _expression = this.expression(_builder, false);
    XExpression _last = IterableExtensions.<XExpression>last(((XBlockExpression) _expression).getExpressions());
    final XIfExpression ifExpr = ((XIfExpression) _last);
    XExpression _then = ifExpr.getThen();
    final XBlockExpression block = ((XBlockExpression) _then);
    final IExpressionScope expressionScope = this._iBatchTypeResolver.resolveTypes(block).getExpressionScope(block, IExpressionScope.Anchor.BEFORE);
    this.contains(expressionScope, "charAt");
    this.contains(expressionScope, "it");
    this.contains(expressionScope, "operator_lessThan");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:19,代码来源:ExpressionScopeTest.java

示例7: testReassignedType_03

import org.eclipse.xtext.xbase.XIfExpression; //导入依赖的package包/类
@Test
public void testReassignedType_03() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("{ var it = new Object() if (it instanceof String) { it = new Object() } }");
    XExpression _expression = this.expression(_builder, false);
    XExpression _last = IterableExtensions.<XExpression>last(((XBlockExpression) _expression).getExpressions());
    final XIfExpression ifExpr = ((XIfExpression) _last);
    XExpression _then = ifExpr.getThen();
    final XBlockExpression block = ((XBlockExpression) _then);
    final XExpression assignment = IterableExtensions.<XExpression>head(block.getExpressions());
    final IExpressionScope expressionScope = this._iBatchTypeResolver.resolveTypes(assignment).getExpressionScope(assignment, IExpressionScope.Anchor.AFTER);
    this.containsNot(expressionScope, "charAt");
    this.contains(expressionScope, "it");
    this.containsNot(expressionScope, "operator_lessThan");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:20,代码来源:ExpressionScopeTest.java

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

示例9: checkDeadCode

import org.eclipse.xtext.xbase.XIfExpression; //导入依赖的package包/类
@Check
public void checkDeadCode(XIfExpression condition) {
	if (!earlyExitComputer.isEarlyExit(condition.getIf())) {
		validateCondition(condition.getIf(), false);
	} else {
		if (!markAsDeadCode(condition.getThen())) {
			markAsDeadCode(condition.getElse());
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:11,代码来源:EarlyExitValidator.java

示例10: internalToConvertedExpression

import org.eclipse.xtext.xbase.XIfExpression; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:35,代码来源:XbaseCompiler.java

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

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

示例13: _exitPoints

import org.eclipse.xtext.xbase.XIfExpression; //导入依赖的package包/类
protected Collection<IEarlyExitComputer.ExitPoint> _exitPoints(final XIfExpression expression) {
  Collection<IEarlyExitComputer.ExitPoint> ifExitPoints = this.getExitPoints(expression.getIf());
  boolean _isNotEmpty = this.isNotEmpty(ifExitPoints);
  if (_isNotEmpty) {
    return ifExitPoints;
  }
  Collection<IEarlyExitComputer.ExitPoint> thenExitPoints = this.getExitPoints(expression.getThen());
  Collection<IEarlyExitComputer.ExitPoint> elseExitPoints = this.getExitPoints(expression.getElse());
  if ((this.isNotEmpty(thenExitPoints) && this.isNotEmpty(elseExitPoints))) {
    Collection<IEarlyExitComputer.ExitPoint> result = Lists.<IEarlyExitComputer.ExitPoint>newArrayList(thenExitPoints);
    result.addAll(elseExitPoints);
    return result;
  }
  return Collections.<IEarlyExitComputer.ExitPoint>emptyList();
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:16,代码来源:DefaultEarlyExitComputer.java

示例14: exitPoints

import org.eclipse.xtext.xbase.XIfExpression; //导入依赖的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());
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:37,代码来源:DefaultEarlyExitComputer.java

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


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