Java Code Examples for org.eclipse.xtext.common.types.JvmDeclaredType#getAnnotations()
The following examples show how to use
org.eclipse.xtext.common.types.JvmDeclaredType#getAnnotations() .
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: SourceBasedJdtTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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()); } }
Example 2
Source File: SourceBasedJdtTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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()); } }
Example 3
Source File: SourceBasedJdtTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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()); } }
Example 4
Source File: AbstractTypeProviderPerformanceTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected JvmDeclaredType loadAndResolve(String name, boolean accessMembers, boolean accessAnnotations, boolean accessTypeParams, boolean accessParameter, boolean accessParameterNames) { JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(name); EcoreUtil.resolveAll(type.eResource()); EcoreUtil.resolveAll(type.eResource().getResourceSet()); Assert.assertNotNull(name, type); if (accessAnnotations) { type.getAnnotations(); } if (accessMembers) { EList<JvmMember> members = type.getMembers(); for (JvmMember member : members) { if (accessAnnotations) { member.getAnnotations(); } if (member instanceof JvmExecutable) { JvmExecutable operation = (JvmExecutable) member; if (accessParameter) { EList<JvmFormalParameter> parameters = operation.getParameters(); for (JvmFormalParameter jvmFormalParameter : parameters) { if (accessAnnotations) { jvmFormalParameter.getAnnotations(); } if (accessParameterNames) { jvmFormalParameter.getName(); } } } } } } return type; }
Example 5
Source File: AbstractTypeProviderPerformanceTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected JvmDeclaredType loadAndResolve(String name, boolean accessMembers, boolean accessAnnotations, boolean accessTypeParams, boolean accessParameter, boolean accessParameterNames) { JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(name); EcoreUtil.resolveAll(type.eResource()); EcoreUtil.resolveAll(type.eResource().getResourceSet()); Assert.assertNotNull(name, type); if (accessAnnotations) { type.getAnnotations(); } if (accessMembers) { EList<JvmMember> members = type.getMembers(); for (JvmMember member : members) { if (accessAnnotations) { member.getAnnotations(); } if (member instanceof JvmExecutable) { JvmExecutable operation = (JvmExecutable) member; if (accessParameter) { EList<JvmFormalParameter> parameters = operation.getParameters(); for (JvmFormalParameter jvmFormalParameter : parameters) { if (accessAnnotations) { jvmFormalParameter.getAnnotations(); } if (accessParameterNames) { jvmFormalParameter.getName(); } } } } } } return type; }
Example 6
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotationWithStringDefault_04() throws Exception { String typeName = AnnotatedClassWithStringDefault.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()); checkDefaultAnnotationValuesAnnotatedExternalClass(annotationReference); }
Example 7
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@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); }
Example 8
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotationWithStringDefault_02() throws Exception { String typeName = AnnotatedInterfaceWithStringDefault.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()); checkDefaultAnnotationValuesAnnotatedExternalClass(annotationReference); }
Example 9
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotationWithStringDefault_01() throws Exception { String typeName = TestAnnotationWithStringDefault.Annotated.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); }
Example 10
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotationWithStringDefault_01() throws Exception { String typeName = TestAnnotationWithStringDefault.Annotated.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); }
Example 11
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotationWithStringDefault_04() throws Exception { String typeName = AnnotatedClassWithStringDefault.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()); checkDefaultAnnotationValuesAnnotatedExternalClass(annotationReference); }
Example 12
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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); }
Example 13
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotationWithStringDefault_02() throws Exception { String typeName = AnnotatedInterfaceWithStringDefault.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()); checkDefaultAnnotationValuesAnnotatedExternalClass(annotationReference); }
Example 14
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotationWithStringDefault_01() throws Exception { String typeName = TestAnnotationWithStringDefault.Annotated.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); }
Example 15
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotationWithStringDefault_04() throws Exception { String typeName = AnnotatedClassWithStringDefault.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()); checkDefaultAnnotationValuesAnnotatedExternalClass(annotationReference); }
Example 16
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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); }
Example 17
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotationWithStringDefault_02() throws Exception { String typeName = AnnotatedInterfaceWithStringDefault.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()); checkDefaultAnnotationValuesAnnotatedExternalClass(annotationReference); }