View Javadoc
1 package jrre.instructionset.typecasting; 2 3 import jrre.instructionset.*; 4 5 import jrre.Stack; 6 import jrre.StackFrame; 7 import jrre.MethodArea; 8 import jrre.types.*; 9 import jrre.api.java.lang.reflect.DescriptorDecoder; 10 import jrre.classloader.classfile.pool_entries.*; 11 12 public class CheckCast extends Instruction{ 13 14 private int operandOne; 15 private int operandTwo; 16 17 public CheckCast(int operandOne,int operandTwo){ 18 //System.out.println("\n\n\nCheckCast\n\n\n"); 19 this.operandOne = operandOne; 20 this.operandTwo = operandTwo; 21 22 name = "checkcast"; 23 length = 2; 24 description = "foo"; 25 } 26 27 public void execute(){ 28 29 int classIndex = (operandOne << 8) | operandTwo; 30 31 //System.out.println("\n\n\nCheckCast\n\n\n"); 32 33 // Get this class. 34 jrre.api.java.lang.Class thisClass = Stack.getClassContainingMethod(); 35 36 CPClass cpClass = (CPClass)thisClass.getSymbol(classIndex); 37 CPUTF8 cpClassUTF8 = (CPUTF8)thisClass.getSymbol(cpClass.getNameIndex()); 38 39 jrre.api.java.lang.Class classToCastTo = MethodArea.getClass(cpClassUTF8.getValue()); 40 if(classToCastTo == null) 41 return; 42 43 jrre.types.ReferenceType objectRef = (jrre.types.ReferenceType)Stack.popOperand(); 44 45 jrre.api.java.lang.Class toCheck = objectRef.getValue().getClassData(); 46 47 if(classToCastTo.getFullyQualifiedName().equals(toCheck.getFullyQualifiedName())) { 48 Stack.pushOperand(objectRef); 49 } 50 else{ 51 //Implement esception handling 52 //throw class cast error 53 System.out.println("Class Cast Exception"); 54 } 55 56 } 57 58 public String toString(){ 59 return name + " " + operandOne + " " + operandTwo; 60 } 61 }

This page was automatically generated by Maven