Esempio n. 1
0
 private boolean acceptableType(String rtype) {
   TypeRef ref = analyzer.getTypeRefFromFQN(rtype);
   try {
     Clazz returnType = analyzer.findClass(ref);
     if (returnType.isEnum()) {
       return true;
     }
     // TODO check this is true for interfaces and annotations
     if (!returnType.isAbstract()
         || (returnType.isInterface() && options.contains(Options.nested))) {
       return true;
     }
     if (!returnType.isInterface()) {
       analyzer.error("Abstract classes not allowed as interface method return values: %s", rtype);
     } else {
       analyzer.error("Nested metatype only allowed with option: nested type %s", rtype);
     }
     return false;
   } catch (Exception e) {
     analyzer.error(
         "could not examine class for return type %s, exception message: %s",
         rtype, e.getMessage());
     return false;
   }
 }
Esempio n. 2
0
 private boolean identifiableCollection(String type, boolean intface, boolean topLevel) {
   try {
     Clazz clazz = analyzer.findClass(analyzer.getTypeRefFromFQN(type));
     if (clazz != null
         && (!topLevel || !clazz.isAbstract())
         && ((intface && clazz.isInterface()) ^ clazz.hasPublicNoArgsConstructor())) {
       TypeRef[] intfs = clazz.getInterfaces();
       if (intfs != null) {
         for (TypeRef intf : intfs) {
           if (COLLECTION.matcher(intf.getFQN()).matches()
               || identifiableCollection(intf.getFQN(), true, false)) {
             return true;
           }
         }
       }
       TypeRef ext = clazz.getSuper();
       return ext != null && identifiableCollection(ext.getFQN(), false, false);
     }
   } catch (Exception e) {
     return false;
   }
   return false;
 }