package org.sahagin.runlib.additionaltestdoc;

import org.sahagin.runlib.external.CaptureStyle;

public class AdditionalMethodTestDoc {
    private String classQualifiedName;
    private String simpleName;
    // null means not overloaded
    private String argClassesStr = null;
    private int variableLengthArgIndex = -1;
    private String testDoc;
    // TODO should not allow stepInCapture for AdditionalTestDoc
    private CaptureStyle captureStyle = CaptureStyle.getDefault();

    public String getClassQualifiedName() {
        return classQualifiedName;
    }

    public void setClassQualifiedName(String classQualifiedName) {
        this.classQualifiedName = classQualifiedName;
    }

    public String getSimpleName() {
        return simpleName;
    }

    public void setSimpleName(String simpleName) {
        this.simpleName = simpleName;
    }

    public String getQualifiedName() {
        if (classQualifiedName == null || simpleName == null) {
            return simpleName;
        } else {
            return classQualifiedName + "." + simpleName;
        }
    }

    public boolean isOverloaded() {
        return argClassesStr != null;
    }

    public String getArgClassesStr() {
        if (!isOverloaded()) {
            throw new IllegalStateException(
                    "not overloaded method, and argument information is not set");
        }
        return argClassesStr;
    }

    public void setNotOverload() {
        argClassesStr = null;
    }

    public void setOverload(String argClassesStr) {
        if (argClassesStr == null) {
            throw new NullPointerException();
        }
        this.argClassesStr = argClassesStr;
    }

    public boolean hasVariableLengthArg() {
        return variableLengthArgIndex != -1;
    }

    public int getVariableLengthArgIndex() {
        return variableLengthArgIndex;
    }

    public void setVariableLengthArgIndex(int variableLengthArgIndex) {
        this.variableLengthArgIndex = variableLengthArgIndex;
    }

    public String getTestDoc() {
        return testDoc;
    }

    public void setTestDoc(String testDoc) {
        this.testDoc = testDoc;
    }

    public CaptureStyle getCaptureStyle() {
        return captureStyle;
    }

    public void setCaptureStyle(CaptureStyle captureStyle) {
        this.captureStyle = captureStyle;
    }

    /*
    public static String generateMethodKey(AdditionalMethodTestDoc testDoc) {
        if (testDoc == null) {
            throw new NullPointerException();
        }
        if (testDoc.isOverloaded()) {
            return generateMethodKey(testDoc.getClassQualifiedName(),
                    testDoc.getSimpleName(), testDoc.getArgClassQualifiedNames());
        } else {
            return generateMethodKey(
                    testDoc.getClassQualifiedName(), testDoc.getSimpleName());
        }
    }

    public static String generateMethodKey(String classQualifiedName,
            String methodSimpleName, String argClassesStr) {
        if (argClassesStr == null) {
            throw new NullPointerException();
        }
        // TODO should use the same rule as getKey method in jdt
        return "_Additional_" + classQualifiedName + "." + methodSimpleName + "_" + argClassesStr;
    }

    // TODO this method should be removed
    public static boolean isAdditionalMethodKey(String methodKey) {
        return methodKey != null && methodKey.startsWith("_Additional_");
    }

    public static String generateMethodKey(String classQualifiedName,
            String methodSimpleName, List<String> argClassQualifiedNames) {
        if (argClassQualifiedNames == null) {
            throw new NullPointerException();
        }
        // TODO should use the same rule as getKey method in jdt
        return "_Additional_" + classQualifiedName + "."
        + methodSimpleName + "_" + argClassQualifiedNamesToStr(argClassQualifiedNames);
    }

    public static String generateMethodKey(String classQualifiedName, String methodSimpleName) {
        // TODO should use the same rule as getKey method in jdt
        return "_Additional_" + classQualifiedName + "." + methodSimpleName;
    }

    // convert to argClassQualifiedNames
    // "void" means no argument, "String" means java.lang.String,
    // "Object" means java.lang.Object
    private static List<String> argClassesStrToList(String argClassesStr) {
        if (argClassesStr == null) {
            throw new NullPointerException();
        }
        String trimmed = argClassesStr.trim();
        if (trimmed.equals("") || trimmed.equals("void")) {
            return new ArrayList<String>(0);
        }

        String[] splitted = trimmed.split(",");
        List<String> result = new ArrayList<String>(splitted.length);
        for (String argClassStr : splitted) {
            if (StringUtils.equals(argClassStr, String.class.getSimpleName())) {
                result.add(String.class.getCanonicalName());
            } else if (StringUtils.equals(argClassesStr, Object.class.getSimpleName())) {
                result.add(Object.class.getCanonicalName());
            } else {
                result.add(argClassStr);
            }
        }
        return result;
    }

    private static String argClassQualifiedNamesToStr(List<String> argClassQualifiedNames) {
        if (argClassQualifiedNames == null) {
            throw new NullPointerException();
        }
        if (argClassQualifiedNames.size() == 0) {
            return "void";
        }
        String result = "";
        for (int i = 0; i < argClassQualifiedNames.size(); i++) {
            if (i != 0) {
                result = result + ",";
            }
            if (StringUtils.equals(argClassQualifiedNames.get(i), String.class.getCanonicalName())) {
                result = result + String.class.getSimpleName();
            } else if (StringUtils.equals(argClassQualifiedNames.get(i), Object.class.getCanonicalName())) {
                result = result + Object.class.getSimpleName();
            } else {
                result = result + argClassQualifiedNames.get(i);
            }
        }
        return result;
    }*/

}

@@ -2349,3804 +2349,6 @@
  %7D%0A%0A
-    /*%0A    public static String generateMethodKey(AdditionalMethodTestDoc testDoc) %7B%0A        if (testDoc == null) %7B%0A            throw new NullPointerException();%0A        %7D%0A        if (testDoc.isOverloaded()) %7B%0A            return generateMethodKey(testDoc.getClassQualifiedName(),%0A                    testDoc.getSimpleName(), testDoc.getArgClassQualifiedNames());%0A        %7D else %7B%0A            return generateMethodKey(%0A                    testDoc.getClassQualifiedName(), testDoc.getSimpleName());%0A        %7D%0A    %7D%0A%0A    public static String generateMethodKey(String classQualifiedName,%0A            String methodSimpleName, String argClassesStr) %7B%0A        if (argClassesStr == null) %7B%0A            throw new NullPointerException();%0A        %7D%0A        // TODO should use the same rule as getKey method in jdt%0A        return %22_Additional_%22 + classQualifiedName + %22.%22 + methodSimpleName + %22_%22 + argClassesStr;%0A    %7D%0A%0A    // TODO this method should be removed%0A    public static boolean isAdditionalMethodKey(String methodKey) %7B%0A        return methodKey != null && methodKey.startsWith(%22_Additional_%22);%0A    %7D%0A%0A    public static String generateMethodKey(String classQualifiedName,%0A            String methodSimpleName, List%3CString%3E argClassQualifiedNames) %7B%0A        if (argClassQualifiedNames == null) %7B%0A            throw new NullPointerException();%0A        %7D%0A        // TODO should use the same rule as getKey method in jdt%0A        return %22_Additional_%22 + classQualifiedName + %22.%22%0A        + methodSimpleName + %22_%22 + argClassQualifiedNamesToStr(argClassQualifiedNames);%0A    %7D%0A%0A    public static String generateMethodKey(String classQualifiedName, String methodSimpleName) %7B%0A        // TODO should use the same rule as getKey method in jdt%0A        return %22_Additional_%22 + classQualifiedName + %22.%22 + methodSimpleName;%0A    %7D%0A%0A    // convert to argClassQualifiedNames%0A    // %22void%22 means no argument, %22String%22 means java.lang.String,%0A    // %22Object%22 means java.lang.Object%0A    private static List%3CString%3E argClassesStrToList(String argClassesStr) %7B%0A        if (argClassesStr == null) %7B%0A            throw new NullPointerException();%0A        %7D%0A        String trimmed = argClassesStr.trim();%0A        if (trimmed.equals(%22%22) %7C%7C trimmed.equals(%22void%22)) %7B%0A            return new ArrayList%3CString%3E(0);%0A        %7D%0A%0A        String%5B%5D splitted = trimmed.split(%22,%22);%0A        List%3CString%3E result = new ArrayList%3CString%3E(splitted.length);%0A        for (String argClassStr : splitted) %7B%0A            if (StringUtils.equals(argClassStr, String.class.getSimpleName())) %7B%0A                result.add(String.class.getCanonicalName());%0A            %7D else if (StringUtils.equals(argClassesStr, Object.class.getSimpleName())) %7B%0A                result.add(Object.class.getCanonicalName());%0A            %7D else %7B%0A                result.add(argClassStr);%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A    private static String argClassQualifiedNamesToStr(List%3CString%3E argClassQualifiedNames) %7B%0A        if (argClassQualifiedNames == null) %7B%0A            throw new NullPointerException();%0A        %7D%0A        if (argClassQualifiedNames.size() == 0) %7B%0A            return %22void%22;%0A        %7D%0A        String result = %22%22;%0A        for (int i = 0; i %3C argClassQualifiedNames.size(); i++) %7B%0A            if (i != 0) %7B%0A                result = result + %22,%22;%0A            %7D%0A            if (StringUtils.equals(argClassQualifiedNames.get(i), String.class.getCanonicalName())) %7B%0A                result = result + String.class.getSimpleName();%0A            %7D else if (StringUtils.equals(argClassQualifiedNames.get(i), Object.class.getCanonicalName())) %7B%0A                result = result + Object.class.getSimpleName();%0A            %7D else %7B%0A                result = result + argClassQualifiedNames.get(i);%0A            %7D%0A        %7D%0A        return result;%0A    %7D*/%0A%0A
 %7D%0A

Remove commented out method