Skip to content
This repository was archived by the owner on Sep 26, 2020. It is now read-only.

Commit c00b01e

Browse files
author
stalcup@google.com
committed
documents and tests the fact that the ArgProcessor allows duplicate args and honors the last one
Review at http://gwt-code-reviews.appspot.com/1901803 git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@11601 8db76d5a-ed1c-0410-87a9-c151d255dfc7
1 parent 72320e4 commit c00b01e

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

dev/core/src/com/google/gwt/dev/ArgProcessorBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
*/
2323
public abstract class ArgProcessorBase extends ToolBase {
2424
/*
25-
* Overridden to make public.
25+
* Configures contained options by parsing the given args. Multiple args can
26+
* set a value for the same option and the last setting wins.
2627
*/
2728
@Override
2829
public final boolean processArgs(String... args) {
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright 2013 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.google.gwt.dev;
17+
18+
import com.google.gwt.dev.util.arg.ArgHandlerDraftCompile;
19+
import com.google.gwt.dev.util.arg.ArgHandlerOptimize;
20+
import com.google.gwt.dev.util.arg.OptionAggressivelyOptimize;
21+
import com.google.gwt.dev.util.arg.OptionOptimize;
22+
23+
/**
24+
* Test for {@link ArgProcessorBase}.
25+
*/
26+
public class ArgProcessorBaseTest extends ArgProcessorTestBase {
27+
28+
private static class OptimizationOptions implements OptionOptimize, OptionAggressivelyOptimize {
29+
30+
private boolean aggressivelyOptimize;
31+
private int level;
32+
33+
@Override
34+
public int getOptimizationLevel() {
35+
return level;
36+
}
37+
38+
@Override
39+
public boolean isAggressivelyOptimize() {
40+
return aggressivelyOptimize;
41+
}
42+
43+
@Override
44+
public void setAggressivelyOptimize(boolean aggressivelyOptimize) {
45+
this.aggressivelyOptimize = aggressivelyOptimize;
46+
}
47+
48+
@Override
49+
public void setOptimizationLevel(int level) {
50+
this.level = level;
51+
}
52+
}
53+
54+
private static class OptimizeArgProcessor extends ArgProcessorBase {
55+
public OptimizeArgProcessor(OptimizationOptions option) {
56+
registerHandler(new ArgHandlerDraftCompile(option));
57+
registerHandler(new ArgHandlerOptimize(option));
58+
}
59+
60+
@Override
61+
protected String getName() {
62+
return this.getClass().getSimpleName();
63+
}
64+
}
65+
66+
private final OptimizeArgProcessor argProcessor;
67+
private final OptimizationOptions options = new OptimizationOptions();
68+
69+
public ArgProcessorBaseTest() {
70+
argProcessor = new OptimizeArgProcessor(options);
71+
}
72+
73+
public void testOptionOrderIsPrecedenceArgs() {
74+
assertProcessSuccess(argProcessor);
75+
assertEquals(0, options.getOptimizationLevel());
76+
77+
assertProcessSuccess(argProcessor, "-optimize", "5");
78+
assertEquals(5, options.getOptimizationLevel());
79+
80+
assertProcessSuccess(argProcessor, "-optimize", "5", "-draftCompile");
81+
assertEquals(0, options.getOptimizationLevel());
82+
83+
assertProcessSuccess(argProcessor, "-optimize", "5", "-draftCompile", "-optimize", "9");
84+
assertEquals(9, options.getOptimizationLevel());
85+
}
86+
}

0 commit comments

Comments
 (0)