Search in sources :

Example 1 with JvmField

use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.

the class XtendGenerator method generateMembersInBody.

@Override
public ITreeAppendable generateMembersInBody(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
    ITreeAppendable _xifexpression = null;
    boolean _isLocal = it.isLocal();
    if (_isLocal) {
        ITreeAppendable _xblockexpression = null;
        {
            appendable.append("{").increaseIndentation();
            EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it));
            final AnonymousClass anonymousClass = ((AnonymousClass) _head);
            if (((!appendable.hasName(Pair.<String, JvmDeclaredType>of("this", it))) && this.needSyntheticThisVariable(anonymousClass, it))) {
                final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(anonymousClass);
                final LightweightTypeReference actualType = resolvedTypes.getActualType(anonymousClass);
                Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("this", it);
                final String thisName = appendable.declareSyntheticVariable(_mappedTo, "_this");
                appendable.newLine().append("final ").append(actualType).append(" ").append(thisName).append(" = this;");
            }
            final Function1<JvmField, Boolean> _function = (JvmField it_1) -> {
                boolean _xblockexpression_1 = false;
                {
                    Procedure1<? super ITreeAppendable> _compilationStrategy = this._jvmTypeExtensions.getCompilationStrategy(it_1);
                    boolean _tripleNotEquals = (_compilationStrategy != null);
                    if (_tripleNotEquals) {
                        return Boolean.valueOf(true);
                    } else {
                        StringConcatenationClient _compilationTemplate = this._jvmTypeExtensions.getCompilationTemplate(it_1);
                        boolean _tripleNotEquals_1 = (_compilationTemplate != null);
                        if (_tripleNotEquals_1) {
                            return Boolean.valueOf(true);
                        } else {
                            boolean _not = (!(it_1.isFinal() && it_1.isStatic()));
                            if (_not) {
                                final XExpression expression = this._iLogicalContainerProvider.getAssociatedExpression(it_1);
                                if (((expression != null) && config.isGenerateExpressions())) {
                                    return Boolean.valueOf(true);
                                }
                            }
                        }
                    }
                    _xblockexpression_1 = false;
                }
                return Boolean.valueOf(_xblockexpression_1);
            };
            final Iterable<JvmField> fieldsWithInitializer = IterableExtensions.<JvmField>filter(it.getDeclaredFields(), _function);
            boolean _isEmpty = IterableExtensions.isEmpty(fieldsWithInitializer);
            boolean _not = (!_isEmpty);
            if (_not) {
                appendable.newLine().append("{").increaseIndentation();
                final Procedure1<LoopParams> _function_1 = (LoopParams it_1) -> {
                    final Function1<ITreeAppendable, ITreeAppendable> _function_2 = (ITreeAppendable it_2) -> {
                        return it_2.newLine();
                    };
                    it_1.setSeparator(_function_2);
                };
                final Procedure1<JvmField> _function_2 = (JvmField it_1) -> {
                    final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
                    memberAppendable.openScope();
                    appendable.newLine();
                    final ITreeAppendable tracedAppendable = appendable.trace(it_1);
                    this._treeAppendableUtil.traceSignificant(tracedAppendable, it_1).append(it_1.getSimpleName());
                    this.generateInitialization(it_1, tracedAppendable, config);
                    tracedAppendable.append(";");
                    memberAppendable.closeScope();
                };
                this._loopExtensions.<JvmField>forEach(appendable, fieldsWithInitializer, _function_1, _function_2);
                appendable.decreaseIndentation().newLine().append("}");
            }
            final Procedure1<LoopParams> _function_3 = (LoopParams it_1) -> {
                final Function1<ITreeAppendable, ITreeAppendable> _function_4 = (ITreeAppendable it_2) -> {
                    return it_2.newLine();
                };
                it_1.setSeparator(_function_4);
            };
            final Procedure1<JvmMember> _function_4 = (JvmMember it_1) -> {
                final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
                memberAppendable.openScope();
                this.generateMember(it_1, memberAppendable, config);
                memberAppendable.closeScope();
            };
            this._loopExtensions.<JvmMember>forEach(appendable, this.getMembersToBeCompiled(it), _function_3, _function_4);
            _xblockexpression = appendable.decreaseIndentation().newLine().append("}");
        }
        _xifexpression = _xblockexpression;
    } else {
        _xifexpression = super.generateMembersInBody(it, appendable, config);
    }
    return _xifexpression;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) ITreeAppendable(org.eclipse.xtext.xbase.compiler.output.ITreeAppendable) LoopParams(org.eclipse.xtext.xbase.compiler.LoopParams) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) EObject(org.eclipse.emf.ecore.EObject) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XExpression(org.eclipse.xtext.xbase.XExpression) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 2 with JvmField

use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.

the class ConstantExpressionsInterpreter method _internalEvaluate.

protected Object _internalEvaluate(final XMemberFeatureCall it, final Context ctx) {
    Object _eGet = it.eGet(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, this.isResolveProxies(it));
    final EObject feature = ((EObject) _eGet);
    boolean _eIsProxy = feature.eIsProxy();
    boolean _not = (!_eIsProxy);
    if (_not) {
        Object _switchResult = null;
        boolean _matched = false;
        if (feature instanceof JvmEnumerationLiteral) {
            _matched = true;
            _switchResult = feature;
        }
        if (!_matched) {
            if (feature instanceof JvmField) {
                _matched = true;
                _switchResult = this.evaluateField(it, ((JvmField) feature), ctx);
            }
        }
        if (!_matched) {
            if (feature instanceof JvmType) {
                _matched = true;
                _switchResult = this.toTypeReference(((JvmType) feature), 0);
            }
        }
        return _switchResult;
    }
    final String featureName = it.getConcreteSyntaxFeatureName();
    try {
        final Object receiver = this.evaluate(it.getMemberCallTarget(), ctx);
        boolean _matched_1 = false;
        if (receiver instanceof JvmTypeReference) {
            _matched_1 = true;
            JvmType _type = ((JvmTypeReference) receiver).getType();
            final JvmType type = _type;
            boolean _matched_2 = false;
            if (type instanceof JvmEnumerationType) {
                _matched_2 = true;
                final Function1<JvmEnumerationLiteral, Boolean> _function = (JvmEnumerationLiteral it_1) -> {
                    String _simpleName = it_1.getSimpleName();
                    return Boolean.valueOf(Objects.equal(_simpleName, featureName));
                };
                final JvmEnumerationLiteral enumValue = IterableExtensions.<JvmEnumerationLiteral>findFirst(((JvmEnumerationType) type).getLiterals(), _function);
                if ((enumValue == null)) {
                    String _simpleName = ((JvmTypeReference) receiver).getSimpleName();
                    String _plus = ((("Couldn\'t find enum value " + featureName) + " on enum ") + _simpleName);
                    throw new ConstantExpressionEvaluationException(_plus, it);
                }
                this.resolveFeature(it, enumValue);
                return enumValue;
            }
            if (!_matched_2) {
                if (type instanceof JvmGenericType) {
                    _matched_2 = true;
                    final Function1<JvmField, Boolean> _function = (JvmField it_1) -> {
                        String _simpleName = it_1.getSimpleName();
                        return Boolean.valueOf(Objects.equal(_simpleName, featureName));
                    };
                    final JvmField field = IterableExtensions.<JvmField>findFirst(Iterables.<JvmField>filter(((JvmGenericType) type).getAllFeatures(), JvmField.class), _function);
                    if ((field == null)) {
                        String _simpleName = ((JvmTypeReference) receiver).getSimpleName();
                        String _plus = ((("Couldn\'t find field " + featureName) + " on type ") + _simpleName);
                        throw new ConstantExpressionEvaluationException(_plus, it);
                    }
                    this.resolveFeature(it, field);
                    return this.evaluateField(it, field, ctx);
                }
            }
        }
        throw new UnresolvableFeatureException(((("Unresolvable feature " + featureName) + " on ") + receiver), it);
    } catch (final Throwable _t) {
        if (_t instanceof UnresolvableFeatureException) {
            final String typeName = this.getFullName(it);
            final JvmType type = this.findTypeByName(it, typeName);
            if ((type != null)) {
                this.resolveType(it, type);
                return this.toTypeReference(type, 0);
            } else {
                throw new UnresolvableFeatureException(("Unresolvable type " + typeName), it);
            }
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
}
Also used : JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) UnresolvableFeatureException(org.eclipse.xtext.xbase.interpreter.UnresolvableFeatureException) JvmType(org.eclipse.xtext.common.types.JvmType) ConstantExpressionEvaluationException(org.eclipse.xtext.xbase.interpreter.ConstantExpressionEvaluationException) StackedConstantExpressionEvaluationException(org.eclipse.xtext.xbase.interpreter.StackedConstantExpressionEvaluationException) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) JvmField(org.eclipse.xtext.common.types.JvmField) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType)

Example 3 with JvmField

use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.

the class CompilationUnitImpl method toMemberDeclaration.

public MemberDeclaration toMemberDeclaration(final JvmMember delegate) {
    final Function1<JvmMember, MemberDeclaration> _function = (JvmMember it) -> {
        MemberDeclaration _switchResult = null;
        boolean _matched = false;
        if (delegate instanceof JvmDeclaredType) {
            _matched = true;
            _switchResult = this.toTypeDeclaration(((JvmDeclaredType) delegate));
        }
        if (!_matched) {
            if (delegate instanceof JvmOperation) {
                _matched = true;
                MemberDeclaration _xifexpression = null;
                JvmDeclaredType _declaringType = ((JvmOperation) delegate).getDeclaringType();
                if ((_declaringType instanceof JvmAnnotationType)) {
                    JvmAnnotationTypeElementDeclarationImpl _xifexpression_1 = null;
                    boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                    if (_isBelongedToCompilationUnit) {
                        MutableJvmAnnotationTypeElementDeclarationImpl _mutableJvmAnnotationTypeElementDeclarationImpl = new MutableJvmAnnotationTypeElementDeclarationImpl();
                        final Procedure1<MutableJvmAnnotationTypeElementDeclarationImpl> _function_1 = (MutableJvmAnnotationTypeElementDeclarationImpl it_1) -> {
                            it_1.setDelegate(((JvmOperation) delegate));
                            it_1.setCompilationUnit(this);
                        };
                        _xifexpression_1 = ObjectExtensions.<MutableJvmAnnotationTypeElementDeclarationImpl>operator_doubleArrow(_mutableJvmAnnotationTypeElementDeclarationImpl, _function_1);
                    } else {
                        JvmAnnotationTypeElementDeclarationImpl _jvmAnnotationTypeElementDeclarationImpl = new JvmAnnotationTypeElementDeclarationImpl();
                        final Procedure1<JvmAnnotationTypeElementDeclarationImpl> _function_2 = (JvmAnnotationTypeElementDeclarationImpl it_1) -> {
                            it_1.setDelegate(((JvmOperation) delegate));
                            it_1.setCompilationUnit(this);
                        };
                        _xifexpression_1 = ObjectExtensions.<JvmAnnotationTypeElementDeclarationImpl>operator_doubleArrow(_jvmAnnotationTypeElementDeclarationImpl, _function_2);
                    }
                    _xifexpression = _xifexpression_1;
                } else {
                    JvmMethodDeclarationImpl _xifexpression_2 = null;
                    boolean _isBelongedToCompilationUnit_1 = this.isBelongedToCompilationUnit(delegate);
                    if (_isBelongedToCompilationUnit_1) {
                        MutableJvmMethodDeclarationImpl _mutableJvmMethodDeclarationImpl = new MutableJvmMethodDeclarationImpl();
                        final Procedure1<MutableJvmMethodDeclarationImpl> _function_3 = (MutableJvmMethodDeclarationImpl it_1) -> {
                            it_1.setDelegate(((JvmOperation) delegate));
                            it_1.setCompilationUnit(this);
                        };
                        _xifexpression_2 = ObjectExtensions.<MutableJvmMethodDeclarationImpl>operator_doubleArrow(_mutableJvmMethodDeclarationImpl, _function_3);
                    } else {
                        JvmMethodDeclarationImpl _jvmMethodDeclarationImpl = new JvmMethodDeclarationImpl();
                        final Procedure1<JvmMethodDeclarationImpl> _function_4 = (JvmMethodDeclarationImpl it_1) -> {
                            it_1.setDelegate(((JvmOperation) delegate));
                            it_1.setCompilationUnit(this);
                        };
                        _xifexpression_2 = ObjectExtensions.<JvmMethodDeclarationImpl>operator_doubleArrow(_jvmMethodDeclarationImpl, _function_4);
                    }
                    _xifexpression = ((MemberDeclaration) _xifexpression_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmConstructor) {
                _matched = true;
                JvmConstructorDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmConstructorDeclarationImpl _mutableJvmConstructorDeclarationImpl = new MutableJvmConstructorDeclarationImpl();
                    final Procedure1<MutableJvmConstructorDeclarationImpl> _function_1 = (MutableJvmConstructorDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmConstructor) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmConstructorDeclarationImpl>operator_doubleArrow(_mutableJvmConstructorDeclarationImpl, _function_1);
                } else {
                    JvmConstructorDeclarationImpl _jvmConstructorDeclarationImpl = new JvmConstructorDeclarationImpl();
                    final Procedure1<JvmConstructorDeclarationImpl> _function_2 = (JvmConstructorDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmConstructor) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmConstructorDeclarationImpl>operator_doubleArrow(_jvmConstructorDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmEnumerationLiteral) {
                _matched = true;
                JvmEnumerationValueDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmEnumerationValueDeclarationImpl _mutableJvmEnumerationValueDeclarationImpl = new MutableJvmEnumerationValueDeclarationImpl();
                    final Procedure1<MutableJvmEnumerationValueDeclarationImpl> _function_1 = (MutableJvmEnumerationValueDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmEnumerationLiteral) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmEnumerationValueDeclarationImpl>operator_doubleArrow(_mutableJvmEnumerationValueDeclarationImpl, _function_1);
                } else {
                    JvmEnumerationValueDeclarationImpl _jvmEnumerationValueDeclarationImpl = new JvmEnumerationValueDeclarationImpl();
                    final Procedure1<JvmEnumerationValueDeclarationImpl> _function_2 = (JvmEnumerationValueDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmEnumerationLiteral) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmEnumerationValueDeclarationImpl>operator_doubleArrow(_jvmEnumerationValueDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmField) {
                _matched = true;
                JvmFieldDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmFieldDeclarationImpl _mutableJvmFieldDeclarationImpl = new MutableJvmFieldDeclarationImpl();
                    final Procedure1<MutableJvmFieldDeclarationImpl> _function_1 = (MutableJvmFieldDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmField) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmFieldDeclarationImpl>operator_doubleArrow(_mutableJvmFieldDeclarationImpl, _function_1);
                } else {
                    JvmFieldDeclarationImpl _jvmFieldDeclarationImpl = new JvmFieldDeclarationImpl();
                    final Procedure1<JvmFieldDeclarationImpl> _function_2 = (JvmFieldDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmField) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmFieldDeclarationImpl>operator_doubleArrow(_jvmFieldDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        return _switchResult;
    };
    return this.<JvmMember, MemberDeclaration>getOrCreate(delegate, _function);
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) MutableJvmConstructorDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmConstructorDeclarationImpl) JvmConstructorDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmConstructorDeclarationImpl) MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) MutableJvmMethodDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmMethodDeclarationImpl) MutableJvmMethodDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmMethodDeclarationImpl) JvmMethodDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmMethodDeclarationImpl) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) MutableJvmFieldDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmFieldDeclarationImpl) JvmFieldDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmFieldDeclarationImpl) JvmAnnotationTypeElementDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationTypeElementDeclarationImpl) MutableJvmAnnotationTypeElementDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmAnnotationTypeElementDeclarationImpl) MutableJvmAnnotationTypeElementDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmAnnotationTypeElementDeclarationImpl) MutableJvmEnumerationValueDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmEnumerationValueDeclarationImpl) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmEnumerationValueDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmEnumerationValueDeclarationImpl) MutableJvmEnumerationValueDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmEnumerationValueDeclarationImpl) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) MutableJvmFieldDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmFieldDeclarationImpl) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) MutableJvmConstructorDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmConstructorDeclarationImpl)

Example 4 with JvmField

use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.

the class XtendJvmModelInferrer method transformCreateExtension.

protected void transformCreateExtension(XtendFunction source, CreateExtensionInfo createExtensionInfo, JvmGenericType container, JvmOperation operation, /* @Nullable */
JvmTypeReference returnType) {
    JvmField cacheVar = jvmTypesBuilder.toField(source, CREATE_CHACHE_VARIABLE_PREFIX + source.getName(), jvmTypesBuilder.inferredType());
    if (cacheVar != null) {
        cacheVar.setFinal(true);
        jvmTypesBuilder.setInitializer(cacheVar, compileStrategies.forCacheVariable(source));
        container.getMembers().add(cacheVar);
        JvmOperation initializer = typesFactory.createJvmOperation();
        container.getMembers().add(initializer);
        initializer.setSimpleName(CREATE_INITIALIZER_PREFIX + source.getName());
        initializer.setVisibility(JvmVisibility.PRIVATE);
        initializer.setReturnType(typeReferences.getTypeForName(Void.TYPE, source));
        for (JvmTypeReference exception : source.getExceptions()) {
            initializer.getExceptions().add(jvmTypesBuilder.cloneWithProxies(exception));
        }
        jvmTypesBuilder.setBody(operation, compileStrategies.forCacheMethod(createExtensionInfo, cacheVar, initializer));
        // the first parameter is the created object
        JvmFormalParameter jvmParam = typesFactory.createJvmFormalParameter();
        jvmParam.setName(createExtensionInfo.getName());
        // TODO consider type parameters
        jvmParam.setParameterType(jvmTypesBuilder.inferredType());
        initializer.getParameters().add(jvmParam);
        associator.associate(createExtensionInfo, jvmParam);
        // add all others
        for (XtendParameter parameter : source.getParameters()) {
            jvmParam = typesFactory.createJvmFormalParameter();
            jvmParam.setName(parameter.getName());
            jvmParam.setParameterType(jvmTypesBuilder.cloneWithProxies(parameter.getParameterType()));
            initializer.getParameters().add(jvmParam);
            associator.associate(parameter, jvmParam);
        }
        associator.associate(source, initializer);
        setBody(operation, createExtensionInfo.getCreateExpression());
        setBody(initializer, source.getExpression());
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmField(org.eclipse.xtext.common.types.JvmField)

Example 5 with JvmField

use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.

the class XtendValidator method checkNonRawTypeInferred.

@Check
public void checkNonRawTypeInferred(XtendField field) {
    if (field.getType() == null) {
        JvmField jvmField = associations.getJvmField(field);
        // field could have been removed by AA, thus the resource is possibly null
        if (jvmField != null && jvmField.eResource() != null) {
            JvmTypeReference fieldType = jvmField.getType();
            validateInferredType(fieldType, field, "The inferred field type ", XTEND_FIELD__NAME);
        }
    }
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmField(org.eclipse.xtext.common.types.JvmField) Check(org.eclipse.xtext.validation.Check)

Aggregations

JvmField (org.eclipse.xtext.common.types.JvmField)36 Test (org.junit.Test)24 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)19 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)18 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)17 JvmMember (org.eclipse.xtext.common.types.JvmMember)12 EObject (org.eclipse.emf.ecore.EObject)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)9 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)3 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Set (java.util.Set)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2