org.eclipse.xtext.common.types.JvmEnumAnnotationValue Java Examples

The following examples show how to use org.eclipse.xtext.common.types.JvmEnumAnnotationValue. 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: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void _setValue(final JvmEnumAnnotationValue it, final EnumerationValueDeclaration[] value, final String componentType, final boolean mustBeArray) {
  this.checkType(it, componentType, mustBeArray);
  for (final EnumerationValueDeclaration enumValue : value) {
    boolean _matched = false;
    if (enumValue instanceof JvmEnumerationValueDeclarationImpl) {
      _matched=true;
      it.getValues().add(((JvmEnumerationValueDeclarationImpl)enumValue).getDelegate());
    }
    if (!_matched) {
      if (enumValue instanceof XtendEnumerationValueDeclarationImpl) {
        _matched=true;
        throw new IllegalArgumentException("Cannot set source elements.");
      }
    }
  }
}
 
Example #2
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private JvmAnnotationValue createEnumAnnotationValue(Object value) {
	JvmEnumAnnotationValue annotationValue = TypesFactory.eINSTANCE.createJvmEnumAnnotationValue();
	if (value != null) {
		InternalEList<JvmEnumerationLiteral> values = (InternalEList<JvmEnumerationLiteral>)annotationValue.getValues();
		if (value instanceof Object[]) {
			for (Object element : (Object[])value) {
				if (element instanceof IVariableBinding) {
					values.addUnique(createEnumLiteralProxy((IVariableBinding)element));
				}
			}
		} else if (value instanceof IVariableBinding) {
			values.addUnique(createEnumLiteralProxy((IVariableBinding)value));
		}
	}
	return annotationValue;
}
 
Example #3
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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());
		}
	}
}
 
Example #4
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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());
		}
	}
}
 
Example #5
Source File: XAnnotationUtil.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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();
}
 
Example #6
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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());
		}
	}
}
 
Example #7
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnumAnnotationValue_02() throws Exception {
	JvmEnumAnnotationValue value = (JvmEnumAnnotationValue) getConstructorParameterAnnotationValue("enumValue");
	assertEquals(1, value.getValues().size());
	JvmEnumerationLiteral enumLiteral = value.getValues().get(0);
	assertFalse(enumLiteral.eIsProxy());
	assertEquals(TestEnum.FirstValue.name(), enumLiteral.getSimpleName());
}
 
Example #8
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDefaultEnumAnnotationValue_01() throws Exception {
	JvmEnumAnnotationValue value = (JvmEnumAnnotationValue) getDefaultAnnotationValue("enumValue");
	assertEquals(1, value.getValues().size());
	JvmEnumerationLiteral literal = value.getValues().get(0);
	assertEquals("org.eclipse.xtext.common.types.testSetups.TestEnum.FirstValue", literal.getIdentifier());
}
 
Example #9
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnumAnnotationValue_03() throws Exception {
	JvmEnumAnnotationValue value = (JvmEnumAnnotationValue) getMethodParameterAnnotationValue("enumValue");
	assertEquals(1, value.getValues().size());
	JvmEnumerationLiteral enumLiteral = value.getValues().get(0);
	assertFalse(enumLiteral.eIsProxy());
	assertEquals(TestEnum.FirstValue.name(), enumLiteral.getSimpleName());
}
 
Example #10
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnumAnnotationValue_02() throws Exception {
	JvmEnumAnnotationValue value = (JvmEnumAnnotationValue) getConstructorParameterAnnotationValue("enumValue");
	assertEquals(1, value.getValues().size());
	JvmEnumerationLiteral enumLiteral = value.getValues().get(0);
	assertFalse(enumLiteral.eIsProxy());
	assertEquals(TestEnum.FirstValue.name(), enumLiteral.getSimpleName());
}
 
Example #11
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnumAnnotationValue_01() throws Exception {
	JvmEnumAnnotationValue value = (JvmEnumAnnotationValue) getAnnotationValue("enumValue");
	assertEquals(1, value.getValues().size());
	JvmEnumerationLiteral enumLiteral = value.getValues().get(0);
	assertFalse(enumLiteral.eIsProxy());
	assertEquals(TestEnum.FirstValue.name(), enumLiteral.getSimpleName());
}
 
Example #12
Source File: JvmAnnotationReferenceBuilder.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visitEnum(final String name, final String desc, final String value) {
	JvmEnumAnnotationValue result = TypesFactory.eINSTANCE.createJvmEnumAnnotationValue();
	JvmEnumerationLiteral enumLiteralProxy = proxies.createEnumLiteral(value, desc);
	((InternalEList<JvmEnumerationLiteral>) result.getValues()).addUnique(enumLiteralProxy);
	result.setOperation(proxies.createMethodProxy(annotationType, name));
	values.addUnique(result);
}
 
Example #13
Source File: JvmAnnotationValueBuilder.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visitEnum(String name, String desc, String value) {
	if (name != null) {
		throw new IllegalStateException();
	}
	if (result == null) {
		result = TypesFactory.eINSTANCE.createJvmEnumAnnotationValue();
	}
	JvmEnumerationLiteral enumLiteralProxy = proxies.createEnumLiteral(value, desc);
	((InternalEList<JvmEnumerationLiteral>) ((JvmEnumAnnotationValue) result).getValues()).addUnique(enumLiteralProxy);
}
 
Example #14
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDefaultEnumAnnotationValue_01() throws Exception {
	JvmEnumAnnotationValue value = (JvmEnumAnnotationValue) getDefaultAnnotationValue("enumValue");
	assertEquals(1, value.getValues().size());
	JvmEnumerationLiteral literal = value.getValues().get(0);
	assertEquals("org.eclipse.xtext.common.types.testSetups.TestEnum.FirstValue", literal.getIdentifier());
}
 
Example #15
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnumAnnotationValue_03() throws Exception {
	JvmEnumAnnotationValue value = (JvmEnumAnnotationValue) getMethodParameterAnnotationValue("enumValue");
	assertEquals(1, value.getValues().size());
	JvmEnumerationLiteral enumLiteral = value.getValues().get(0);
	assertFalse(enumLiteral.eIsProxy());
	assertEquals(TestEnum.FirstValue.name(), enumLiteral.getSimpleName());
}
 
Example #16
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnumAnnotationValue_02() throws Exception {
	JvmEnumAnnotationValue value = (JvmEnumAnnotationValue) getConstructorParameterAnnotationValue("enumValue");
	assertEquals(1, value.getValues().size());
	JvmEnumerationLiteral enumLiteral = value.getValues().get(0);
	assertFalse(enumLiteral.eIsProxy());
	assertEquals(TestEnum.FirstValue.name(), enumLiteral.getSimpleName());
}
 
Example #17
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnumAnnotationValue_01() throws Exception {
	JvmEnumAnnotationValue value = (JvmEnumAnnotationValue) getAnnotationValue("enumValue");
	assertEquals(1, value.getValues().size());
	JvmEnumerationLiteral enumLiteral = value.getValues().get(0);
	assertFalse(enumLiteral.eIsProxy());
	assertEquals(TestEnum.FirstValue.name(), enumLiteral.getSimpleName());
}
 
Example #18
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _toJavaLiteral(final JvmEnumAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) {
  final Procedure1<JvmEnumerationLiteral> _function = (JvmEnumerationLiteral it_1) -> {
    appendable.append(it_1.getDeclaringType());
    appendable.append(".");
    appendable.append(this.makeJavaIdentifier(it_1.getSimpleName()));
  };
  this._loopExtensions.<JvmEnumerationLiteral>forEachWithShortcut(appendable, it.getValues(), _function);
}
 
Example #19
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDefaultEnumAnnotationValue_01() throws Exception {
	JvmEnumAnnotationValue value = (JvmEnumAnnotationValue) getDefaultAnnotationValue("enumValue");
	assertEquals(1, value.getValues().size());
	JvmEnumerationLiteral literal = value.getValues().get(0);
	assertEquals("org.eclipse.xtext.common.types.testSetups.TestEnum.FirstValue", literal.getIdentifier());
}
 
Example #20
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnumAnnotationValue_03() throws Exception {
	JvmEnumAnnotationValue value = (JvmEnumAnnotationValue) getMethodParameterAnnotationValue("enumValue");
	assertEquals(1, value.getValues().size());
	JvmEnumerationLiteral enumLiteral = value.getValues().get(0);
	assertFalse(enumLiteral.eIsProxy());
	assertEquals(TestEnum.FirstValue.name(), enumLiteral.getSimpleName());
}
 
Example #21
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnumAnnotationValue_01() throws Exception {
	JvmEnumAnnotationValue value = (JvmEnumAnnotationValue) getAnnotationValue("enumValue");
	assertEquals(1, value.getValues().size());
	JvmEnumerationLiteral enumLiteral = value.getValues().get(0);
	assertFalse(enumLiteral.eIsProxy());
	assertEquals(TestEnum.FirstValue.name(), enumLiteral.getSimpleName());
}
 
Example #22
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public void toJavaLiteral(final JvmAnnotationValue value, final ITreeAppendable appendable, final GeneratorConfig config) {
  if (value instanceof JvmAnnotationAnnotationValue) {
    _toJavaLiteral((JvmAnnotationAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmBooleanAnnotationValue) {
    _toJavaLiteral((JvmBooleanAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmByteAnnotationValue) {
    _toJavaLiteral((JvmByteAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmCharAnnotationValue) {
    _toJavaLiteral((JvmCharAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmCustomAnnotationValue) {
    _toJavaLiteral((JvmCustomAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmDoubleAnnotationValue) {
    _toJavaLiteral((JvmDoubleAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmEnumAnnotationValue) {
    _toJavaLiteral((JvmEnumAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmFloatAnnotationValue) {
    _toJavaLiteral((JvmFloatAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmIntAnnotationValue) {
    _toJavaLiteral((JvmIntAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmLongAnnotationValue) {
    _toJavaLiteral((JvmLongAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmShortAnnotationValue) {
    _toJavaLiteral((JvmShortAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmStringAnnotationValue) {
    _toJavaLiteral((JvmStringAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmTypeAnnotationValue) {
    _toJavaLiteral((JvmTypeAnnotationValue)value, appendable, config);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(value, appendable, config).toString());
  }
}
 
Example #23
Source File: SarlCompiler.java    From sarl with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"checkstyle:returncount", "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity"})
private static String getAnnotationStringValue(JvmAnnotationValue value) {
	if (value instanceof JvmAnnotationAnnotationValue) {
		return ((JvmAnnotationAnnotationValue) value).getValues().get(0).getAnnotation().getIdentifier();
	}
	if (value instanceof JvmBooleanAnnotationValue) {
		return ((JvmBooleanAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmByteAnnotationValue) {
		return ((JvmByteAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmCharAnnotationValue) {
		return ((JvmCharAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmCustomAnnotationValue) {
		final EObject evalue = ((JvmCustomAnnotationValue) value).getValues().get(0);
		if (evalue instanceof XStringLiteral) {
			return ((XStringLiteral) evalue).getValue();
		}
		if (evalue instanceof XNumberLiteral) {
			return ((XNumberLiteral) evalue).getValue();
		}
		if (evalue instanceof XBooleanLiteral) {
			return ((XNumberLiteral) evalue).getValue();
		}
		if (evalue instanceof XTypeLiteral) {
			return ((XTypeLiteral) evalue).getType().getIdentifier();
		}
	}
	if (value instanceof JvmDoubleAnnotationValue) {
		return ((JvmDoubleAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmEnumAnnotationValue) {
		return ((JvmEnumAnnotationValue) value).getValues().get(0).getSimpleName();
	}
	if (value instanceof JvmFloatAnnotationValue) {
		return ((JvmFloatAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmIntAnnotationValue) {
		return ((JvmIntAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmLongAnnotationValue) {
		return ((JvmLongAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmShortAnnotationValue) {
		return ((JvmShortAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmStringAnnotationValue) {
		return ((JvmStringAnnotationValue) value).getValues().get(0);
	}
	if (value instanceof JvmTypeAnnotationValue) {
		return ((JvmTypeAnnotationValue) value).getValues().get(0).getIdentifier();
	}
	return null;
}