use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method getExplicitAnnotationValue.
public JvmAnnotationValue getExplicitAnnotationValue(String name, JvmAnnotationTarget target) {
JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
for (JvmAnnotationValue value : annotationReference.getExplicitValues()) {
if (name.equals(value.getValueName()))
return value;
}
fail("Cannot find annotationValue " + name);
return null;
}
use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testBug427098.
@Test
public void testBug427098() {
String typeName = Bug427098.class.getName();
JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
JvmAnnotationReference annotationReference = type.getAnnotations().get(0);
JvmTypeAnnotationValue annotationValue = getClassArrayAnnotationValue(annotationReference);
assertEquals("classArray", annotationValue.getOperation().getSimpleName());
List<JvmTypeReference> typeReferences = annotationValue.getValues();
assertEquals(5, typeReferences.size());
assertTypeReference("int", typeReferences, 0);
assertTypeReference("void", typeReferences, 1);
assertTypeReference("double[][][]", typeReferences, 2);
assertTypeReference("CharSequence[]", typeReferences, 3);
assertTypeReference("Iterable", typeReferences, 4);
}
use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testAnnotatedParameter_04.
@Test
public void testAnnotatedParameter_04() throws Exception {
String typeName = TestAnnotation.Annotated.class.getName();
JvmAnnotationType annotationType = (JvmAnnotationType) getTypeProvider().findTypeByName(TestAnnotation.class.getName());
JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
JvmOperation method = getMethodFromType(type, TestAnnotation.Annotated.class, "method(java.lang.String,java.lang.String,java.lang.String)");
JvmAnnotationTarget target = method.getParameters().get(0);
assertEquals(2, target.getAnnotations().size());
JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
assertSame(annotationType, annotationReference.getAnnotation());
annotationType = (JvmAnnotationType) getTypeProvider().findTypeByName(TestAnnotation.NestedAnnotation.class.getName());
annotationReference = target.getAnnotations().get(1);
assertSame(annotationType, annotationReference.getAnnotation());
}
use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testAnnotationWithStringDefault_03.
@Test
public void testAnnotationWithStringDefault_03() throws Exception {
String typeName = TestAnnotationWithStringDefault.AnnotatedInterface.class.getName();
JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
List<JvmAnnotationReference> annotations = type.getAnnotations();
assertEquals(1, annotations.size());
JvmAnnotationReference annotationReference = annotations.get(0);
assertEquals(TestAnnotationWithStringDefault.class.getName(), annotationReference.getAnnotation().getIdentifier());
checkDefaultAnnotationValues(annotationReference);
}
use of org.eclipse.xtext.common.types.JvmAnnotationReference in project xtext-eclipse by eclipse.
the class SourceBasedJdtTypeProviderTest method testClassAnnotationValue_07.
@Test
public void testClassAnnotationValue_07() 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 ", "@SimpleAnnotation( type = DoesNotExist.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);
assertTrue(((JvmTypeAnnotationValue) value).getValues().isEmpty());
} finally {
javaFile.setContents(new StringInputStream(content), IResource.NONE, new NullProgressMonitor());
}
}
Aggregations