protected JvmTypeReference getSwitchLocalVariableType(XSwitchExpression expr) { JvmFormalParameter declaredParam = expr.getDeclaredParam(); if (declaredParam == null) { return getType(expr.getSwitch()); } return getParameterType(declaredParam); }
public LightweightTypeReference getSwitchVariableType(final XSwitchExpression it) { @Extension final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(it); final JvmFormalParameter declaredParam = it.getDeclaredParam(); if ((declaredParam == null)) { return resolvedTypes.getActualType(it.getSwitch()); } final LightweightTypeReference paramType = resolvedTypes.getActualType(declaredParam); LightweightTypeReference _elvis = null; if (paramType != null) { _elvis = paramType; } else { LightweightTypeReference _actualType = resolvedTypes.getActualType(it.getSwitch()); _elvis = _actualType; } return _elvis; }
builder.append(enumerationType.getQualifiedName()); String message = builder.toString(); addIssue(message, switchExpression.getSwitch(), null, IssueCodes.INCOMPLETE_CASES_ON_ENUM, expectedEnumerationLiterals.toArray(new String[0]));
protected String getSwitchLocalVariableSimpleName(XSwitchExpression expr) { IdentifiableSimpleNameProvider nameProvider = getNameProvider(); String varName = nameProvider.getSimpleName(expr.getDeclaredParam()); if (varName != null) { return varName; } XExpression expression = expr.getSwitch(); if (!(expression instanceof XFeatureCall)) { return null; } XFeatureCall featureCall = (XFeatureCall) expression; JvmIdentifiableElement feature = featureCall.getFeature(); return nameProvider.getSimpleName(feature); }
protected Collection<IEarlyExitComputer.ExitPoint> _exitPoints(final XSwitchExpression expression) { Collection<IEarlyExitComputer.ExitPoint> switchExitPoints = this.getExitPoints(expression.getSwitch()); boolean _isNotEmpty = this.isNotEmpty(switchExitPoints); if (_isNotEmpty) {
return declaredParam; return getRefinableCandidate(switchExpression.getSwitch(), state);
@Check public void checkDuplicatedCases(XSwitchExpression switchExpression) { LightweightTypeReference switchType = typeResolver.resolveTypes(switchExpression).getActualType(switchExpression.getSwitch()); if (switchType == null || switchType.isType(Boolean.TYPE) || switchType.isUnknown()) { return;
checkInitializationRec(switchExpr.getSwitch(), fields, initializedForSure, initializedMaybe, visited); Set<JvmField> initializedAllCasesForSure = null; Set<JvmField> initializedAllCasesMaybe = Sets.newLinkedHashSet(initializedMaybe);
@Check public void checkTypeGuards(XCasePart casePart) { if (casePart.getTypeGuard() == null) return; LightweightTypeReference typeGuard = toLightweightTypeReference(casePart.getTypeGuard()); if (typeGuard.isPrimitive()) { error("Primitives are not allowed as type guards", Literals.XCASE_PART__TYPE_GUARD, INVALID_USE_OF_TYPE); return; } LightweightTypeReference targetTypeRef = getActualType(((XSwitchExpression) casePart.eContainer()).getSwitch()); checkCast(casePart.getTypeGuard(), typeGuard, targetTypeRef); }
protected String getSwitchLocalVariableName(XSwitchExpression expr, ITreeAppendable b) { JvmFormalParameter declaredParam = expr.getDeclaredParam(); if (declaredParam != null) { if (b.hasName(declaredParam)) { return b.getName(declaredParam); } return null; } XExpression switchExpression = expr.getSwitch(); if (b.hasName(switchExpression)) { return b.getName(switchExpression); } if (switchExpression instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) switchExpression; JvmIdentifiableElement feature = featureCall.getFeature(); if (b.hasName(feature)) { return b.getName(feature); } } return null; }
if (hasSideEffects(expression.getSwitch(), context)) { return true;
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)); }
if (container != null && EcoreUtil.isAncestor(container.getCase(), expression)) { XSwitchExpression switchExpression = (XSwitchExpression) container.eContainer(); if (switchExpression.getSwitch() != null) { LightweightTypeReference switchVarType = batchTypeResolver.resolveTypes(expression).getActualType(switchExpression.getSwitch()); if (switchVarType != null && literal.getEnumType() == switchVarType.getType()) { return true;
protected void _toJavaIfElseStatement(XSwitchExpression expr, ITreeAppendable b, boolean isReferenced) { String switchResultName = declareSwitchResultVariable(expr, b, isReferenced); internalToJavaStatement(expr.getSwitch(), b, true);
protected String declareLocalVariable(XSwitchExpression expr, ITreeAppendable b) { // declare local var for the switch expression String variableName = getSwitchLocalVariableName(expr, b); if (variableName != null) { return variableName; } String name = createSwitchLocalVariableName(expr); JvmTypeReference variableType = getSwitchLocalVariableType(expr); b.newLine().append("final "); serialize(variableType, expr, b); b.append(" "); variableName = declareAndAppendSwitchSyntheticLocalVariable(expr, name, b); b.append(" = "); internalToJavaExpression(expr.getSwitch(), b); b.append(";"); return variableName; }
if (feature instanceof XSwitchExpression) { _matched=true; return this.isConstantExpression(((XSwitchExpression)feature).getSwitch());
boolean _matched_1 = false; if (container instanceof XSwitchExpression) { XExpression _switch = ((XSwitchExpression)container).getSwitch(); boolean _tripleNotEquals = (_switch != null); if (_tripleNotEquals) { _matched_1=true; return this.doEvaluate(((XSwitchExpression)container).getSwitch(), context);
protected void _toJavaSwitchStatement(XSwitchExpression expr, ITreeAppendable b, boolean isReferenced) { final LightweightTypeReference switchType = batchTypeResolver.resolveTypes(expr).getActualType(expr.getSwitch()); final boolean enumeration = switchType.isSubtypeOf(Enum.class); final boolean needNullCheck = !switchType.isPrimitive(); internalToJavaStatement(expr.getSwitch(), b, true); final String variableName = declareLocalVariable(expr, b);
generate(switchStatement.getSwitch(), it, context); it.newLine(); boolean first = true;