/** * 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; }
/** * 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; }
return; LightweightTypeReference switchType = switchExpressions.getSwitchVariableType(switchExpression); if (switchType == null || switchType.isUnknown()) { return; if (!switchExpressions.isJavaCaseExpression(switchExpression, casePart)) { return;
public XExpression getThen(final XCasePart casePart, final XSwitchExpression switchExpression) { final XExpression then = casePart.getThen(); if ((then != null)) { return then; } final int casePartIndex = switchExpression.getCases().indexOf(casePart); if ((casePartIndex == (-1))) { return null; } final int count = switchExpression.getCases().size(); if ((casePartIndex == (count - 1))) { return switchExpression.getDefault(); } if (((casePartIndex + 1) < count)) { return this.getThen(switchExpression.getCases().get((casePartIndex + 1)), switchExpression); } return null; } }
/** * Determine whether the given switch expression is valid for Java version 6 or lower. */ public boolean isJavaSwitchExpression(final XSwitchExpression it) { boolean _xblockexpression = false; { final LightweightTypeReference switchType = this.getSwitchVariableType(it); if ((switchType == null)) { return false; } boolean _isSubtypeOf = switchType.isSubtypeOf(Integer.TYPE); if (_isSubtypeOf) { return true; } boolean _isSubtypeOf_1 = switchType.isSubtypeOf(Enum.class); if (_isSubtypeOf_1) { return true; } _xblockexpression = false; } return _xblockexpression; }
Set<JvmField> initializedInCaseForSure = Sets.newLinkedHashSet(initializedForSure); Set<JvmField> initializedInCaseMaybe = Sets.newLinkedHashSet(initializedMaybe); XExpression then = switchExpressions.getThen(casepart, switchExpr); checkInitializationRec(then, fields, initializedInCaseForSure, initializedInCaseMaybe, visited); if (initializedAllCasesForSure == null)
/** * Determine whether the given switch expression is valid for Java version 7 or higher. */ public boolean isJava7SwitchExpression(final XSwitchExpression it) { boolean _xblockexpression = false; { final LightweightTypeReference switchType = this.getSwitchVariableType(it); if ((switchType == null)) { return false; } boolean _isSubtypeOf = switchType.isSubtypeOf(Integer.TYPE); if (_isSubtypeOf) { return true; } boolean _isSubtypeOf_1 = switchType.isSubtypeOf(Enum.class); if (_isSubtypeOf_1) { return true; } boolean _isSubtypeOf_2 = switchType.isSubtypeOf(String.class); if (_isSubtypeOf_2) { return true; } _xblockexpression = false; } return _xblockexpression; }
protected Object _doEvaluate(XSwitchExpression switchExpression, IEvaluationContext context, CancelIndicator indicator) { IEvaluationContext forkedContext = context.fork(); Object conditionResult = internalEvaluate(switchExpression.getSwitch(), forkedContext, indicator); String simpleName = featureNameProvider.getSimpleName(switchExpression.getDeclaredParam()); if (simpleName != null) { forkedContext.newValue(QualifiedName.create(simpleName), conditionResult); } for (XCasePart casePart : switchExpression.getCases()) { JvmTypeReference typeGuard = casePart.getTypeGuard(); if (typeGuard != null && switchExpression.getSwitch() == null) throw new IllegalStateException("Switch without expression or implicit 'this' may not use type guards"); if (typeGuard == null || isInstanceoOf(conditionResult, typeGuard)) { if (casePart.getCase() != null) { Object casePartResult = internalEvaluate(casePart.getCase(), forkedContext, indicator); if (Boolean.TRUE.equals(casePartResult) || eq(conditionResult, casePartResult)) { XExpression then = switchExpressions.getThen(casePart, switchExpression); return internalEvaluate(then, forkedContext, indicator); } } else { XExpression then = switchExpressions.getThen(casePart, switchExpression); return internalEvaluate(then, forkedContext, indicator); } } } if (switchExpression.getDefault() != null) { Object defaultResult = internalEvaluate(switchExpression.getDefault(), forkedContext, indicator); return defaultResult; } return getDefaultObjectValue(typeResolver.resolveTypes(switchExpression).getActualType(switchExpression)); }
public boolean isJavaCaseExpression(final XSwitchExpression it, final XCasePart casePart) { boolean _xblockexpression = false; { JvmTypeReference _typeGuard = casePart.getTypeGuard(); boolean _tripleNotEquals = (_typeGuard != null); if (_tripleNotEquals) { return false; } final XExpression case_ = casePart.getCase(); if ((case_ == null)) { return false; } @Extension final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(it); final LightweightTypeReference caseType = resolvedTypes.getActualType(case_); if ((caseType == null)) { return false; } final LightweightTypeReference switchType = this.getSwitchVariableType(it); boolean _isAssignableFrom = switchType.isAssignableFrom(caseType); boolean _not = (!_isAssignableFrom); if (_not) { return false; } _xblockexpression = true; } return _xblockexpression; }