Search in sources :

Example 6 with JvmAnnotationValue

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

the class AnnotationReferenceBuildContextImpl method setValues.

protected void setValues(final String name, final Object values, final String componentType, final boolean mustBeArray) {
    final JvmOperation op = this.findOperation(name, mustBeArray);
    final JvmAnnotationValue newValue = this.createAnnotationValue(op, values);
    newValue.setOperation(op);
    this.setValue(newValue, values, componentType, mustBeArray);
    this.remove(op);
    this.delegate.getExplicitValues().add(newValue);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue)

Example 7 with JvmAnnotationValue

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

the class JvmAnnotationReferenceImpl method getExpression.

@Override
public Expression getExpression(final String property) {
    final JvmOperation op = this.findOperation(property);
    final Function1<JvmAnnotationValue, Boolean> _function = (JvmAnnotationValue it) -> {
        return Boolean.valueOf((Objects.equal(it.getOperation(), op) || ((it.getOperation() == null) && Objects.equal(op.getSimpleName(), "value"))));
    };
    final JvmAnnotationValue annotationValue = IterableExtensions.<JvmAnnotationValue>findFirst(this.getDelegate().getValues(), _function);
    boolean _matched = false;
    if (annotationValue instanceof JvmCustomAnnotationValue) {
        _matched = true;
        EObject _head = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) annotationValue).getValues());
        final XExpression expression = ((XExpression) _head);
        if (((expression != null) && this.getCompilationUnit().isBelongedToCompilationUnit(expression))) {
            return this.getCompilationUnit().toExpression(expression);
        }
    }
    return null;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmCustomAnnotationValue(org.eclipse.xtext.common.types.JvmCustomAnnotationValue) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue)

Example 8 with JvmAnnotationValue

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

the class JvmAnnotationReferenceImpl method getValue.

@Override
public Object getValue(final String property) {
    try {
        final JvmOperation op = this.findOperation(property);
        final Function1<JvmAnnotationValue, Boolean> _function = (JvmAnnotationValue it) -> {
            return Boolean.valueOf((Objects.equal(it.getOperation(), op) || ((it.getOperation() == null) && Objects.equal(op.getSimpleName(), "value"))));
        };
        final JvmAnnotationValue annotationValue = IterableExtensions.<JvmAnnotationValue>findFirst(this.getDelegate().getValues(), _function);
        final boolean isArrayType = ((op != null) && this.getCompilationUnit().getTypeReferences().isArray(op.getReturnType()));
        if ((annotationValue != null)) {
            return this.getCompilationUnit().translateAnnotationValue(annotationValue, isArrayType);
        }
    } catch (final Throwable _t) {
        if (_t instanceof ConstantExpressionEvaluationException) {
            final ConstantExpressionEvaluationException e = (ConstantExpressionEvaluationException) _t;
            this.getCompilationUnit().getProblemSupport().addError(this, e.getMessage());
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
    return null;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) ConstantExpressionEvaluationException(org.eclipse.xtext.xbase.interpreter.ConstantExpressionEvaluationException) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue)

Aggregations

JvmAnnotationValue (org.eclipse.xtext.common.types.JvmAnnotationValue)8 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)7 EObject (org.eclipse.emf.ecore.EObject)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 JvmCustomAnnotationValue (org.eclipse.xtext.common.types.JvmCustomAnnotationValue)3 XExpression (org.eclipse.xtext.xbase.XExpression)3 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)2 JvmMember (org.eclipse.xtext.common.types.JvmMember)2 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)2 Test (org.junit.Test)2 List (java.util.List)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 AnnotationReferenceBuildContextImpl (org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl)1 JvmAnnotationReferenceImpl (org.eclipse.xtend.core.macro.declaration.JvmAnnotationReferenceImpl)1 XtendField (org.eclipse.xtend.core.xtend.XtendField)1 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)1 Active (org.eclipse.xtend.lib.macro.Active)1 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)1 JvmType (org.eclipse.xtext.common.types.JvmType)1 JvmTypeAnnotationValue (org.eclipse.xtext.common.types.JvmTypeAnnotationValue)1