private DbJVClass importClass(JavaClass claz, Controller controller) throws DbException {

    String packName = claz.getPackageName();
    String qualifiedName = claz.getClassName();
    int idx = qualifiedName.lastIndexOf('.');
    String classname = qualifiedName.substring(idx + 1);
    DbJVClass dbClaz = null;

    try {
      if (m_classModel != null) {
        DbJVPackage pack = findPackageByName(packName);

        // create class or interface
        int value = claz.isInterface() ? JVClassCategory.INTERFACE : JVClassCategory.CLASS;
        JVClassCategory catg = JVClassCategory.getInstance(value);
        dbClaz =
            (pack == null) ? new DbJVClass(this.m_classModel, catg) : new DbJVClass(pack, catg);
        dbClaz.setName(classname);

        // set class modifiers
        dbClaz.setAbstract(claz.isAbstract());
        dbClaz.setFinal(claz.isFinal());
        dbClaz.setStatic(claz.isStatic());
        dbClaz.setStrictfp(claz.isStrictfp());
        dbClaz.setVisibility(toVisibility(claz));

        // create inheritances
        importInheritances(dbClaz, claz);

        // create fields
        if (m_params.createFields) {
          Field[] fields = claz.getFields();
          for (Field field : fields) {
            importField(dbClaz, field);
          }
        }

        // create methods
        if (m_params.createMethods) {
          Method[] methods = claz.getMethods();
          for (Method method : methods) {
            importMethod(dbClaz, method);
          }
        }

        // keep user informed of progression
        String pattern = LocaleMgr.misc.getString("0SuccessfullyCreated");
        String msg = MessageFormat.format(pattern, qualifiedName);
        controller.println(msg);
      } // end if
    } catch (DbException ex) {
      controller.println(ex.toString());
    } // end try

    return dbClaz;
  } // end importClass()
Ejemplo n.º 2
0
  /**
   * Initialize with existing class.
   *
   * @param clazz JavaClass object (e.g. read from file)
   */
  public ClassGen(JavaClass clazz) {
    class_name_index = clazz.getClassNameIndex();
    superclass_name_index = clazz.getSuperclassNameIndex();
    class_name = clazz.getClassName();
    super_class_name = clazz.getSuperclassName();
    file_name = clazz.getSourceFileName();
    access_flags = clazz.getAccessFlags();
    cp = new ConstantPoolGen(clazz.getConstantPool());
    major = clazz.getMajor();
    minor = clazz.getMinor();

    Attribute[] attributes = clazz.getAttributes();
    Method[] methods = clazz.getMethods();
    Field[] fields = clazz.getFields();
    String[] interfaces = clazz.getInterfaceNames();

    for (int i = 0; i < interfaces.length; i++) addInterface(interfaces[i]);

    for (int i = 0; i < attributes.length; i++) addAttribute(attributes[i]);

    for (int i = 0; i < methods.length; i++) addMethod(methods[i]);

    for (int i = 0; i < fields.length; i++) addField(fields[i]);
  }