Java Code Examples for org.eclipse.xtext.common.types.JvmAnnotationReference#getValues()

The following examples show how to use org.eclipse.xtext.common.types.JvmAnnotationReference#getValues() . 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: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDefaultAnnotationAnnotationValueByReference() throws Exception {
	String typeName = Bug334943Client.class.getName();
	JvmDeclaredType client = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	JvmOperation operation = Iterables.get(client.getDeclaredOperations(), 0);
	List<JvmAnnotationReference> annotations = operation.getAnnotations();
	assertEquals(1, annotations.size());
	JvmAnnotationReference annotation = annotations.get(0);
	for (JvmAnnotationValue value : annotation.getValues()) {
		if ("enumValue".equals(value.getValueName())) {
			JvmEnumAnnotationValue enumValue = (JvmEnumAnnotationValue) value;
			assertEquals(1, enumValue.getValues().size());
			assertEquals("FirstValue", enumValue.getValues().get(0).getSimpleName());
		}
	}
}
 
Example 2
Source File: XAnnotationUtil.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public Set<ElementType> getAnnotationTargets(JvmAnnotationType annotation) {
	EList<JvmAnnotationReference> annotations = annotation.getAnnotations();
	for (JvmAnnotationReference annoRef : annotations) {
		if (Target.class.getName().equals(annoRef.getAnnotation().getIdentifier())) {
			EList<JvmAnnotationValue> values = annoRef.getValues();
			JvmAnnotationValue value = values.isEmpty() ? null : values.get(0);
			if (value instanceof JvmEnumAnnotationValue) {
				Set<ElementType> result = newHashSet();
				for (JvmEnumerationLiteral elementType : ((JvmEnumAnnotationValue) value).getValues()) {
					final String simpleName = elementType.getSimpleName();
					result.add(ElementType.valueOf(simpleName));
				}
				return result;
			}
		}
	}
	return emptySet();
}
 
Example 3
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDefaultAnnotationAnnotationValueByReference() throws Exception {
	String typeName = Bug334943Client.class.getName();
	JvmDeclaredType client = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	JvmOperation operation = Iterables.get(client.getDeclaredOperations(), 0);
	List<JvmAnnotationReference> annotations = operation.getAnnotations();
	assertEquals(1, annotations.size());
	JvmAnnotationReference annotation = annotations.get(0);
	for (JvmAnnotationValue value : annotation.getValues()) {
		if ("enumValue".equals(value.getValueName())) {
			JvmEnumAnnotationValue enumValue = (JvmEnumAnnotationValue) value;
			assertEquals(1, enumValue.getValues().size());
			assertEquals("FirstValue", enumValue.getValues().get(0).getSimpleName());
		}
	}
}
 
Example 4
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDefaultAnnotationAnnotationValueByReference() throws Exception {
	String typeName = Bug334943Client.class.getName();
	JvmDeclaredType client = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	JvmOperation operation = Iterables.get(client.getDeclaredOperations(), 0);
	List<JvmAnnotationReference> annotations = operation.getAnnotations();
	assertEquals(1, annotations.size());
	JvmAnnotationReference annotation = annotations.get(0);
	for (JvmAnnotationValue value : annotation.getValues()) {
		if ("enumValue".equals(value.getValueName())) {
			JvmEnumAnnotationValue enumValue = (JvmEnumAnnotationValue) value;
			assertEquals(1, enumValue.getValues().size());
			assertEquals("FirstValue", enumValue.getValues().get(0).getSimpleName());
		}
	}
}
 
Example 5
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public JvmAnnotationValue getDefaultOrExplicitAnnotationValue(String name, JvmAnnotationTarget target) {
	JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
	for (JvmAnnotationValue value : annotationReference.getValues()) {
		if (name.equals(value.getValueName()))
			return value;
	}
	fail("Cannot find annotationValue " + name);
	return null;
}
 
Example 6
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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 7
Source File: FeatureCallCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private static boolean isConstantExpression(JvmAnnotationReference reference) {
	for (final JvmAnnotationValue annotationValue: reference.getValues()) {
		if ("constantExpression".equals(annotationValue.getValueName())) {
			if (annotationValue instanceof JvmBooleanAnnotationValue) {
				return ((JvmBooleanAnnotationValue) annotationValue).getValues().get(0).booleanValue();
			} else if (annotationValue instanceof JvmCustomAnnotationValue) {
				final EObject value = ((JvmCustomAnnotationValue) annotationValue).getValues().get(0);
				if (value instanceof XBooleanLiteral) {
					return ((XBooleanLiteral) value).isIsTrue();
				}
			}
		}
	}
	return false;
}
 
Example 8
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public JvmAnnotationValue getDefaultOrExplicitAnnotationValue(String name, JvmAnnotationTarget target) {
	JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
	for (JvmAnnotationValue value : annotationReference.getValues()) {
		if (name.equals(value.getValueName()))
			return value;
	}
	fail("Cannot find annotationValue " + name);
	return null;
}
 
Example 9
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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 10
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public JvmAnnotationValue getDefaultOrExplicitAnnotationValue(String name, JvmAnnotationTarget target) {
	JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
	for (JvmAnnotationValue value : annotationReference.getValues()) {
		if (name.equals(value.getValueName()))
			return value;
	}
	fail("Cannot find annotationValue " + name);
	return null;
}
 
Example 11
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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());
}