org.eclipse.xtend.lib.macro.declaration.AnnotationReference Java Examples

The following examples show how to use org.eclipse.xtend.lib.macro.declaration.AnnotationReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationReferenceProviderImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public AnnotationReference newAnnotationReference(final String annotationTypeName, final Procedure1<AnnotationReferenceBuildContext> initializer) {
  AnnotationReference _xblockexpression = null;
  {
    this.compilationUnit.checkCanceled();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("annotationTypeName cannot be null");
    Preconditions.checkArgument((annotationTypeName != null), _builder);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("initializer cannot be null");
    Preconditions.checkArgument((initializer != null), _builder_1);
    final JvmAnnotationReference jvmAnnotationReference = this.createJvmAnnotationReference(this.compilationUnit.getTypeReferences().findDeclaredType(annotationTypeName, this.compilationUnit.getXtendFile()));
    if ((jvmAnnotationReference == null)) {
      return null;
    }
    AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
    final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
      it.setDelegate(jvmAnnotationReference);
      it.setCompilationUnit(this.compilationUnit);
    };
    final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
    initializer.apply(buildContext);
    _xblockexpression = this.compilationUnit.toAnnotationReference(jvmAnnotationReference);
  }
  return _xblockexpression;
}
 
Example #2
Source File: AnnotationWithNestedEnumProcessor.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
  final MutableInterfaceDeclaration interfaceType = context.findInterface(this.getInterfaceName(annotatedClass));
  context.setPrimarySourceElement(interfaceType, annotatedClass);
  try {
    final EnumerationValueDeclaration value = annotatedClass.findAnnotation(context.findTypeGlobally(AnnotationWithNestedEnum.class)).getEnumValue("value");
    final Procedure1<AnnotationReferenceBuildContext> _function = (AnnotationReferenceBuildContext it) -> {
      it.setEnumValue("value", value);
    };
    final AnnotationReference ref = context.newAnnotationReference(AnnotationWithNestedEnum.class, _function);
    interfaceType.addAnnotation(ref);
  } catch (final Throwable _t) {
    if (_t instanceof Exception) {
      final Exception exc = (Exception)_t;
      String _message = exc.getMessage();
      String _plus = ("failed: " + _message);
      context.addError(annotatedClass, _plus);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example #3
Source File: JvmAnnotationTargetImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public AnnotationReference addAnnotation(final AnnotationReference annotationReference) {
  AnnotationReference _xblockexpression = null;
  {
    this.checkMutable();
    Preconditions.checkArgument((annotationReference != null), "annotationReference cannot be null");
    AnnotationReference _xifexpression = null;
    if ((annotationReference instanceof JvmAnnotationReferenceImpl)) {
      AnnotationReference _xblockexpression_1 = null;
      {
        final JvmAnnotationReference jvmAnnotationReference = EcoreUtil2.<JvmAnnotationReference>cloneWithProxies(((JvmAnnotationReferenceImpl)annotationReference).getDelegate());
        EList<JvmAnnotationReference> _annotations = this.getDelegate().getAnnotations();
        _annotations.add(jvmAnnotationReference);
        _xblockexpression_1 = this.getCompilationUnit().toAnnotationReference(jvmAnnotationReference);
      }
      _xifexpression = _xblockexpression_1;
    } else {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append(annotationReference);
      _builder.append(" is not annotation reference");
      throw new IllegalArgumentException(_builder.toString());
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example #4
Source File: FinalFieldsConstructorProcessor.java    From xtext-lib with Eclipse Public License 2.0 6 votes vote down vote up
public void addFinalFieldsConstructor(final MutableClassDeclaration it) {
  boolean _isEmpty = this.getFinalFieldsConstructorArgumentTypes(it).isEmpty();
  if (_isEmpty) {
    final AnnotationReference anno = it.findAnnotation(this.context.findTypeGlobally(FinalFieldsConstructor.class));
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("There are no final fields, this annotation has no effect");
    this.context.addWarning(anno, _builder.toString());
    return;
  }
  boolean _hasFinalFieldsConstructor = this.hasFinalFieldsConstructor(it);
  if (_hasFinalFieldsConstructor) {
    this.context.addError(it, this.getConstructorAlreadyExistsMessage(it));
    return;
  }
  final Procedure1<MutableConstructorDeclaration> _function = (MutableConstructorDeclaration it_1) -> {
    this.context.setPrimarySourceElement(it_1, this.context.getPrimarySourceElement(it_1.getDeclaringType()));
    this.makeFinalFieldsConstructor(it_1);
  };
  it.addConstructor(_function);
}
 
Example #5
Source File: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testAnnotation3() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("@test.Annotation");
  _builder.newLine();
  _builder.append("class MyClass {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("@test.Annotation2 String foo");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
    final AnnotationReference anno = IterableExtensions.head(it.getTypeLookup().findClass("MyClass").getAnnotations());
    final AnnotationReference anno2 = IterableExtensions.head(IterableExtensions.head(it.getTypeLookup().findClass("MyClass").getDeclaredFields()).getAnnotations());
    final Procedure1<AnnotationReferenceBuildContext> _function_1 = (AnnotationReferenceBuildContext it_1) -> {
      it_1.set("annotation2Value", anno2);
    };
    it.getTypeLookup().findClass("MyClass").addAnnotation(it.getAnnotationReferenceProvider().newAnnotationReference(anno, _function_1));
    it.getTypeLookup().findClass("MyClass").removeAnnotation(anno);
    Object _value = anno.getValue("annotation2Value");
    Assert.assertEquals(IterableExtensions.head(IterableExtensions.head(it.getTypeLookup().findClass("MyClass").getDeclaredFields()).getAnnotations()).getAnnotationTypeDeclaration(), ((AnnotationReference) _value).getAnnotationTypeDeclaration());
  };
  this.asCompilationUnit(this.validFile(_builder), _function);
}
 
Example #6
Source File: CompilationUnitImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected Object translateAnnotationValue(final XExpression value, final JvmTypeReference expectedType) {
  Object _xblockexpression = null;
  {
    if ((value instanceof XAnnotation)) {
      return this.translateAnnotation(((XAnnotation)value));
    }
    if ((value instanceof XListLiteral)) {
      final Iterable<XAnnotation> annotations = Iterables.<XAnnotation>filter(((XListLiteral)value).getElements(), XAnnotation.class);
      int _size = ((XListLiteral)value).getElements().size();
      int _size_1 = IterableExtensions.size(annotations);
      boolean _equals = (_size == _size_1);
      if (_equals) {
        final ArrayList<AnnotationReference> annotationReferences = CollectionLiterals.<AnnotationReference>newArrayList();
        for (final XAnnotation annotation : annotations) {
          AnnotationReference _translateAnnotation = this.translateAnnotation(annotation);
          annotationReferences.add(_translateAnnotation);
        }
        final AnnotationReference[] result = ((AnnotationReference[])Conversions.unwrapArray(annotationReferences, AnnotationReference.class));
        return result;
      }
    }
    _xblockexpression = this.translate(this.evaluate(value, expectedType));
  }
  return _xblockexpression;
}
 
Example #7
Source File: XtendAnnotationTargetImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends AnnotationReference> getAnnotations() {
  final Function1<XAnnotation, AnnotationReference> _function = (XAnnotation it) -> {
    return this.getCompilationUnit().toAnnotationReference(it);
  };
  return ImmutableList.<AnnotationReference>copyOf(ListExtensions.<XAnnotation, AnnotationReference>map(this.getDelegate().getAnnotations(), _function));
}
 
Example #8
Source File: GetProcessor.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doTransform(final List<? extends MutableMethodDeclaration> methods, @Extension final TransformationContext context) {
  for (final MutableMethodDeclaration m : methods) {
    {
      final AnnotationReference annotation = m.findAnnotation(context.findTypeGlobally(Get.class));
      final Object pattern = annotation.getValue("value");
      if ((pattern == null)) {
        context.addError(annotation, "A URL pattern must be provided.");
      } else {
      }
    }
  }
}
 
Example #9
Source File: DotAttributeProcessor.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private Object annotationValue(MutableFieldDeclaration field,
		TransformationContext context, String property) {
	for (AnnotationReference reference : field.getAnnotations()) {
		if (DotAttribute.class.getName().equals(reference
				.getAnnotationTypeDeclaration().getQualifiedName())) {
			return reference.getValue(property);
		}
	}
	throw new IllegalArgumentException("No DotAttribute annotation found.");
}
 
Example #10
Source File: ToStringProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
  AnnotationReference _findAnnotation = it.findAnnotation(context.findTypeGlobally(Data.class));
  boolean _tripleNotEquals = (_findAnnotation != null);
  if (_tripleNotEquals) {
    return;
  }
  @Extension
  final ToStringProcessor.Util util = new ToStringProcessor.Util(context);
  final AnnotationReference annotation = it.findAnnotation(context.findTypeGlobally(ToString.class));
  final ToStringConfiguration configuration = new ToStringConfiguration(annotation);
  boolean _hasToString = util.hasToString(it);
  if (_hasToString) {
    context.addWarning(annotation, "toString is already defined, this annotation has no effect.");
  } else {
    TypeReference _extendedClass = it.getExtendedClass();
    TypeReference _object = context.getObject();
    boolean _notEquals = (!Objects.equal(_extendedClass, _object));
    if (_notEquals) {
      util.addReflectiveToString(it, configuration);
    } else {
      final Function1<MutableFieldDeclaration, Boolean> _function = (MutableFieldDeclaration it_1) -> {
        return Boolean.valueOf(((context.isThePrimaryGeneratedJavaElement(it_1) && (!it_1.isStatic())) && (!it_1.isTransient())));
      };
      util.addToString(it, IterableExtensions.filter(it.getDeclaredFields(), _function), configuration);
    }
  }
}
 
Example #11
Source File: ToStringProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
public ToStringConfiguration getToStringConfig(final ClassDeclaration it) {
  ToStringConfiguration _xblockexpression = null;
  {
    final AnnotationReference anno = it.findAnnotation(this.context.findTypeGlobally(ToString.class));
    ToStringConfiguration _xifexpression = null;
    if ((anno == null)) {
      _xifexpression = null;
    } else {
      _xifexpression = new ToStringConfiguration(anno);
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example #12
Source File: JvmAnnotationTargetImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public boolean removeAnnotation(final AnnotationReference annotationReference) {
  this.checkMutable();
  if ((annotationReference instanceof JvmAnnotationReferenceImpl)) {
    return this.getDelegate().getAnnotations().remove(((JvmAnnotationReferenceImpl)annotationReference).getDelegate());
  }
  return false;
}
 
Example #13
Source File: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAnnotation() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("@SuppressWarnings(\"unused\")");
  _builder.newLine();
  _builder.append("class MyClass {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("@com.google.inject.Inject(optional=true) MyClass foo");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
    Assert.assertNull(it.getPackageName());
    TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
    final ClassDeclaration clazz = ((ClassDeclaration) _head);
    Assert.assertEquals("MyClass", clazz.getQualifiedName());
    final AnnotationReference suppressWarning = IterableExtensions.head(clazz.getAnnotations());
    final AnnotationTypeDeclaration supressWarningsDeclaration = suppressWarning.getAnnotationTypeDeclaration();
    Assert.assertEquals("java.lang.SuppressWarnings", supressWarningsDeclaration.getQualifiedName());
    Assert.assertEquals("unused", suppressWarning.getStringArrayValue("value")[0]);
    Assert.assertEquals(2, IterableExtensions.size(supressWarningsDeclaration.getAnnotations()));
    final AnnotationTypeElementDeclaration valueProperty = IterableExtensions.<AnnotationTypeElementDeclaration>head(Iterables.<AnnotationTypeElementDeclaration>filter(supressWarningsDeclaration.getDeclaredMembers(), AnnotationTypeElementDeclaration.class));
    Assert.assertEquals("String[]", valueProperty.getType().toString());
    Assert.assertEquals("value", valueProperty.getSimpleName());
    MemberDeclaration _head_1 = IterableExtensions.head(clazz.getDeclaredMembers());
    final FieldDeclaration field = ((FieldDeclaration) _head_1);
    final AnnotationReference inject = IterableExtensions.head(field.getAnnotations());
    Object _value = inject.getValue("optional");
    Assert.assertTrue((((Boolean) _value)).booleanValue());
  };
  this.asCompilationUnit(this.validFile(_builder), _function);
}
 
Example #14
Source File: JvmMemberDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public void setDeprecated(final boolean deprecated) {
  this.checkMutable();
  if (deprecated) {
    T _delegate = this.getDelegate();
    _delegate.setDeprecated(true);
    this.addAnnotation(this.getCompilationUnit().getAnnotationReferenceProvider().newAnnotationReference(Deprecated.class));
  } else {
    T _delegate_1 = this.getDelegate();
    _delegate_1.setDeprecated(false);
    final AnnotationReference existingReference = this.findAnnotation(this.getCompilationUnit().getTypeLookup().findTypeGlobally(Deprecated.class));
    if ((existingReference != null)) {
      this.removeAnnotation(existingReference);
    }
  }
}
 
Example #15
Source File: FinalFieldsConstructorProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
protected void _transform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
  AnnotationReference _findAnnotation = it.findAnnotation(context.findTypeGlobally(Data.class));
  boolean _tripleNotEquals = (_findAnnotation != null);
  if (_tripleNotEquals) {
    return;
  }
  AnnotationReference _findAnnotation_1 = it.findAnnotation(context.findTypeGlobally(Accessors.class));
  boolean _tripleNotEquals_1 = (_findAnnotation_1 != null);
  if (_tripleNotEquals_1) {
    return;
  }
  @Extension
  final FinalFieldsConstructorProcessor.Util util = new FinalFieldsConstructorProcessor.Util(context);
  util.addFinalFieldsConstructor(it);
}
 
Example #16
Source File: EqualsHashCodeProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
  AnnotationReference _findAnnotation = it.findAnnotation(context.findTypeGlobally(Data.class));
  boolean _tripleNotEquals = (_findAnnotation != null);
  if (_tripleNotEquals) {
    return;
  }
  @Extension
  final EqualsHashCodeProcessor.Util util = new EqualsHashCodeProcessor.Util(context);
  boolean _hasEquals = util.hasEquals(it);
  if (_hasEquals) {
    final AnnotationReference annotation = it.findAnnotation(context.findTypeGlobally(EqualsHashCode.class));
    context.addWarning(annotation, "equals is already defined, this annotation has no effect");
  } else {
    boolean _hasHashCode = util.hasHashCode(it);
    if (_hasHashCode) {
      context.addWarning(it, "hashCode is already defined, this annotation has no effect");
    } else {
      final Function1<MutableFieldDeclaration, Boolean> _function = (MutableFieldDeclaration it_1) -> {
        return Boolean.valueOf((((!it_1.isStatic()) && (!it_1.isTransient())) && context.isThePrimaryGeneratedJavaElement(it_1)));
      };
      final Iterable<? extends MutableFieldDeclaration> fields = IterableExtensions.filter(it.getDeclaredFields(), _function);
      util.addEquals(it, fields, util.hasSuperEquals(it));
      util.addHashCode(it, fields, util.hasSuperHashCode(it));
    }
  }
}
 
Example #17
Source File: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=465007
 */
@Test
public void testAnnotation4() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("class MyClass {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("@test.Annotation2 String foo");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("@test.Annotation2(\"hubble\") String foo2");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("@test.Annotation2(value=\"hubble\") String foo3");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
    final AnnotationReference anno = IterableExtensions.head(IterableExtensions.head(it.getTypeLookup().findClass("MyClass").getDeclaredFields()).getAnnotations());
    final AnnotationReference copied = it.getAnnotationReferenceProvider().newAnnotationReference(anno);
    Assert.assertTrue(((JvmAnnotationReferenceImpl) copied).getDelegate().getExplicitValues().isEmpty());
    final AnnotationReference anno2 = IterableExtensions.head((((MutableFieldDeclaration[])Conversions.unwrapArray(it.getTypeLookup().findClass("MyClass").getDeclaredFields(), MutableFieldDeclaration.class))[1]).getAnnotations());
    final AnnotationReference copied2 = it.getAnnotationReferenceProvider().newAnnotationReference(anno2);
    Assert.assertEquals(1, ((JvmAnnotationReferenceImpl) copied2).getDelegate().getExplicitValues().size());
    final AnnotationReference anno3 = IterableExtensions.head((((MutableFieldDeclaration[])Conversions.unwrapArray(it.getTypeLookup().findClass("MyClass").getDeclaredFields(), MutableFieldDeclaration.class))[2]).getAnnotations());
    final AnnotationReference copied3 = it.getAnnotationReferenceProvider().newAnnotationReference(anno3);
    Assert.assertEquals(1, ((JvmAnnotationReferenceImpl) copied3).getDelegate().getExplicitValues().size());
  };
  this.asCompilationUnit(this.validFile(_builder), _function);
}
 
Example #18
Source File: CompilationUnitImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public AnnotationReference toAnnotationReference(final JvmAnnotationReference delegate) {
  final Function1<JvmAnnotationReference, JvmAnnotationReferenceImpl> _function = (JvmAnnotationReference it) -> {
    JvmAnnotationReferenceImpl _jvmAnnotationReferenceImpl = new JvmAnnotationReferenceImpl();
    final Procedure1<JvmAnnotationReferenceImpl> _function_1 = (JvmAnnotationReferenceImpl it_1) -> {
      it_1.setDelegate(delegate);
      it_1.setCompilationUnit(this);
    };
    return ObjectExtensions.<JvmAnnotationReferenceImpl>operator_doubleArrow(_jvmAnnotationReferenceImpl, _function_1);
  };
  return this.<JvmAnnotationReference, JvmAnnotationReferenceImpl>getOrCreate(delegate, _function);
}
 
Example #19
Source File: TypeAdapterImplProcessor.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
  final AnnotationReference typeAdapterImplAnnotation = annotatedClass.findAnnotation(context.findTypeGlobally(TypeAdapterImpl.class));
  final TypeReference targetType = typeAdapterImplAnnotation.getClassValue("value");
  this.generateImpl(annotatedClass, targetType, context);
  String _qualifiedName = annotatedClass.getQualifiedName();
  String _plus = (_qualifiedName + ".Factory");
  this.generateFactory(context.findClass(_plus), annotatedClass, targetType, context);
}
 
Example #20
Source File: CompilationUnitImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public AnnotationReference toAnnotationReference(final XAnnotation delegate) {
  final Function1<XAnnotation, XtendAnnotationReferenceImpl> _function = (XAnnotation it) -> {
    XtendAnnotationReferenceImpl _xtendAnnotationReferenceImpl = new XtendAnnotationReferenceImpl();
    final Procedure1<XtendAnnotationReferenceImpl> _function_1 = (XtendAnnotationReferenceImpl it_1) -> {
      it_1.setDelegate(delegate);
      it_1.setCompilationUnit(this);
    };
    return ObjectExtensions.<XtendAnnotationReferenceImpl>operator_doubleArrow(_xtendAnnotationReferenceImpl, _function_1);
  };
  return this.<XAnnotation, XtendAnnotationReferenceImpl>getOrCreate(delegate, _function);
}
 
Example #21
Source File: XtendAnnotationTargetImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public AnnotationReference findAnnotation(final Type annotationType) {
  final Function1<AnnotationReference, Boolean> _function = (AnnotationReference it) -> {
    AnnotationTypeDeclaration _annotationTypeDeclaration = it.getAnnotationTypeDeclaration();
    return Boolean.valueOf(Objects.equal(_annotationTypeDeclaration, annotationType));
  };
  return IterableExtensions.findFirst(this.getAnnotations(), _function);
}
 
Example #22
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _internalSet(final String name, final AnnotationReference[] values, final boolean mustBeArray) {
  ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(values)), "values");
  AnnotationReference _head = IterableExtensions.<AnnotationReference>head(((Iterable<AnnotationReference>)Conversions.doWrapArray(values)));
  AnnotationTypeDeclaration _annotationTypeDeclaration = null;
  if (_head!=null) {
    _annotationTypeDeclaration=_head.getAnnotationTypeDeclaration();
  }
  String _qualifiedName = null;
  if (_annotationTypeDeclaration!=null) {
    _qualifiedName=_annotationTypeDeclaration.getQualifiedName();
  }
  this.setValues(name, values, _qualifiedName, mustBeArray);
}
 
Example #23
Source File: AnnotationReferenceProviderImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AnnotationReference newAnnotationReference(final Class<?> annotationClass) {
  final Procedure1<AnnotationReferenceBuildContext> _function = (AnnotationReferenceBuildContext it) -> {
  };
  return this.newAnnotationReference(annotationClass, _function);
}
 
Example #24
Source File: CompilationUnitImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends AnnotationReference> getAnnotations() {
  return CollectionLiterals.<AnnotationReference>emptyList();
}
 
Example #25
Source File: JsonRpcDataTransformationContext.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public AnnotationReference newAnnotationReference(final Type arg0) {
  return this.delegate.newAnnotationReference(arg0);
}
 
Example #26
Source File: AnnotationReferenceProviderImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AnnotationReference newAnnotationReference(final Type annotationTypeDelcaration, final Procedure1<AnnotationReferenceBuildContext> initializer) {
  Object _xblockexpression = null;
  {
    this.compilationUnit.checkCanceled();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("annotationTypeDelcaration cannot be null");
    Preconditions.checkArgument((annotationTypeDelcaration != null), _builder);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("initializer cannot be null");
    Preconditions.checkArgument((initializer != null), _builder_1);
    JvmDeclaredType _switchResult = null;
    boolean _matched = false;
    if (annotationTypeDelcaration instanceof JvmAnnotationTypeDeclarationImpl) {
      _matched=true;
      _switchResult = ((JvmAnnotationTypeDeclarationImpl)annotationTypeDelcaration).getDelegate();
    }
    if (!_matched) {
      if (annotationTypeDelcaration instanceof XtendAnnotationTypeDeclarationImpl) {
        _matched=true;
        _switchResult = this.compilationUnit.getJvmModelAssociations().getInferredType(((XtendAnnotationTypeDeclarationImpl)annotationTypeDelcaration).getDelegate());
      }
    }
    if (!_matched) {
      throw new IllegalArgumentException(("couldn\'t construct type reference for type " + annotationTypeDelcaration));
    }
    final JvmDeclaredType type = _switchResult;
    if ((type instanceof JvmAnnotationType)) {
      final JvmAnnotationReference newJvmAnnotationReference = this.createJvmAnnotationReference(type);
      AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
      final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
        it.setDelegate(newJvmAnnotationReference);
        it.setCompilationUnit(this.compilationUnit);
      };
      final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
      initializer.apply(buildContext);
      return this.compilationUnit.toAnnotationReference(newJvmAnnotationReference);
    }
    _xblockexpression = null;
  }
  return ((AnnotationReference)_xblockexpression);
}
 
Example #27
Source File: TransformationContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public AnnotationReference newAnnotationReference(final Type annotationTypeDelcaration, final Procedure1<AnnotationReferenceBuildContext> initializer) {
  return this.getAnnotationReferenceProvider().newAnnotationReference(annotationTypeDelcaration, initializer);
}
 
Example #28
Source File: CompilationUnitImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected Object translate(final Object object) {
  if ((object instanceof XAnnotation[])) {
    final AnnotationReference[] result = new AnnotationReference[((Object[])object).length];
    int _length = ((Object[])object).length;
    ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _length, true);
    for (final Integer i : _doubleDotLessThan) {
      result[(i).intValue()] = this.translateAnnotation(((XAnnotation[])object)[(i).intValue()]);
    }
    return result;
  }
  if ((object instanceof XAnnotation)) {
    return this.translateAnnotation(((XAnnotation)object));
  }
  if ((object instanceof JvmTypeReference[])) {
    final TypeReference[] result_1 = new TypeReference[((Object[])object).length];
    int _length_1 = ((Object[])object).length;
    ExclusiveRange _doubleDotLessThan_1 = new ExclusiveRange(0, _length_1, true);
    for (final Integer i_1 : _doubleDotLessThan_1) {
      Object _translate = this.translate(((Object[])object)[(i_1).intValue()]);
      result_1[(i_1).intValue()] = ((TypeReference) _translate);
    }
    return result_1;
  }
  if ((object instanceof JvmTypeReference)) {
    return this.toTypeReference(((JvmTypeReference)object));
  }
  if ((object instanceof JvmEnumerationLiteral[])) {
    final EnumerationValueDeclaration[] result_2 = new EnumerationValueDeclaration[((Object[])object).length];
    int _length_2 = ((Object[])object).length;
    ExclusiveRange _doubleDotLessThan_2 = new ExclusiveRange(0, _length_2, true);
    for (final Integer i_2 : _doubleDotLessThan_2) {
      Object _translate_1 = this.translate(((Object[])object)[(i_2).intValue()]);
      result_2[(i_2).intValue()] = ((EnumerationValueDeclaration) _translate_1);
    }
    return result_2;
  }
  if ((object instanceof JvmEnumerationLiteral)) {
    return this.toMemberDeclaration(((JvmMember)object));
  }
  return object;
}
 
Example #29
Source File: AnnotationReferenceProviderImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AnnotationReference newAnnotationReference(final AnnotationReference annotationReference) {
  final Procedure1<AnnotationReferenceBuildContext> _function = (AnnotationReferenceBuildContext it) -> {
  };
  return this.newAnnotationReference(annotationReference, _function);
}
 
Example #30
Source File: JvmAnnotationTargetImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Iterable<? extends AnnotationReference> getAnnotations() {
  final Function1<JvmAnnotationReference, AnnotationReference> _function = (JvmAnnotationReference it) -> {
    return this.getCompilationUnit().toAnnotationReference(it);
  };
  return ImmutableList.<AnnotationReference>copyOf(ListExtensions.<JvmAnnotationReference, AnnotationReference>map(this.getDelegate().getAnnotations(), _function));
}