示例#1
0
 /**
  * Insert the source code details, if available.
  *
  * @param ped The given program element.
  */
 public void addSourcePosition(ProgramElementDoc ped, int indent) {
   if (!addSrcInfo) return;
   if (JDiff.javaVersion.startsWith("1.1")
       || JDiff.javaVersion.startsWith("1.2")
       || JDiff.javaVersion.startsWith("1.3")) {
     return; // position() only appeared in J2SE1.4
   }
   try {
     // Could cache the method for improved performance
     Class c = ProgramElementDoc.class;
     Method m = c.getMethod("position", null);
     Object sp = m.invoke(ped, null);
     if (sp != null) {
       for (int i = 0; i < indent; i++) outputFile.print(" ");
       outputFile.println("src=\"" + sp + "\"");
     }
   } catch (NoSuchMethodException e2) {
     System.err.println("Error: method \"position\" not found");
     e2.printStackTrace();
   } catch (IllegalAccessException e4) {
     System.err.println("Error: class not permitted to be instantiated");
     e4.printStackTrace();
   } catch (InvocationTargetException e5) {
     System.err.println("Error: method \"position\" could not be invoked");
     e5.printStackTrace();
   } catch (Exception e6) {
     System.err.println("Error: ");
     e6.printStackTrace();
   }
 }
示例#2
0
 public String toString(String comp) {
   RobotType rt;
   try {
     rt = RobotType.valueOf(comp);
   } catch (IllegalArgumentException e) {
     return null;
   }
   StringBuilder builder = new StringBuilder();
   try {
     append(builder, "Level", rt.level.name());
     append(builder, "Max Energon", String.format("%1.0f", rt.maxEnergon));
     append(builder, "Max Flux", String.format("%1.0f", rt.maxFlux));
     if (rt.spawnCost > 0) append(builder, "Spawn Cost", String.format("%1.0f", rt.spawnCost));
     if (rt.moveDelayOrthogonal > 0) {
       append(builder, "Move Delay Orthogonal", String.format("%d", rt.moveDelayOrthogonal));
       append(builder, "Move Delay Diagonal", String.format("%d", rt.moveDelayDiagonal));
       // display cost for archons even though it's zero
       append(builder, "Move Cost", String.format("%1.1f", rt.moveCost));
     }
     if (rt.sensorAngle > 0) {
       append(builder, "Sensor Radius Squared", String.format("%d", rt.sensorRadiusSquared));
       append(builder, "Sensor Angle", String.format("%1.0f", rt.sensorAngle));
     }
     if (rt.canAttackAir || rt.canAttackGround) {
       append(
           builder, "Min Attack Radius Squared", String.format("%d", rt.attackRadiusMinSquared));
       append(
           builder, "Max Attack Radius Squared", String.format("%d", rt.attackRadiusMaxSquared));
       append(builder, "Attack Angle", String.format("%1.0f", rt.attackAngle));
       append(builder, "Attack Power", String.format("%1.1f", rt.attackPower));
       append(builder, "Attack Delay", String.format("%d", rt.attackDelay));
       String attacks;
       if (rt.canAttackAir && rt.canAttackGround) attacks = "Air, Ground";
       else if (rt.canAttackAir) attacks = "Air";
       else attacks = "Ground";
       append(builder, "Attacks", attacks);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return builder.toString();
 }
示例#3
0
  public static boolean start(RootDoc root) {
    try {
      init(root);
      ClassDoc[] classes = root.classes();
      ArrayList<String> generatesTestClasses = new ArrayList<String>();
      for (int i = 0; i < classes.length; i++) {
        ClassDoc classDoc = classes[i];
        if (classDoc.isAbstract()
            || classDoc.isInterface()
            || classDoc.isEnum()
            || classDoc.isPrivate()
            || classDoc.isAnnotationType()) {
        } else if (!hasDefaultConstructor(classDoc)) {
          System.out.println(classDoc.qualifiedTypeName() + " does not have default Constructor.");
        } else {
          ClassBean testClassBean = ClassBeanCreator.create(classDoc);
          if (testClassBean.hasMethods()) {
            JavaCodeWriter writer = getWriter(testClassBean);
            if (writer != null) {
              JavaCodeGenerator.generate(testClassBean, writer);
              generatesTestClasses.add(classDoc.qualifiedTypeName());
              writer.close();
            }
          } else {
            System.out.println(
                classDoc.qualifiedTypeName() + " does not have any methods to cover.");
          }
        }
      }
      System.out.println("---------REPORT-----------------------------------------------");
      for (Iterator iterator = generatesTestClasses.iterator(); iterator.hasNext(); ) {
        String clsName = (String) iterator.next();
        System.out.println("\t" + clsName);
      }
      System.out.println("-------------------------------------------------------------");

      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }