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

The following examples show how to use org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration. 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: XtendAnnotationReferenceImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public AnnotationTypeDeclaration getAnnotationTypeDeclaration() {
  AnnotationTypeDeclaration _switchResult = null;
  JvmType _annotationType = this.getAnnotationType();
  final JvmType type = _annotationType;
  boolean _matched = false;
  if (type instanceof JvmAnnotationType) {
    _matched=true;
    TypeDeclaration _typeDeclaration = this.getCompilationUnit().toTypeDeclaration(((JvmDeclaredType)type));
    _switchResult = ((AnnotationTypeDeclaration) _typeDeclaration);
  }
  if (!_matched) {
    _switchResult = null;
  }
  return _switchResult;
}
 
Example #2
Source File: JvmAnnotationReferenceImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
private JvmOperation findOperation(final String name) {
  ConditionUtils.checkJavaIdentifier(name, "name");
  AnnotationTypeDeclaration _annotationTypeDeclaration = this.getAnnotationTypeDeclaration();
  final JvmAnnotationType jvmAnnoType = ((JvmAnnotationTypeDeclarationImpl) _annotationTypeDeclaration).getDelegate();
  final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> {
    String _simpleName = it.getSimpleName();
    return Boolean.valueOf(Objects.equal(_simpleName, name));
  };
  final JvmOperation jvmOperation = IterableExtensions.<JvmOperation>findFirst(jvmAnnoType.getDeclaredOperations(), _function);
  if ((jvmOperation == null)) {
    String _identifier = jvmAnnoType.getIdentifier();
    String _plus = ((("The annotation property \'" + name) + "\' is not declared on the annotation type \'") + _identifier);
    String _plus_1 = (_plus + "\'.");
    throw new IllegalArgumentException(_plus_1);
  }
  return jvmOperation;
}
 
Example #3
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 #4
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 #5
Source File: JvmAnnotationTargetImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
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 #6
Source File: TypeLookupImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public AnnotationTypeDeclaration findSourceAnnotationType(final String qualifiedName) {
  final XtendTypeDeclarationImpl<? extends XtendTypeDeclaration> type = this.findSourceType(qualifiedName);
  XtendTypeDeclarationImpl<? extends XtendTypeDeclaration> _switchResult = null;
  boolean _matched = false;
  if (type instanceof AnnotationTypeDeclaration) {
    _matched=true;
    _switchResult = ((XtendTypeDeclarationImpl<? extends XtendTypeDeclaration>)type);
  }
  return ((AnnotationTypeDeclaration)_switchResult);
}
 
Example #7
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 #8
Source File: JvmAnnotationReferenceImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AnnotationTypeDeclaration getAnnotationTypeDeclaration() {
  TypeDeclaration _typeDeclaration = this.getCompilationUnit().toTypeDeclaration(this.getDelegate().getAnnotation());
  return ((AnnotationTypeDeclaration) _typeDeclaration);
}
 
Example #9
Source File: MutableJvmInterfaceDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableAnnotationTypeDeclaration> getDeclaredAnnotationTypes() {
  Iterable<? extends AnnotationTypeDeclaration> _declaredAnnotationTypes = super.getDeclaredAnnotationTypes();
  return ((Iterable<? extends MutableAnnotationTypeDeclaration>) _declaredAnnotationTypes);
}
 
Example #10
Source File: XtendTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends AnnotationTypeDeclaration> getDeclaredAnnotationTypes() {
  return Iterables.<AnnotationTypeDeclaration>filter(this.getDeclaredMembers(), AnnotationTypeDeclaration.class);
}
 
Example #11
Source File: MutableJvmEnumerationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableAnnotationTypeDeclaration> getDeclaredAnnotationTypes() {
  Iterable<? extends AnnotationTypeDeclaration> _declaredAnnotationTypes = super.getDeclaredAnnotationTypes();
  return ((Iterable<? extends MutableAnnotationTypeDeclaration>) _declaredAnnotationTypes);
}
 
Example #12
Source File: JvmTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Iterable<? extends AnnotationTypeDeclaration> getDeclaredAnnotationTypes() {
  return Iterables.<AnnotationTypeDeclaration>filter(this.getDeclaredMembers(), AnnotationTypeDeclaration.class);
}
 
Example #13
Source File: MutableJvmClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableAnnotationTypeDeclaration> getDeclaredAnnotationTypes() {
  Iterable<? extends AnnotationTypeDeclaration> _declaredAnnotationTypes = super.getDeclaredAnnotationTypes();
  return ((Iterable<? extends MutableAnnotationTypeDeclaration>) _declaredAnnotationTypes);
}
 
Example #14
Source File: MutableJvmAnnotationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableAnnotationTypeDeclaration> getDeclaredAnnotationTypes() {
  Iterable<? extends AnnotationTypeDeclaration> _declaredAnnotationTypes = super.getDeclaredAnnotationTypes();
  return ((Iterable<? extends MutableAnnotationTypeDeclaration>) _declaredAnnotationTypes);
}
 
Example #15
Source File: RegisterGlobalsContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public AnnotationTypeDeclaration findSourceAnnotationType(final String qualifiedName) {
  return this.getTypeLookup().findSourceAnnotationType(qualifiedName);
}
 
Example #16
Source File: AbstractAnnotationTypeProcessor.java    From xtext-lib with Eclipse Public License 2.0 4 votes vote down vote up
public void doValidate(List<? extends AnnotationTypeDeclaration> annotatedAnnotationTypes, @Extension ValidationContext context) {
	for (AnnotationTypeDeclaration annotatedAnnotationType : annotatedAnnotationTypes) {
		doValidate(annotatedAnnotationType, context);
	}
}
 
Example #17
Source File: AbstractAnnotationTypeProcessor.java    From xtext-lib with Eclipse Public License 2.0 4 votes vote down vote up
public void doGenerateCode(List<? extends AnnotationTypeDeclaration> annotatedSourceElements, @Extension CodeGenerationContext context) {
	for (AnnotationTypeDeclaration annotatedAnnotationType : annotatedSourceElements) {
		doGenerateCode(annotatedAnnotationType, context);
	}
}
 
Example #18
Source File: AbstractAnnotationTypeProcessor.java    From xtext-lib with Eclipse Public License 2.0 4 votes vote down vote up
public void doRegisterGlobals(List<? extends AnnotationTypeDeclaration> annotatedAnnotationTypes, @Extension RegisterGlobalsContext context) {
	for (AnnotationTypeDeclaration annotatedAnnotationType : annotatedAnnotationTypes) {
		doRegisterGlobals(annotatedAnnotationType, context);
	}
}
 
Example #19
Source File: SourceTypeLookup.java    From xtext-lib with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * @param qualifiedName
 *            the qualified name of the type to look up. Nested class delimiter is expected to be the '.' (dot).
 * @return the <code>AnnotationTypeDeclaration</code> with given
 *         qualified name, or <code>null</code> if no such class declaration
 *         is contained in the currently processed
 *         <code>CompilationUnit</code>
 */
AnnotationTypeDeclaration findSourceAnnotationType(String qualifiedName);
 
Example #20
Source File: AbstractAnnotationTypeProcessor.java    From xtext-lib with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Invoked by the validator
 * @param annotatedAnnotationType the generated annotation type that should be validated 
 * @param context 
 * @see #doValidate(List, ValidationContext)
 * @since 2.7
 */
public void doValidate(AnnotationTypeDeclaration annotatedAnnotationType, @Extension ValidationContext context) {}
 
Example #21
Source File: AbstractAnnotationTypeProcessor.java    From xtext-lib with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Called during code generation. 
 * 
 * @param annotatedAnnotationType a source element annotated with the annotation this processor is responsible for.
 * @param context
 * @see CodeGenerationParticipant#doGenerateCode(List, CodeGenerationContext)
 */
public void doGenerateCode(AnnotationTypeDeclaration annotatedAnnotationType, @Extension CodeGenerationContext context) {}
 
Example #22
Source File: AbstractAnnotationTypeProcessor.java    From xtext-lib with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Called during global symbol collecting.
 * 
 * @param annotatedAnnotationType a source element annotated with the annotation this processor is responsible for.
 * @param context
 */
public void doRegisterGlobals(AnnotationTypeDeclaration annotatedAnnotationType, @Extension RegisterGlobalsContext context) {}