org.eclipse.xtext.common.types.JvmStringAnnotationValue Java Examples
The following examples show how to use
org.eclipse.xtext.common.types.JvmStringAnnotationValue.
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: SARLValidator.java From sarl with Apache License 2.0 | 6 votes |
@SuppressWarnings({"checkstyle:cyclomaticcomplexity"}) private static String parseIssueOnCallAnnotation(List<JvmAnnotationValue> values) { final StringBuilder message = new StringBuilder(); for (final JvmAnnotationValue value : values) { if (value instanceof JvmStringAnnotationValue) { message.append(((JvmStringAnnotationValue) value).getValues()); } else if (value instanceof JvmCustomAnnotationValue) { for (final Object obj : ((JvmCustomAnnotationValue) value).getValues()) { if (obj instanceof XStringLiteral) { message.append(((XStringLiteral) obj).getValue()); } } } } return message.toString(); }
Example #2
Source File: JvmAnnotationReferenceBuilder.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * Creates and returns an annotation reference of the given annotation type's name and the given value. * * @param annotationTypeName * the type name of the created annotation. * @param values * the string value of the annotation's 'values' property. * * @return a result representing an annotation reference to the given annotation type, <code>null<code> if * annotationType are <code>null</code>. */ //TODO Move up the code used in Xtend's CompilationUnitImpl so we can reuse it here. //TODO Support other types and setting non default properties /* @Nullable */ public JvmAnnotationReference annotationRef(/* @Nullable */ String annotationTypeName, /* @Nullable */ String... values) { if (context == null || annotationTypeName == null) return null; JvmAnnotationReference result = typesFactory.createJvmAnnotationReference(); JvmType jvmType = references.findDeclaredType(annotationTypeName, context); if (jvmType == null) { throw new IllegalArgumentException("The type "+annotationTypeName +" is not on the classpath."); } if (!(jvmType instanceof JvmAnnotationType)) { throw new IllegalArgumentException("The given class " + annotationTypeName + " is not an annotation type."); } result.setAnnotation((JvmAnnotationType) jvmType); if (values != null && values.length>0) { JvmStringAnnotationValue annotationValue = typesFactory.createJvmStringAnnotationValue(); for (String value : values) { annotationValue.getValues().add(value); } result.getExplicitValues().add(annotationValue); } return result; }
Example #3
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testDefaultAnnotationAnnotationValue_02() throws Exception { JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getDefaultAnnotationValue( "annotationArrayValue"); assertEquals(2, value.getValues().size()); JvmAnnotationReference reference1 = value.getValues().get(0); assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(), reference1.getAnnotation().getIdentifier()); JvmAnnotationValue nestedAnnotationValue1 = reference1.getValues().get(0); assertTrue(nestedAnnotationValue1 instanceof JvmStringAnnotationValue); assertEquals("AnotherString", ((JvmStringAnnotationValue) nestedAnnotationValue1).getValues().get(0)); JvmAnnotationReference reference2 = value.getValues().get(1); assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(), reference2.getAnnotation().getIdentifier()); JvmAnnotationValue nestedAnnotationValue2 = reference2.getValues().get(0); assertTrue(nestedAnnotationValue2 instanceof JvmStringAnnotationValue); assertEquals("MyString", ((JvmStringAnnotationValue) nestedAnnotationValue2).getValues().get(0)); }
Example #4
Source File: JvmTypesBuilder.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * Creates and returns an annotation reference of the given annotation type's name and the given value. * * @param sourceElement * the source element to associate the created element with. * @param annotationTypeName * the type name of the created annotation. * @param value * the value of the annotation reference. Can be <code>null</code> if the reference doesn't have any value. * * @return a result representing an annotation reference to the given annotation type, <code>null<code> if * sourceElement or annotationType are <code>null</code>. * * @deprecated use {@link JvmAnnotationReferenceBuilder#annotationRef(String, String...)} instead */ //TODO Move up the code used in Xtend's CompilationUnitImpl so we can reuse it here. /* @Nullable */ @Deprecated public JvmAnnotationReference toAnnotation(/* @Nullable */ EObject sourceElement, /* @Nullable */ String annotationTypeName, /* @Nullable */ Object value) { JvmAnnotationReference result = typesFactory.createJvmAnnotationReference(); JvmType jvmType = references.findDeclaredType(annotationTypeName, sourceElement); if (jvmType == null) { throw new IllegalArgumentException("The type "+annotationTypeName +" is not on the classpath."); } if (!(jvmType instanceof JvmAnnotationType)) { throw new IllegalArgumentException("The given class " + annotationTypeName + " is not an annotation type."); } result.setAnnotation((JvmAnnotationType) jvmType); if (value != null) { if (value instanceof String) { JvmStringAnnotationValue annotationValue = typesFactory.createJvmStringAnnotationValue(); annotationValue.getValues().add((String) value); result.getExplicitValues().add(annotationValue); } } return result; }
Example #5
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testDefaultAnnotationAnnotationValue_02() throws Exception { JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getDefaultAnnotationValue( "annotationArrayValue"); assertEquals(2, value.getValues().size()); JvmAnnotationReference reference1 = value.getValues().get(0); assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(), reference1.getAnnotation().getIdentifier()); JvmAnnotationValue nestedAnnotationValue1 = reference1.getValues().get(0); assertTrue(nestedAnnotationValue1 instanceof JvmStringAnnotationValue); assertEquals("AnotherString", ((JvmStringAnnotationValue) nestedAnnotationValue1).getValues().get(0)); JvmAnnotationReference reference2 = value.getValues().get(1); assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(), reference2.getAnnotation().getIdentifier()); JvmAnnotationValue nestedAnnotationValue2 = reference2.getValues().get(0); assertTrue(nestedAnnotationValue2 instanceof JvmStringAnnotationValue); assertEquals("MyString", ((JvmStringAnnotationValue) nestedAnnotationValue2).getValues().get(0)); }
Example #6
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testDefaultAnnotationAnnotationValue_02() throws Exception { JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getDefaultAnnotationValue( "annotationArrayValue"); assertEquals(2, value.getValues().size()); JvmAnnotationReference reference1 = value.getValues().get(0); assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(), reference1.getAnnotation().getIdentifier()); JvmAnnotationValue nestedAnnotationValue1 = reference1.getValues().get(0); assertTrue(nestedAnnotationValue1 instanceof JvmStringAnnotationValue); assertEquals("AnotherString", ((JvmStringAnnotationValue) nestedAnnotationValue1).getValues().get(0)); JvmAnnotationReference reference2 = value.getValues().get(1); assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(), reference2.getAnnotation().getIdentifier()); JvmAnnotationValue nestedAnnotationValue2 = reference2.getValues().get(0); assertTrue(nestedAnnotationValue2 instanceof JvmStringAnnotationValue); assertEquals("MyString", ((JvmStringAnnotationValue) nestedAnnotationValue2).getValues().get(0)); }
Example #7
Source File: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private JvmAnnotationValue createStringAnnotationValue(Object value) { JvmStringAnnotationValue annotationValue = TypesFactory.eINSTANCE.createJvmStringAnnotationValue(); if (value != null) { @SuppressWarnings("unchecked") InternalEList<Object> values = (InternalEList<Object>)(InternalEList<?>)annotationValue.getValues(); if (value instanceof Object[]) { for (Object element : (Object[])value) { if (element instanceof String) { values.addUnique(element); } } } else { values.addUnique(value); } } return annotationValue; }
Example #8
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotatedField_01() throws Exception { String typeName = TestAnnotation.Annotated.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmField field = getFieldFromType(type, TestAnnotation.Annotated.class, "field"); assertNotNull(field); JvmStringAnnotationValue value = (JvmStringAnnotationValue) getDefaultOrExplicitAnnotationValue("value", field); assertEquals(1, value.getValues().size()); String s = value.getValues().get(0); assertEquals("MyString", s); }
Example #9
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotatedConstructor_04() throws Exception { String typeName = TestAnnotation.Annotated.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated(java.lang.String,java.lang.String)"); assertNotNull(constructor); JvmStringAnnotationValue value = (JvmStringAnnotationValue) getExplicitAnnotationValue("value", constructor); assertEquals(1, value.getValues().size()); String s = value.getValues().get(0); assertEquals("thirdConstructorWithBody", s); }
Example #10
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotationAnnotationValue_02() throws Exception { JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getConstructorParameterAnnotationValue( "annotationValue"); assertEquals(1, value.getValues().size()); JvmAnnotationReference annotationReference = value.getValues().get(0); assertEquals(TestAnnotation.NestedAnnotation.class.getName(), annotationReference.getAnnotation().getIdentifier()); assertEquals(1, annotationReference.getValues().size()); JvmStringAnnotationValue nestedValue = (JvmStringAnnotationValue) annotationReference.getValues().get(0); assertEquals(1, nestedValue.getValues().size()); assertEquals("MyString", nestedValue.getValues().get(0)); }
Example #11
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testDefaultAnnotationAnnotationValue_01() throws Exception { JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getDefaultAnnotationValue( "annotationValue"); assertEquals(1, value.getValues().size()); JvmAnnotationReference reference = value.getValues().get(0); assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(), reference.getAnnotation().getIdentifier()); JvmAnnotationValue nestedAnnotationValue = reference.getValues().get(0); assertTrue(nestedAnnotationValue instanceof JvmStringAnnotationValue); assertEquals("AnotherString", ((JvmStringAnnotationValue) nestedAnnotationValue).getValues().get(0)); }
Example #12
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testDefaultStringAnnotationValue_01() throws Exception { JvmStringAnnotationValue value = (JvmStringAnnotationValue) getDefaultAnnotationValue("stringValue"); assertEquals(1, value.getValues().size()); String string = value.getValues().get(0); assertEquals("", string); }
Example #13
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testDefaultStringAnnotationValue_02() throws Exception { JvmStringAnnotationValue value = (JvmStringAnnotationValue) getDefaultAnnotationValue("stringArrayValue"); assertEquals(1, value.getValues().size()); String string = value.getValues().get(0); assertEquals("arrayValue", string); }
Example #14
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void checkDefaultAnnotationValues(JvmAnnotationReference annotationReference) { List<JvmAnnotationValue> values = annotationReference.getValues(); assertEquals(2, values.size()); Map<String, String> nameToValue = Maps.newHashMap(); nameToValue.put("emptyString", ""); nameToValue.put("string", "string"); for (JvmAnnotationValue value : values) { String defaultValue = nameToValue.remove(value.getValueName()); assertNotNull(value.getValueName(), defaultValue); JvmStringAnnotationValue castedValue = (JvmStringAnnotationValue) value; assertEquals(1, castedValue.getValues().size()); assertEquals(defaultValue, castedValue.getValues().get(0)); } assertTrue(nameToValue.isEmpty()); }
Example #15
Source File: JvmStringAnnotationValueItemProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * This handles model notifications by calling {@link #updateChildren} to update any cached * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void notifyChanged(Notification notification) { updateChildren(notification); switch (notification.getFeatureID(JvmStringAnnotationValue.class)) { case TypesPackage.JVM_STRING_ANNOTATION_VALUE__VALUES: fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true)); return; } super.notifyChanged(notification); }
Example #16
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotatedConstructor_03() throws Exception { String typeName = TestAnnotation.Annotated.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated(java.lang.String,T)"); assertNotNull(constructor); JvmStringAnnotationValue value = (JvmStringAnnotationValue) getExplicitAnnotationValue("value", constructor); assertEquals(1, value.getValues().size()); String s = value.getValues().get(0); assertEquals("parameterizedConstructor", s); }
Example #17
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotatedConstructor_03() throws Exception { String typeName = TestAnnotation.Annotated.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated(java.lang.String,T)"); assertNotNull(constructor); JvmStringAnnotationValue value = (JvmStringAnnotationValue) getExplicitAnnotationValue("value", constructor); assertEquals(1, value.getValues().size()); String s = value.getValues().get(0); assertEquals("parameterizedConstructor", s); }
Example #18
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotationAnnotationValue_03() throws Exception { JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getMethodParameterAnnotationValue( "annotationValue"); assertEquals(1, value.getValues().size()); JvmAnnotationReference annotationReference = value.getValues().get(0); assertEquals(TestAnnotation.NestedAnnotation.class.getName(), annotationReference.getAnnotation().getIdentifier()); assertEquals(1, annotationReference.getValues().size()); JvmStringAnnotationValue nestedValue = (JvmStringAnnotationValue) annotationReference.getValues().get(0); assertEquals(1, nestedValue.getValues().size()); assertEquals("MyString", nestedValue.getValues().get(0)); }
Example #19
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testStringAnnotationValue_05() throws Exception { JvmStringAnnotationValue value = (JvmStringAnnotationValue) getConstructorParameterAnnotationValue( "stringValue"); assertEquals(1, value.getValues().size()); String s = value.getValues().get(0); assertEquals("stringValue", s); }
Example #20
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testStringAnnotationValue_04() throws Exception { JvmStringAnnotationValue value = (JvmStringAnnotationValue) getMethodParameterAnnotationValue( "stringArrayValue"); assertEquals(2, value.getValues().size()); String s = value.getValues().get(0); assertEquals("array", s); s = value.getValues().get(1); assertEquals("value", s); }
Example #21
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testStringAnnotationValue_03() throws Exception { JvmStringAnnotationValue value = (JvmStringAnnotationValue) getMethodParameterAnnotationValue("stringValue"); assertEquals(1, value.getValues().size()); String s = value.getValues().get(0); assertEquals("stringValue", s); }
Example #22
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testStringAnnotationValue_02() throws Exception { JvmStringAnnotationValue value = (JvmStringAnnotationValue) getAnnotationValue("stringArrayValue"); assertEquals(4, value.getValues().size()); String s = value.getValues().get(0); assertEquals("array", s); s = value.getValues().get(1); assertEquals("value", s); s = value.getValues().get(2); assertEquals("duplicate", s); s = value.getValues().get(3); assertEquals("duplicate", s); }
Example #23
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testStringAnnotationValue_01() throws Exception { JvmStringAnnotationValue value = (JvmStringAnnotationValue) getAnnotationValue("stringValue"); assertEquals(1, value.getValues().size()); String s = value.getValues().get(0); assertEquals("stringValue", s); }
Example #24
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void checkDefaultAnnotationValues(JvmAnnotationReference annotationReference) { List<JvmAnnotationValue> values = annotationReference.getValues(); assertEquals(2, values.size()); Map<String, String> nameToValue = Maps.newHashMap(); nameToValue.put("emptyString", ""); nameToValue.put("string", "string"); for (JvmAnnotationValue value : values) { String defaultValue = nameToValue.remove(value.getValueName()); assertNotNull(value.getValueName(), defaultValue); JvmStringAnnotationValue castedValue = (JvmStringAnnotationValue) value; assertEquals(1, castedValue.getValues().size()); assertEquals(defaultValue, castedValue.getValues().get(0)); } assertTrue(nameToValue.isEmpty()); }
Example #25
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testDefaultStringAnnotationValue_02() throws Exception { JvmStringAnnotationValue value = (JvmStringAnnotationValue) getDefaultAnnotationValue("stringArrayValue"); assertEquals(1, value.getValues().size()); String string = value.getValues().get(0); assertEquals("arrayValue", string); }
Example #26
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testDefaultStringAnnotationValue_01() throws Exception { JvmStringAnnotationValue value = (JvmStringAnnotationValue) getDefaultAnnotationValue("stringValue"); assertEquals(1, value.getValues().size()); String string = value.getValues().get(0); assertEquals("", string); }
Example #27
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testDefaultAnnotationAnnotationValue_01() throws Exception { JvmAnnotationAnnotationValue value = (JvmAnnotationAnnotationValue) getDefaultAnnotationValue( "annotationValue"); assertEquals(1, value.getValues().size()); JvmAnnotationReference reference = value.getValues().get(0); assertEquals(TestAnnotationWithDefaults.NestedAnnotation.class.getName(), reference.getAnnotation().getIdentifier()); JvmAnnotationValue nestedAnnotationValue = reference.getValues().get(0); assertTrue(nestedAnnotationValue instanceof JvmStringAnnotationValue); assertEquals("AnotherString", ((JvmStringAnnotationValue) nestedAnnotationValue).getValues().get(0)); }
Example #28
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotatedField_01() throws Exception { String typeName = TestAnnotation.Annotated.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmField field = getFieldFromType(type, TestAnnotation.Annotated.class, "field"); assertNotNull(field); JvmStringAnnotationValue value = (JvmStringAnnotationValue) getDefaultOrExplicitAnnotationValue("value", field); assertEquals(1, value.getValues().size()); String s = value.getValues().get(0); assertEquals("MyString", s); }
Example #29
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotatedConstructor_04() throws Exception { String typeName = TestAnnotation.Annotated.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated(java.lang.String,java.lang.String)"); assertNotNull(constructor); JvmStringAnnotationValue value = (JvmStringAnnotationValue) getExplicitAnnotationValue("value", constructor); assertEquals(1, value.getValues().size()); String s = value.getValues().get(0); assertEquals("thirdConstructorWithBody", s); }
Example #30
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testStringAnnotationValue_02() throws Exception { JvmStringAnnotationValue value = (JvmStringAnnotationValue) getAnnotationValue("stringArrayValue"); assertEquals(4, value.getValues().size()); String s = value.getValues().get(0); assertEquals("array", s); s = value.getValues().get(1); assertEquals("value", s); s = value.getValues().get(2); assertEquals("duplicate", s); s = value.getValues().get(3); assertEquals("duplicate", s); }