private void throwExceptionForNoStackElement(int size, ClassNode targetType, boolean coerce) { if (size > 0) return; StringBuilder sb = new StringBuilder(); sb.append("Internal compiler error while compiling ") .append(controller.getSourceUnit().getName()) .append("\n"); MethodNode methodNode = controller.getMethodNode(); if (methodNode != null) { sb.append("Method: "); sb.append(methodNode); sb.append("\n"); } ConstructorNode constructorNode = controller.getConstructorNode(); if (constructorNode != null) { sb.append("Constructor: "); sb.append(methodNode); sb.append("\n"); } sb.append("Line ").append(controller.getLineNumber()).append(","); sb.append(" expecting ") .append(coerce ? "coercion" : "casting") .append(" to ") .append(targetType.toString(false)); sb.append(" but operand stack is empty"); throw new ArrayIndexOutOfBoundsException(sb.toString()); }
public ClassNode getTopOperand() { int size = stack.size(); try { if (size == 0) throw new ArrayIndexOutOfBoundsException("size==0"); } catch (ArrayIndexOutOfBoundsException ai) { System.err.println("index problem in " + controller.getSourceUnit().getName()); throw ai; } return stack.get(size - 1); }
/** replace top level element with new element of given type */ public void replace(ClassNode type) { int size = stack.size(); try { if (size == 0) throw new ArrayIndexOutOfBoundsException("size==0"); } catch (ArrayIndexOutOfBoundsException ai) { System.err.println("index problem in " + controller.getSourceUnit().getName()); throw ai; } stack.set(size - 1, type); }