package me.nallar.javatransformer.api;

import me.nallar.javatransformer.internal.util.JVMUtil;

import java.util.*;
import java.util.function.*;

public interface ClassInfo extends ClassMember {
	default void add(ClassMember member) {
		if (member instanceof MethodInfo)
			add((MethodInfo) member);
		else if (member instanceof FieldInfo)
			add((FieldInfo) member);
		else
			throw new TransformationException("Can't add member of type " + member.getClass().getCanonicalName() + " to " + this);
	}

	void add(MethodInfo method);

	void add(FieldInfo field);

	default void remove(ClassMember member) {
		if (member instanceof MethodInfo)
			remove((MethodInfo) member);
		else if (member instanceof FieldInfo)
			remove((FieldInfo) member);
		else
			throw new TransformationException("Can't remove member of type " + member.getClass().getCanonicalName() + " to " + this);
	}

	void remove(MethodInfo method);

	void remove(FieldInfo field);

	Type getSuperType();

	List<Type> getInterfaceTypes();

	default MethodInfo get(MethodInfo like) {
		for (MethodInfo methodInfo : getMethods()) {
			if (like.similar(methodInfo))
				return methodInfo;
		}

		return null;
	}

	default FieldInfo get(FieldInfo like) {
		for (FieldInfo fieldInfo : getFields()) {
			if (like.similar(fieldInfo))
				return fieldInfo;
		}

		return null;
	}

	default Type getType() {
		return Type.of(getName());
	}

	List<MethodInfo> getMethods();

	List<FieldInfo> getFields();

	List<ClassMember> getMembers();

	default void accessFlags(Function<AccessFlags, AccessFlags> c) {
		setAccessFlags(c.apply(getAccessFlags()));
	}
}

@@ -37,65 +37,8 @@
 i;%0A%0A
-import me.nallar.javatransformer.internal.util.JVMUtil;%0A%0A
 impo
@@ -935,24 +935,351 @@
 ceTypes();%0A%0A
+%09default ClassMember get(ClassMember member) %7B%0A%09%09if (member instanceof MethodInfo)%0A%09%09%09return get((MethodInfo) member);%0A%09%09else if (member instanceof FieldInfo)%0A%09%09%09return get((FieldInfo) member);%0A%09%09else%0A%09%09%09throw new TransformationException(%22Can't get member of type %22 + member.getClass().getCanonicalName() + %22 in %22 + this);%0A%09%7D%0A%0A
 %09default Met

Add get(ClassMember)