use of org.eclipse.xtend.lib.macro.declaration.Type in project xtext-xtend by eclipse.
the class DeclarationsTest method testIsAssignable.
@Test
public void testIsAssignable() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("class BaseClass implements InterfaceA {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class SubType extends BaseClass implements InterfaceA {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("interface InterfaceA {}");
_builder.newLine();
_builder.append("interface InterfaceB {}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
TypeDeclaration _get = ((TypeDeclaration[]) Conversions.unwrapArray(it.getSourceTypeDeclarations(), TypeDeclaration.class))[0];
final ClassDeclaration baseClass = ((ClassDeclaration) _get);
final MutableClassDeclaration subClass = it.getTypeLookup().findClass("foo.SubType");
TypeDeclaration _get_1 = ((TypeDeclaration[]) Conversions.unwrapArray(it.getSourceTypeDeclarations(), TypeDeclaration.class))[2];
final InterfaceDeclaration interfaceA = ((InterfaceDeclaration) _get_1);
TypeDeclaration _get_2 = ((TypeDeclaration[]) Conversions.unwrapArray(it.getSourceTypeDeclarations(), TypeDeclaration.class))[3];
final InterfaceDeclaration interfaceB = ((InterfaceDeclaration) _get_2);
final Type object = it.getTypeReferenceProvider().getObject().getType();
Assert.assertTrue(object.isAssignableFrom(baseClass));
Assert.assertTrue(object.isAssignableFrom(subClass));
Assert.assertTrue(object.isAssignableFrom(interfaceA));
Assert.assertTrue(object.isAssignableFrom(interfaceB));
Assert.assertTrue(baseClass.isAssignableFrom(baseClass));
Assert.assertTrue(baseClass.isAssignableFrom(subClass));
Assert.assertFalse(baseClass.isAssignableFrom(interfaceB));
Assert.assertFalse(baseClass.isAssignableFrom(interfaceA));
Assert.assertFalse(baseClass.isAssignableFrom(object));
Assert.assertTrue(interfaceA.isAssignableFrom(baseClass));
Assert.assertTrue(interfaceA.isAssignableFrom(subClass));
Assert.assertTrue(interfaceA.isAssignableFrom(interfaceA));
Assert.assertFalse(interfaceA.isAssignableFrom(interfaceB));
Assert.assertFalse(interfaceA.isAssignableFrom(object));
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.lib.macro.declaration.Type in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toType.
public Type toType(final JvmType delegate) {
final Function1<JvmType, Type> _function = (JvmType it) -> {
Type _switchResult = null;
boolean _matched = false;
if (delegate instanceof JvmDeclaredType) {
_matched = true;
_switchResult = this.toTypeDeclaration(((JvmDeclaredType) delegate));
}
if (!_matched) {
if (delegate instanceof JvmTypeParameter) {
_matched = true;
_switchResult = this.toTypeParameterDeclaration(((JvmTypeParameter) delegate));
}
}
if (!_matched) {
if (delegate instanceof JvmVoid) {
_matched = true;
VoidTypeImpl _voidTypeImpl = new VoidTypeImpl();
final Procedure1<VoidTypeImpl> _function_1 = (VoidTypeImpl it_1) -> {
it_1.setDelegate(((JvmVoid) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<VoidTypeImpl>operator_doubleArrow(_voidTypeImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof JvmPrimitiveType) {
_matched = true;
PrimitiveTypeImpl _primitiveTypeImpl = new PrimitiveTypeImpl();
final Procedure1<PrimitiveTypeImpl> _function_1 = (PrimitiveTypeImpl it_1) -> {
it_1.setDelegate(((JvmPrimitiveType) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<PrimitiveTypeImpl>operator_doubleArrow(_primitiveTypeImpl, _function_1);
}
}
return _switchResult;
};
return this.<JvmType, Type>getOrCreate(delegate, _function);
}
use of org.eclipse.xtend.lib.macro.declaration.Type in project xtext-xtend by eclipse.
the class TypeLookupImpl method findType.
private Type findType(final String qualifiedName) {
final Function1<JvmDeclaredType, String> _function = (JvmDeclaredType type) -> {
return type.getQualifiedName('.');
};
final Function1<JvmDeclaredType, Iterable<? extends JvmDeclaredType>> _function_1 = (JvmDeclaredType type) -> {
return Iterables.<JvmDeclaredType>filter(type.getMembers(), JvmDeclaredType.class);
};
final JvmDeclaredType result = this.<JvmDeclaredType>recursiveFindType(qualifiedName, Iterables.<JvmDeclaredType>filter(this.compilationUnit.getXtendFile().eResource().getContents(), JvmDeclaredType.class), _function, _function_1);
Type _xifexpression = null;
if ((result != null)) {
_xifexpression = this.compilationUnit.toType(result);
}
return _xifexpression;
}
use of org.eclipse.xtend.lib.macro.declaration.Type in project xtext-xtend by eclipse.
the class TypeLookupImpl method findAnnotationType.
@Override
public MutableAnnotationTypeDeclaration findAnnotationType(final String qualifiedName) {
final Type type = this.findType(qualifiedName);
MutableAnnotationTypeDeclaration _switchResult = null;
boolean _matched = false;
if (type instanceof MutableAnnotationTypeDeclaration) {
_matched = true;
_switchResult = ((MutableAnnotationTypeDeclaration) type);
}
return _switchResult;
}
use of org.eclipse.xtend.lib.macro.declaration.Type in project xtext-xtend by eclipse.
the class TypeLookupImpl method findInterface.
@Override
public MutableInterfaceDeclaration findInterface(final String qualifiedName) {
final Type type = this.findType(qualifiedName);
MutableInterfaceDeclaration _switchResult = null;
boolean _matched = false;
if (type instanceof MutableInterfaceDeclaration) {
_matched = true;
_switchResult = ((MutableInterfaceDeclaration) type);
}
return _switchResult;
}
Aggregations