1 11 package org.eclipse.jdt.internal.debug.eval.ast.instructions; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.jdt.core.dom.Message; 19 import org.eclipse.jdt.debug.eval.ICompiledExpression; 20 21 public class InstructionSequence implements ICompiledExpression { 22 23 private List fInstructions; 24 28 private List fErrors; 29 private String fSnippet; 30 private CoreException fException; 31 32 public InstructionSequence(String snippet) { 33 fInstructions= new ArrayList (10); 34 fErrors= new ArrayList (); 35 fSnippet= snippet; 36 } 37 38 42 public CoreException getException() { 43 return fException; 44 } 45 46 49 public String getSnippet() { 50 return fSnippet; 51 } 52 53 57 public void addError(String error) { 58 fErrors.add(error); 59 } 60 61 64 public boolean hasErrors() { 65 return !fErrors.isEmpty(); 66 } 67 68 72 public Message[] getErrors() { 73 Message[] messages= new Message[fErrors.size()]; 74 int i= 0; 75 for (Iterator iter= fErrors.iterator(); iter.hasNext();) { 76 messages[i++]= new Message((String ) iter.next(), -1); 77 } 78 return messages; 79 } 80 81 84 public String [] getErrorMessages() { 85 return (String [])fErrors.toArray(new String [fErrors.size()]); 86 } 87 88 91 public Instruction[] getInstructions() { 92 int size= fInstructions.size(); 93 Instruction[] instructions= new Instruction[size]; 94 if (size > 0) { 95 fInstructions.toArray(instructions); 96 } 97 return instructions; 98 } 99 100 103 public Instruction getInstruction(int address) { 104 return (Instruction)fInstructions.get(address); 105 } 106 107 110 public void add(Instruction instruction) { 111 fInstructions.add(instruction); 112 } 113 114 public int indexOf(Instruction instruction) { 115 return fInstructions.indexOf(instruction); 116 } 117 118 121 public boolean isEmpty() { 122 return fInstructions.isEmpty(); 123 } 124 125 133 public void insert(Instruction instruction, int index) { 134 fInstructions.add(index, instruction); 135 } 136 137 public Instruction get(int address) { 138 return (Instruction)fInstructions.get(address); 139 } 140 141 public int getEnd() { 142 return fInstructions.size() - 1; 143 } 144 } 145 | Popular Tags |