Search in sources :

Example 1 with JvmOperation

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

the class AbstractAssignabilityTest method isAssignableFrom.

public void isAssignableFrom(final Pair<String, String> lhsAndParams, final String rhs, final boolean expectation) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def ");
        {
            boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(lhsAndParams.getValue());
            boolean _not = (!_isNullOrEmpty);
            if (_not) {
                _builder.append("<");
                String _value = lhsAndParams.getValue();
                _builder.append(_value);
                _builder.append("> ");
            }
        }
        _builder.append("void method(");
        String _fixup = this.fixup(lhsAndParams.getKey());
        _builder.append(_fixup);
        _builder.append(" lhs, ");
        String _fixup_1 = this.fixup(rhs);
        _builder.append(_fixup_1);
        _builder.append(" rhs) {}");
        final String signature = _builder.toString();
        final XtendFunction function = this.function(signature.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        LightweightTypeReference _xifexpression = null;
        String _key = lhsAndParams.getKey();
        boolean _tripleNotEquals = (_key != null);
        if (_tripleNotEquals) {
            _xifexpression = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType());
        } else {
            _xifexpression = this.getOwner().newAnyTypeReference();
        }
        final LightweightTypeReference lhsType = _xifexpression;
        LightweightTypeReference _xifexpression_1 = null;
        if ((rhs != null)) {
            _xifexpression_1 = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>last(operation.getParameters()).getParameterType());
        } else {
            _xifexpression_1 = this.getOwner().newAnyTypeReference();
        }
        final LightweightTypeReference rhsType = _xifexpression_1;
        String _simpleName = lhsType.getSimpleName();
        String _plus = (_simpleName + " := ");
        String _simpleName_1 = rhsType.getSimpleName();
        String _plus_1 = (_plus + _simpleName_1);
        Assert.assertEquals(_plus_1, Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(lhsType, rhsType)));
        if (expectation) {
            List<LightweightTypeReference> _allSuperTypes = lhsType.getAllSuperTypes();
            for (final LightweightTypeReference superType : _allSuperTypes) {
                if (((superType.isArray() == lhsType.isArray()) || (lhsType.isArray() == rhsType.isArray()))) {
                    Assert.assertEquals(superType.toString(), Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(superType, rhsType)));
                }
            }
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 2 with JvmOperation

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

the class AnnotationReferenceBuildContextImpl method findOperation.

protected JvmOperation findOperation(final String name, final boolean mustBeArray) {
    final JvmOperation result = this.findOperation(name);
    JvmTypeReference _returnType = result.getReturnType();
    JvmType _type = null;
    if (_returnType != null) {
        _type = _returnType.getType();
    }
    final JvmType returnType = _type;
    boolean _and = false;
    if (!mustBeArray) {
        _and = false;
    } else {
        EClass _eClass = null;
        if (returnType != null) {
            _eClass = returnType.eClass();
        }
        boolean _notEquals = (!Objects.equal(_eClass, TypesPackage.Literals.JVM_ARRAY_TYPE));
        _and = _notEquals;
    }
    if (_and) {
        throw new IllegalArgumentException("Cannot assign array value to simple annotation property");
    }
    return result;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EClass(org.eclipse.emf.ecore.EClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 3 with JvmOperation

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

the class AnnotationReferenceBuildContextImpl method findOperation.

protected JvmOperation findOperation(final String name) {
    ConditionUtils.checkJavaIdentifier(name, "name");
    final JvmAnnotationType annotationType = this.delegate.getAnnotation();
    final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> {
        String _simpleName = it.getSimpleName();
        return Boolean.valueOf(Objects.equal(_simpleName, name));
    };
    final JvmOperation jvmOperation = IterableExtensions.<JvmOperation>findFirst(annotationType.getDeclaredOperations(), _function);
    if ((jvmOperation == null)) {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("The annotation property \'");
        _builder.append(name);
        _builder.append("\' is not declared on the annotation type \'");
        String _identifier = annotationType.getIdentifier();
        _builder.append(_identifier);
        _builder.append("\'.");
        throw new IllegalArgumentException(_builder.toString());
    }
    return jvmOperation;
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 4 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation 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 5 with JvmOperation

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

the class JvmInterfaceDeclarationImpl method addMethod.

@Override
public MutableMethodDeclaration addMethod(final String name, final Procedure1<MutableMethodDeclaration> initializer) {
    this.checkMutable();
    ConditionUtils.checkJavaIdentifier(name, "name");
    Preconditions.checkArgument((initializer != null), "initializer cannot be null");
    final JvmOperation newMethod = TypesFactory.eINSTANCE.createJvmOperation();
    newMethod.setVisibility(JvmVisibility.PUBLIC);
    newMethod.setSimpleName(name);
    newMethod.setReturnType(this.getCompilationUnit().toJvmTypeReference(this.getCompilationUnit().getTypeReferenceProvider().getPrimitiveVoid()));
    newMethod.setAbstract(true);
    this.getDelegate().getMembers().add(newMethod);
    MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(newMethod);
    final MutableMethodDeclaration mutableMethodDeclaration = ((MutableMethodDeclaration) _memberDeclaration);
    initializer.apply(mutableMethodDeclaration);
    return mutableMethodDeclaration;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration) MutableMethodDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration)

Aggregations

JvmOperation (org.eclipse.xtext.common.types.JvmOperation)202 Test (org.junit.Test)127 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)101 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)73 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)71 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)62 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)49 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)38 EObject (org.eclipse.emf.ecore.EObject)30 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)26 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)22 XExpression (org.eclipse.xtext.xbase.XExpression)20 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)20 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)20 JvmField (org.eclipse.xtext.common.types.JvmField)18 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)15 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)15 JvmMember (org.eclipse.xtext.common.types.JvmMember)15 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)11 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)10