/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setDefault(XExpression newDefault) { if (newDefault != default_) { NotificationChain msgs = null; if (default_ != null) msgs = ((InternalEObject)default_).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XSWITCH_EXPRESSION__DEFAULT, null, msgs); if (newDefault != null) msgs = ((InternalEObject)newDefault).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XSWITCH_EXPRESSION__DEFAULT, null, msgs); msgs = basicSetDefault(newDefault, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, XbasePackage.XSWITCH_EXPRESSION__DEFAULT, newDefault, newDefault)); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setNewValue(XExpression newNewValue) { if (newNewValue != newValue) { NotificationChain msgs = null; if (newValue != null) msgs = ((InternalEObject)newValue).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - CheckcfgPackage.CONFIGURED_PARAMETER__NEW_VALUE, null, msgs); if (newNewValue != null) msgs = ((InternalEObject)newNewValue).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - CheckcfgPackage.CONFIGURED_PARAMETER__NEW_VALUE, null, msgs); msgs = basicSetNewValue(newNewValue, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, CheckcfgPackage.CONFIGURED_PARAMETER__NEW_VALUE, newNewValue, newNewValue)); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setImplicitReceiver(XExpression newImplicitReceiver) { if (newImplicitReceiver != implicitReceiver) { NotificationChain msgs = null; if (implicitReceiver != null) msgs = ((InternalEObject)implicitReceiver).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XABSTRACT_FEATURE_CALL__IMPLICIT_RECEIVER, null, msgs); if (newImplicitReceiver != null) msgs = ((InternalEObject)newImplicitReceiver).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XABSTRACT_FEATURE_CALL__IMPLICIT_RECEIVER, null, msgs); msgs = basicSetImplicitReceiver(newImplicitReceiver, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, XbasePackage.XABSTRACT_FEATURE_CALL__IMPLICIT_RECEIVER, newImplicitReceiver, newImplicitReceiver)); }
/** * Returns false if the argument expression is a lambda and the expected type * of the argument is not a function type or {@link Object}. * Returns true in all other cases. * * This serves as a shortcut to rule out decision path's where a method is overloaded * and one of the overloads accepts a function type but the other doesn't. In those cases * it is not necessary to compute the type of the lamdba expression twice. * * An example for this pattern is {@link IterableExtensions#filter(Iterable, Class)} vs * {@link IterableExtensions#filter(Iterable, org.eclipse.xtext.xbase.lib.Functions.Function1)}. */ protected boolean isPossibleFunctionType(int idx) { if (idx < arguments.getArgumentCount()) { XExpression argument = arguments.getArgument(idx); if (argument instanceof XClosure) { XClosure closure = (XClosure) argument; LightweightTypeReference declaredType = arguments.getDeclaredTypeForLambda(idx); if (declaredType != null && !declaredType.isType(Object.class)) { CommonTypeComputationServices services = getState().getReferenceOwner().getServices(); JvmOperation operation = services.getFunctionTypes().findImplementingOperation(declaredType); if (operation == null) { return false; } if (closure.isExplicitSyntax() && closure.getDeclaredFormalParameters().size() != operation.getParameters().size()) { return false; } } } } return true; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case FormatPackage.MATCHER__LOCATOR: setLocator((Locator)newValue); return; case FormatPackage.MATCHER__TYPE: setType((MatcherType)newValue); return; case FormatPackage.MATCHER__CONDITION: setCondition((XExpression)newValue); return; } super.eSet(featureID, newValue); }
public EvaluationResult evaluateAssociatedExpression(final XExpression it, final EvaluationContext context) { EvaluationResult _switchResult = null; boolean _matched = false; if (it instanceof XAbstractFeatureCall) { JvmIdentifiableElement _feature = ((XAbstractFeatureCall)it).getFeature(); if ((_feature instanceof JvmEnumerationLiteral)) { _matched=true; final EvaluationResult arg = this.doEvaluate(it, context); Object _rawValue = arg.getRawValue(); return new EvaluationResult(_rawValue, false); } } if (!_matched) { _switchResult = this.doEvaluate(it, context); } return _switchResult; }
private void convertMultiType(LightweightTypeReference expectation, CompoundTypeReference multiType, XExpression context, ITreeAppendable b, Later expression) { LightweightTypeReference castTo = null; List<LightweightTypeReference> components = multiType.getMultiTypeComponents(); ITypeReferenceOwner owner = multiType.getOwner(); LightweightTypeReference commonType = owner.getServices().getTypeConformanceComputer().getCommonSuperType(components, owner); if (!isJavaConformant(expectation, commonType)) { for(LightweightTypeReference candidate: multiType.getMultiTypeComponents()) { if (isJavaConformant(expectation, candidate)) { castTo = candidate; break; } } } if (castTo != null && mustInsertTypeCast(context, castTo)) { b.append("(("); b.append(castTo); b.append(")"); expression.exec(b); b.append(")"); } else { expression.exec(b); } }
public ResolvedFeatures toResolvedOperations(final Class<?> type) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("typeof("); String _canonicalName = type.getCanonicalName(); _builder.append(_canonicalName); _builder.append(")"); XExpression _expression = this.expression(_builder); final XTypeLiteral typeLiteral = ((XTypeLiteral) _expression); JvmType _type = typeLiteral.getType(); final ResolvedFeatures result = this.overrideHelper.getResolvedFeatures(((JvmDeclaredType) _type)); return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setOperand(XExpression newOperand) { if (newOperand != operand) { NotificationChain msgs = null; if (operand != null) msgs = ((InternalEObject)operand).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XPOSTFIX_OPERATION__OPERAND, null, msgs); if (newOperand != null) msgs = ((InternalEObject)newOperand).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XPOSTFIX_OPERATION__OPERAND, null, msgs); msgs = basicSetOperand(newOperand, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, XbasePackage.XPOSTFIX_OPERATION__OPERAND, newOperand, newOperand)); }
protected boolean isImplicitReturn(ITypeComputationResult expressionResult) { int flags = expressionResult.getConformanceFlags(); if ((ConformanceFlags.NO_IMPLICIT_RETURN & flags) != 0) { return false; } XExpression expression = expressionResult.getExpression(); if (expression == null) { return true; } if (expression.eClass() == XbasePackage.Literals.XRETURN_EXPRESSION) { return false; } TreeIterator<EObject> contents = expression.eAllContents(); while (contents.hasNext()) { EObject next = contents.next(); if (next.eClass() == XbasePackage.Literals.XRETURN_EXPRESSION) { return false; } if (next.eClass() == XbasePackage.Literals.XCLOSURE) { contents.prune(); } } return true; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setExpression(XExpression newExpression) { if (newExpression != expression) { NotificationChain msgs = null; if (expression != null) msgs = ((InternalEObject)expression).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XBASIC_FOR_LOOP_EXPRESSION__EXPRESSION, null, msgs); if (newExpression != null) msgs = ((InternalEObject)newExpression).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XBASIC_FOR_LOOP_EXPRESSION__EXPRESSION, null, msgs); msgs = basicSetExpression(newExpression, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, XbasePackage.XBASIC_FOR_LOOP_EXPRESSION__EXPRESSION, newExpression, newExpression)); }
@Test public void testExtends() { try { final XExpression expression = this.expression("null", false); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { it.setAbstract(true); EList<JvmTypeReference> _superTypes = it.getSuperTypes(); JvmTypeReference _typeRef = this.typeRef(expression, AbstractList.class, String.class); this.builder.<JvmTypeReference>operator_add(_superTypes, _typeRef); }; final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function); final Class<?> compiled = this.compile(expression.eResource(), clazz); Assert.assertTrue(Iterable.class.isAssignableFrom(compiled)); Assert.assertTrue(AbstractList.class.isAssignableFrom(compiled)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testSwitchDeclaredParameter_5() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{"); _builder.newLine(); _builder.append("\t"); _builder.append("switch (Integer x : \"lalala\") {"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XExpression block = this.expression(_builder); this._validationTestHelper.assertError(block, XbasePackage.Literals.XSTRING_LITERAL, IssueCodes.INCOMPATIBLE_TYPES); this._validationTestHelper.assertWarning(block, TypesPackage.Literals.JVM_FORMAL_PARAMETER, IssueCodes.UNUSED_LOCAL_VARIABLE); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
protected boolean isVariableDeclarationRequired(XAbstractFeatureCall featureCall, XExpression expression, ITreeAppendable b) { if (featureCall == null) return false; XExpression actualReceiver = normalizeBlockExpression(getActualReceiver(featureCall)); List<XExpression> arguments = getActualArguments(featureCall); XExpression argument = normalizeBlockExpression(expression); int argumentIndex = -1; if (actualReceiver != argument) { argumentIndex = arguments.indexOf(argument); if (argumentIndex == -1) return false; } if (!expressionHelper.hasSideEffects(argument)) return false; int startIndex = argumentIndex + 1; int endIndex = arguments.size(); for (int i = startIndex; i < endIndex; i++) { if (isVariableDeclarationRequired(arguments.get(i), b, false)) return true; } return false; }
protected void evaluatesTo(final Pair<String, String> typeAndExpression, final Procedure1<? super Object> assertions) { try { final String type = typeAndExpression.getKey(); final String expression = typeAndExpression.getValue(); StringConcatenation _builder = new StringConcatenation(); _builder.append("{"); _builder.newLine(); _builder.append("\t"); _builder.append("val"); { if ((type != null)) { _builder.append(" "); _builder.append(type, "\t"); } } _builder.append(" testFoo = "); _builder.append(expression, "\t"); _builder.newLineIfNotEmpty(); _builder.append("}"); _builder.newLine(); final String charSequence = _builder.toString(); XExpression _expression = this.expression(charSequence, true); final XBlockExpression blockExpression = ((XBlockExpression) _expression); XExpression _head = IterableExtensions.<XExpression>head(blockExpression.getExpressions()); final XVariableDeclaration variableDeclaration = ((XVariableDeclaration) _head); this.evaluatesTo(variableDeclaration, assertions); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
protected void mergeExpressionTypesIntoParent(ResolvedTypes parent) { Map<XExpression, List<TypeData>> expressionTypes = basicGetExpressionTypes(); if (!expressionTypes.isEmpty()) { for(Map.Entry<XExpression, List<TypeData>> entry: expressionTypes.entrySet()) { List<TypeData> list = entry.getValue(); for (int i = 0, size = list.size(); i < size; i++) { parent.acceptType(entry.getKey(), prepareMerge(list.get(i), parent.getReferenceOwner())); } } } }
@Test public void testSealedType() { try { final XExpression e = this.expression("null"); JvmType _findDeclaredType = this._typeReferences.findDeclaredType(String.class, e); Assert.assertEquals("java.lang.String", this._jvmDeclaredTypeSignatureHashProvider.getHash(((JvmDeclaredType) _findDeclaredType))); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
protected List<XClosure> findClosures(final CharSequence expression) { try { final String expressionAsString = expression.toString().replace("ClosureTypeResolutionTestData", "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeResolutionTestData").replace("$$", "org::eclipse::xtext::xbase::lib::"); final XExpression xExpression = this.expression(expressionAsString, false); final List<XClosure> Closures = IteratorExtensions.<XClosure>toList(Iterators.<XClosure>filter(EcoreUtil2.eAll(xExpression), XClosure.class)); final Function1<XClosure, Integer> _function = (XClosure it) -> { return Integer.valueOf(NodeModelUtils.findActualNodeFor(it).getOffset()); }; return IterableExtensions.<XClosure, Integer>sortBy(Closures, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
public ConstantExpressionEvaluationException notConstantExpression(final XExpression expression) { String _text = null; if (expression!=null) { _text=this.toText(expression); } String _plus = ("Not a constant expression : \'" + _text); String _plus_1 = (_plus + "\'"); return new ConstantExpressionEvaluationException(_plus_1, expression); }
protected String getDefaultValueLiteral(XExpression expr) { LightweightTypeReference type = getTypeForVariableDeclaration(expr); if (type.isPrimitive()) { if (type.getPrimitiveKind() == Primitives.Primitive.Boolean) { return "false"; } else { return "(" + type.getSimpleName() + ") 0"; } } return "null"; }
@Override public EList<XExpression> getExplicitArguments() { BasicEList<XExpression> result = new BasicEList<XExpression>(); if (getOperand()!=null) result.add(getOperand()); return result; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EList<XExpression> getElements() { if (elements == null) { elements = new EObjectContainmentEList<XExpression>(XExpression.class, this, XbasePackage.XCOLLECTION_LITERAL__ELEMENTS); } return elements; }
@Test public void testBasicForLoopExpression_2() throws Exception { XBasicForLoopExpression loop = (XBasicForLoopExpression) expression("for(;;) {}"); for (XExpression initExpression : loop.getInitExpressions()) { assertExpected(null, initExpression); } assertExpected(null, loop.getExpression()); for (XExpression updateExpression : loop.getUpdateExpressions()) { assertExpected(null, updateExpression); } }
protected IScope createTypeLiteralScope(XExpression featureCall, XExpression receiver, IFeatureScopeSession session, IResolvedTypes resolvedTypes, LightweightTypeReference receiverType, JvmIdentifiableElement linkedReceiver) { if (linkedReceiver instanceof JvmDeclaredType) { IFeatureLinkingCandidate candidate = resolvedTypes.getLinkingCandidate(asAbstractFeatureCall(receiver)); if (candidate != null && candidate.isTypeLiteral()) { JvmDeclaredType declaringType = (JvmDeclaredType) linkedReceiver; IScope result = createNestedTypeLiteralScope(featureCall, receiverType, declaringType, IScope.NULLSCOPE, session); result = createStaticFeatureOnTypeLiteralScope(asAbstractFeatureCall(featureCall), declaringType, receiver, receiverType, result, session); return result; } } return null; }
public void recordExpectation(final XExpression expression, final ITypeComputationState state) { List<? extends ITypeExpectation> _expectations = state.getExpectations(); Iterables.<ITypeExpectation>addAll(this.finalExpectations, _expectations); final Function1<ITypeExpectation, String> _function = (ITypeExpectation it) -> { LightweightTypeReference _expectedType = it.getExpectedType(); String _simpleName = null; if (_expectedType!=null) { _simpleName=_expectedType.getSimpleName(); } return _simpleName; }; List<String> _map = ListExtensions.map(state.getExpectations(), _function); Iterables.<String>addAll(this.expectations, _map); this.expressions.add(expression); }
protected void computeFixedArityArgumentType(IFeatureCallArgumentSlot slot, TypeParameterSubstitutor<?> substitutor) { XExpression argument = slot.getArgumentExpression(); if (argument != null) { LightweightTypeReference parameterType = slot.getDeclaredType(); if (parameterType == null) { parameterType = state.getReferenceOwner().newUnknownTypeReference(); } LightweightTypeReference substitutedParameterType = substitutor.substitute(parameterType); AbstractTypeComputationState argumentState = createLinkingTypeComputationState(substitutedParameterType); resolveArgumentType(argument, substitutedParameterType, argumentState); } }
public List<LightweightTypeReference> getThrownExceptions(XExpression obj, IResolvedTypes types, ITypeReferenceOwner owner) { if (obj == null) { return Collections.emptyList(); } final List<LightweightTypeReference> result = Lists.newArrayListWithExpectedSize(2); ThrownExceptionDelegate delegate = createDelegate(result, types, owner); Switch<Boolean> collector = createThrownExceptionCollector(delegate); delegate.collectWith(collector); delegate.collectThrownExceptions(obj); return result; }
@Test public void testIncompatibleSwitchCase_01() throws Exception { String expressionAsString = "{ var boolean b = switch o: new Object { String: o } b.toString }"; XExpression xExpression = expression(expressionAsString, false); List<Issue> issues = helper.validate(xExpression); assertEquals(issues.toString(), 1, issues.size()); Issue singleIssue = issues.get(0); assertEquals(expressionAsString.indexOf(": o") + 2, singleIssue.getOffset().intValue()); assertEquals("o".length(), singleIssue.getLength().intValue()); }
protected int getArityMismatch(JvmExecutable executable, List<XExpression> arguments) { int fixedArityParamCount = executable.getParameters().size(); if (executable.isVarArgs()) { fixedArityParamCount--; if (arguments.size() >= fixedArityParamCount) { return 0; } } return fixedArityParamCount - arguments.size(); }
protected void setRefinedType(XExpression expression) { if (refinedTypes == null) { refinedTypes = Sets.newHashSet(expression); } else { refinedTypes.add(expression); } }
protected BucketedEObjectDescription createExtensionDescription(QualifiedName name, JvmFeature feature, XExpression receiver, LightweightTypeReference receiverType, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> receiverTypeParameterMapping, ExpressionBucket bucket, boolean validStaticState) { if (helper == null || !helper.isPossibleExtension(feature)) { return null; } return doCreateExtensionDescription(name, feature, receiver, receiverType, receiverTypeParameterMapping, bucket, validStaticState); }
protected void assertCompilesTo(final CharSequence expectedJavaCode, final CharSequence xbaseCode, GeneratorConfig generatorConfig, boolean resolve) throws Exception { XExpression model = expression(xbaseCode.toString(), resolve); XbaseCompiler compiler = get(XbaseCompiler.class); FakeTreeAppendable tracing = createAppendable(); tracing.setGeneratorConfig(generatorConfig); LightweightTypeReference returnType = typeResolver.resolveTypes(model).getReturnType(model); if (returnType == null) { throw new IllegalStateException(); } compiler.compile(model, tracing, returnType); assertEquals(expectedJavaCode.toString().trim(), tracing.getContent().toString().trim()); }
@Test public void testBinaryPromotion_2() throws Exception { XExpression expression = expression("{" + " val int x = Integer::parseInt('1')" + " val long y = 1" + " x * y" + "}", true); assertEquals("long", getType(expression).getIdentifier()); }
protected void _format(final XReturnExpression expr, @Extension final IFormattableDocument format) { final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.oneSpace(); }; format.<XExpression>prepend(expr.getExpression(), _function); format.<XExpression>format(expr.getExpression()); }
protected void acceptCandidate(XExpression expression, IApplicableCandidate candidate) { IApplicableCandidate prev = ensureLinkingMapExists().put(expression, candidate); if (prev != null) { throw new IllegalStateException("Expression " + expression + " was already linked to: " + prev + "\nCannot relink to: " + candidate); } }
@Override public EList<XExpression> getExplicitArguments() { BasicEList<XExpression> result = new BasicEList<XExpression>(); result.addAll(getFeatureCallArguments()); return result; }
protected void assertConformanceError(String expression, EClass objectType, String... messageParts) throws Exception { final XExpression xExpression = expression(expression, false); helper.assertError(xExpression, objectType, INCOMPATIBLE_TYPES, messageParts); }
@Test public void testConstructor_2() throws Exception { XExpression expr = expression("new testdata.DeprecatedMembers.InnerMember2(1f)"); assertWarning(expr, XCONSTRUCTOR_CALL); }
@Test public void testDeprecatedFunction_1() throws Exception { XExpression expr = expression("new testdata.DeprecatedMembers.InnerMember1(1f).deprecatedFunction"); assertWarning(expr, XABSTRACT_FEATURE_CALL, "The method deprecatedFunction() from the type DeprecatedMembers.InnerMember1 is deprecated"); }
@Test public void testNonStatementExpressionInBlock_02() throws Exception { XExpression expr = expression("{ val x = 'foo' 'bar' 42 }"); helper.assertError(expr, XSTRING_LITERAL, INVALID_INNER_EXPRESSION); }