Ejemplo n.º 1
0
  /**
   * Parses a field type definition
   *
   * @param docField
   * @return
   */
  protected static Field ParseField(FieldDoc docField) {
    assert (docField != null);

    Field xmlField = new Field();

    xmlField.name = docField.name();
    xmlField.comment = docField.commentText();
    xmlField.type = ParseType(docField.type());
    xmlField.isFinal = docField.isFinal();
    if (xmlField.isFinal) {
      xmlField.finalExpression = docField.constantValueExpression();
    } else if (docField.constantValueExpression() != null) {
      // how would a non-final field have a constant value expression?
      // my understanding is that this field is only != null when is not final
      assert (false);
    }
    xmlField.isStatic = docField.isStatic();
    xmlField.isVolatile = docField.isVolatile();
    xmlField.isTransient = docField.isTransient();
    xmlField.scope = DetermineScope(docField);

    // parse annotations from the field
    xmlField.annotationInstances =
        ParseAnnotationInstances(docField.annotations(), docField.qualifiedName());

    return xmlField;
  }
Ejemplo n.º 2
0
  /* OVERRIDE: This method handles instance fields */
  protected String addStructMember(FieldDoc member, String cname, boolean padWord)
      throws ClassNotFoundException {
    String res = null;

    if (member.isStatic()) {
      res = addStaticStructMember(member, cname);
      //   if (res == null) /* JNI didn't handle it, print comment. */
      //  res = "    /* Inaccessible static: " + member + " */" + lineSep;
    } else {
      if (padWord) res = "    java_int padWord" + padFieldNum++ + ";" + lineSep;
      res = "    " + llniType(member.type(), false, false) + " " + llniFieldName(member);
      if (isLongOrDouble(member.type())) res = res + "[2]";
      res = res + ";" + lineSep;
    }
    return res;
  }
Ejemplo n.º 3
0
  protected void forwardDecls(PrintWriter pw, ClassDoc clazz) throws ClassNotFoundException {
    ClassDoc clazzfield = null;

    if (clazz.qualifiedName().equals("java.lang.Object")) return;
    genHandleType(pw, clazz.qualifiedName());
    ClassDoc superClass = clazz.superclass();

    if (superClass != null) {
      String superClassName = superClass.qualifiedName();
      forwardDecls(pw, superClass);
    }

    for (int i = 0; i < fields.length; i++) {
      FieldDoc field = (FieldDoc) fields[i];

      if (!field.isStatic()) {
        Type t = field.type();
        String tname = t.qualifiedTypeName();
        TypeSignature newTypeSig = new TypeSignature(root);
        String sig = newTypeSig.getTypeSignature(tname);

        if (sig.charAt(0) != '[') forwardDeclsFromSig(pw, sig);
      }
    }

    for (int i = 0; i < methods.length; i++) {
      MethodDoc method = (MethodDoc) methods[i];

      if (method.isNative()) {
        Type retType = method.returnType();
        String typesig = method.signature();
        TypeSignature newTypeSig = new TypeSignature(root);
        String sig = newTypeSig.getTypeSignature(typesig, retType);

        if (sig.charAt(0) != '[') forwardDeclsFromSig(pw, sig);
      }
    }
  }
Ejemplo n.º 4
0
  /**
   * Prints associations recovered from the fields of a class. An association is inferred only if
   * another relation between the two classes is not already in the graph.
   *
   * @param classes
   */
  public void printInferredRelations(ClassDoc c) {
    Options opt = optionProvider.getOptionsFor(c);

    // check if the source is excluded from inference
    if (hidden(c)) return;

    for (FieldDoc field : c.fields(false)) {
      if (hidden(field)) continue;

      // skip statics
      if (field.isStatic()) continue;

      // skip primitives
      FieldRelationInfo fri = getFieldRelationInfo(field);
      if (fri == null) continue;

      // check if the destination is excluded from inference
      if (hidden(fri.cd)) continue;

      String destAdornment = fri.multiple ? "*" : "";
      relation(opt, opt.inferRelationshipType, c, fri.cd, "", "", destAdornment);
    }
  }
Ejemplo n.º 5
0
  /*
   * This method only handles static final fields.
   */
  protected String addStaticStructMember(FieldDoc field, String cname)
      throws ClassNotFoundException {
    String res = null;
    Object exp = null;

    if (!field.isStatic()) return res;
    if (!field.isFinal()) return res;

    exp = field.constantValue();

    if (exp != null) {
      /* Constant. */

      String cn = cname + "_" + field.name();
      String suffix = null;
      long val = 0;
      /* Can only handle int, long, float, and double fields. */
      if (exp instanceof Integer) {
        suffix = "L";
        val = ((Integer) exp).intValue();
      }
      if (exp instanceof Long) {
        // Visual C++ supports the i64 suffix, not LL
        suffix = isWindows ? "i64" : "LL";
        val = ((Long) exp).longValue();
      }
      if (exp instanceof Float) suffix = "f";
      if (exp instanceof Double) suffix = "";
      if (suffix != null) {
        // Some compilers will generate a spurious warning
        // for the integer constants for Integer.MIN_VALUE
        // and Long.MIN_VALUE so we handle them specially.
        if ((suffix.equals("L") && (val == Integer.MIN_VALUE))
            || (suffix.equals("LL") && (val == Long.MIN_VALUE))) {
          res =
              "    #undef  "
                  + cn
                  + lineSep
                  + "    #define "
                  + cn
                  + " ("
                  + (val + 1)
                  + suffix
                  + "-1)"
                  + lineSep;
        } else {
          res =
              "    #undef  "
                  + cn
                  + lineSep
                  + "    #define "
                  + cn
                  + " "
                  + exp.toString()
                  + suffix
                  + lineSep;
        }
      }
    }
    return res;
  }