use of org.eclipse.xtend.lib.macro.declaration.TypeReference in project xtext-xtend by eclipse.
the class ConditionUtils method checkInferredTypeReferences.
public static void checkInferredTypeReferences(final String typeName, final TypeReference... types) {
for (final TypeReference type : types) {
if (((type != null) && type.isInferred())) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Cannot use inferred type as ");
_builder.append(typeName);
_builder.append(".");
throw new IllegalArgumentException(_builder.toString());
}
}
}
use of org.eclipse.xtend.lib.macro.declaration.TypeReference in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toTypeReference.
public TypeReference toTypeReference(final JvmTypeReference delegate) {
TypeReference _xblockexpression = null;
{
if ((delegate == null)) {
return null;
}
TypeReference _switchResult = null;
boolean _matched = false;
if (delegate instanceof XComputedTypeReferenceImplCustom) {
boolean _isEquivalentComputed = ((XComputedTypeReferenceImplCustom) delegate).isEquivalentComputed();
boolean _not = (!_isEquivalentComputed);
if (_not) {
_matched = true;
InferredTypeReferenceImpl _inferredTypeReferenceImpl = new InferredTypeReferenceImpl();
final Procedure1<InferredTypeReferenceImpl> _function = (InferredTypeReferenceImpl it) -> {
it.setDelegate(((XComputedTypeReferenceImplCustom) delegate));
it.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<InferredTypeReferenceImpl>operator_doubleArrow(_inferredTypeReferenceImpl, _function);
}
}
if (!_matched) {
_switchResult = this.toTypeReference(this.typeRefFactory.toLightweightReference(delegate), delegate);
}
_xblockexpression = _switchResult;
}
return _xblockexpression;
}
use of org.eclipse.xtend.lib.macro.declaration.TypeReference in project xtext-xtend by eclipse.
the class CompilationUnitImpl method translateAnnotationValue.
public Object translateAnnotationValue(final JvmAnnotationValue value, final boolean isArray) {
Pair<List<?>, Class<?>> _switchResult = null;
boolean _matched = false;
if (value instanceof JvmCustomAnnotationValue) {
if ((((JvmCustomAnnotationValue) value).getValues().isEmpty() && isArray)) {
_matched = true;
List<Object> _emptyList = CollectionLiterals.<Object>emptyList();
Class<?> _arrayComponentType = this.toArrayComponentType(this.findExpectedType(value));
_switchResult = Pair.<List<?>, Class<?>>of(_emptyList, _arrayComponentType);
}
}
if (!_matched) {
if (value instanceof JvmCustomAnnotationValue) {
_matched = true;
final JvmTypeReference expectedType = this.findExpectedType(value);
final Function1<XExpression, Object> _function = (XExpression it) -> {
return this.evaluate(it, expectedType);
};
final Object result = IterableExtensions.<Object>head(IterableExtensions.<XExpression, Object>map(Iterables.<XExpression>filter(((JvmCustomAnnotationValue) value).getValues(), XExpression.class), _function));
return this.translateAnnotationValue(result, expectedType, isArray);
}
}
if (!_matched) {
if (value instanceof JvmTypeAnnotationValue) {
_matched = true;
final Function1<JvmTypeReference, TypeReference> _function = (JvmTypeReference it) -> {
return this.toTypeReference(it);
};
List<TypeReference> _map = ListExtensions.<JvmTypeReference, TypeReference>map(((JvmTypeAnnotationValue) value).getValues(), _function);
_switchResult = Pair.<List<?>, Class<?>>of(_map, TypeReference.class);
}
}
if (!_matched) {
if (value instanceof JvmAnnotationAnnotationValue) {
_matched = true;
final Function1<JvmAnnotationReference, AnnotationReference> _function = (JvmAnnotationReference it) -> {
return this.toAnnotationReference(it);
};
List<AnnotationReference> _map = ListExtensions.<JvmAnnotationReference, AnnotationReference>map(((JvmAnnotationAnnotationValue) value).getValues(), _function);
_switchResult = Pair.<List<?>, Class<?>>of(_map, AnnotationReference.class);
}
}
if (!_matched) {
if (value instanceof JvmStringAnnotationValue) {
_matched = true;
EList<String> _values = ((JvmStringAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, String.class);
}
}
if (!_matched) {
if (value instanceof JvmBooleanAnnotationValue) {
_matched = true;
EList<Boolean> _values = ((JvmBooleanAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, boolean.class);
}
}
if (!_matched) {
if (value instanceof JvmIntAnnotationValue) {
_matched = true;
EList<Integer> _values = ((JvmIntAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, int.class);
}
}
if (!_matched) {
if (value instanceof JvmByteAnnotationValue) {
_matched = true;
EList<Byte> _values = ((JvmByteAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, byte.class);
}
}
if (!_matched) {
if (value instanceof JvmCharAnnotationValue) {
_matched = true;
EList<Character> _values = ((JvmCharAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, char.class);
}
}
if (!_matched) {
if (value instanceof JvmDoubleAnnotationValue) {
_matched = true;
EList<Double> _values = ((JvmDoubleAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, double.class);
}
}
if (!_matched) {
if (value instanceof JvmEnumAnnotationValue) {
_matched = true;
final Function1<JvmEnumerationLiteral, NamedElement> _function = (JvmEnumerationLiteral it) -> {
return this.toNamedElement(it);
};
List<NamedElement> _map = ListExtensions.<JvmEnumerationLiteral, NamedElement>map(((JvmEnumAnnotationValue) value).getValues(), _function);
_switchResult = Pair.<List<?>, Class<?>>of(_map, EnumerationValueDeclaration.class);
}
}
if (!_matched) {
if (value instanceof JvmFloatAnnotationValue) {
_matched = true;
EList<Float> _values = ((JvmFloatAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, float.class);
}
}
if (!_matched) {
if (value instanceof JvmLongAnnotationValue) {
_matched = true;
EList<Long> _values = ((JvmLongAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, long.class);
}
}
if (!_matched) {
if (value instanceof JvmShortAnnotationValue) {
_matched = true;
EList<Short> _values = ((JvmShortAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, short.class);
}
}
if (!_matched) {
List<Object> _emptyList = CollectionLiterals.<Object>emptyList();
_switchResult = Pair.<List<?>, Class<?>>of(_emptyList, Object.class);
}
final Pair<List<?>, Class<?>> result = _switchResult;
if (isArray) {
return this.toArrayOfType(result.getKey(), result.getValue());
} else {
return IterableExtensions.head(result.getKey());
}
}
use of org.eclipse.xtend.lib.macro.declaration.TypeReference in project xtext-xtend by eclipse.
the class JvmExecutableDeclarationImpl method addTypeParameter.
public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) {
this.checkMutable();
ConditionUtils.checkJavaIdentifier(name, "name");
ConditionUtils.checkIterable(((Iterable<?>) Conversions.doWrapArray(upperBounds)), "upperBounds");
ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds);
final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter();
param.setName(name);
this.getDelegate().getTypeParameters().add(param);
for (final TypeReference upper : upperBounds) {
{
final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper);
final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
jvmUpperBound.setTypeReference(typeRef);
param.getConstraints().add(jvmUpperBound);
}
}
TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param);
return ((MutableTypeParameterDeclaration) _typeParameterDeclaration);
}
use of org.eclipse.xtend.lib.macro.declaration.TypeReference in project xtext-xtend by eclipse.
the class JvmTypeDeclarationImpl method findDeclaredConstructor.
public ConstructorDeclaration findDeclaredConstructor(final TypeReference... parameterTypes) {
ConstructorDeclaration _xblockexpression = null;
{
ConditionUtils.checkIterable(((Iterable<?>) Conversions.doWrapArray(parameterTypes)), "parameterTypes");
final Function1<ConstructorDeclaration, Boolean> _function = (ConstructorDeclaration constructor) -> {
final Function1<ParameterDeclaration, TypeReference> _function_1 = (ParameterDeclaration it) -> {
return it.getType();
};
List<TypeReference> _list = IterableExtensions.<TypeReference>toList(IterableExtensions.map(constructor.getParameters(), _function_1));
List<TypeReference> _list_1 = IterableExtensions.<TypeReference>toList(((Iterable<TypeReference>) Conversions.doWrapArray(parameterTypes)));
return Boolean.valueOf(Objects.equal(_list, _list_1));
};
_xblockexpression = IterableExtensions.findFirst(this.getDeclaredConstructors(), _function);
}
return _xblockexpression;
}
Aggregations