/*
 * Forge Mod Loader
 * Copyright (c) 2012-2013 cpw.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 *
 * Contributors:
 *     cpw - implementation
 */

package net.minecraftforge.fml.common.discovery.asm;

import java.util.ArrayList;
import java.util.Map;

import net.minecraftforge.fml.common.discovery.asm.ASMModParser.AnnotationType;

import org.objectweb.asm.Type;

import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

public class ModAnnotation
{
    public class EnumHolder
    {
        private String desc;
        private String value;

        public EnumHolder(String desc, String value)
        {
            this.desc = desc;
            this.value = value;
        }

    }
    AnnotationType type;
    Type asmType;
    String member;
    Map<String,Object> values = Maps.newHashMap();
    private ArrayList<Object> arrayList;
    private String arrayName;
    public ModAnnotation(AnnotationType type, Type asmType, String member)
    {
        this.type = type;
        this.asmType = asmType;
        this.member = member;
    }

    public ModAnnotation(AnnotationType type, Type asmType, ModAnnotation parent)
    {
        this.type = type;
        this.asmType = asmType;
    }
    @Override
    public String toString()
    {
        return Objects.toStringHelper("Annotation")
                .add("type",type)
                .add("name",asmType.getClassName())
                .add("member",member)
                .add("values", values)
                .toString();
    }
    public AnnotationType getType()
    {
        return type;
    }
    public Type getASMType()
    {
        return asmType;
    }
    public String getMember()
    {
        return member;
    }
    public Map<String, Object> getValues()
    {
        return values;
    }
    public void addArray(String name)
    {
        this.arrayList = Lists.newArrayList();
        this.arrayName = name;
    }
    public void addProperty(String key, Object value)
    {
        if (this.arrayList != null)
        {
            arrayList.add(value);
        }
        else
        {
            values.put(key, value);
        }
    }

    public void addEnumProperty(String key, String enumName, String value)
    {
        values.put(key, new EnumHolder(enumName, value));
    }

    public void endArray()
    {
        values.put(arrayName, arrayList);
        arrayList = null;
    }
    public ModAnnotation addChildAnnotation(String name, String desc)
    {
        ModAnnotation child = new ModAnnotation(AnnotationType.SUBTYPE, Type.getType(desc), this);
        if (arrayList != null)
        {
            arrayList.add(child.getValues());
        }
        return child;
    }
}

@@ -3,24 +3,23 @@
 %0A * 
-Forge Mod Loader
+Minecraft Forge
 %0A * 
@@ -39,109 +39,91 @@
  201
-2-2013 cpw.%0A * All rights reserved. This program and the accompanying materials%0A * are made available
+6.%0A *%0A * This library is free software; you can redistribute it and/or%0A * modify it
  und
@@ -157,14 +157,25 @@
 ser 
+General 
 Public
+%0A *
  Lic
@@ -183,177 +183,563 @@
 nse 
-v2.1%0A * which accompanies this distribution, and is available at%0A * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html%0A *%0A * Contributors:%0A *     cpw - implementation
+as published by the Free Software Foundation version 2.1%0A * of the License.%0A *%0A * This library is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A * Lesser General Public License for more details.%0A *%0A * You should have received a copy of the GNU Lesser General Public%0A * License along with this library; if not, write to the Free Software%0A * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 %0A */
@@ -1152,24 +1152,30 @@
     private 
+final 
 String desc;
@@ -1187,24 +1187,30 @@
     private 
+final 
 String value
@@ -1344,24 +1344,181 @@
 %0A        %7D%0A%0A
+        public String getDesc()%0A        %7B%0A            return desc;%0A        %7D%0A%0A        public String getValue()%0A        %7B%0A            return value;%0A        %7D%0A
     %7D%0A    An
@@ -3038,34 +3038,35 @@
   %7B%0A        
-values.put
+addProperty
 (key, new En
@@ -3394,67 +3394,26 @@
     
-if (arrayList != null)%0A        %7B%0A            arrayList.add(
+addProperty(name, 
 chil
@@ -3428,26 +3428,16 @@
 ues());%0A
-        %7D%0A
         

Make ASMDataTable more useful: (#2911)