Changeset 162 for trunk/src/org/expeditee/actions/Simple.java
- Timestamp:
- 07/28/08 15:08:13 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Simple.java
r161 r162 162 162 do { 163 163 next = FrameIO.LoadNext(next); 164 } while (next != null && next.isTestFrame());164 } while (next != null && !next.isTestFrame()); 165 165 FrameUtils.DisplayFrame(next, true); 166 166 } … … 170 170 do { 171 171 prev = FrameIO.LoadPrevious(prev); 172 } while (prev != null && prev.isTestFrame());172 } while (prev != null && !prev.isTestFrame()); 173 173 174 174 FrameUtils.DisplayFrame(prev, true); … … 783 783 // Check for set statements 784 784 } else if (tokens[0].startsWith("calculatestring")) { 785 assertMinParametreCount(tokens, 2); 786 String toCalculate = context.getPrimitives().getStringValue(tokens[1]); 785 assertMinParametreCount(tokens, 1); 786 String toCalculate = context.getPrimitives().getStringValue( 787 tokens[1]); 787 788 boolean result = true; 789 String error = ""; 788 790 ExpediteeJEP myParser = new ExpediteeJEP(); 789 // Add the variables in the system791 // Add the variables in the system 790 792 context.getPrimitives().addToParser(myParser); 791 793 Node equation = myParser.parseExpression(toCalculate); 792 //TODO get the answer 793 794 // TODO get the answer 795 if (equation == null) { 796 result = false; 797 error = myParser.getErrorInfo().replace("\n", ""); 798 } else { 799 double value = myParser.getValue(); 800 if (myParser.hasError()) { 801 result = false; 802 error = myParser.getErrorInfo().replace("\n", ""); 803 } else { 804 // Add a new variable if its an assignment statement 805 String newVar = myParser.getNewVariable(); 806 if (newVar.length() > 0) { 807 try { 808 context.getPrimitives().setValue(newVar, 809 new SReal(value)); 810 } catch (IncorrectTypeException e) { 811 result = false; 812 error = e.getMessage(); 813 } 814 } 815 if (tokens.length > 2) { 816 context.getPrimitives().setValue(tokens[2], 817 new SReal(value)); 818 } 819 } 820 } 821 // Set the result variable if there is one 822 if (tokens.length > 3) { 823 context.getPrimitives().setValue(tokens[3], 824 new SBoolean(result)); 825 // Set the result variable if there is one 826 if (tokens.length > 4 && !result) { 827 context.getPrimitives().setValue(tokens[4], error); 828 } 829 } 794 830 } else if (tokens[0].startsWith("calculateitem")) { 795 831 assertMinParametreCount(tokens, 1); 796 832 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 797 Item item = (Item)context.getPointers().getVariable(tokens[1]).getValue(); 833 Item item = (Item) context.getPointers().getVariable(tokens[1]) 834 .getValue(); 798 835 Frame frame = null; 799 if (tokens.length > 2){836 if (tokens.length > 2) { 800 837 assertVariableType(tokens[2], 2, SPointer.framePrefix); 801 frame = (Frame)context.getPointers().getVariable(tokens[2]).getValue(); 838 frame = (Frame) context.getPointers().getVariable(tokens[2]) 839 .getValue(); 802 840 } 803 841 Misc.calculate(frame, item); 804 } else if (tokens[0].startsWith("issearchpatternvalid")) {842 } else if (tokens[0].startsWith("issearchpatternvalid")) { 805 843 assertExactParametreCount(tokens, 2); 806 844 boolean result = true; … … 885 923 String pattern = context.getPrimitives().getStringValue( 886 924 tokens[2]); 887 SearchAgent searchAgent = new SearchFrameset(); 925 long firstFrame = 1; 926 long maxFrame = Long.MAX_VALUE; 927 if(tokens.length > 7){ 928 firstFrame = context.getPrimitives().getIntegerValue(tokens[7]); 929 if(tokens.length > 8){ 930 maxFrame = context.getPrimitives().getIntegerValue(tokens[8]); 931 } 932 } 933 934 SearchAgent searchAgent = new SearchFrameset(firstFrame, maxFrame); 888 935 searchAgent.initialise(null, null, frameset, resultsFrameset, 889 936 replacementString, pattern); … … 1187 1234 .getStringValue(tokens[1]), context.getPrimitives() 1188 1235 .getStringValue(tokens[2])); 1236 } else if (tokens[0].equals("assertequalframes")) { 1237 assertExactParametreCount(tokens, 2); 1238 assertVariableType(tokens[1], 1, SPointer.framePrefix); 1239 assertVariableType(tokens[2], 2, SPointer.framePrefix); 1240 Frame frame1 = (Frame) context.getPointers().getVariable( 1241 tokens[1]).getValue(); 1242 Frame frame2 = (Frame) context.getPointers().getVariable( 1243 tokens[2]).getValue(); 1244 // Check that all the items on the frame are the same 1245 List<Item> items1 = frame1.getVisibleItems(); 1246 List<Item> items2 = frame2.getVisibleItems(); 1247 if (items1.size() != items2.size()) { 1248 throw new UnitTestFailedException(items1.size() + " items", 1249 items2.size() + " items"); 1250 } else { 1251 for (int i = 0; i < items1.size(); i++) { 1252 Item i1 = items1.get(i); 1253 Item i2 = items2.get(i); 1254 String s1 = i1.getText(); 1255 String s2 = i2.getText(); 1256 if (!s1.equals(s2)) { 1257 throw new UnitTestFailedException(s1, s2); 1258 } 1259 } 1260 } 1189 1261 } else if (tokens[0].equals("assertdefined")) { 1190 1262 assertExactParametreCount(tokens, 1); … … 1193 1265 "not defined"); 1194 1266 } 1267 } else { 1268 throw new RuntimeException("Invalid Assert statement"); 1195 1269 } 1196 1270 } else if (tokens[0].startsWith("goto")) { … … 1957 2031 freshCopy.setFrameset(destinationFrameset); 1958 2032 }// Otherwise add it to the end of this frameset 1959 freshCopy.setFrameNumber(FrameIO.getLastNumber(freshCopy 1960 .getFramesetName()) + 1); 1961 context.getPointers().setObject(tokens[2], freshCopy); 1962 String fileContents = FrameIO.ForceSaveFrame(freshCopy); 2033 int nextNumber = FrameIO.getLastNumber(freshCopy.getFramesetName()) + 1; 2034 // if the frameset doesnt already exist then create it 2035 if (nextNumber <= 0) { 2036 try { 2037 FrameIO.CreateFrameset(freshCopy.getFramesetName(), 2038 frameToCopy.path); 2039 nextNumber = 1; 2040 } catch (Exception e) { 2041 } 2042 } 2043 boolean success = false; 2044 if (nextNumber > 0) { 2045 freshCopy.setFrameNumber(nextNumber); 2046 context.getPointers().setObject(tokens[2], freshCopy); 2047 String fileContents = FrameIO.ForceSaveFrame(freshCopy); 2048 success = fileContents != null; 2049 } 1963 2050 FrameIO.ResumeCache(); 1964 // Need to add the new copy to the cache in case it is edited by 1965 // other simple statements 1966 FrameIO.addToCache(freshCopy); 1967 boolean success = fileContents != null; 2051 if (success) { 2052 // Need to add the new copy to the cache in case it is edited by 2053 // other simple statements 2054 FrameIO.addToCache(freshCopy); 2055 } 1968 2056 if (!success && _verbose) 1969 2057 MessageBay.warningMessage("Error copying "
Note:
See TracChangeset
for help on using the changeset viewer.