Java Code Examples for org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation#getValue()
The following examples show how to use
org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation#getValue() .
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: XbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void _toJavaExpression(final XAnnotation annotation, final ITreeAppendable b) { b.append("@"); b.append(annotation.getAnnotationType()); XExpression value = annotation.getValue(); if (value != null) { b.append("("); internalToJavaExpression(value, b); b.append(")"); } else { EList<XAnnotationElementValuePair> valuePairs = annotation.getElementValuePairs(); if (valuePairs.isEmpty()) return; b.append("("); for (int i = 0; i < valuePairs.size(); i++) { XAnnotationElementValuePair pair = valuePairs.get(i); b.append(pair.getElement().getSimpleName()); b.append(" = "); internalToJavaExpression(pair.getValue(), b); if (i < valuePairs.size()-1) { b.append(", "); } } b.append(")"); } }
Example 2
Source File: JvmAnnotationReferencePrinter.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected String _internalToString(XAnnotation reference) { StringBuilder buffer = new StringBuilder(); buffer.append("@"); buffer.append(createLinkWithLabel(XtextElementLinks.XTEXTDOC_SCHEME, EcoreUtil.getURI(reference.getAnnotationType()), reference.getAnnotationType().getSimpleName())); if (reference.getValue() != null) { buffer.append("("); buffer.append(reference.getValue()); buffer.append(")"); } else if (!reference.getElementValuePairs().isEmpty()) { buffer.append("("); buffer.append(reference.getElementValuePairs().stream().map(evPair -> { StringBuilder builder = new StringBuilder(); Iterable<JvmOperation> declaredOperations = ((JvmAnnotationType) reference.getAnnotationType()).getDeclaredOperations(); builder.append(createLinkToOperation(evPair.getElement(), declaredOperations)); builder.append("="); builder.append(internalToString(evPair.getValue())); return builder.toString(); }).collect(Collectors.joining(", "))); buffer.append(")"); } return buffer.toString(); }
Example 3
Source File: Utils.java From sarl with Apache License 2.0 | 6 votes |
private static void addAnnotationToSignature(StringBuilder textRepresentation, SARLGrammarKeywordAccess elements, ISerializer serializer, ImportManager importManager, XAnnotation annotation) { textRepresentation.append(elements.getCommercialAtKeyword()); textRepresentation.append(getSignatureType(annotation.getAnnotationType(), importManager)); final XExpression value = annotation.getValue(); if (value != null) { textRepresentation.append(elements.getLeftParenthesisKeyword()); textRepresentation.append(serializer.serialize(value).trim()); textRepresentation.append(elements.getRightParenthesisKeyword()); } else if (!annotation.getElementValuePairs().isEmpty()) { textRepresentation.append(elements.getLeftParenthesisKeyword()); boolean addComa = false; for (final XAnnotationElementValuePair pair : annotation.getElementValuePairs()) { if (addComa) { textRepresentation.append(elements.getCommaKeyword()); } else { addComa = true; } textRepresentation.append(elements.getEqualsSignKeyword()); textRepresentation.append(serializer.serialize(pair.getValue()).trim()); } textRepresentation.append(elements.getRightParenthesisKeyword()); } }
Example 4
Source File: JvmTypesBuilder.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * Translates a single {@link XAnnotation} to {@link JvmAnnotationReference} that can be added to a {@link JvmAnnotationTarget}. * * @param anno the source annotation * * @return a {@link JvmAnnotationReference} that can be attached to some {@link JvmAnnotationTarget} */ /* @Nullable */ public JvmAnnotationReference getJvmAnnotationReference(/* @Nullable */ XAnnotation anno) { if(anno == null) return null; JvmAnnotationReference reference = typesFactory.createJvmAnnotationReference(); final JvmType annotation = (JvmType) anno.eGet( XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, false); if (annotation.eIsProxy()) { JvmAnnotationType copiedProxy = TypesFactory.eINSTANCE.createJvmAnnotationType(); ((InternalEObject)copiedProxy).eSetProxyURI(EcoreUtil.getURI(annotation)); reference.setAnnotation(copiedProxy); } else if (annotation instanceof JvmAnnotationType){ reference.setAnnotation((JvmAnnotationType) annotation); } for (XAnnotationElementValuePair val : anno.getElementValuePairs()) { XExpression valueExpression = val.getValue(); JvmAnnotationValue annotationValue = toJvmAnnotationValue(valueExpression); if (annotationValue != null) { JvmOperation op = (JvmOperation) val.eGet( XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT, false); annotationValue.setOperation(op); reference.getExplicitValues().add(annotationValue); } } if (anno.getValue() != null) { JvmAnnotationValue value = toJvmAnnotationValue(anno.getValue()); if (value != null) { reference.getExplicitValues().add(value); } } associate(anno, reference); return reference; }
Example 5
Source File: XbaseWithAnnotationsTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void computeChildTypesForUnknownAnnotation(XAnnotation object, ITypeComputationState state) { XExpression expression = object.getValue(); if (expression != null) state.withNonVoidExpectation().computeTypes(expression); else { List<XAnnotationElementValuePair> valuePairs = object.getElementValuePairs(); for(XAnnotationElementValuePair pair: valuePairs) { computeTypes(object, pair.getElement(), pair.getValue(), state); } } }
Example 6
Source File: XAnnotationUtil.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public XExpression findValue(XAnnotation annotation, JvmOperation jvmOperation) { if (jvmOperation.getSimpleName().equals("value") && annotation.getValue() != null) { return annotation.getValue(); } for (XAnnotationElementValuePair pair : annotation.getElementValuePairs()) { if (pair.getElement() == jvmOperation) return pair.getValue(); } return null; }