private void checkExtends(
     ClassDeclaration classDeclaration, PackageDeclaration packageDeclaration) {
   String scName = classDeclaration.getSuperclass().toString();
   int lt = scName.indexOf('<');
   if (lt != -1) {
     scName = scName.substring(0, lt);
   }
   int dot = scName.lastIndexOf('.');
   if (dot != -1) {
     String superClassPackageName = scName.substring(0, dot);
     if (!superClassPackageName.equals(packageDeclaration.getQualifiedName())) {
       scName = ""; // force error below
     } else {
       scName = scName.substring(dot + 1);
     }
   }
   if (!scName.equals(classDeclaration.getSimpleName() + "Gen")) {
     error(
         classDeclaration,
         classDeclaration.getQualifiedName()
             + " must extend "
             + classDeclaration.getQualifiedName()
             + "Gen for @Bean to work properly");
   }
 }
 private boolean checkInheritedMethod(
     Thing data,
     String methodName,
     String returnType,
     ClassDeclaration superclass,
     boolean finalOk,
     InheritCheck inheritCheck) {
   if (inheritCheck != null) {
     if (inheritCheck.isInherited(data, superclass)) {
       return true;
     }
   }
   for (MethodDeclaration methodDeclaration : superclass.getMethods()) {
     if (methodName.equals(methodDeclaration.getSimpleName())
         && methodDeclaration.getParameters().isEmpty()
         && returnType.equals(methodDeclaration.getReturnType().toString())) {
       data.put(methodName + "Inherited", true);
       Collection<Modifier> modifiers = methodDeclaration.getModifiers();
       if ((modifiers.contains(Modifier.FINAL) || modifiers.contains(Modifier.PRIVATE))
           && !finalOk) {
         // TBD TBD TBD - ERROR!!! cannot extend class with superclass method like this - how to
         // report?
       } else if (modifiers.contains(Modifier.PROTECTED)) {
         data.put(methodName + "Modifiers", "protected");
       } else if (modifiers.contains(Modifier.PUBLIC)) {
         data.put(methodName + "Modifiers", "public");
       } else {
         data.put(methodName + "Modifiers", "");
       }
       return true;
     }
   }
   if (superclass.getSuperclass() != null) {
     if (superclass.getSuperclass().getDeclaration() != null) {
       if (checkInheritedMethod(
           data,
           methodName,
           returnType,
           superclass.getSuperclass().getDeclaration(),
           finalOk,
           inheritCheck)) {
         return true;
       }
     }
   }
   return false;
 }
Example #3
0
 @Test(result = {"null"})
 ClassType objectHasNoSuperclass() {
   return object.getSuperclass();
 }