use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair in project xtext-eclipse by eclipse.
the class XbaseWithAnnotationsProposalProvider method completeXAnnotationElementValuePair_Element.
@Override
public void completeXAnnotationElementValuePair_Element(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
XAnnotation annotationReference = null;
if (model instanceof XAnnotationElementValuePair) {
annotationReference = (XAnnotation) model.eContainer();
} else if (model instanceof XAnnotation) {
annotationReference = (XAnnotation) model;
}
if (annotationReference != null) {
JvmType annotationType = annotationReference.getAnnotationType();
if (annotationType != null && !annotationType.eIsProxy() && annotationType instanceof JvmAnnotationType) {
// do not propose features like #toString, #hashCode etc
JvmAnnotationType casted = (JvmAnnotationType) annotationType;
final Set<JvmOperation> operations = Sets.newHashSet(casted.getDeclaredOperations());
Predicate<IEObjectDescription> predicate = Predicates.and(new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription in) {
return operations.contains(in.getEObjectOrProxy());
}
}, getFeatureDescriptionPredicate(context));
lookupCrossReference(((CrossReference) assignment.getTerminal()), context, acceptor, predicate);
}
}
}
use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair in project xtext-eclipse by eclipse.
the class JvmAnnotationReferencePrinter method _internalToString.
protected String _internalToString(final XAnnotation reference) {
final StringBuilder buffer = new StringBuilder();
buffer.append("@");
final URI uri = EcoreUtil.getURI(reference.getAnnotationType());
buffer.append(this.createLinkWithLabel(XtextElementLinks.XTEXTDOC_SCHEME, uri, reference.getAnnotationType().getSimpleName()));
XExpression _value = reference.getValue();
boolean _tripleNotEquals = (_value != null);
if (_tripleNotEquals) {
buffer.append("(");
buffer.append(reference.getValue());
buffer.append(")");
} else {
boolean _isEmpty = reference.getElementValuePairs().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
buffer.append("(");
final Function1<XAnnotationElementValuePair, String> _function = (XAnnotationElementValuePair it) -> {
final StringBuilder builder = new StringBuilder();
JvmOperation _elvis = null;
JvmOperation _element = it.getElement();
if (_element != null) {
_elvis = _element;
} else {
JvmType _annotationType = reference.getAnnotationType();
final Function1<JvmOperation, Boolean> _function_1 = (JvmOperation it_1) -> {
String _simpleName = it_1.getSimpleName();
return Boolean.valueOf(Objects.equal(_simpleName, "value"));
};
JvmOperation _findFirst = IterableExtensions.<JvmOperation>findFirst(((JvmAnnotationType) _annotationType).getDeclaredOperations(), _function_1);
_elvis = _findFirst;
}
final JvmOperation operation = _elvis;
final URI operationUri = EcoreUtil.getURI(operation);
builder.append(this.createLinkWithLabel(XtextElementLinks.XTEXTDOC_SCHEME, operationUri, operation.getSimpleName()));
builder.append("=");
builder.append(this.internalToString(it.getValue()));
return builder.toString();
};
buffer.append(IterableExtensions.join(ListExtensions.<XAnnotationElementValuePair, String>map(reference.getElementValuePairs(), _function), ", "));
buffer.append(")");
}
}
return buffer.toString();
}
use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair 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;
}
use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method testAnnotationValues.
@Test
public void testAnnotationValues() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("@test.Annotation(annotation2Value=@test.Annotation2(\'foo\'))");
_builder.newLine();
_builder.append("class C { ");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
final XAnnotationElementValuePair pair = IterableExtensions.<XAnnotationElementValuePair>head(IterableExtensions.<XAnnotation>head(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getAnnotations()).getElementValuePairs());
Object _evaluate = this.interpreter.evaluate(pair.getValue(), pair.getElement().getReturnType());
final XAnnotation anno = ((XAnnotation) _evaluate);
Assert.assertEquals("test.Annotation2", anno.getAnnotationType().getIdentifier());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations