Java 类org.eclipse.xtext.common.types.JvmAnnotationType 实例源码

项目:xtext-extras    文件:ReusedTypeProviderTest.java   
@Test
@Override
public void testFindTypeByName_AbstractMultimap_02() {
  String typeName = "com.google.common.collect.AbstractMultimap";
  JvmType _findTypeByName = this.getTypeProvider().findTypeByName(typeName);
  JvmGenericType type = ((JvmGenericType) _findTypeByName);
  JvmFeature _onlyElement = Iterables.<JvmFeature>getOnlyElement(type.findAllFeaturesByName("containsValue"));
  JvmOperation containsValue = ((JvmOperation) _onlyElement);
  Assert.assertNotNull(containsValue);
  JvmFormalParameter firstParam = containsValue.getParameters().get(0);
  Assert.assertEquals(1, firstParam.getAnnotations().size());
  JvmAnnotationReference annotationReference = firstParam.getAnnotations().get(0);
  JvmAnnotationType annotationType = annotationReference.getAnnotation();
  Assert.assertTrue(annotationType.eIsProxy());
  Assert.assertEquals("java:/Objects/javax.annotation.Nullable", EcoreUtil.getURI(annotationType).trimFragment().toString());
}
项目:xtext-extras    文件:ResourceDescriptionProviderTest.java   
@Test
public void testStubGeneration_04() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("public @interface MyTest {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("String value();");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<IResourceDescription> _function = (IResourceDescription it) -> {
    Assert.assertEquals("MyTest", IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getQualifiedName().toString());
    EObject _eObjectOrProxy = IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getEObjectOrProxy();
    Assert.assertTrue((_eObjectOrProxy instanceof JvmAnnotationType));
    Assert.assertEquals(1, IterableExtensions.size(it.getExportedObjects()));
  };
  this.resultsIn(_builder, _function);
}
项目:xtext-extras    文件:TypeInsteadOfConstructorLinkingCandidate.java   
@Override
public boolean validate(IAcceptor<? super AbstractDiagnostic> result) {
    JvmType type = (JvmType) description.getElementOrProxy();
    String typeKind = "";
    if (type instanceof JvmPrimitiveType || type instanceof JvmVoid) {
        typeKind = "primitive type";
    } else if (type instanceof JvmAnnotationType) {
        typeKind = "annotation type";
    } else if (type instanceof JvmEnumerationType) {
        typeKind = "enum type";
    } else if (type instanceof JvmGenericType && ((JvmGenericType) type).isInterface()) {
        typeKind = "interface type";
    } else if (type instanceof JvmTypeParameter) {
        typeKind = "type parameter";
    }
    String message = String.format("Cannot instantiate the %s %s", typeKind, type.getSimpleName());
    AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(Severity.ERROR,
            IssueCodes.ILLEGAL_CLASS_INSTANTIATION, message, getExpression(),
            XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, -1, null);
    result.accept(diagnostic);
    return false;
}
项目:xtext-extras    文件:JvmTypesBuilder.java   
/**
 * Creates and returns an annotation reference of the given annotation type's name and the given value.
 * 
 * @param sourceElement
 *            the source element to associate the created element with.
 * @param annotationTypeName
 *            the type name of the created annotation.
 * @param value
 *            the value of the annotation reference. Can be <code>null</code> if the reference doesn't have any value.
 *            
 * @return a result representing an annotation reference to the given annotation type, <code>null<code> if 
 *      sourceElement or annotationType are <code>null</code>.
 * 
 * @deprecated use {@link JvmAnnotationReferenceBuilder#annotationRef(String, String...)} instead
 */
//TODO Move up the code used in Xtend's CompilationUnitImpl so we can reuse it here.
/* @Nullable */ 
@Deprecated
public JvmAnnotationReference toAnnotation(/* @Nullable */ EObject sourceElement, /* @Nullable */ String annotationTypeName, /* @Nullable */ Object value) {
    JvmAnnotationReference result = typesFactory.createJvmAnnotationReference();
    JvmType jvmType = references.findDeclaredType(annotationTypeName, sourceElement);
    if (jvmType == null) {
        throw new IllegalArgumentException("The type "+annotationTypeName +" is not on the classpath.");
    }
    if (!(jvmType instanceof JvmAnnotationType)) {
        throw new IllegalArgumentException("The given class " + annotationTypeName + " is not an annotation type.");
    }
    result.setAnnotation((JvmAnnotationType) jvmType);
    if (value != null) {
        if (value instanceof String) {
            JvmStringAnnotationValue annotationValue = typesFactory.createJvmStringAnnotationValue();
            annotationValue.getValues().add((String) value);
            result.getExplicitValues().add(annotationValue);
        }
    }
    return result;
}
项目:xtext-extras    文件:JvmAnnotationReferenceBuilder.java   
/**
 * Creates and returns an annotation reference of the given annotation type's name and the given value.
 * 
 * @param annotationTypeName
 *            the type name of the created annotation.
 * @param values
 *            the string value of the annotation's 'values' property.
 *            
 * @return a result representing an annotation reference to the given annotation type, <code>null<code> if 
 *      annotationType are <code>null</code>.  
 */
//TODO Move up the code used in Xtend's CompilationUnitImpl so we can reuse it here.
//TODO Support other types and setting non default properties
/* @Nullable */ 
public JvmAnnotationReference annotationRef(/* @Nullable */ String annotationTypeName, /* @Nullable */ String... values) {
    if (context == null || annotationTypeName == null)
        return null;
    JvmAnnotationReference result = typesFactory.createJvmAnnotationReference();
    JvmType jvmType = references.findDeclaredType(annotationTypeName, context);
    if (jvmType == null) {
        throw new IllegalArgumentException("The type "+annotationTypeName +" is not on the classpath.");
    }
    if (!(jvmType instanceof JvmAnnotationType)) {
        throw new IllegalArgumentException("The given class " + annotationTypeName + " is not an annotation type.");
    }
    result.setAnnotation((JvmAnnotationType) jvmType);
    if (values != null && values.length>0) {
        JvmStringAnnotationValue annotationValue = typesFactory.createJvmStringAnnotationValue();
        for (String value : values) {
            annotationValue.getValues().add(value);
        }
        result.getExplicitValues().add(annotationValue);
    }
    return result;
}
项目:xtext-extras    文件:JvmModelCompleter.java   
public void complete(JvmIdentifiableElement element) {
    if (element instanceof JvmGenericType) {
        completeJvmGenericType((JvmGenericType)element);
    }
    if (element instanceof JvmDeclaredType) {
        JvmDeclaredType declaredType = (JvmDeclaredType) element;
        complete(declaredType.getMembers());
    }
    if(element instanceof JvmConstructor) {
        completeJvmConstructor((JvmConstructor) element);
    }
    if (element instanceof JvmEnumerationType) {
        completeJvmEnumerationType((JvmEnumerationType)element);
    }
    if (element instanceof JvmEnumerationLiteral) {
        completeJvmEnumerationLiteral((JvmEnumerationLiteral)element);
    }
    if (element instanceof JvmAnnotationType) {
        completeJvmAnnotationType((JvmAnnotationType)element);
    }
}
项目:xtext-extras    文件:XbaseWithAnnotationsValidator.java   
@Check
public void checkAllAttributesConfigured(XAnnotation annotation) {
    JvmType annotationType = annotation.getAnnotationType();
    if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType))
        return;
    Iterable<JvmOperation> attributes = ((JvmAnnotationType) annotationType).getDeclaredOperations();
    for (JvmOperation jvmOperation : attributes) {
        XExpression value = annotationUtil.findValue(annotation, jvmOperation);
        if(value == null) {
            if (jvmOperation.getDefaultValue() == null) {
                error("The annotation must define the attribute '"+jvmOperation.getSimpleName()+"'.", annotation, null, 
                        ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ANNOTATIONS_MISSING_ATTRIBUTE_DEFINITION);
            }
        } else
            annotationValueValidator.validateAnnotationValue(value, this);
    }
}
项目:xtext-extras    文件:XbaseWithAnnotationsBatchScopeProvider.java   
@Override
public IScope getScope(EObject context, EReference reference) {
    if (reference == XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT) {
        XAnnotation annotation = EcoreUtil2.getContainerOfType(context, XAnnotation.class);
        JvmType annotationType = annotation.getAnnotationType();
        if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) {
            return IScope.NULLSCOPE;
        }
        Iterable<JvmOperation> operations = ((JvmAnnotationType) annotationType).getDeclaredOperations();
        Iterable<IEObjectDescription> descriptions = transform(operations, new Function<JvmOperation, IEObjectDescription>() {
            @Override
            public IEObjectDescription apply(JvmOperation from) {
                return EObjectDescription.create(QualifiedName.create(from.getSimpleName()), from);
            }
        });
        return MapBasedScope.createScope(IScope.NULLSCOPE, descriptions);
    }
    return super.getScope(context, reference);
}
项目:xtext-extras    文件:XAnnotationUtil.java   
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();
}
项目:xtext-extras    文件:JvmTypesBuilderTest.java   
@Test
public void testStringAnnotation() {
  try {
    final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE;
    final XExpression e = this.expression("\'Foo\'");
    final XAnnotation anno = f.createXAnnotation();
    JvmType _findDeclaredType = this.references.findDeclaredType(Inject.class, e);
    anno.setAnnotationType(((JvmAnnotationType) _findDeclaredType));
    anno.setValue(e);
    final JvmGenericType type = this.typesFactory.createJvmGenericType();
    this._jvmTypesBuilder.addAnnotation(type, anno);
    Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation());
    JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues());
    EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _head).getValues());
    Assert.assertTrue((_head_1 instanceof XStringLiteral));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:JvmTypesBuilderTest.java   
@Test
public void testAnnotationDefaultValue() {
  try {
    final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE;
    final XExpression e = this.expression("\'Foo\'");
    final XAnnotation anno = f.createXAnnotation();
    JvmType _findDeclaredType = this.references.findDeclaredType(Named.class, e);
    anno.setAnnotationType(((JvmAnnotationType) _findDeclaredType));
    anno.setValue(e);
    final JvmGenericType type = this.typesFactory.createJvmGenericType();
    this._jvmTypesBuilder.addAnnotation(type, anno);
    Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation());
    JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues());
    EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _head).getValues());
    Assert.assertTrue((_head_1 instanceof XStringLiteral));
    Assert.assertNull(IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues()).getOperation());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:JvmTypesBuilderTest.java   
@Test
public void testStringAnnotationWithNullExpression() {
  try {
    final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE;
    final XExpression context = this.expression("\'Foo\'");
    final XAnnotation anno = f.createXAnnotation();
    JvmType _findDeclaredType = this.references.findDeclaredType(Inject.class, context);
    anno.setAnnotationType(((JvmAnnotationType) _findDeclaredType));
    final XAnnotationElementValuePair pair = f.createXAnnotationElementValuePair();
    EList<XAnnotationElementValuePair> _elementValuePairs = anno.getElementValuePairs();
    this._jvmTypesBuilder.<XAnnotationElementValuePair>operator_add(_elementValuePairs, pair);
    final JvmGenericType type = this.typesFactory.createJvmGenericType();
    this._jvmTypesBuilder.addAnnotation(type, anno);
    Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation());
    Assert.assertTrue(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getExplicitValues().isEmpty());
    Assert.assertFalse(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues().isEmpty());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:JvmTypesBuilderTest.java   
@Test
public void testIntegerAnnotation() {
  try {
    final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE;
    final XExpression e = this.expression("\'Foo\'");
    final XAnnotation anno = f.createXAnnotation();
    JvmType _findDeclaredType = this.references.findDeclaredType(TestAnnotation3.class, e);
    final JvmAnnotationType annotatiomType = ((JvmAnnotationType) _findDeclaredType);
    anno.setAnnotationType(annotatiomType);
    final XAnnotationElementValuePair pair = f.createXAnnotationElementValuePair();
    pair.setElement(IterableExtensions.<JvmOperation>head(annotatiomType.getDeclaredOperations()));
    pair.setValue(this.expression("10"));
    EList<XAnnotationElementValuePair> _elementValuePairs = anno.getElementValuePairs();
    this._jvmTypesBuilder.<XAnnotationElementValuePair>operator_add(_elementValuePairs, pair);
    final JvmGenericType type = this.typesFactory.createJvmGenericType();
    this._jvmTypesBuilder.addAnnotation(type, anno);
    Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation());
    Assert.assertEquals(1, IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues().size());
    JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues());
    final JvmCustomAnnotationValue value = ((JvmCustomAnnotationValue) _head);
    EObject _head_1 = IterableExtensions.<EObject>head(value.getValues());
    Assert.assertTrue((_head_1 instanceof XNumberLiteral));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:JvmModelGeneratorTest.java   
@Test
public void testAnnotation_1() {
  try {
    final XExpression expression = this.expression("42", false);
    final Procedure1<JvmAnnotationType> _function = (JvmAnnotationType it) -> {
      EList<JvmMember> _members = it.getMembers();
      final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> {
        this.builder.setBody(it_1, expression);
      };
      JvmOperation _method = this.builder.toMethod(expression, "theTruth", this.references.getTypeForName(int.class, expression), _function_1);
      this.builder.<JvmOperation>operator_add(_members, _method);
    };
    final JvmAnnotationType clazz = this.builder.toAnnotationType(expression, "my.test.Foo", _function);
    final Class<?> compiledClass = this.compile(expression.eResource(), clazz);
    Assert.assertTrue(compiledClass.isAnnotation());
    final Method method = IterableExtensions.<Method>head(((Iterable<Method>)Conversions.doWrapArray(compiledClass.getMethods())));
    Assert.assertEquals("theTruth", method.getName());
    Assert.assertEquals(Integer.valueOf(42), method.getDefaultValue());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:JvmModelGeneratorTest.java   
@Test
public void testNestedAnnotationType() {
  try {
    final XExpression expression = this.expression("42");
    final JvmGenericType outerClass = this.builder.toClass(expression, "my.outer.Clazz");
    EList<JvmMember> _members = outerClass.getMembers();
    final Procedure1<JvmAnnotationType> _function = (JvmAnnotationType it) -> {
      EList<JvmMember> _members_1 = it.getMembers();
      final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> {
        this.builder.setBody(it_1, expression);
      };
      JvmOperation _method = this.builder.toMethod(expression, "theTruth", this.references.getTypeForName(int.class, expression), _function_1);
      this.builder.<JvmOperation>operator_add(_members_1, _method);
    };
    JvmAnnotationType _annotationType = this.builder.toAnnotationType(expression, "MyAnnotation", _function);
    this.builder.<JvmAnnotationType>operator_add(_members, _annotationType);
    final Class<?> compiled = IterableExtensions.<Class<?>>head(((Iterable<Class<?>>)Conversions.doWrapArray(this.compile(expression.eResource(), outerClass).getDeclaredClasses())));
    Assert.assertEquals("my.outer.Clazz.MyAnnotation", compiled.getCanonicalName());
    Assert.assertEquals(Integer.valueOf(42), IterableExtensions.<Method>head(((Iterable<Method>)Conversions.doWrapArray(compiled.getDeclaredMethods()))).getDefaultValue());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:JvmAnnotationReferenceImpl.java   
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
    switch (featureID)
    {
        case TypesPackage.JVM_ANNOTATION_REFERENCE__ANNOTATION:
            setAnnotation((JvmAnnotationType)newValue);
            return;
        case TypesPackage.JVM_ANNOTATION_REFERENCE__EXPLICIT_VALUES:
            getExplicitValues().clear();
            getExplicitValues().addAll((Collection<? extends JvmAnnotationValue>)newValue);
            return;
    }
    super.eSet(featureID, newValue);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testMemberCount_14() {
    String typeName = TestAnnotation.class.getName();
    JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
    int methodCount = TestAnnotation.class.getDeclaredMethods().length;
    assertEquals(15, methodCount);
    int innerTypesCount = TestAnnotation.class.getDeclaredClasses().length;
    assertEquals(2, innerTypesCount);
    int fieldCount = TestAnnotation.class.getDeclaredFields().length;
    assertEquals(1, fieldCount);
    assertEquals(fieldCount + methodCount + innerTypesCount, type.getMembers().size());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testMemberCount_17() {
    String typeName = TestAnnotationWithDefaults.class.getName();
    JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
    int methodCount = TestAnnotationWithDefaults.class.getDeclaredMethods().length;
    assertEquals(15, methodCount);
    int innerTypesCount = TestAnnotationWithDefaults.class.getDeclaredClasses().length;
    assertEquals(1, innerTypesCount);
    assertEquals(methodCount + innerTypesCount, type.getMembers().size());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testAnnotationType_01() throws Exception {
    String typeName = TestAnnotation.class.getName();
    JvmType type = getTypeProvider().findTypeByName(typeName);
    assertNotNull(type);
    assertTrue(type instanceof JvmAnnotationType);
    assertTrue(((JvmDeclaredType) type).isAbstract());
    assertFalse(((JvmDeclaredType) type).isStatic());
    diagnose(type);
    Resource resource = type.eResource();
    getAndResolveAllFragments(resource);
    recomputeAndCheckIdentifiers(resource);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testAnnotationType_02() throws Exception {
    String typeName = TestAnnotation.class.getName();
    JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
    assertEquals(1, type.getSuperTypes().size());
    assertEquals(Annotation.class.getName(), type.getSuperTypes().get(0).getIdentifier());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testNestedAnnotationType_01() throws Exception {
    String typeName = TestAnnotation.NestedAnnotation.class.getName();
    JvmType type = getTypeProvider().findTypeByName(typeName);
    assertNotNull(type);
    assertTrue(type instanceof JvmAnnotationType);
    assertTrue(((JvmDeclaredType) type).isAbstract());
    assertTrue(((JvmDeclaredType) type).isStatic());
    diagnose(type);
    Resource resource = type.eResource();
    getAndResolveAllFragments(resource);
    recomputeAndCheckIdentifiers(resource);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testNestedAnnotationType_02() throws Exception {
    String typeName = TestAnnotation.NestedAnnotation.class.getName();
    JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
    assertEquals(1, type.getSuperTypes().size());
    assertEquals(Annotation.class.getName(), type.getSuperTypes().get(0).getIdentifier());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testAnnotationType_03() throws Exception {
    String typeName = TestAnnotationWithDefaults.class.getName();
    JvmType type = getTypeProvider().findTypeByName(typeName);
    assertNotNull(type);
    assertTrue(type instanceof JvmAnnotationType);
    diagnose(type);
    Resource resource = type.eResource();
    getAndResolveAllFragments(resource);
    recomputeAndCheckIdentifiers(resource);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testAnnotationType_04() throws Exception {
    String typeName = TestAnnotationWithDefaults.class.getName();
    JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
    assertEquals(1, type.getSuperTypes().size());
    assertEquals(Annotation.class.getName(), type.getSuperTypes().get(0).getIdentifier());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
private void doTestAnnotation_01(JvmAnnotationTarget target) {
    JvmAnnotationType annotationType = (JvmAnnotationType) getTypeProvider()
            .findTypeByName(TestAnnotation.class.getName());
    assertEquals(1, target.getAnnotations().size());
    JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
    assertSame(annotationType, annotationReference.getAnnotation());
    if (isDefaultValueSupported())
        assertEquals(14, annotationReference.getExplicitValues().size());
    assertEquals(15, annotationReference.getValues().size());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@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());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testAnnotatedParameter_06() throws Exception {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmAnnotationType annotationType = (JvmAnnotationType) getTypeProvider()
            .findTypeByName(TestAnnotation.NestedAnnotation.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(2);
    assertEquals(1, target.getAnnotations().size());
    JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
    assertSame(annotationType, annotationReference.getAnnotation());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
public JvmAnnotationValue getDefaultAnnotationValue(String name) {
    String typeName = TestAnnotationWithDefaults.class.getName();
    JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
    JvmOperation operation = getMethodFromType(type, TestAnnotationWithDefaults.class, name + "()");
    JvmAnnotationValue result = operation.getDefaultValue();
    assertNotNull(result);
    assertSame(operation, result.getOperation());
    return result;
}
项目:xtext-extras    文件:JvmTypesBuilder.java   
/**
 * Creates a public annotation declaration, associated to the given sourceElement. It sets the given name, which might be
 * fully qualified using the standard Java notation.
 * 
 * @param sourceElement
 *            the sourceElement the resulting element is associated with.
 * @param name
 *            the qualified name of the resulting class.
 * @param initializer
 *            the initializer to apply on the created annotation. If <code>null</code>, the annotation won't be initialized.
 * 
 * @return a {@link JvmAnnotationType} representing a Java annotation of the given name, <code>null</code> 
 *            if sourceElement or name are <code>null</code>.
 */
/* @Nullable */ 
public JvmAnnotationType toAnnotationType(/* @Nullable */ EObject sourceElement, /* @Nullable */ String name, 
        /* @Nullable */ Procedure1<? super JvmAnnotationType> initializer) {
    if (sourceElement == null || name == null)
        return null;
    Pair<String, String> fullName = splitQualifiedName(name);
    JvmAnnotationType annotationType = typesFactory.createJvmAnnotationType();
    annotationType.setSimpleName(fullName.getSecond());
    annotationType.setAbstract(true);
    if (fullName.getFirst() != null)
        annotationType.setPackageName(fullName.getFirst());
    associate(sourceElement, annotationType);
    return initializeSafely(annotationType, initializer);
}
项目:xtext-extras    文件:JvmTypesBuilder.java   
/**
 * Translates a single {@link XAnnotation} to {@link JvmAnnotationReference} that can be added to a {@link JvmAnnotationTarget}.
 * 
 * @param anno the source annotation
 * 
 * @return a {@link JvmAnnotationReference} that can be attached to some {@link JvmAnnotationTarget}
 */
/* @Nullable */ 
public JvmAnnotationReference getJvmAnnotationReference(/* @Nullable */ XAnnotation anno) {
    if(anno == null)
        return null;
    JvmAnnotationReference reference = typesFactory.createJvmAnnotationReference();
    final JvmType annotation = (JvmType) anno.eGet(
            XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, false);
    if (annotation.eIsProxy()) {
        JvmAnnotationType copiedProxy = TypesFactory.eINSTANCE.createJvmAnnotationType();
        ((InternalEObject)copiedProxy).eSetProxyURI(EcoreUtil.getURI(annotation));
        reference.setAnnotation(copiedProxy);
    } else if (annotation instanceof JvmAnnotationType){
        reference.setAnnotation((JvmAnnotationType) annotation);
    }
    for (XAnnotationElementValuePair val : anno.getElementValuePairs()) {
        XExpression valueExpression = val.getValue();
        JvmAnnotationValue annotationValue = toJvmAnnotationValue(valueExpression);
        if (annotationValue != null) {
            JvmOperation op = (JvmOperation) val.eGet(
                    XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT, false);
            annotationValue.setOperation(op);
            reference.getExplicitValues().add(annotationValue);
        }
    }
    if (anno.getValue() != null) {
        JvmAnnotationValue value = toJvmAnnotationValue(anno.getValue());
        if (value != null) {
            reference.getExplicitValues().add(value);
        }
    }
    associate(anno, reference);
    return reference;
}
项目:xtext-extras    文件:JvmModelCompleter.java   
protected void completeJvmAnnotationType(JvmAnnotationType element) {
    addAnnotations(element);
    if (element.getSuperTypes().isEmpty()) {
        JvmTypeReference objectType = references.getTypeForName(Annotation.class, element);
        if (objectType != null)
            element.getSuperTypes().add(objectType);
    }
}
项目:xtext-extras    文件:JvmModelCompleter.java   
private JvmOperation getOperation(JvmAnnotationType annotationType, String operationName) {
    for (JvmOperation operation : annotationType.getDeclaredOperations()) {
        if (operationName.equals(operation.getSimpleName()))
            return operation;
    }
    return null;
}
项目:xtext-extras    文件:UnresolvedAnnotationTypeAwareMessageProvider.java   
protected boolean isPropertyOfUnresolvedAnnotation(ILinkingDiagnosticContext context) {
    EObject object = context.getContext();
    if (object instanceof XAnnotationElementValuePair && context.getReference() == XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT) {
        XAnnotation annotation = EcoreUtil2.getContainerOfType(object, XAnnotation.class);
        if (annotation != null) {
            JvmType annotationType = annotation.getAnnotationType();
            if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) {
                return true;
            }
        }
    }
    return false;
}
项目:xtext-extras    文件:XAnnotationUtil.java   
public JvmOperation findSingleValueAttribute(JvmAnnotationType type) {
    Iterable<JvmOperation> operations = type.getDeclaredOperations();
    for (JvmOperation operation : operations) {
        if (operation.getSimpleName().equals("value")) {
            return operation;
        }
    }
    return null;
}
项目:xtext-extras    文件:JvmModelGenerator.java   
/**
 * @deprecated Additional annotations should be created in the JVM model.
 */
@Deprecated
public ITreeAppendable generateAnnotationsWithSyntheticSuppressWarnings(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    final Function1<JvmAnnotationReference, Boolean> _function = (JvmAnnotationReference it_1) -> {
      JvmAnnotationType _annotation = it_1.getAnnotation();
      String _identifier = null;
      if (_annotation!=null) {
        _identifier=_annotation.getIdentifier();
      }
      String _name = SuppressWarnings.class.getName();
      return Boolean.valueOf((!Objects.equal(_identifier, _name)));
    };
    final Function1<JvmAnnotationReference, Boolean> noSuppressWarningsFilter = _function;
    this.generateAnnotations(IterableExtensions.<JvmAnnotationReference>filter(it.getAnnotations(), noSuppressWarningsFilter), appendable, true, config);
    ITreeAppendable _xifexpression = null;
    EObject _eContainer = it.eContainer();
    boolean _tripleEquals = (_eContainer == null);
    if (_tripleEquals) {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("@SuppressWarnings(\"all\")");
      _xifexpression = appendable.append(_builder).newLine();
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
项目:xtext-extras    文件:JvmModelGenerator.java   
protected ITreeAppendable _generateBody(final JvmAnnotationType it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    this.generateJavaDoc(it, appendable, config);
    final ITreeAppendable childAppendable = appendable.trace(it);
    this.generateAnnotations(it.getAnnotations(), childAppendable, true, config);
    this.generateModifier(it, childAppendable, config);
    childAppendable.append("@interface ");
    this._treeAppendableUtil.traceSignificant(childAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName()));
    childAppendable.append(" {");
    Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(this.getMembersToBeCompiled(it), JvmDeclaredType.class);
    for (final JvmDeclaredType innerType : _filter) {
      {
        final ITreeAppendable innerTypeAppendable = childAppendable.trace(innerType);
        innerTypeAppendable.increaseIndentation();
        this.generateMember(innerType, innerTypeAppendable, config);
        innerTypeAppendable.decreaseIndentation();
      }
    }
    Iterable<JvmOperation> _filter_1 = Iterables.<JvmOperation>filter(this.getMembersToBeCompiled(it), JvmOperation.class);
    for (final JvmOperation operation : _filter_1) {
      this.generateAnnotationMethod(operation, childAppendable, config);
    }
    childAppendable.newLine().append("}");
    ITreeAppendable _xifexpression = null;
    EObject _eContainer = it.eContainer();
    boolean _not = (!(_eContainer instanceof JvmType));
    if (_not) {
      _xifexpression = appendable.newLine();
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
项目:xtext-extras    文件:JvmModelGenerator.java   
public ITreeAppendable generateBody(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
  if (it instanceof JvmAnnotationType) {
    return _generateBody((JvmAnnotationType)it, appendable, config);
  } else if (it instanceof JvmEnumerationType) {
    return _generateBody((JvmEnumerationType)it, appendable, config);
  } else if (it instanceof JvmGenericType) {
    return _generateBody((JvmGenericType)it, appendable, config);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, appendable, config).toString());
  }
}
项目:xtext-extras    文件:XbaseHighlightingCalculator.java   
protected void highlightAnnotation(XAnnotation annotation, IHighlightedPositionAcceptor acceptor, String highlightingConfiguration) {
    JvmType annotationType = annotation.getAnnotationType();
    if (annotationType != null && !annotationType.eIsProxy() && annotationType instanceof JvmAnnotationType) {
        ICompositeNode xannotationNode = NodeModelUtils.findActualNodeFor(annotation);
        if (xannotationNode != null) {
            ILeafNode firstLeafNode = NodeModelUtils.findLeafNodeAtOffset(xannotationNode, xannotationNode.getOffset() );
            if(firstLeafNode != null)
                highlightNode(acceptor, firstLeafNode, highlightingConfiguration);
        }
        highlightReferenceJvmType(acceptor, annotation, XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, annotationType, highlightingConfiguration);
    }
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testMemberCount_14() {
    String typeName = TestAnnotation.class.getName();
    JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
    int methodCount = TestAnnotation.class.getDeclaredMethods().length;
    assertEquals(15, methodCount);
    int innerTypesCount = TestAnnotation.class.getDeclaredClasses().length;
    assertEquals(2, innerTypesCount);
    int fieldCount = TestAnnotation.class.getDeclaredFields().length;
    assertEquals(1, fieldCount);
    assertEquals(fieldCount + methodCount + innerTypesCount, type.getMembers().size());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testMemberCount_17() {
    String typeName = TestAnnotationWithDefaults.class.getName();
    JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
    int methodCount = TestAnnotationWithDefaults.class.getDeclaredMethods().length;
    assertEquals(15, methodCount);
    int innerTypesCount = TestAnnotationWithDefaults.class.getDeclaredClasses().length;
    assertEquals(1, innerTypesCount);
    assertEquals(methodCount + innerTypesCount, type.getMembers().size());
}