use of org.eclipse.xtext.common.types.JvmAnnotationValue 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.xtext.common.types.JvmAnnotationValue in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method initialize.
protected void initialize(XtendAnnotationType source, JvmAnnotationType inferredJvmType) {
inferredJvmType.setVisibility(source.getVisibility());
inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
inferredJvmType.setAbstract(true);
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField) {
XtendField field = (XtendField) member;
if (!Strings.isEmpty(field.getName())) {
JvmOperation operation = typesFactory.createJvmOperation();
associator.associatePrimary(member, operation);
operation.setSimpleName(field.getName());
JvmTypeReference returnType = null;
XExpression initialValue = field.getInitialValue();
if (field.getType() != null) {
returnType = jvmTypesBuilder.cloneWithProxies(field.getType());
} else if (initialValue != null) {
returnType = jvmTypesBuilder.inferredType(initialValue);
}
operation.setReturnType(returnType);
if (initialValue != null) {
JvmAnnotationValue jvmAnnotationValue = jvmTypesBuilder.toJvmAnnotationValue(initialValue);
if (jvmAnnotationValue != null) {
operation.setDefaultValue(jvmAnnotationValue);
jvmAnnotationValue.setOperation(operation);
}
jvmTypesBuilder.setBody(operation, initialValue);
}
operation.setVisibility(JvmVisibility.PUBLIC);
translateAnnotationsTo(member.getAnnotations(), operation);
jvmTypesBuilder.copyDocumentationTo(member, operation);
inferredJvmType.getMembers().add(operation);
}
}
}
}
use of org.eclipse.xtext.common.types.JvmAnnotationValue in project xtext-xtend by eclipse.
the class JvmModelTests method testEmptyListAsAnnotationValueDefault.
@Test
public void testEmptyListAsAnnotationValueDefault() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("annotation Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("String[] bar = #[]");
_builder.newLine();
_builder.append("}");
_builder.newLine();
JvmMember _head = IterableExtensions.<JvmMember>head(this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString())).getMembers());
final JvmOperation inferred = ((JvmOperation) _head);
Assert.assertEquals("java.lang.String[]", inferred.getReturnType().getIdentifier());
JvmAnnotationValue _defaultValue = inferred.getDefaultValue();
Assert.assertTrue((_defaultValue instanceof JvmCustomAnnotationValue));
JvmAnnotationValue _defaultValue_1 = inferred.getDefaultValue();
EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _defaultValue_1).getValues());
Assert.assertTrue((_head_1 instanceof XListLiteral));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmAnnotationValue in project xtext-xtend by eclipse.
the class JvmModelTests method testAnnotationDefaultAssociatedWithJvmOperation.
@Test
public void testAnnotationDefaultAssociatedWithJvmOperation() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("annotation Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("val bar = \'\'");
_builder.newLine();
_builder.append("}");
_builder.newLine();
JvmMember _head = IterableExtensions.<JvmMember>head(this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString())).getMembers());
final JvmOperation inferred = ((JvmOperation) _head);
final JvmAnnotationValue defaultValue = inferred.getDefaultValue();
Assert.assertSame(inferred, defaultValue.getOperation());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmAnnotationValue in project xtext-xtend by eclipse.
the class XAnnotationExtensions method getProcessorType.
public JvmType getProcessorType(final JvmAnnotationType it) {
final Function1<JvmAnnotationReference, Boolean> _function = (JvmAnnotationReference it_1) -> {
JvmAnnotationType _annotation = it_1.getAnnotation();
String _identifier = null;
if (_annotation != null) {
_identifier = _annotation.getIdentifier();
}
String _name = Active.class.getName();
return Boolean.valueOf(Objects.equal(_identifier, _name));
};
final JvmAnnotationReference activeAnnotation = IterableExtensions.<JvmAnnotationReference>findFirst(it.getAnnotations(), _function);
final Function1<JvmAnnotationValue, Boolean> _function_1 = (JvmAnnotationValue it_1) -> {
return Boolean.valueOf(((it_1.getOperation() == null) || Objects.equal(it_1.getOperation().getSimpleName(), "value")));
};
final JvmAnnotationValue annoVal = IterableExtensions.<JvmAnnotationValue>findFirst(activeAnnotation.getValues(), _function_1);
boolean _matched = false;
if (annoVal instanceof JvmTypeAnnotationValue) {
_matched = true;
JvmTypeReference _head = IterableExtensions.<JvmTypeReference>head(((JvmTypeAnnotationValue) annoVal).getValues());
JvmType _type = null;
if (_head != null) {
_type = _head.getType();
}
return _type;
}
if (!_matched) {
if (annoVal instanceof JvmCustomAnnotationValue) {
_matched = true;
EObject _head = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) annoVal).getValues());
JvmOperation _operation = ((JvmCustomAnnotationValue) annoVal).getOperation();
JvmTypeReference _returnType = null;
if (_operation != null) {
_returnType = _operation.getReturnType();
}
final Object type = this.constantExpressionsInterpreter.evaluate(((XExpression) _head), _returnType);
if ((type instanceof JvmTypeReference)) {
return ((JvmTypeReference) type).getType();
}
}
}
return null;
}
Aggregations