2013-03-08 00:25:48 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2013-10-09 17:57:52 +00:00
|
|
|
*
|
2013-03-08 00:25:48 +00:00
|
|
|
* Contributors:
|
|
|
|
* cpw - implementation
|
|
|
|
*/
|
|
|
|
|
2014-09-23 05:01:24 +00:00
|
|
|
package net.minecraftforge.fml.common.discovery.asm;
|
2012-07-22 14:26:38 +00:00
|
|
|
|
2012-08-09 02:10:56 +00:00
|
|
|
import java.util.ArrayList;
|
2012-07-22 14:26:38 +00:00
|
|
|
import java.util.Map;
|
|
|
|
|
2014-09-23 05:01:24 +00:00
|
|
|
import net.minecraftforge.fml.common.discovery.asm.ASMModParser.AnnotationType;
|
|
|
|
|
2012-07-22 14:26:38 +00:00
|
|
|
import org.objectweb.asm.Type;
|
|
|
|
|
|
|
|
import com.google.common.base.Objects;
|
2012-08-09 02:10:56 +00:00
|
|
|
import com.google.common.collect.Lists;
|
2012-07-22 14:26:38 +00:00
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
|
|
public class ModAnnotation
|
|
|
|
{
|
2012-08-09 02:10:56 +00:00
|
|
|
public class EnumHolder
|
|
|
|
{
|
|
|
|
private String desc;
|
|
|
|
private String value;
|
|
|
|
|
|
|
|
public EnumHolder(String desc, String value)
|
|
|
|
{
|
|
|
|
this.desc = desc;
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-07-22 14:26:38 +00:00
|
|
|
AnnotationType type;
|
|
|
|
Type asmType;
|
|
|
|
String member;
|
|
|
|
Map<String,Object> values = Maps.newHashMap();
|
2012-08-09 02:10:56 +00:00
|
|
|
private ArrayList<Object> arrayList;
|
|
|
|
private String arrayName;
|
2012-07-22 14:26:38 +00:00
|
|
|
public ModAnnotation(AnnotationType type, Type asmType, String member)
|
|
|
|
{
|
|
|
|
this.type = type;
|
|
|
|
this.asmType = asmType;
|
|
|
|
this.member = member;
|
|
|
|
}
|
2013-10-09 17:57:52 +00:00
|
|
|
|
2012-08-09 02:10:56 +00:00
|
|
|
public ModAnnotation(AnnotationType type, Type asmType, ModAnnotation parent)
|
|
|
|
{
|
|
|
|
this.type = type;
|
|
|
|
this.asmType = asmType;
|
|
|
|
}
|
2012-07-22 14:26:38 +00:00
|
|
|
@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;
|
|
|
|
}
|
2012-08-09 02:10:56 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2013-10-09 17:57:52 +00:00
|
|
|
|
2012-08-09 02:10:56 +00:00
|
|
|
public void addEnumProperty(String key, String enumName, String value)
|
|
|
|
{
|
|
|
|
values.put(key, new EnumHolder(enumName, value));
|
|
|
|
}
|
2013-10-09 17:57:52 +00:00
|
|
|
|
2012-08-09 02:10:56 +00:00
|
|
|
public void endArray()
|
|
|
|
{
|
|
|
|
values.put(arrayName, arrayList);
|
|
|
|
arrayList = null;
|
|
|
|
}
|
|
|
|
public ModAnnotation addChildAnnotation(String name, String desc)
|
|
|
|
{
|
2013-10-09 17:57:52 +00:00
|
|
|
ModAnnotation child = new ModAnnotation(AnnotationType.SUBTYPE, Type.getType(desc), this);
|
|
|
|
if (arrayList != null)
|
|
|
|
{
|
|
|
|
arrayList.add(child.getValues());
|
|
|
|
}
|
|
|
|
return child;
|
2012-08-09 02:10:56 +00:00
|
|
|
}
|
2013-03-08 00:25:48 +00:00
|
|
|
}
|