/** Get every attributes this class has. But no protected attributes. */
  private void getAttributes() {
    if (cUnit == null) {
      return;
    }
    // Initialize parameters that building a new attribute instance needs
    ClassAttribute attribute = null;
    String attributeName = "";
    String accessModifier = "";
    String attributeType = "";
    for (TypeDeclaration typeDeclaration : cUnit.getTypes()) {
      List<BodyDeclaration> memebers = typeDeclaration.getMembers();
      if (memebers == null) {
        return;
      }
      for (BodyDeclaration bodyDeclaration : memebers) {
        FieldDeclaration fieldDeclaration;
        try {
          // Conversion here may cause exception
          fieldDeclaration = (FieldDeclaration) bodyDeclaration;
          accessModifier = GetModifier(fieldDeclaration.getModifiers());
          if (accessModifier == "+" || accessModifier == "-") {
            attributeName = fieldDeclaration.getVariables().get(0).getId().getName();
            attributeType = fieldDeclaration.getType().toString();
            attribute = new ClassAttribute(attributeName, accessModifier, attributeType);
            this.classAttributes.add(attribute);
          }
        } catch (Exception e) {

        }
      }
    }
  }
示例#2
0
  public void visit(FieldDeclaration n, Object arg) {
    if (n.getJavaDoc() != null) {
      n.getJavaDoc().accept(this, arg);
    }
    printMemberAnnotations(n.getAnnotations(), arg);
    printModifiers(n.getModifiers());
    n.getType().accept(this, arg);

    for (Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext(); ) {
      VariableDeclarator var = i.next();
      var.accept(this, arg);
      if (i.hasNext()) {}
    }
  }
 public void visit(FieldDeclaration n, A arg) {
   if (n.getJavaDoc() != null) {
     n.getJavaDoc().accept(this, arg);
   }
   if (n.getAnnotations() != null) {
     for (AnnotationExpr a : n.getAnnotations()) {
       a.accept(this, arg);
     }
   }
   n.getType().accept(this, arg);
   for (VariableDeclarator var : n.getVariables()) {
     var.accept(this, arg);
   }
 }