Beispiel #1
0
 public void onWrite(ClassPool pool, String className)
     throws NotFoundException, CannotCompileException {
   CtClass cc = pool.get(className);
   try {
     if (isPersistent(className)) {
       CtClass base = cc.getSuperclass();
       CtConstructor cons = new CtConstructor(constructorParams, cc);
       if (base.subclassOf(persistent) || base == object) {
         cons.setBody(null);
         cc.addConstructor(cons);
         if (base == object) {
           cc.setSuperclass(persistent);
         }
       } else {
         if (!isPersistent(base.getName())) {
           throw new NotFoundException(
               "Base class " + base.getName() + " was not declared as persistent");
         }
         cons.setBody("super($0);");
         cc.addConstructor(cons);
       }
       preprocessMethods(cc, true, true);
       if (base == persistent || base == object) {
         CtMethod m = new CtMethod(isRecursive, cc, null);
         m.setBody("return false;");
         cc.addMethod(m);
         addSerializeMethods(cc, false);
       } else if (base.subtypeOf(serializable)) {
         addSerializeMethods(cc, true);
       }
       if ((cc.getModifiers() & Modifier.PRIVATE) == 0) {
         CtClass f = pool.makeClass(className + "LoadFactory");
         f.addInterface(factory);
         CtMethod c = new CtMethod(create, f, null);
         c.setBody("return new " + className + "($1);");
         f.addMethod(c);
         CtNewConstructor.defaultConstructor(f);
       }
     } else {
       preprocessMethods(
           cc, cc.subtypeOf(persistent) && cc != persistent, !className.startsWith("org.nachodb"));
     }
   } catch (Exception x) {
     x.printStackTrace();
   }
 }
Beispiel #2
0
 /* 200:    */
 /* 201:    */ public boolean visibleFrom(CtClass clazz) /* 202:    */ {
   /* 203:170 */ int mod = getModifiers();
   /* 204:171 */ if (Modifier.isPublic(mod)) {
     /* 205:172 */ return true;
     /* 206:    */ }
   /* 207:173 */ if (Modifier.isPrivate(mod)) {
     /* 208:174 */ return clazz == this.declaringClass;
     /* 209:    */ }
   /* 210:176 */ String declName = this.declaringClass.getPackageName();
   /* 211:177 */ String fromName = clazz.getPackageName();
   /* 212:    */ boolean visible;
   /* 213:    */ boolean visible;
   /* 214:179 */ if (declName == null) {
     /* 215:180 */ visible = fromName == null;
     /* 216:    */ } else {
     /* 217:182 */ visible = declName.equals(fromName);
     /* 218:    */ }
   /* 219:184 */ if ((!visible) && (Modifier.isProtected(mod))) {
     /* 220:185 */ return clazz.subclassOf(this.declaringClass);
     /* 221:    */ }
   /* 222:187 */ return visible;
   /* 223:    */ }