Permalink
Browse files

kellerkeller, look at line 30

  • Loading branch information...
1 parent 601c197 commit 7f04a0f24d3064b0c685c054e5e38b71e895e42a @Radvendii committed Mar 14, 2012
Showing with 9 additions and 5 deletions.
  1. +9 −5 StringHolder.java
View
@@ -7,7 +7,10 @@
* @since 29/3/12
*/
public class StringHolder
-{ //Standard declaration of the ArrayLists that will contain the individual strings,
+{
+ //methodIndicator should be a short string that would not appear at the beginning of a line in valid Java code
+ public static final methodIndicator = "}";
+ //Standard declaration of the ArrayLists that will contain the individual strings,
//divided by type, in the order that they were entered.
public ArrayList<String> orders;
public ArrayList<String> methods;
@@ -24,12 +27,12 @@ public StringHolder(){
* @param entry The string that is to be added to the file
*/
void add(String entry){
- entry.matches(" *import .*;");
+ entry.matches(" *import .*;"); //What is this for?
if (entry.matches(" *import .*;")){
imports.add(entry);
lastEntry = "import";
}
- else if (entry.matches("}.*")){
+ else if (entry.matches(methodIndicator + ".*")){
methods.add(entry.substring(1));
lastEntry = "method";
}
@@ -38,7 +41,7 @@ else if (entry.matches("}.*")){
lastEntry = "order";
}
/**
- * Returns the updated String that should be compiled
+ * Returns the updated String that should be compiled
* @return the new string that should be compiled into a file.
*/
String toFile(){
@@ -47,9 +50,10 @@ String toFile(){
base = base.concat(" public class " + RunCode.CLASS + "{\n");
base = combine(methods, base);
base = base.concat("public static void main(String[] args){\n");
- base = combine(orders.subList(0, (orders.size()-2)>0 ? orders.size()-2 : 0), base);
+ base = combine(orders.subList(0, (orders.size()-2)>0 ? orders.size()-2 : 0), base); //all of the orders except the last one (none if there is only one
//still get error about void methods
if (lastEntry.equals("order")) base = base.concat("System.out.println( "+orders.get(orders.size()-1).substring(0,orders.get(orders.size()-1).length()-1)+");\n");
+ //Print the last command with the last character (the ;) removed
base = base.concat("}\n}");
return base;
}

0 comments on commit 7f04a0f

Please sign in to comment.