本文整理汇总了Java中org.eclipse.xtext.xbase.XSwitchExpression.getCases方法的典型用法代码示例。如果您正苦于以下问题:Java XSwitchExpression.getCases方法的具体用法?Java XSwitchExpression.getCases怎么用?Java XSwitchExpression.getCases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.xbase.XSwitchExpression
的用法示例。
在下文中一共展示了XSwitchExpression.getCases方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkTypeGuardsOrder
import org.eclipse.xtext.xbase.XSwitchExpression; //导入方法依赖的package包/类
@Check
public void checkTypeGuardsOrder(XSwitchExpression expression) {
if (isIgnored(IssueCodes.UNREACHABLE_CASE)) {
return;
}
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), expression);
List<LightweightTypeReference> previousTypeReferences = new ArrayList<LightweightTypeReference>();
for (XCasePart casePart : expression.getCases()) {
JvmTypeReference typeGuard = casePart.getTypeGuard();
if (typeGuard == null) {
continue;
}
LightweightTypeReference actualType = owner.toLightweightTypeReference(typeGuard);
if (actualType == null) {
continue;
}
if (isHandled(actualType, previousTypeReferences)) {
addIssue("Unreachable code: The case can never match. It is already handled by a previous condition.", typeGuard, IssueCodes.UNREACHABLE_CASE);
continue;
}
if (casePart.getCase() == null) {
previousTypeReferences.add(actualType);
}
}
}
示例2: checkTypeGuardsOrderWithGenerics
import org.eclipse.xtext.xbase.XSwitchExpression; //导入方法依赖的package包/类
@Check
public void checkTypeGuardsOrderWithGenerics(XSwitchExpression expression) {
if (isIgnored(IssueCodes.UNREACHABLE_CASE)) {
return;
}
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), expression);
List<LightweightTypeReference> previousTypeReferences = new ArrayList<LightweightTypeReference>();
for (XCasePart casePart : expression.getCases()) {
JvmTypeReference typeGuard = casePart.getTypeGuard();
if (typeGuard == null) {
continue;
}
LightweightTypeReference typeReference = owner.toLightweightTypeReference(typeGuard);
LightweightTypeReference actualType = typeReference.getRawTypeReference();
if (actualType == null || typeReference == actualType) {
continue;
}
if (isHandled(actualType, previousTypeReferences)) {
addIssue("Unreachable code: The case can never match. It is already handled by a previous condition (with the same type erasure).", typeGuard, IssueCodes.UNREACHABLE_CASE);
continue;
}
if (casePart.getCase() == null) {
previousTypeReferences.add(actualType);
}
}
}
示例3: isCompiledToJava7Switch
import org.eclipse.xtext.xbase.XSwitchExpression; //导入方法依赖的package包/类
/**
* Determine whether the given switch expression should be compiled to a Java switch for Java version 7 or higher.
*/
protected boolean isCompiledToJava7Switch(XSwitchExpression expr) {
// NOTE: This method could be merged with #isCompiledToJavaSwitch(XSwitchExpression)
if (!switchExpressions.isJava7SwitchExpression(expr)) {
return false;
}
for (XCasePart casePart : expr.getCases()) {
if (!switchExpressions.isJavaCaseExpression(expr, casePart)) {
return false;
}
if (!switchExpressions.isConstant(casePart)) {
return false;
}
}
return true;
}
示例4: checkDeadCode
import org.eclipse.xtext.xbase.XSwitchExpression; //导入方法依赖的package包/类
@Check
public void checkDeadCode(XSwitchExpression switchExpression) {
List<XCasePart> cases = switchExpression.getCases();
for(int i = 0, size = cases.size(); i < size; i++) {
XCasePart casePart = cases.get(i);
XExpression caseExpression = casePart.getCase();
if (!earlyExitComputer.isEarlyExit(caseExpression)) {
validateCondition(caseExpression, false);
} else if (!markAsDeadCode(casePart.getThen())) {
if (casePart.getTypeGuard() == null) {
i = markAsDeadCode(cases, casePart, i, size);
}
}
}
}
示例5: isCompiledToJavaSwitch
import org.eclipse.xtext.xbase.XSwitchExpression; //导入方法依赖的package包/类
/**
* Determine whether the given switch expression should be compiled to a Java switch for Java version 6 or lower.
*/
protected boolean isCompiledToJavaSwitch(XSwitchExpression expr) {
if (!switchExpressions.isJavaSwitchExpression(expr)) {
return false;
}
for (XCasePart casePart : expr.getCases()) {
if (!switchExpressions.isJavaCaseExpression(expr, casePart)) {
return false;
}
if (!switchExpressions.isConstant(casePart)) {
return false;
}
}
return true;
}
示例6: allCasesAreExitedEarly
import org.eclipse.xtext.xbase.XSwitchExpression; //导入方法依赖的package包/类
protected boolean allCasesAreExitedEarly(XSwitchExpression expr) {
for(XCasePart casePart: expr.getCases()) {
if(casePart.getThen() != null && !isEarlyExit(casePart.getThen())) {
return false;
}
}
return true;
}
示例7: testSwitchExpression_0
import org.eclipse.xtext.xbase.XSwitchExpression; //导入方法依赖的package包/类
@Test public void testSwitchExpression_0() throws Exception {
XSwitchExpression exp = (XSwitchExpression) expressionWithExpectedType(
"switch null {" +
" java.lang.Boolean case null : null" +
" default : null" +
"}", "String");
assertExpected(null,exp.getSwitch());
for (XCasePart cp : exp.getCases()) {
assertExpected(null, cp.getCase());
assertExpected("java.lang.String", cp.getThen());
}
assertExpected("java.lang.String", exp.getDefault());
}
示例8: testSwitchExpression_1
import org.eclipse.xtext.xbase.XSwitchExpression; //导入方法依赖的package包/类
@Test public void testSwitchExpression_1() throws Exception {
XSwitchExpression exp = (XSwitchExpression) expressionWithExpectedType(
"switch true {" +
" java.lang.Boolean case null : null" +
" default : null" +
"}", "String");
for (XCasePart cp : exp.getCases()) {
assertExpected(null, cp.getCase());
assertExpected("java.lang.String", cp.getThen());
}
assertExpected("java.lang.String", exp.getDefault());
}
示例9: isIntentionalEarlyExit
import org.eclipse.xtext.xbase.XSwitchExpression; //导入方法依赖的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;
}
示例10: isDefiniteEarlyExit
import org.eclipse.xtext.xbase.XSwitchExpression; //导入方法依赖的package包/类
public boolean isDefiniteEarlyExit(XExpression expression) {
// TODO further improvements
if (expression instanceof XIfExpression) {
XIfExpression ifExpression = (XIfExpression) expression;
return isDefiniteEarlyExit(ifExpression.getThen()) && isDefiniteEarlyExit(ifExpression.getElse());
} else if (expression instanceof XSwitchExpression) {
XSwitchExpression switchExpression = (XSwitchExpression) expression;
if (isDefiniteEarlyExit(switchExpression.getDefault())) {
for(XCasePart caseExpression: switchExpression.getCases()) {
if (!isDefiniteEarlyExit(caseExpression.getThen())) {
return false;
}
}
return true;
}
return false;
} else if (expression instanceof XTryCatchFinallyExpression) {
XTryCatchFinallyExpression tryExpression = (XTryCatchFinallyExpression) expression;
if (isDefiniteEarlyExit(tryExpression.getFinallyExpression())) {
return true;
}
if (isDefiniteEarlyExit(tryExpression.getExpression())) {
for(XCatchClause catchClause: tryExpression.getCatchClauses()) {
if (!isDefiniteEarlyExit(catchClause.getExpression())) {
return false;
}
}
return true;
}
return false;
} else if (expression instanceof XBlockExpression) {
List<XExpression> expressions = ((XBlockExpression) expression).getExpressions();
for(int i = expressions.size() - 1; i >= 0; i--) {
if (isDefiniteEarlyExit(expressions.get(i))) {
return true;
}
}
} else if (expression instanceof XSynchronizedExpression) {
return isDefiniteEarlyExit(((XSynchronizedExpression) expression).getExpression());
}
return expression instanceof XReturnExpression || expression instanceof XThrowExpression;
}
示例11: getCases
import org.eclipse.xtext.xbase.XSwitchExpression; //导入方法依赖的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.
*/
protected List<XCasePart> getCases(XSwitchExpression switchExpression) {
return switchExpression.getCases();
}