use of org.eclipse.ceylon.compiler.java.language.EnumeratedTypeError in project ceylon by eclipse.
the class Predicates method isDeclarationOfKind.
/**
* Returns a Predicate for Declarations being of the given kind
* (Class, Interface, Function, Value etc)
* @param kind A TypeDescriptor for the sought declaration kind.
*/
public static Predicate<Declaration> isDeclarationOfKind(TypeDescriptor kind) {
if (kind instanceof TypeDescriptor.Class) {
Class<?> declarationClass = (Class<?>) ((TypeDescriptor.Class) kind).getKlass();
if (declarationClass == ceylon.language.meta.declaration.ValueDeclaration.class) {
return DECLARATION_IS_VALUE;
} else if (declarationClass == ceylon.language.meta.declaration.FunctionDeclaration.class) {
return DECLARATION_IS_FUNCTION;
} else if (declarationClass == ceylon.language.meta.declaration.FunctionOrValueDeclaration.class) {
return DECLARATION_IS_FUNCTION_OR_VALUE;
} else if (declarationClass == ceylon.language.meta.declaration.ClassDeclaration.class) {
return DECLARATION_IS_CLASS;
} else if (declarationClass == ceylon.language.meta.declaration.ClassWithInitializerDeclaration.class) {
return DECLARATION_IS_CLASS_WITH_INIT;
} else if (declarationClass == ceylon.language.meta.declaration.ClassWithConstructorsDeclaration.class) {
return DECLARATION_IS_CLASS_WITH_CTORS;
} else if (declarationClass == ceylon.language.meta.declaration.InterfaceDeclaration.class) {
return DECLARATION_IS_INTERFACE;
} else if (declarationClass == ceylon.language.meta.declaration.ClassOrInterfaceDeclaration.class) {
return DECLARATION_IS_CLASS_OR_INTERFACE;
} else if (declarationClass == ceylon.language.meta.declaration.AliasDeclaration.class) {
return DECLARATION_IS_ALIAS;
} else if (declarationClass == ceylon.language.meta.declaration.ConstructorDeclaration.class) {
return DECLARATION_IS_CONSTRUCTOR;
} else if (declarationClass == ceylon.language.meta.declaration.CallableConstructorDeclaration.class) {
return DECLARATION_IS_CALLABLE_CONSTRUCTOR;
} else if (declarationClass == ceylon.language.meta.declaration.ValueConstructorDeclaration.class) {
return DECLARATION_IS_VALUE_CONSTRUCTOR;
} else if (declarationClass == ceylon.language.meta.declaration.NestableDeclaration.class) {
return true_();
}
throw new EnumeratedTypeError("Supposedly exhaustive switch was not exhaustive");
} else if (kind instanceof TypeDescriptor.Union) {
TypeDescriptor[] members = ((TypeDescriptor.Union) kind).getMembers();
@SuppressWarnings("unchecked") Predicate<Declaration>[] preds = new Predicate[members.length];
int ii = 0;
for (TypeDescriptor member : members) {
preds[ii++] = isDeclarationOfKind(member);
}
return or(preds);
} else if (kind instanceof TypeDescriptor.Intersection) {
TypeDescriptor[] members = ((TypeDescriptor.Intersection) kind).getMembers();
@SuppressWarnings("unchecked") Predicate<Declaration>[] preds = new Predicate[members.length];
int ii = 0;
for (TypeDescriptor member : members) {
preds[ii++] = isDeclarationOfKind(member);
}
return and(preds);
} else if (kind == TypeDescriptor.NothingType) {
return false_();
}
throw new EnumeratedTypeError("Supposedly exhaustive switch was not exhaustive");
}
Aggregations