package com.ragnarok.jparseutil.dataobject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ragnarok on 15/5/24.
 * represent information for a Java Class
 */
public class ClassInfo {
    
    private String qualifiedName;
    private String simpleName;
    
    private ArrayList<VariableInfo> variableInfos = new ArrayList<>();

    private ArrayList<AnnotationModifier> annotationModifiers = new ArrayList<>();
    
    private ArrayList<MethodInfo> methodInfos = new ArrayList<>();

    public void setQualifiedName(String className) {
        this.qualifiedName = className;
    }
    
    public void setSimpleName(String className) {
        this.simpleName = className;
    }
    
    public String getQualifiedName() {
        return this.qualifiedName;
    }
    
    public String getSimpleName() {
        return this.simpleName;
    }
    
    public void addVariable(VariableInfo variableInfo) {
        this.variableInfos.add(variableInfo);
    }
    
    public void updateVariable(String variableName, VariableInfo variableInfo) {
        int index = -1;
        for (int i = 0; i < this.variableInfos.size(); i++) {
            if (this.variableInfos.get(i).getVariableName().equals(variableName)) {
                index = i;
                break;
            }
        }
        if (index != -1) {
            this.variableInfos.set(index, variableInfo);
        }
    }
    
    public ArrayList<VariableInfo> getAllVariables() {
        return this.variableInfos;
    }

    public void putAnnotation(AnnotationModifier annotationModifier) {
        this.annotationModifiers.add(annotationModifier);
    }
    
    public List<AnnotationModifier> getAllAnnotationModifiers() {
        return annotationModifiers;
    }
    
    public void putMethod(MethodInfo method) {
        this.methodInfos.add(method);
    }
    
    public List<MethodInfo> getAllMethods() {
        return methodInfos;
    }
    
    public void updateMethod(String methodName, MethodInfo newMethod) {
        int index = -1;
        for (int i = 0; i < this.methodInfos.size(); i++) {
            if (this.methodInfos.get(i).getMethodName().equals(methodName)) {
                index = i;
                break;
            }
        }
        if (index != -1) {
            this.methodInfos.set(index, newMethod);
        }
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        result.append("{Class, ");
        result.append(String.format("qualifiedName: %s, ", qualifiedName));
        result.append(String.format("simpleName: %s, ", simpleName));
        result.append("\n");
        if (variableInfos.size() > 0) {
            for (VariableInfo variableInfo : variableInfos) {
                result.append(variableInfo.toString() + ", ");
                result.append("\n");
            }
        }
        result.append("\n");
        if (annotationModifiers.size() > 0) {
            for (AnnotationModifier annotationModifier : annotationModifiers) {
                result.append(annotationModifier.toString() + ", ");
                result.append("\n");
            }
        }
        result.append("\n");
        if (methodInfos.size() > 0) {
            for (MethodInfo methodInfo : methodInfos) {
                result.append(methodInfo.toString() + ",");
                result.append("\n");
            }
        }
        result.append("}");
        return result.toString();
    }
}

@@ -83,19 +83,67 @@
 va.util.
-Lis
+HashSet;%0Aimport java.util.List;%0Aimport java.util.Se
 t;%0A%0A/**%0A
@@ -319,24 +319,84 @@
 eName;%0A    %0A
+    private Set%3CModifier%3E modifiers = new HashSet%3C%3E();%0A    %0A
     private 
@@ -2450,24 +2450,201 @@
      %7D%0A    %7D
+%0A    %0A    public void addModifier(Modifier modifier) %7B%0A        this.modifiers.add(modifier);%0A    %7D%0A    %0A    public Set%3CModifier%3E getModifiers() %7B%0A        return modifiers;%0A    %7D
 %0A%0A    @Overr
@@ -2919,36 +2919,284 @@
         
-result.append(%22%5Cn%22);
+if (modifiers.size() %3E 0) %7B%0A            result.append(%22%5Cn%22);%0A            result.append(%22%7Bmodifiers: %22);%0A            for (Modifier modifier : modifiers) %7B%0A                result.append(modifier.toString() + %22, %22);%0A            %7D%0A            result.append(%22%7D%22);%0A        %7D
 %0A       
@@ -3220,32 +3220,65 @@
 s.size() %3E 0) %7B%0A
+            result.append(%22%5Cn%22);%0A
             for 
@@ -3451,37 +3451,8 @@
   %7D%0A
-        result.append(%22%5Cn%22);%0A
     
@@ -3485,32 +3485,65 @@
 s.size() %3E 0) %7B%0A
+            result.append(%22%5Cn%22);%0A
             for 
@@ -3740,37 +3740,8 @@
   %7D%0A
-        result.append(%22%5Cn%22);%0A
     
@@ -3766,32 +3766,65 @@
 s.size() %3E 0) %7B%0A
+            result.append(%22%5Cn%22);%0A
             for 

add modifiers information for ClassInfo