Newer
Older
org.ntlab.reverseDebugger / org.ntlab.reverseDebugger / src / org / ntlab / reversedebugger / SeedAliasLabelProvider.java
package org.ntlab.reversedebugger;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.ntlab.debuggingControl.MethodCaller;

import com.sun.jdi.ClassNotLoadedException;
import com.sun.jdi.IncompatibleThreadStateException;
import com.sun.jdi.IntegerValue;
import com.sun.jdi.InvalidTypeException;
import com.sun.jdi.InvocationException;
import com.sun.jdi.ObjectReference;
import com.sun.jdi.StringReference;
import com.sun.jdi.Value;

public class SeedAliasLabelProvider extends LabelProvider implements ITableLabelProvider {

	@Override
	public String getColumnText(Object element, int columnIndex) {
		if (element instanceof MethodCaller) {
			MethodCaller mc = (MethodCaller)element;
			try {
				switch (columnIndex) {
				case 0:
					return ((StringReference)mc.callInstanceMethod("getObjectId")).value();
				case 1:
					return ((StringReference)mc.callInstanceMethod("getClassName")).value();
				case 2:
					return String.valueOf(((IntegerValue)mc.callInstanceMethod("getLineNo")).value());
				case 3:
					return ((StringReference)mc.callInstanceMethod("getStatementType")).value();
				case 4:
					return ((StringReference)mc.callInstanceMethod("getStatementSignature")).value();
				case 5:
					return getColumnTextOfOccurrenceExp(mc);
				}				
			} catch (InvalidTypeException | ClassNotLoadedException
					| InvocationException | IncompatibleThreadStateException e) {
				e.printStackTrace();
			}
		}
		return "テスト用テキスト" + columnIndex;
	}
	
	private String getColumnTextOfOccurrenceExp(MethodCaller mc) 
			throws InvalidTypeException, ClassNotLoadedException, InvocationException, IncompatibleThreadStateException {
		int occurrenceEXP = ((IntegerValue)mc.callInstanceMethod("getOccurrenceExp")).value();
		String statementType = ((StringReference)mc.callInstanceMethod("getStatementType")).value();
		switch (statementType) {
		case "FieldAccess":
		case "FieldUpdate":
			return (occurrenceEXP == 0) ? "container" : "field";
		case "ArrayAccess":
		case "ArrayUpdate":
			return (occurrenceEXP == 0) ? "arrayObject" : "arrayValue";
		case "ArrayCreate":
			return "return";
		case "MethodInvocation":
			if (occurrenceEXP <= 0) {
				return (occurrenceEXP == 0) ? "receiver" : "return";
			}
			final String[] ORDER_TEXT = {"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th"}; // 0-13に対応
			final String ARG = " arg";
			if (occurrenceEXP % 100 >= ORDER_TEXT.length) {
				return occurrenceEXP + ORDER_TEXT[occurrenceEXP % 10] + ARG; // 下2桁が14以上なら, 下1桁の数字に対応させる
			} else if (occurrenceEXP % 100 >= 0) {
				return occurrenceEXP + ORDER_TEXT[occurrenceEXP % 100] + ARG; // 下2桁が0以上13以下なら, 下2桁の数字に対応させる
			}
		}	
		return String.valueOf(occurrenceEXP);
	}
	
	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		return getImage(element);
	}
	
	@Override
	public Image getImage(Object element) {
		return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
	}
}