Search in sources :

Example 6 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class XtendValidator method checkMemberNamesAreUnique.

@Check
public void checkMemberNamesAreUnique(XtendTypeDeclaration xtendType) {
    final Multimap<String, XtendField> name2field = HashMultimap.create();
    final Multimap<String, XtendTypeDeclaration> name2type = HashMultimap.create();
    final Multimap<JvmType, XtendField> type2extension = HashMultimap.create();
    for (XtendMember member : xtendType.getMembers()) {
        if (member instanceof XtendField) {
            XtendField field = (XtendField) member;
            if (isEmpty(field.getName())) {
                if (field.isExtension()) {
                    JvmTypeReference typeReference = field.getType();
                    if (typeReference != null) {
                        JvmType type = typeReference.getType();
                        if (type != null)
                            type2extension.put(type, field);
                    }
                }
            } else {
                name2field.put(field.getName(), field);
            }
        } else if (member instanceof XtendTypeDeclaration) {
            String name = ((XtendTypeDeclaration) member).getName();
            if (name != null && name.length() > 0) {
                name2type.put(name, (XtendTypeDeclaration) member);
            }
        }
    }
    for (String name : name2field.keySet()) {
        Collection<XtendField> fields = name2field.get(name);
        if (fields.size() > 1) {
            for (XtendField field : fields) error("Duplicate field " + name, field, XtendPackage.Literals.XTEND_FIELD__NAME, DUPLICATE_FIELD);
        }
    }
    for (String name : name2type.keySet()) {
        Collection<XtendTypeDeclaration> types = name2type.get(name);
        if (types.size() > 1) {
            for (XtendTypeDeclaration type : types) error("Duplicate nested type " + name, type, XtendPackage.Literals.XTEND_TYPE_DECLARATION__NAME, DUPLICATE_TYPE_NAME);
        }
    }
    for (JvmType type : type2extension.keySet()) {
        Collection<XtendField> fields = type2extension.get(type);
        if (fields.size() > 1) {
            for (XtendField field : fields) error("Duplicate extension with same type", field, XTEND_FIELD__TYPE, DUPLICATE_FIELD);
        }
    }
}
Also used : XtendMember(org.eclipse.xtend.core.xtend.XtendMember) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) RichString(org.eclipse.xtend.core.xtend.RichString) JvmType(org.eclipse.xtext.common.types.JvmType) XtendField(org.eclipse.xtend.core.xtend.XtendField) Check(org.eclipse.xtext.validation.Check)

Example 7 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class ProblemSupportImpl method getSignificantFeature.

public EStructuralFeature getSignificantFeature(final EObject obj) {
    EStructuralFeature _switchResult = null;
    boolean _matched = false;
    if (obj instanceof XtendTypeDeclaration) {
        _matched = true;
        _switchResult = XtendPackage.eINSTANCE.getXtendTypeDeclaration_Name();
    }
    if (!_matched) {
        if (obj instanceof XtendField) {
            _matched = true;
            _switchResult = XtendPackage.eINSTANCE.getXtendField_Name();
        }
    }
    if (!_matched) {
        if (obj instanceof XtendFunction) {
            _matched = true;
            _switchResult = XtendPackage.eINSTANCE.getXtendFunction_Name();
        }
    }
    if (!_matched) {
        if (obj instanceof JvmFormalParameter) {
            _matched = true;
            _switchResult = TypesPackage.eINSTANCE.getJvmFormalParameter_Name();
        }
    }
    if (!_matched) {
        if (obj instanceof XAnnotation) {
            _matched = true;
            _switchResult = XAnnotationsPackage.eINSTANCE.getXAnnotation_AnnotationType();
        }
    }
    return _switchResult;
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 8 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class TypeLookupImpl method findSourceType.

private XtendTypeDeclarationImpl<? extends XtendTypeDeclaration> findSourceType(final String qualifiedName) {
    EObject _head = IterableExtensions.<EObject>head(this.compilationUnit.getXtendFile().eResource().getContents());
    final Function1<XtendTypeDeclaration, String> _function = (XtendTypeDeclaration type) -> {
        return this.compilationUnit.getQualifiedNameConverter().toString(this.compilationUnit.getQualifiedNameProvider().getFullyQualifiedName(type));
    };
    final Function1<XtendTypeDeclaration, Iterable<? extends XtendTypeDeclaration>> _function_1 = (XtendTypeDeclaration type) -> {
        return Iterables.<XtendTypeDeclaration>filter(type.getMembers(), XtendTypeDeclaration.class);
    };
    final XtendTypeDeclaration result = this.<XtendTypeDeclaration>recursiveFindType(qualifiedName, ((XtendFile) _head).getXtendTypes(), _function, _function_1);
    XtendTypeDeclarationImpl<? extends XtendTypeDeclaration> _xifexpression = null;
    if ((result != null)) {
        _xifexpression = this.compilationUnit.toXtendTypeDeclaration(result);
    }
    return _xifexpression;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration)

Example 9 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class XtendMemberDeclarationImpl method getDeclaringType.

@Override
public TypeDeclaration getDeclaringType() {
    XtendTypeDeclarationImpl<? extends XtendTypeDeclaration> _switchResult = null;
    EObject _eContainer = this.getDelegate().eContainer();
    final EObject container = _eContainer;
    boolean _matched = false;
    if (container instanceof XtendTypeDeclaration) {
        _matched = true;
        _switchResult = this.getCompilationUnit().toXtendTypeDeclaration(((XtendTypeDeclaration) container));
    }
    if (!_matched) {
        _switchResult = null;
    }
    return _switchResult;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration)

Example 10 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class XtendTypeDeclarationImpl method getQualifiedName.

private String getQualifiedName(final XtendTypeDeclaration decl) {
    boolean _isAnonymous = decl.isAnonymous();
    if (_isAnonymous) {
        return null;
    }
    final EObject container = decl.eContainer();
    if ((container instanceof XtendFile)) {
        final String package_ = ((XtendFile) container).getPackage();
        if ((package_ == null)) {
            return decl.getName();
        }
        String _name = decl.getName();
        return ((package_ + ".") + _name);
    }
    if ((container instanceof XtendTypeDeclaration)) {
        final String containerName = this.getQualifiedName(((XtendTypeDeclaration) container));
        if ((containerName == null)) {
            return null;
        }
        String _name_1 = decl.getName();
        return ((containerName + ".") + _name_1);
    }
    return null;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration)

Aggregations

XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)134 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)98 Test (org.junit.Test)91 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)77 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)57 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)39 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 XExpression (org.eclipse.xtext.xbase.XExpression)36 EObject (org.eclipse.emf.ecore.EObject)34 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)29 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)19 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)13 Resource (org.eclipse.emf.ecore.resource.Resource)12 XtendField (org.eclipse.xtend.core.xtend.XtendField)12 JvmType (org.eclipse.xtext.common.types.JvmType)11 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8