package com.artemis;

import com.artemis.utils.reflect.ClassReflection;


/**
 * Identifies components in artemis without having to use classes.
 * <p>
 * This class keeps a list of all generated component types for fast
 * retrieval.
 * </p>
 *
 * @author Arni Arent
 */
public class ComponentType {
	enum Taxonomy {
		BASIC, POOLED, PACKED;
	}

	
	/** The class type of the component type. */
	private final Class<? extends Component> type;
	/** True if component type is a {@link PackedComponent} */
	private final Taxonomy taxonomy;
	
	private final int index;

	/**
	 * <b>Do not call this constructor!</b> This method is only public so that
	 * we play nice with GWT.
	 * 
	 *  @@see {@link ComponentType#getTypeFor(Class)}
	 */
	public ComponentType(Class<? extends Component> type, int index) {
		
		this.index = index;
		this.type = type;
		if (ClassReflection.isAssignableFrom(PackedComponent.class, type)) {
			taxonomy = Taxonomy.PACKED;
		} else if (ClassReflection.isAssignableFrom(PooledComponent.class, type)) {
			taxonomy = Taxonomy.POOLED;
		} else {
			taxonomy = Taxonomy.BASIC;
		}
	}

	/**
	 * Get the component type's index.
	 *
	 * @return the component types index
	 */
	public int getIndex() {
		return index;
	}
	
	protected Taxonomy getTaxonomy() {
		return taxonomy;
	}
	
	public boolean isPackedComponent() {
		return taxonomy == Taxonomy.PACKED;
	}
	
	protected Class<? extends Component> getType() {
		return type;
	}
	
	@Override
	public String toString() {
		return "ComponentType["+ ClassReflection.getSimpleName(type) +"] ("+index+")";
	}
}

@@ -65,16 +65,62 @@
 ection;%0A
+import com.artemis.utils.reflect.Constructor;%0A
 %0A%0A/**%0A *
@@ -576,17 +576,64 @@
 xonomy;%0A
-%09
+%0A    boolean packedHasWorldConstructor = false;%0A
 %0A%09privat
@@ -1032,24 +1032,91 @@
 omy.PACKED;%0A
+            packedHasWorldConstructor = hasWorldConstructor(type);%0A
 %09%09%7D else if 
@@ -1257,20 +1257,472 @@
 IC;%0A%09%09%7D%0A
-
 %09%7D%0A%0A
+    private static boolean hasWorldConstructor(Class%3C? extends Component%3E type) %7B%0A        Constructor%5B%5D constructors = ClassReflection.getConstructors(type);%0A        for (int i = 0; constructors.length %3E i; i++) %7B%0A            @SuppressWarnings(%22rawtypes%22)%0A            Class%5B%5D types = constructors%5Bi%5D.getParameterTypes();%0A            if (types.length == 1 && types%5B0%5D == World.class)%0A                return true;%0A        %7D%0A%0A        return false;%0A    %7D%0A%0A
 %09/**%0A%09 *

Update ComponentType with packedHasWorldConstructor.