001: ////////////////////////////////////////////////////////////////////////////////
002: // Test case file for checkstyle.
003: // Created: 2003
004: ////////////////////////////////////////////////////////////////////////////////
005: package com.puppycrawl.tools.checkstyle;
006:
007: import javax.swing.AbstractAction;
008: import javax.swing.Action;
009: import java.awt.event.ActionEvent;
010:
011: /**
012: * Test case for detecting missing final parameters.
013: * @author Lars Kühne
014: **/
015: class InputFinalParameters {
016: /** no param constructor */
017: InputFinalParameters() {
018: }
019:
020: /** non final param constructor */
021: InputFinalParameters(String s) {
022: }
023:
024: /** non final param constructor */
025: InputFinalParameters(final Integer i) {
026: }
027:
028: /** final param constructor with annotation */
029: InputFinalParameters(final @MyAnnotation3
030: Class i) {
031: }
032:
033: /** non-final param constructor with annotation*/
034: InputFinalParameters(@MyAnnotation3
035: Boolean i) {
036: }
037:
038: /** mixed */
039: InputFinalParameters(String s, final Integer i) {
040: }
041:
042: /** no param method */
043: void method() {
044: }
045:
046: /** non final param method */
047: void method(String s) {
048: }
049:
050: /** final param method */
051: void method(final Integer i) {
052: }
053:
054: /** final param method with annotation **/
055: void method(@MyAnnotation3
056: final Object s) {
057:
058: }
059:
060: /** non-final param method with annotation **/
061: void method(@MyAnnotation3
062: Class s) {
063:
064: }
065:
066: /** mixed */
067: void method(String s, final Integer i) {
068: }
069:
070: /** interface methods should not be flagged. */
071: interface TestInterface {
072: void method(String s);
073: }
074:
075: /** methods in anonymous inner classes */
076: void holder() {
077: Action a = new AbstractAction() {
078: public void actionPerformed(ActionEvent e) {
079: }
080:
081: void somethingElse(@MyAnnotation3
082: ActionEvent e) {
083: }
084: };
085:
086: Action b = new AbstractAction() {
087: public void actionPerformed(final ActionEvent e) {
088: }
089:
090: void somethingElse(@MyAnnotation3
091: final ActionEvent e) {
092: }
093: };
094: }
095:
096: /** methods with complicated types of the parameters. */
097: void methodA(java.lang.String aParam) {
098: }
099:
100: void methodB(String[] args) {
101: }
102:
103: void methodC(java.lang.String[] args) {
104: }
105:
106: /** some catch blocks */
107: void method1() {
108: try {
109: System.err.println("");
110: } catch (java.lang.NullPointerException npe) {
111: npe.printStackTrace();
112: } catch (@MyAnnotation3
113: final ClassCastException e) {
114: e.printStackTrace();
115: } catch (RuntimeException e) {
116: e.printStackTrace();
117: } catch (@MyAnnotation3
118: NoClassDefFoundError e) {
119: e.printStackTrace();
120: }
121: }
122: }
123:
124: abstract class AbstractClass {
125: public abstract void abstractMethod(int aParam);
126: }
127:
128: class Foo {
129: /* Some for-each clauses */
130: public void Bar() {
131: for (String s : someExpression()) {
132:
133: }
134: for (final String s : someExpression()) {
135:
136: }
137: for (@MyAnnotation3
138: String s : someExpression()) {
139:
140: }
141: for (@MyAnnotation3
142: final String s : someExpression()) {
143:
144: }
145: }
146:
147: private String[] someExpression() {
148: return null;
149: }
150: }
151:
152: @interface MyAnnotation3 {
153: }
|