org.eclipse.xtext.common.types.JvmTypeAnnotationValue Java Examples
The following examples show how to use
org.eclipse.xtext.common.types.JvmTypeAnnotationValue.
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: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private JvmAnnotationValue createTypeAnnotationValue(Object value) { JvmTypeAnnotationValue annotationValue = TypesFactory.eINSTANCE.createJvmTypeAnnotationValue(); if (value != null) { InternalEList<JvmTypeReference> values = (InternalEList<JvmTypeReference>)annotationValue.getValues(); if (value instanceof Object[]) { for (Object element : (Object[])value) { if (element instanceof ITypeBinding) { values.addUnique(createTypeReference((ITypeBinding)element)); } } } else if (value instanceof ITypeBinding) { values.addUnique(createTypeReference((ITypeBinding)value)); } } return annotationValue; }
Example #2
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 #3
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 #4
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 #5
Source File: SARLJvmModelInferrer.java From sarl with Apache License 2.0 | 6 votes |
/** Create an annotation with classes as values. * * @param type the type of the annotation. * @param values the values. * @return the reference to the JVM annotation. */ private JvmAnnotationReference annotationClassRef(Class<? extends Annotation> type, List<? extends JvmTypeReference> values) { try { final JvmAnnotationReference annot = this._annotationTypesBuilder.annotationRef(type); final JvmTypeAnnotationValue annotationValue = this.services.getTypesFactory().createJvmTypeAnnotationValue(); for (final JvmTypeReference value : values) { annotationValue.getValues().add(this.typeBuilder.cloneWithProxies(value)); } annot.getExplicitValues().add(annotationValue); return annot; } catch (IllegalArgumentException exception) { // ignore } return null; }
Example #6
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_02() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getAnnotationValue("classArray"); assertEquals(2, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); type = value.getValues().get(1).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); }
Example #7
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testDefaultTypeAnnotationValue_01() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getDefaultAnnotationValue("charSequenceClass"); assertEquals(1, value.getValues().size()); JvmTypeReference typeReference = value.getValues().get(0); assertEquals(String.class.getName(), typeReference.getIdentifier()); }
Example #8
Source File: SARLReentrantTypeResolver.java From sarl with Apache License 2.0 | 5 votes |
/** Replies the type of the field that represents a SARL capacity buffer. * * @param resolvedTypes the resolver of types. * @param field the field. * @return the type, never {@code null}. */ protected LightweightTypeReference getSarlCapacityFieldType(IResolvedTypes resolvedTypes, JvmField field) { // For capacity call redirection LightweightTypeReference fieldType = resolvedTypes.getActualType(field); final JvmAnnotationReference capacityAnnotation = this.annotationLookup.findAnnotation(field, ImportedCapacityFeature.class); if (capacityAnnotation != null) { final JvmTypeReference ref = ((JvmTypeAnnotationValue) capacityAnnotation.getValues().get(0)).getValues().get(0); fieldType = resolvedTypes.getActualType(ref.getType()); } return fieldType; }
Example #9
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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); }
Example #10
Source File: AnnotationReferenceBuildContextImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void _setValue(final JvmTypeAnnotationValue it, final TypeReference[] value, final String componentType, final boolean mustBeArray) { EList<JvmTypeReference> _values = it.getValues(); final Function1<TypeReferenceImpl, JvmTypeReference> _function = (TypeReferenceImpl it_1) -> { return this.compilationUnit.toJvmTypeReference(it_1); }; Iterable<JvmTypeReference> _map = IterableExtensions.<TypeReferenceImpl, JvmTypeReference>map(Iterables.<TypeReferenceImpl>filter(((Iterable<?>)Conversions.doWrapArray(value)), TypeReferenceImpl.class), _function); Iterables.<JvmTypeReference>addAll(_values, _map); }
Example #11
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_01() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getAnnotationValue("charSequenceClass"); assertEquals(1, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(String.class.getName(), type.getIdentifier()); }
Example #12
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_06() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getConstructorParameterAnnotationValue("classArray"); assertEquals(2, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); type = value.getValues().get(1).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); }
Example #13
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_04() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getMethodParameterAnnotationValue("charSequenceClass"); assertEquals(1, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(String.class.getName(), type.getIdentifier()); }
Example #14
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_03() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getMethodParameterAnnotationValue("classArray"); assertEquals(2, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); type = value.getValues().get(1).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); }
Example #15
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_05() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getConstructorParameterAnnotationValue( "charSequenceClass"); assertEquals(1, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(String.class.getName(), type.getIdentifier()); }
Example #16
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_06() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getConstructorParameterAnnotationValue("classArray"); assertEquals(2, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); type = value.getValues().get(1).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); }
Example #17
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testDefaultTypeAnnotationValue_01() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getDefaultAnnotationValue("charSequenceClass"); assertEquals(1, value.getValues().size()); JvmTypeReference typeReference = value.getValues().get(0); assertEquals(String.class.getName(), typeReference.getIdentifier()); }
Example #18
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@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); }
Example #19
Source File: JvmTypeAnnotationValueItemProvider.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(JvmTypeAnnotationValue.class)) { case TypesPackage.JVM_TYPE_ANNOTATION_VALUE__VALUES: fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false)); return; } super.notifyChanged(notification); }
Example #20
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_05() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getConstructorParameterAnnotationValue( "charSequenceClass"); assertEquals(1, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(String.class.getName(), type.getIdentifier()); }
Example #21
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_02() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getAnnotationValue("classArray"); assertEquals(2, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); type = value.getValues().get(1).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); }
Example #22
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_04() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getMethodParameterAnnotationValue("charSequenceClass"); assertEquals(1, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(String.class.getName(), type.getIdentifier()); }
Example #23
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_03() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getMethodParameterAnnotationValue("classArray"); assertEquals(2, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); type = value.getValues().get(1).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); }
Example #24
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_05() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getConstructorParameterAnnotationValue( "charSequenceClass"); assertEquals(1, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(String.class.getName(), type.getIdentifier()); }
Example #25
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_06() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getConstructorParameterAnnotationValue("classArray"); assertEquals(2, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); type = value.getValues().get(1).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(TestAnnotation.Annotated.class.getName(), type.getIdentifier()); }
Example #26
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testDefaultTypeAnnotationValue_01() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getDefaultAnnotationValue("charSequenceClass"); assertEquals(1, value.getValues().size()); JvmTypeReference typeReference = value.getValues().get(0); assertEquals(String.class.getName(), typeReference.getIdentifier()); }
Example #27
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_01() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getAnnotationValue("charSequenceClass"); assertEquals(1, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(String.class.getName(), type.getIdentifier()); }
Example #28
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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); }
Example #29
Source File: ReflectionTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected JvmTypeAnnotationValue getClassArrayAnnotationValue(JvmAnnotationReference annotationReference) { for(JvmAnnotationValue candidate: annotationReference.getExplicitValues()) { if (candidate instanceof JvmTypeAnnotationValue && candidate.getValueName().equals("classArray")) { return (JvmTypeAnnotationValue) candidate; } } fail("Cannot find annotation value 'classArray'"); return null; }
Example #30
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassAnnotationValue_01() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getAnnotationValue("charSequenceClass"); assertEquals(1, value.getValues().size()); JvmType type = value.getValues().get(0).getType(); assertNotNull(type); assertFalse(type.eIsProxy()); assertEquals(String.class.getName(), type.getIdentifier()); }