001: ////////////////////////////////////////////////////////////////////////////////
002: // Test case file for checkstyle.
003: // Created: 2001
004: ////////////////////////////////////////////////////////////////////////////////
005: package com.puppycrawl.tools.checkstyle;
006:
007: /**
008: * Class for testing whitespace issues.
009: * error missing author tag
010: **/
011: class InputWhitespace {
012: /** ignore assignment **/
013: private int mVar1 = 1;
014: /** ignore assignment **/
015: private int mVar2 = 1;
016: /** Should be ok **/
017: private int mVar3 = 1;
018:
019: /** method **/
020: void method1() {
021: final int a = 1;
022: int b = 1; // Ignore 1
023: b = 1; // Ignore 1
024: b += 1; // Ignore 1
025: b -= -1 + (+b); // Ignore 2
026: b = b++ + b--; // Ignore 1
027: b = ++b - --b; // Ignore 1
028: }
029:
030: /** method **/
031: void method2() {
032: synchronized (this ) {
033: }
034: try {
035: } catch (RuntimeException e) {
036: }
037: }
038:
039: /**
040: skip blank lines between comment and code,
041: should be ok
042: **/
043:
044: private int mVar4 = 1;
045:
046: /** test WS after void return */
047: private void fastExit() {
048: boolean complicatedStuffNeeded = true;
049: if (!complicatedStuffNeeded) {
050: return; // should not complain about missing WS after return
051: } else {
052: // do complicated stuff
053: }
054: }
055:
056: /** test WS after non void return
057: @return 2
058: */
059: private int nonVoid() {
060: if (true) {
061: return (2); // should complain about missing WS after return
062: } else {
063: return 2; // this is ok
064: }
065: }
066:
067: /** test casts **/
068: private void testCasts() {
069: Object o = (Object) new Object(); // ok
070: o = (Object) o; // error
071: o = (Object) o; // ok
072: o = (Object) o; // ok
073: }
074:
075: /** test questions **/
076: private void testQuestions() {
077: boolean b = (1 == 2) ? true : false;
078: b = (1 == 2) ? false : true;
079: }
080:
081: /** star test **/
082: private void starTest() {
083: int x = 2 * 3 * 4;
084: }
085:
086: /** boolean test **/
087: private void boolTest() {
088: boolean a = true;
089: boolean x = !a;
090: int z = ~1 + ~2;
091: }
092:
093: /** division test **/
094: private void divTest() {
095: int a = 4 % 2;
096: int b = 4 % 2;
097: int c = 4 % 2;
098: int d = 4 % 2;
099: int e = 4 / 2;
100: int f = 4 / 2;
101: int g = 4 / 2;
102: int h = 4 / 2;
103: }
104:
105: /** @return dot test **/
106: private java.lang.String dotTest() {
107: Object o = new java.lang.Object();
108: o.toString();
109: o.toString();
110: o.toString();
111: return o.toString();
112: }
113:
114: /** assert statement test */
115: public void assertTest() {
116: // OK
117: assert true;
118:
119: // OK
120: assert true : "Whups";
121:
122: // evil colons, should be OK
123: assert "OK".equals(null) ? false : true : "Whups";
124:
125: // missing WS around assert
126: assert (true);
127:
128: // missing WS around colon
129: assert true : "Whups";
130: }
131:
132: /** another check */
133: void donBradman(Runnable aRun) {
134: donBradman(new Runnable() {
135: public void run() {
136: }
137: });
138:
139: final Runnable r = new Runnable() {
140: public void run() {
141: }
142: };
143: }
144:
145: /** rfe 521323, detect whitespace before ';' */
146: void rfe521323() {
147: doStuff();
148: // ^ whitespace
149: for (int i = 0; i < 5; i++) {
150: // ^ whitespace
151: }
152: }
153:
154: /** bug 806243 (NoWhitespaceBeforeCheck error for anonymous inner class) */
155: private int i;
156: // ^ whitespace
157: private int i1, i2, i3;
158: // ^ whitespace
159: private int i4, i5, i6;
160:
161: /** bug 806243 (NoWhitespaceBeforeCheck error for anonymous inner class) */
162: void bug806243() {
163: Object o = new InputWhitespace() {
164: private int j;
165: // ^ whitespace
166: };
167: }
168:
169: void doStuff() {
170: }
171: }
172:
173: /**
174: * Bug 806242 (NoWhitespaceBeforeCheck error with an interface).
175: * @author o_sukhodolsky
176: * @version 1.0
177: */
178: interface IFoo {
179: void foo();
180: // ^ whitespace
181: }
182:
183: /**
184: * Avoid Whitespace errors in for loop.
185: * @author lkuehne
186: * @version 1.0
187: */
188: class SpecialCasesInForLoop {
189: void forIterator() {
190: // avoid conflict between WhiteSpaceAfter ';' and ParenPad(nospace)
191: for (int i = 0; i++ < 5;) {
192: // ^ no whitespace
193: }
194:
195: // bug 895072
196: // avoid confilct between ParenPad(space) and NoWhiteSpace before ';'
197: int i = 0;
198: for (; i < 5; i++) {
199: // ^ whitespace
200: }
201: for (int anInt : getSomeInts()) {
202: //Should be ignored
203: }
204: }
205:
206: int[] getSomeInts() {
207: int i = (int) (2 / 3);
208: return null;
209: }
210: }
|