001: ////////////////////////////////////////////////////////////////////////////////
002: // Test case file for checkstyle.
003: // Created: 2001
004: ////////////////////////////////////////////////////////////////////////////////
005: package com.puppycrawl.tools.checkstyle;
006:
007: /**
008: * Test case for correct use of braces.
009: * @author Oliver Burn
010: **/
011: class InputBraces {
012: /** @return helper func **/
013: boolean condition() {
014: return false;
015: }
016:
017: /** Test do/while loops **/
018: void testDoWhile() {
019: // Valid
020: do {
021: testDoWhile();
022: } while (condition());
023:
024: // Invalid
025: do
026: testDoWhile();
027: while (condition());
028: }
029:
030: /** Test while loops **/
031: void testWhile() {
032: // Valid
033: while (condition()) {
034: testWhile();
035: }
036:
037: // Invalid
038: while (condition())
039: ;
040: while (condition())
041: testWhile();
042: while (condition())
043: if (condition())
044: testWhile();
045: }
046:
047: /** Test for loops **/
048: void testFor() {
049: // Valid
050: for (int i = 1; i < 5; i++) {
051: testFor();
052: }
053:
054: // Invalid
055: for (int i = 1; i < 5; i++)
056: ;
057: for (int i = 1; i < 5; i++)
058: testFor();
059: for (int i = 1; i < 5; i++)
060: if (i > 2)
061: testFor();
062: }
063:
064: /** Test if constructs **/
065: public void testIf() {
066: // Valid
067: if (condition()) {
068: testIf();
069: } else if (condition()) {
070: testIf();
071: } else {
072: testIf();
073: }
074:
075: // Invalid
076: if (condition())
077: ;
078: if (condition())
079: testIf();
080: if (condition())
081: testIf();
082: else
083: testIf();
084: if (condition())
085: testIf();
086: else {
087: testIf();
088: }
089: if (condition()) {
090: testIf();
091: } else
092: testIf();
093: if (condition())
094: if (condition())
095: testIf();
096: }
097:
098: void whitespaceAfterSemi() {
099: //reject
100: int i = 1;
101: int j = 2;
102:
103: //accept
104: for (;;) {
105: }
106: }
107:
108: /** Empty constructor block. **/
109: public InputBraces() {
110: }
111:
112: /** Empty method block. **/
113: public void emptyImplementation() {
114: }
115: }
|