Search in sources :

Example 1 with XtendConstructor

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

the class XAnnotationExtensions method getAnnotatedTarget.

public XtendAnnotationTarget getAnnotatedTarget(final XAnnotation annotation) {
    XtendAnnotationTarget _switchResult = null;
    EObject _eContainer = annotation.eContainer();
    final EObject container = _eContainer;
    boolean _matched = false;
    if (container instanceof XtendAnnotationType) {
        _matched = true;
    }
    if (!_matched) {
        if (container instanceof XtendClass) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendInterface) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendEnum) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendField) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendFunction) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendConstructor) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendEnumLiteral) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendParameter) {
            _matched = true;
        }
    }
    if (_matched) {
        _switchResult = ((XtendAnnotationTarget) container);
    }
    if (!_matched) {
        if (container instanceof XtendAnnotationTarget) {
            _matched = true;
            XtendAnnotationTarget _xblockexpression = null;
            {
                final EObject containerContainer = ((XtendAnnotationTarget) container).eContainer();
                XtendAnnotationTarget _xifexpression = null;
                if ((containerContainer instanceof XtendAnnotationTarget)) {
                    _xifexpression = ((XtendAnnotationTarget) containerContainer);
                } else {
                    _xifexpression = ((XtendAnnotationTarget) container);
                }
                _xblockexpression = _xifexpression;
            }
            _switchResult = _xblockexpression;
        }
    }
    if (!_matched) {
        if (container instanceof XAnnotation) {
            _matched = true;
            _switchResult = this.getAnnotatedTarget(((XAnnotation) container));
        }
    }
    if (!_matched) {
        _switchResult = null;
    }
    return _switchResult;
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XtendField(org.eclipse.xtend.core.xtend.XtendField) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendAnnotationTarget(org.eclipse.xtend.core.xtend.XtendAnnotationTarget) XtendAnnotationType(org.eclipse.xtend.core.xtend.XtendAnnotationType) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendInterface(org.eclipse.xtend.core.xtend.XtendInterface) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) XtendEnum(org.eclipse.xtend.core.xtend.XtendEnum) XtendEnumLiteral(org.eclipse.xtend.core.xtend.XtendEnumLiteral)

Example 2 with XtendConstructor

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

the class CompilationUnitImpl method toXtendMemberDeclaration.

public MemberDeclaration toXtendMemberDeclaration(final XtendMember delegate) {
    final Function1<XtendMember, XtendMemberDeclarationImpl<? extends XtendMember>> _function = (XtendMember it) -> {
        XtendMemberDeclarationImpl<? extends XtendMember> _switchResult = null;
        boolean _matched = false;
        if (delegate instanceof XtendTypeDeclaration) {
            _matched = true;
            _switchResult = this.toXtendTypeDeclaration(((XtendTypeDeclaration) delegate));
        }
        if (!_matched) {
            if (delegate instanceof XtendFunction) {
                _matched = true;
                XtendMethodDeclarationImpl _xtendMethodDeclarationImpl = new XtendMethodDeclarationImpl();
                final Procedure1<XtendMethodDeclarationImpl> _function_1 = (XtendMethodDeclarationImpl it_1) -> {
                    it_1.setDelegate(((XtendFunction) delegate));
                    it_1.setCompilationUnit(this);
                };
                _switchResult = ObjectExtensions.<XtendMethodDeclarationImpl>operator_doubleArrow(_xtendMethodDeclarationImpl, _function_1);
            }
        }
        if (!_matched) {
            if (delegate instanceof XtendConstructor) {
                _matched = true;
                XtendConstructorDeclarationImpl _xtendConstructorDeclarationImpl = new XtendConstructorDeclarationImpl();
                final Procedure1<XtendConstructorDeclarationImpl> _function_1 = (XtendConstructorDeclarationImpl it_1) -> {
                    it_1.setDelegate(((XtendConstructor) delegate));
                    it_1.setCompilationUnit(this);
                };
                _switchResult = ObjectExtensions.<XtendConstructorDeclarationImpl>operator_doubleArrow(_xtendConstructorDeclarationImpl, _function_1);
            }
        }
        if (!_matched) {
            if (delegate instanceof XtendField) {
                _matched = true;
                XtendMemberDeclarationImpl<XtendField> _xifexpression = null;
                EObject _eContainer = ((XtendField) delegate).eContainer();
                if ((_eContainer instanceof XtendAnnotationType)) {
                    XtendAnnotationTypeElementDeclarationImpl _xtendAnnotationTypeElementDeclarationImpl = new XtendAnnotationTypeElementDeclarationImpl();
                    final Procedure1<XtendAnnotationTypeElementDeclarationImpl> _function_1 = (XtendAnnotationTypeElementDeclarationImpl it_1) -> {
                        it_1.setDelegate(((XtendField) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<XtendAnnotationTypeElementDeclarationImpl>operator_doubleArrow(_xtendAnnotationTypeElementDeclarationImpl, _function_1);
                } else {
                    XtendFieldDeclarationImpl _xtendFieldDeclarationImpl = new XtendFieldDeclarationImpl();
                    final Procedure1<XtendFieldDeclarationImpl> _function_2 = (XtendFieldDeclarationImpl it_1) -> {
                        it_1.setDelegate(((XtendField) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<XtendFieldDeclarationImpl>operator_doubleArrow(_xtendFieldDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof XtendEnumLiteral) {
                _matched = true;
                XtendEnumerationValueDeclarationImpl _xtendEnumerationValueDeclarationImpl = new XtendEnumerationValueDeclarationImpl();
                final Procedure1<XtendEnumerationValueDeclarationImpl> _function_1 = (XtendEnumerationValueDeclarationImpl it_1) -> {
                    it_1.setDelegate(((XtendEnumLiteral) delegate));
                    it_1.setCompilationUnit(this);
                };
                _switchResult = ObjectExtensions.<XtendEnumerationValueDeclarationImpl>operator_doubleArrow(_xtendEnumerationValueDeclarationImpl, _function_1);
            }
        }
        return _switchResult;
    };
    return this.<XtendMember, XtendMemberDeclarationImpl<? extends XtendMember>>getOrCreate(delegate, _function);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMethodDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendMethodDeclarationImpl) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XtendEnumerationValueDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendEnumerationValueDeclarationImpl) XtendConstructorDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendConstructorDeclarationImpl) XtendField(org.eclipse.xtend.core.xtend.XtendField) XtendFieldDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendFieldDeclarationImpl) XtendAnnotationType(org.eclipse.xtend.core.xtend.XtendAnnotationType) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtendAnnotationTypeElementDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendAnnotationTypeElementDeclarationImpl) XtendEnumLiteral(org.eclipse.xtend.core.xtend.XtendEnumLiteral) XtendMemberDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendMemberDeclarationImpl)

Example 3 with XtendConstructor

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

the class XtendQualifiedNameProvider method getFullyQualifiedName.

@Override
public QualifiedName getFullyQualifiedName(EObject obj) {
    if (obj instanceof XtendTypeDeclaration) {
        XtendTypeDeclaration typeDecl = (XtendTypeDeclaration) obj;
        String typeName = typeDecl.getName();
        if (typeDecl.eContainer() instanceof XtendFile) {
            if (typeName == null)
                return null;
            XtendFile file = (XtendFile) typeDecl.eContainer();
            String packageName = file.getPackage();
            if (packageName != null) {
                return qualifiedNameConverter.toQualifiedName(packageName).append(typeName);
            }
            return QualifiedName.create(typeName);
        } else {
            return concatNames(obj, typeName);
        }
    }
    if (obj instanceof XtendConstructor) {
        return getFullyQualifiedName(obj.eContainer());
    }
    if (obj instanceof JvmIdentifiableElement && !(obj instanceof JvmTypeParameter)) {
        return getFullyQualifiedName((JvmIdentifiableElement) obj);
    }
    if (obj instanceof XtendField) {
        return concatNames(obj, ((XtendField) obj).getName());
    }
    if (obj instanceof XtendFunction) {
        return concatNames(obj, ((XtendFunction) obj).getName());
    }
    if (obj instanceof XtendEnumLiteral) {
        return concatNames(obj, ((XtendEnumLiteral) obj).getName());
    }
    return null;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtendEnumLiteral(org.eclipse.xtend.core.xtend.XtendEnumLiteral) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 4 with XtendConstructor

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

the class XtendHighlightingCalculator method highlightDeprecatedXtendAnnotationTarget.

protected void highlightDeprecatedXtendAnnotationTarget(IHighlightedPositionAcceptor acceptor, XtendAnnotationTarget target, XAnnotation annotation) {
    JvmType annotationType = annotation.getAnnotationType();
    if (annotationType instanceof JvmAnnotationType && DeprecationUtil.isDeprecatedAnnotation((JvmAnnotationType) annotationType)) {
        if (target instanceof XtendConstructor) {
            ICompositeNode compositeNode = NodeModelUtils.getNode(target);
            for (ILeafNode leaf : compositeNode.getLeafNodes()) {
                if (leaf.getGrammarElement() == xtendGrammarAccess.getMemberAccess().getNewKeyword_2_2_2()) {
                    highlightNode(acceptor, leaf, XbaseHighlightingStyles.DEPRECATED_MEMBERS);
                    highlightNode(acceptor, leaf, HighlightingStyles.KEYWORD_ID);
                    return;
                }
            }
        } else {
            EStructuralFeature nameFeature = target.eClass().getEStructuralFeature("name");
            if (nameFeature != null) {
                highlightFeature(acceptor, target, nameFeature, XbaseHighlightingStyles.DEPRECATED_MEMBERS);
            }
        }
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 5 with XtendConstructor

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

the class XtendJvmModelInferrer method initialize.

protected void initialize(XtendClass source, JvmGenericType inferredJvmType) {
    inferredJvmType.setVisibility(source.getVisibility());
    boolean isStatic = source.isStatic() && !isTopLevel(source);
    if (!isStatic) {
        JvmDeclaredType declaringType = inferredJvmType.getDeclaringType();
        if (declaringType instanceof JvmGenericType) {
            if (((JvmGenericType) declaringType).isInterface())
                isStatic = true;
        } else if (declaringType instanceof JvmAnnotationType) {
            isStatic = true;
        }
    }
    inferredJvmType.setStatic(isStatic);
    inferredJvmType.setAbstract(source.isAbstract());
    inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
    if (!inferredJvmType.isAbstract()) {
        inferredJvmType.setFinal(source.isFinal());
    }
    translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
    JvmTypeReference extendsClause = source.getExtends();
    if (extendsClause == null || extendsClause.getType() == null) {
        JvmTypeReference typeRefToObject = typeReferences.getTypeForName(Object.class, source);
        if (typeRefToObject != null)
            inferredJvmType.getSuperTypes().add(typeRefToObject);
    } else {
        inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(extendsClause));
    }
    for (JvmTypeReference intf : source.getImplements()) {
        inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
    }
    fixTypeParameters(inferredJvmType);
    addDefaultConstructor(source, inferredJvmType);
    for (XtendMember member : source.getMembers()) {
        if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null) || member instanceof XtendConstructor) {
            transform(member, inferredJvmType, true);
        }
    }
    appendSyntheticDispatchMethods(source, inferredJvmType);
    jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
    nameClashResolver.resolveNameClashes(inferredJvmType);
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Aggregations

XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)28 Test (org.junit.Test)18 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)9 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)7 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)7 XExpression (org.eclipse.xtext.xbase.XExpression)7 XtendField (org.eclipse.xtend.core.xtend.XtendField)6 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)6 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)5 XtendEnumLiteral (org.eclipse.xtend.core.xtend.XtendEnumLiteral)3 EObject (org.eclipse.emf.ecore.EObject)2 XtendAnnotationType (org.eclipse.xtend.core.xtend.XtendAnnotationType)2 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)2 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)2 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)2 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2