Skip to content

Commit 5bdcae4

Browse files
committed
Added the untracked files mentioned in the previous commit message.
Changes to be committed: new file: drjava/lib/jline-2.14.4.jar new file: drjava/lib/junit-4.12.jar new file: drjava/lib/scala-parser-combinators_2.12-1.0.6.jar new file: drjava/lib/scala-swing_2.12-2.0.0.jar new file: drjava/lib/scala-xml_2.12-1.0.6.jar new file: drjava/lib/scalap-2.12.3.jar new file: drjava/src/edu/rice/cs/drjava/config/ArrayListOption.java new file: drjava/src/edu/rice/cs/drjava/config/ArrayListOptionTest.java new file: drjava/src/edu/rice/cs/drjava/ui/config/ArrayListAbsRelFileOptionComponent.java new file: drjava/src/edu/rice/cs/drjava/ui/config/ArrayListClassnameOptionComponent.java new file: drjava/src/edu/rice/cs/drjava/ui/config/ArrayListFileOptionComponent.java new file: drjava/src/edu/rice/cs/drjava/ui/config/ArrayListFileOptionComponentTest.java new file: drjava/src/edu/rice/cs/drjava/ui/config/ArrayListKeyStrokeOptionComponent.java new file: drjava/src/edu/rice/cs/drjava/ui/config/ArrayListKeyStrokeOptionComponentTest.java new file: drjava/src/edu/rice/cs/drjava/ui/config/ArrayListOptionComponent.java new file: drjava/src/edu/rice/cs/drjava/ui/config/ArrayListStringOptionComponent.java
1 parent 0498c90 commit 5bdcae4

16 files changed

+1846
-0
lines changed

drjava/lib/jline-2.14.4.jar

262 KB
Binary file not shown.

drjava/lib/junit-4.12.jar

308 KB
Binary file not shown.
207 KB
Binary file not shown.
720 KB
Binary file not shown.
535 KB
Binary file not shown.

drjava/lib/scalap-2.12.3.jar

497 KB
Binary file not shown.
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/*BEGIN_COPYRIGHT_BLOCK
2+
*
3+
* Copyright (c) 2001-2017, JavaPLT group at Rice University ([email protected]). All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6+
* following conditions are met:
7+
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8+
* disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10+
* following disclaimer in the documentation and/or other materials provided with the distribution.
11+
* * Neither the names of DrJava, DrScala, the JavaPLT group, Rice University, nor the names of its contributors may
12+
* be used to endorse or promote products derived from this software without specific prior written permission.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
15+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
20+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21+
*
22+
* This software is Open Source Initiative approved Open Source Software.
23+
* Open Source Initative Approved is a trademark of the Open Source Initiative.
24+
*
25+
* This file is part of DrScala. Download the current version of this project from http://www.drscala.org/.
26+
*
27+
* END_COPYRIGHT_BLOCK*/
28+
29+
package edu.rice.cs.drjava.config;
30+
31+
import java.util.ArrayList;
32+
import java.io.StreamTokenizer;
33+
import java.io.StringReader;
34+
import java.io.IOException;
35+
36+
/** Abstract class defining behavior shared by all configuration options with values of type ArrayList<T>.
37+
* ArrayListOption<String> now allows empty strings, i.e. "[,]" is a vector of two empty strings.
38+
* "[]" will be interpreted as a vector of one empty string, and "" is an empty vector.
39+
* @version $Id: ArrayListOption.java 5594 2012-06-21 11:23:40Z rcartwright $
40+
*/
41+
public class ArrayListOption<T> extends Option<ArrayList<T>> {
42+
43+
protected ParseStrategy<T> parser;
44+
protected FormatStrategy<T> formatter;
45+
public final String header;
46+
public final char delim;
47+
public final String footer;
48+
49+
/** @param key The name of this option.
50+
* @param parser the parsing strategy for an element in this option
51+
* @param formatter the formatting strategy for an element in this option
52+
*/
53+
private ArrayListOption(String key, ParseStrategy<T> parser, FormatStrategy<T> formatter,
54+
String header, char delim, String footer, ArrayList<T> def) {
55+
super(key,def);
56+
this.parser = parser;
57+
this.formatter = formatter;
58+
this.header = header;
59+
this.delim = delim;
60+
this.footer = footer;
61+
}
62+
63+
public ArrayListOption(String key, Option<T> strategy, String header,
64+
char delim, String footer, ArrayList<T> def) {
65+
this(key, strategy, strategy, header, delim, footer,def);
66+
}
67+
68+
/** Defaults the "header", "footer", and "delim" fields
69+
* to open bracket, close bracket, and comma, repsectively.
70+
* @param key The name of this option.
71+
* @param option The object that knows how to parse and format
72+
* an element of type T.
73+
*/
74+
public ArrayListOption(String key, Option<T> option, ArrayList<T> def) {
75+
this(key,option,option,"[",',',"]",def);
76+
}
77+
78+
/** @param s The String to be parsed.
79+
* @return An instance of ArrayList<T> represented by "s".
80+
* @exception IllegalArgumentException if "s" is not formatted
81+
* according to the method ArrayList<T>.toString().
82+
*/
83+
public ArrayList<T> parse(String s) {
84+
s= s.trim();
85+
ArrayList<T> res = new ArrayList<T>();
86+
if (s.equals("")) { return res; }
87+
88+
int startFirstElement = header.length();
89+
int startFooter = s.length() - footer.length();
90+
91+
if (!s.startsWith(header) && !s.endsWith(footer)) {
92+
// not formatted as a vector, try parsing this as a singleton vector
93+
res.add(parser.parse(s));
94+
return res;
95+
}
96+
if (startFooter < startFirstElement || !s.startsWith(header) || ! s.endsWith(footer)) {
97+
throw new OptionParseException(name, s, "Value must start with " + header + " and end " + "with " + footer +
98+
" to be a valid vector.");
99+
}
100+
s = s.substring(startFirstElement, startFooter);
101+
if (s.equals("")) {
102+
res.add(parser.parse(""));
103+
return res;
104+
}
105+
106+
// String d = String.valueOf(delim);
107+
108+
StreamTokenizer st = new StreamTokenizer(new StringReader(s));
109+
st.resetSyntax();
110+
st.wordChars(0,255);
111+
st.ordinaryChar('|');
112+
st.ordinaryChar(delim);
113+
try {
114+
int tok = st.nextToken();
115+
int prevtok = -4;
116+
StringBuilder sb = new StringBuilder();
117+
while (tok!=StreamTokenizer.TT_EOF) {
118+
if (tok=='|') {
119+
if (prevtok=='|') {
120+
// second pipe in a row, append a pipe to string builder
121+
sb.append('|');
122+
prevtok = tok = -4;
123+
}
124+
else {
125+
// first pipe, next token decides
126+
prevtok = tok;
127+
}
128+
}
129+
else if (tok==delim) {
130+
if (prevtok=='|') {
131+
// pipe followed by delimiter --> escaped delimiter
132+
// append delimiter to string builder
133+
sb.append(delim);
134+
prevtok = tok = -4;
135+
}
136+
else {
137+
// no preceding pipe --> real delimiter
138+
res.add(parser.parse(sb.toString()));
139+
sb.setLength(0); // clear string builder
140+
prevtok = tok;
141+
}
142+
}
143+
else {
144+
// not a pipe or delimiter
145+
if (prevtok=='|') {
146+
// backslash followed by neither a backslash nor a delimiter
147+
// invalid
148+
throw new OptionParseException(name, s, "A pipe | was discovered before the token '" + st.sval +
149+
"'. A pipe is only allowed in front of another pipe " +
150+
"or the delimiter " + delim + ".");
151+
}
152+
sb.append(st.sval);
153+
prevtok = tok;
154+
}
155+
156+
tok = st.nextToken();
157+
}
158+
159+
res.add(parser.parse(sb.toString()));
160+
}
161+
catch(IOException ioe) {
162+
throw new OptionParseException(name, s, "An IOException occurred while parsing a vector.");
163+
}
164+
165+
return res;
166+
}
167+
168+
/** Formats the ArrayList v. The overall String format is determined by the method ArrayList<T>.tString(), but each
169+
* element of the vector is formatted by calling formatElement().
170+
* @param v The ArrayList to be formatted.
171+
* @return A String representing "v".
172+
*/
173+
public String format(ArrayList<T> v) {
174+
if (v.size() == 0) { return ""; }
175+
176+
// String d = String.valueOf(delim);
177+
final StringBuilder res = new StringBuilder(header);
178+
179+
int size = v.size();
180+
int i = 0;
181+
while (i < size) {
182+
String str = formatter.format(v.get(i));
183+
str = str.replaceAll("\\|","||");
184+
str = str.replaceAll(",","|,");
185+
res.append(str);
186+
i++;
187+
if (i < size) res.append(delim);
188+
}
189+
String str = res.append(footer).toString();
190+
return str;
191+
}
192+
}
193+
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*BEGIN_COPYRIGHT_BLOCK
2+
*
3+
* Copyright (c) 2001-2017, JavaPLT group at Rice University ([email protected]). All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6+
* following conditions are met:
7+
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8+
* disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10+
* following disclaimer in the documentation and/or other materials provided with the distribution.
11+
* * Neither the names of DrJava, DrScala, the JavaPLT group, Rice University, nor the names of its contributors may
12+
* be used to endorse or promote products derived from this software without specific prior written permission.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
15+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
20+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21+
*
22+
* This software is Open Source Initiative approved Open Source Software.
23+
* Open Source Initative Approved is a trademark of the Open Source Initiative.
24+
*
25+
* This file is part of DrScala. Download the current version of this project from http://www.drscala.org/.
26+
*
27+
* END_COPYRIGHT_BLOCK*/
28+
29+
package edu.rice.cs.drjava.config;
30+
31+
import edu.rice.cs.drjava.DrScalaTestCase;
32+
33+
import java.util.ArrayList;
34+
35+
36+
/** Class according to the JUnit protocol. Tests the proper functionality of the class ArrayListOption.
37+
* @version $Id: ArrayListOptionTest.java 5594 2012-06-21 11:23:40Z rcartwright $
38+
*/
39+
public final class ArrayListOptionTest extends DrScalaTestCase {
40+
private ArrayListOption<String> _svo;
41+
private ArrayListOption<Integer> _ivo;
42+
private ArrayListOption<Boolean> _bvo;
43+
44+
public void setUp() throws Exception {
45+
super.setUp();
46+
// name fields are irrelevant at this point.
47+
_svo = new ArrayListOption<String>("whatever", new StringOption("", null), (ArrayList<String>) null);
48+
_ivo = new ArrayListOption<Integer>("something", new IntegerOption("", null), (ArrayList<Integer>) null);
49+
_bvo = new ArrayListOption<Boolean>("everwhat", new BooleanOption("", null), (ArrayList<Boolean>) null);
50+
}
51+
52+
public void testGetName() {
53+
assertEquals("whatever", _svo.getName());
54+
assertEquals("everwhat", _bvo.getName());
55+
}
56+
57+
public void testParse() {
58+
assertTrue(_svo.parse("").isEmpty());
59+
assertTrue(_bvo.parse("").isEmpty());
60+
61+
ArrayList<String> v = _svo.parse("[]");
62+
assertEquals(1, v.size());
63+
assertEquals("", v.get(0));
64+
65+
v = _svo.parse("[x]");
66+
assertEquals(1, v.size());
67+
assertEquals("x", v.get(0));
68+
69+
v = _svo.parse("[||]");
70+
assertEquals(1, v.size());
71+
assertEquals("|", v.get(0));
72+
73+
v = _svo.parse("[|,]");
74+
assertEquals(1, v.size());
75+
assertEquals(",", v.get(0));
76+
77+
v = _svo.parse("[|,,]");
78+
assertEquals(2, v.size());
79+
assertEquals(",", v.get(0));
80+
assertEquals("", v.get(1));
81+
82+
v = _svo.parse("[,]");
83+
assertEquals(2, v.size());
84+
assertEquals("", v.get(0));
85+
assertEquals("", v.get(1));
86+
87+
try { _svo.parse("[|x]"); fail("Pipe not in front of another pipe or delimiter."); }
88+
catch (OptionParseException e) { }
89+
90+
try { _svo.parse("[11"); fail("Missing footer."); }
91+
catch (OptionParseException e) { }
92+
93+
v = _svo.parse("[11,]");
94+
assertEquals(2, v.size());
95+
assertEquals("11", v.get(0));
96+
assertEquals("", v.get(1));
97+
98+
try { _svo.parse("11]"); fail("Missing header."); }
99+
catch (OptionParseException e) { }
100+
101+
v = _svo.parse("[11,,22]");
102+
assertEquals(3, v.size());
103+
assertEquals("11", v.get(0));
104+
assertEquals("", v.get(1));
105+
assertEquals("22", v.get(2));
106+
107+
v = _svo.parse("[11,|,,22]");
108+
assertEquals(3, v.size());
109+
assertEquals("11", v.get(0));
110+
assertEquals(",", v.get(1));
111+
assertEquals("22", v.get(2));
112+
113+
v = _svo.parse("[11,abc|,def,22]");
114+
assertEquals(3, v.size());
115+
assertEquals("11", v.get(0));
116+
assertEquals("abc,def", v.get(1));
117+
assertEquals("22", v.get(2));
118+
119+
v = _svo.parse("[11,||,22]");
120+
assertEquals(3, v.size());
121+
assertEquals("11", v.get(0));
122+
assertEquals("|", v.get(1));
123+
assertEquals("22", v.get(2));
124+
125+
// parsing this as a vector of strings is okay, because it will treat it
126+
// as a singleton vector
127+
v = _svo.parse("{11,22}");
128+
assertEquals(1, v.size());
129+
assertEquals("{11,22}", v.get(0));
130+
131+
// but parsing this as a vector of integers will fail
132+
try { _ivo.parse("{11,22}"); fail("Should not have parsed this as singleton list."); }
133+
catch (OptionParseException e) { }
134+
135+
ArrayList<Boolean> bv = _bvo.parse("[true]");
136+
137+
assertEquals(1, bv.size());
138+
assertEquals(Boolean.TRUE, bv.get(0));
139+
140+
bv = _bvo.parse("[true,false,true,true]");
141+
142+
assertEquals(4, bv.size());
143+
assertEquals(Boolean.TRUE, bv.get(0));
144+
assertEquals(Boolean.FALSE, bv.get(1));
145+
assertEquals(Boolean.TRUE, bv.get(2));
146+
assertEquals(Boolean.TRUE, bv.get(3));
147+
148+
try { _bvo.parse("[11]"); fail("Number instead of boolean."); }
149+
catch (OptionParseException e) { }
150+
151+
try { _bvo.parse("[true;false]"); fail("Illegal delimiter."); }
152+
catch (OptionParseException e) { }
153+
}
154+
155+
public void testFormat() {
156+
ArrayList<String> sv = new ArrayList<String>();
157+
assertEquals("", _svo.format(sv));
158+
159+
sv.add("");
160+
assertEquals("[]", _svo.format(sv));
161+
162+
sv.add("-33");
163+
assertEquals("[,-33]", _svo.format(sv));
164+
165+
sv.add("2");
166+
assertEquals("[,-33,2]", _svo.format(sv));
167+
168+
sv.add("");
169+
assertEquals("[,-33,2,]", _svo.format(sv));
170+
171+
sv.add(",");
172+
assertEquals("[,-33,2,,|,]", _svo.format(sv));
173+
174+
sv.add("0");
175+
assertEquals("[,-33,2,,|,,0]", _svo.format(sv));
176+
}
177+
}

0 commit comments

Comments
 (0)