use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testAnnotatedParameter_03.
@Test
public void testAnnotatedParameter_03() throws Exception {
String typeName = TestAnnotation.Annotated.class.getName();
JvmAnnotationType annotationType = (JvmAnnotationType) getTypeProvider().findTypeByName(TestAnnotation.NestedAnnotation.class.getName());
JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated(java.lang.String,java.lang.String,java.lang.String)");
JvmAnnotationTarget target = constructor.getParameters().get(2);
assertEquals(1, target.getAnnotations().size());
JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
assertSame(annotationType, annotationReference.getAnnotation());
}
use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class SourceBasedJdtTypeProviderTest method testClassAnnotationValue_09.
@Test
public void testClassAnnotationValue_09() throws Exception {
IJavaProject project = projectProvider.getJavaProject(null);
String typeName = EmptyAbstractClass.class.getName();
IFile javaFile = (IFile) project.getProject().findMember(new Path("src/" + typeName.replace('.', '/') + ".java"));
assertNotNull(javaFile);
String content = Files.readStreamIntoString(javaFile.getContents());
try {
String newContent = content.replace("public abstract ", "@TestAnnotation( classArray = ) public abstract ");
javaFile.setContents(new StringInputStream(newContent), IResource.NONE, new NullProgressMonitor());
JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
List<JvmAnnotationReference> annotations = type.getAnnotations();
assertEquals(1, annotations.size());
JvmAnnotationReference annotation = annotations.get(0);
assertEquals(1, annotation.getExplicitValues().size());
JvmAnnotationValue value = annotation.getExplicitValues().get(0);
assertTrue(value instanceof JvmTypeAnnotationValue);
List<JvmTypeReference> typeLiterals = ((JvmTypeAnnotationValue) value).getValues();
assertEquals(0, typeLiterals.size());
} finally {
javaFile.setContents(new StringInputStream(content), IResource.NONE, new NullProgressMonitor());
}
}
use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class SourceBasedJdtTypeProviderTest method testClassAnnotationValue_08.
@Test
public void testClassAnnotationValue_08() throws Exception {
IJavaProject project = projectProvider.getJavaProject(null);
String typeName = EmptyAbstractClass.class.getName();
IFile javaFile = (IFile) project.getProject().findMember(new Path("src/" + typeName.replace('.', '/') + ".java"));
assertNotNull(javaFile);
String content = Files.readStreamIntoString(javaFile.getContents());
try {
String newContent = content.replace("public abstract ", "@TestAnnotation( classArray = { String.class, DoesNotExist.class, String.class } ) public abstract ");
javaFile.setContents(new StringInputStream(newContent), IResource.NONE, new NullProgressMonitor());
JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
List<JvmAnnotationReference> annotations = type.getAnnotations();
assertEquals(1, annotations.size());
JvmAnnotationReference annotation = annotations.get(0);
assertEquals(1, annotation.getExplicitValues().size());
JvmAnnotationValue value = annotation.getExplicitValues().get(0);
assertTrue(value instanceof JvmTypeAnnotationValue);
List<JvmTypeReference> typeLiterals = ((JvmTypeAnnotationValue) value).getValues();
assertEquals(2, typeLiterals.size());
} finally {
javaFile.setContents(new StringInputStream(content), IResource.NONE, new NullProgressMonitor());
}
}
use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testAnnotationAnnotationValue_03.
@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));
}
use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testDefaultAnnotationAnnotationValueByReference.
@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());
}
}
}
Aggregations