package sds.classfile;

import java.io.IOException;

import static sds.util.AccessFlags.get;
import static sds.util.DescriptorParser.parse;
import static sds.util.Utf8ValueExtractor.extract;

/**
 * This adapter class is for info of class has member.
 * @author inagaki
 */
public class MemberInfo implements Info {
	private String[] declaration;
	private Attributes attr;

	/**
	 * returns access flag of member.
	 * @return access flag
	 */
	public String getAccessFlags() {
		return declaration[0];
	}

	/**
	 * returns member name.
	 * @return member name
	 */
	public String getName() {
		return declaration[1];
	}

	/**
	 * returns member descriptor.
	 * @return member descriptor
	 */
	public String getDescriptor() {
		return declaration[2];
	}

	/**
	 * returns attributes of member.
	 * @return attributes
	 */
	public Attributes getAttr() {
		return attr;
	}

	/**
	 * returns type of member.
	 * @return type
	 */
	public String getType() {
		if(declaration[2].contains("(")) {
			return "method";
		}
		return "field";
	}

	/**
	 * sets attributes of member.
	 * @param attr attributes
	 */
	public void setAttr(Attributes attr) {
		this.attr = attr;
	}

	@Override
	public void read(ClassFileStream data, ConstantPool pool) throws IOException {
		int acc = data.readShort();
		int nameIndex = data.readShort();
		int descIndex = data.readShort();
		this.declaration = new String[3];
		declaration[1] = extract(pool.get(nameIndex - 1), pool);
		declaration[2] = parse(extract(pool.get(descIndex - 1), pool));
		declaration[0] = get(acc, getType());
	}
}
@@ -1557,10 +1557,112 @@
 e());%0A%09%7D
+%0A%0A%09@Override%0A%09public String toString() %7B%0A%09%09return declaration%5B0%5D + declaration%5B1%5D + declaration%5B2%5D;%0A%09%7D
 %0A%7D

implement toString method.