private static boolean lookForInterface( java.lang.Class<?> klass, String className, Set<java.lang.Class<?>> alreadyVisited) { if (klass.getName().equals(className)) return true; // did we already visit this type? if (!alreadyVisited.add(klass)) return false; // first see if it satisfies it directly SatisfiedTypes satisfiesAnnotation = klass.getAnnotation(SatisfiedTypes.class); if (satisfiesAnnotation != null) { for (String satisfiedType : satisfiesAnnotation.value()) { satisfiedType = declClassName(satisfiedType); int i = satisfiedType.indexOf('<'); if (i > 0) { satisfiedType = satisfiedType.substring(0, i); } try { if (lookForInterface( java.lang.Class.forName(satisfiedType, true, klass.getClassLoader()), className, alreadyVisited)) { return true; } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } } // now look at this class's interfaces for (java.lang.Class<?> intrface : klass.getInterfaces()) { if (lookForInterface(intrface, className, alreadyVisited)) return true; } // no luck return false; }
private static boolean classExtendsClass(java.lang.Class<?> klass, String className) { if (klass == null) return false; if (klass.getName().equals(className)) return true; if ((className.equals("ceylon.language.Basic")) && klass != java.lang.Object.class && !isSubclassOfString(klass) // && klass!=java.lang.String.class && !klass.isAnnotationPresent(Class.class) && (!klass.isInterface() || !klass.isAnnotationPresent(Ceylon.class))) { // TODO: this is broken for a Java class that // extends a Ceylon class return true; } Class classAnnotation = klass.getAnnotation(Class.class); if (classAnnotation != null) { String superclassName = declClassName(classAnnotation.extendsType()); int i = superclassName.indexOf('<'); if (i > 0) { superclassName = superclassName.substring(0, i); } if (superclassName.isEmpty()) { return false; } try { return classExtendsClass( java.lang.Class.forName(superclassName, true, klass.getClassLoader()), className); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } return classExtendsClass(klass.getSuperclass(), className); }
private static boolean classSatisfiesInterface( java.lang.Class<?> klass, String className, Set<java.lang.Class<?>> alreadyVisited) { if (klass == null || klass == ceylon.language.Anything.class) return false; if ((className.equals("ceylon.language.Identifiable")) && klass != java.lang.Object.class // && klass!=java.lang.String.class && !klass.isAnnotationPresent(Ceylon.class)) { // TODO: this is broken for a Java class that // extends a Ceylon class return true; } if (className.equals("ceylon.language.Identifiable") && isSubclassOfString(klass)) { return false; } // try the interfaces if (lookForInterface(klass, className, alreadyVisited)) return true; // try its superclass Class classAnnotation = klass.getAnnotation(Class.class); String superclassName; if (classAnnotation != null) { superclassName = declClassName(classAnnotation.extendsType()); int i = superclassName.indexOf('<'); if (i > 0) { superclassName = superclassName.substring(0, i); } } else { // Maybe the class didn't have an extends, so implictly Basic superclassName = "ceylon.language.Basic"; } if (!superclassName.isEmpty()) { try { return classSatisfiesInterface( java.lang.Class.forName(superclassName, true, klass.getClassLoader()), className, alreadyVisited); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } return classSatisfiesInterface(klass.getSuperclass(), className, alreadyVisited); }