예제 #1
0
  public void addToCommentBefore(List<String> s) {
    String b = getCommentBefore();
    List<String> ss = new ArrayList<String>();
    if (b != null && (b = cleanComment(b)).length() > 0) ss.add(b);
    for (String a : s) if (a != null && (a = cleanComment(a)).length() > 0) ss.add(a);
    // s);
    // if (b != null && b.trim().length() > 0)
    //	ss.add(0, b);

    setCommentBefore(ss.isEmpty() ? null : StringUtils.implode(ss, "\n"));
  }
  private Identifier getUndefinedTypeName(Identifier name) {

    String nameStr = name == null ? null : name.toString();
    String trimmed = StringUtils.trimUnderscores(nameStr);
    if (trimmed != null && !nameStr.equals(trimmed)) {
      String nicerName = trimmed;
      Pair<TypeDef, Declarator> pair = typeDefs.get(nicerName);
      if (pair != null) {
        String target = pair.getFirst().getValueType().toString();
        if (target.equals(nameStr)) // || target.equals(nameStr+"*"))
        name = ident(nameStr = nicerName);
      }
    }
    return name;
  }
 @Override
 public String toString() {
   return StringUtils.implode(sourceFiles, "\n");
 }
 public Identifier getLibraryClassSimpleName(String library) {
   return ident(StringUtils.capitalize(library) + "Library");
 }
  @Override
  public void visitEnum(Enum e) {
    super.visitEnum(e);
    if (e.getTag() == null) {
      // Hack to infer the enum name from the next typedef NSUInteger
      // NSSomethingThatLooksLikeTheEnumsIdentifiers
      Element nextDeclaration = e.getNextSibling();
      if (nextDeclaration != null && (nextDeclaration instanceof TypeDef)) {
        TypeDef typeDef = (TypeDef) nextDeclaration;
        TypeRef type = typeDef.getValueType();
        if (type instanceof TypeRef.SimpleTypeRef) {
          String simpleTypeStr = ((TypeRef.SimpleTypeRef) type).getName().toString();
          if (simpleTypeStr.equals("NSUInteger")
              || simpleTypeStr.equals("NSInteger")
              || simpleTypeStr.equals("CFIndex")) {
            Declarator bestPlainStorage = null;
            for (Declarator st : typeDef.getDeclarators()) {
              if (st instanceof DirectDeclarator) {
                String name = st.resolveName();
                boolean niceName = StringUtils.trimUnderscores(name).equals(name);
                ;
                if (bestPlainStorage == null || niceName) {
                  bestPlainStorage = st;
                  if (niceName) break;
                }
              }
            }
            if (bestPlainStorage != null) {
              String name = bestPlainStorage.resolveName();
              System.err.println("Automatic struct name matching : " + name);
              e.setTag(ident(name));
            }
          }
        }
      }
    }

    Identifier name = e.getTag();
    String lib = getLibrary(e);
    if (name == null) getList(enumsByLibrary, lib).add(e);
    else {
      Enum oldEnum = enumsByName.get(name);

      if (oldEnum == null
          || oldEnum.isForwardDeclaration()
          || (!(oldEnum.getParentElement() instanceof TypeDef)
              && oldEnum.getParentElement() instanceof TypeDef)) {
        enumsByName.put(name, e);

        // if (e.getTag() != null) {
        //	enumsByName.put(e.getTag(), e);
        // }
        getList(enumsByLibrary, lib).add(e);

        Identifier identifier = getTaggedTypeIdentifierInJava(e);
        if (identifier != null) {
          enumsFullNames.add(identifier);
        }
      }
    }
  }