use of org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl in project xtext-xtend by eclipse.
the class AnnotationReferenceProviderImpl method newAnnotationReference.
@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;
}
use of org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl in project xtext-xtend by eclipse.
the class AnnotationReferenceProviderImpl method newAnnotationReference.
@Override
public AnnotationReference newAnnotationReference(final AnnotationReference annotationReference, final Procedure1<AnnotationReferenceBuildContext> initializer) {
Object _xblockexpression = null;
{
this.compilationUnit.checkCanceled();
StringConcatenation _builder = new StringConcatenation();
_builder.append("annotationReference cannot be null");
Preconditions.checkArgument((annotationReference != null), _builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("initializer cannot be null");
Preconditions.checkArgument((initializer != null), _builder_1);
if ((annotationReference instanceof JvmAnnotationReferenceImpl)) {
final JvmAnnotationReference baseJvmAnnotationReference = ((JvmAnnotationReferenceImpl) annotationReference).getDelegate();
ConditionUtils.notRemoved(baseJvmAnnotationReference, "annotationReference");
final JvmAnnotationReference newJvmAnnotationReference = this.createJvmAnnotationReference(baseJvmAnnotationReference.getAnnotation());
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);
final Function1<JvmAnnotationValue, String> _function_1 = (JvmAnnotationValue it) -> {
String _elvis = null;
String _valueName = it.getValueName();
if (_valueName != null) {
_elvis = _valueName;
} else {
_elvis = "value";
}
return _elvis;
};
List<String> _map = ListExtensions.<JvmAnnotationValue, String>map(baseJvmAnnotationReference.getExplicitValues(), _function_1);
for (final String valueName : _map) {
{
final Object value = ((JvmAnnotationReferenceImpl) annotationReference).getValue(valueName);
buildContext.set(valueName, value);
}
}
initializer.apply(buildContext);
return this.compilationUnit.toAnnotationReference(newJvmAnnotationReference);
}
_xblockexpression = null;
}
return ((AnnotationReference) _xblockexpression);
}
use of org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl in project xtext-xtend by eclipse.
the class AnnotationReferenceProviderImpl method newAnnotationReference.
@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);
}
use of org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl in project xtext-xtend by eclipse.
the class CompilationUnitImpl method translateAnnotation.
protected AnnotationReference translateAnnotation(final XAnnotation annotation) {
AnnotationReference _xblockexpression = null;
{
AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
it.setCompilationUnit(this);
JvmAnnotationReference _createJvmAnnotationReference = this.typesFactory.createJvmAnnotationReference();
final Procedure1<JvmAnnotationReference> _function_1 = (JvmAnnotationReference reference) -> {
JvmType _annotationType = annotation.getAnnotationType();
reference.setAnnotation(((JvmAnnotationType) _annotationType));
};
JvmAnnotationReference _doubleArrow = ObjectExtensions.<JvmAnnotationReference>operator_doubleArrow(_createJvmAnnotationReference, _function_1);
it.setDelegate(_doubleArrow);
};
final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
EList<XAnnotationElementValuePair> _elementValuePairs = annotation.getElementValuePairs();
for (final XAnnotationElementValuePair valuePair : _elementValuePairs) {
{
final XExpression value = valuePair.getValue();
if ((value != null)) {
final JvmOperation operation = valuePair.getElement();
final Object annotationValue = this.translateAnnotationValue(value, operation.getReturnType());
buildContext.set(operation.getSimpleName(), annotationValue);
}
}
}
XExpression _value = annotation.getValue();
boolean _tripleNotEquals = (_value != null);
if (_tripleNotEquals) {
final Object annotationValue = this.translateAnnotationValue(annotation.getValue(), null);
buildContext.set("value", annotationValue);
}
_xblockexpression = this.toAnnotationReference(buildContext.getDelegate());
}
return _xblockexpression;
}
Aggregations