View Javadoc
1   package com.github.sevntu.checkstyle.checks.coding;
2   
3   public class InputRedundantReturn {
4   
5   	/**
6   	 * @param args
7   	 */
8   	public InputRedundantReturn(){
9   		//allowed/not empty c-tor
10  		return; //WARNING if option 'allowReturnInEmptyMethodsAndConstructors' is off
11  	}//c-tor
12  	
13  	public	InputRedundantReturn(String s){
14  		//non empty constructor
15  		boolean b = true;
16  		b = b ? true: false;
17  		return;	//WARNING
18  	}//c-tor2
19  	
20  	public void testMethod1(){
21  		//check the allowed/not empty method
22  		return;	//WARNING if option 'allowReturnInEmptyMethodsAndConstructors' is off
23  	}//testMethod1
24  	
25  	public void testMethod2(){
26  		//nested method definition
27  		MyTestClass test = new MyTestClass(){
28  			public void testMethod(){
29  				int y=0;
30  				int u=8;
31  				int e=u-y;
32  				return;	//WARNING
33  			}
34  		};
35  		
36  		for (int i = 0; i < 10; i++) {
37  			i++;
38  		}
39  		return;	//WARNING
40  	}//testMethod1
41  	
42  	public static void main(String[] args) {
43  		System.out.println("Hello, World !!!");
44  	}//void main
45  	
46  	public void testTryCatch()
47  	{
48  		try {
49  			int y=0;
50  			int u=8;
51  			int e=u-y;
52  			return;	//WARNING
53  		} 
54  		catch (Exception e) {
55  			System.out.println(e);
56  			return;	//WARNING
57  		}
58  		finally
59  		{
60  			return;	//WARNING
61  		}
62  	}
63  	
64  	public void testTryCatch2()
65  	{
66  		try {
67  		} 
68  		catch (Exception e) {
69  		}
70  		finally
71  		{
72  		}
73  	}
74  	
75  	public void testNoBraces(){
76  		int i=0;
77  		while(true) if(i++ == 10) return;
78  	}//testNoBraces
79  
80  	public void testNoBraces2(){
81  		for(int i=0;true;i++) if(i == 10) return;
82  	}//testNoBraces2
83  	
84  	private class MyTestClass{
85  		public MyTestClass(){}
86  		public void testMethod(){
87  			return;	//WARNING if option 'allowReturnInEmptyMethodsAndConstructors' is off
88  		}	
89  	}//myTestClass
90  	
91  	public void testTryCatch3()
92  	{
93  		try {
94  			int y=0;
95  			int u=8;
96  			int e=u-y;
97  		} 
98  		catch (IllegalArgumentException e) {
99  			System.out.println(e);
100 			return;	//WARNING
101 		}
102 		catch (IllegalStateException ex) {
103 		    	System.out.println(ex);
104 		    	return;	//WARNING
105 		}
106 	}
107 	
108     public void testTryCatch4()
109     {
110 	    int y=0;
111         int u=8;
112         try {
113             int e=u-y;
114         } 
115         catch (IllegalArgumentException e) {
116             System.out.println(e);
117             return;	//WARNING
118         }
119     }
120     public void setFormats() {
121 		try {
122 			int k = 4;
123 		} catch (Exception e) {
124 			Object k = null;
125 			if (k != null)
126 				k = "ss";
127 			else {
128 				return; //WARNING
129 			}
130 		}
131     }
132     public void setFormats1() {
133 		try {
134 			int k = 4;
135 		} catch (Exception e) {
136 			Object k = null;
137 			if (k != null) {
138 				k = "ss";
139 			} else {
140 				return; //WARNING
141 			}
142 		}
143     }
144     public void setFormats2() {
145 		try {
146 			int k = 4;
147 		} catch (Exception e) {
148 			Object k = null;
149 			if (k != null) {
150 				k = "ss";
151 				return;	//WARNING
152 			} 
153 		}
154     }
155     public void setFormats3() {
156 		try {
157 			int k = 4;
158 		} catch (Exception e) {
159 			Object k = null;
160 			if (k != null) {
161 				k = "ss";
162 				
163 			} 
164 		}
165     }
166     public int getRandomNumber() {
167     	return 4;
168     }
169     public InputRedundantReturn(double content) {
170     	
171     }
172     public void setFormat() {
173 		try {
174 			int k = 4;
175 		} catch (Exception e) {
176 			Object k = null;
177 			if (k != null) {
178 				k = "ss";
179 				if (k.toString().concat("ss") == "ssss") {
180 					if (e.getMessage() == "Exception") {
181 						return;	// WARNING
182 					}
183 				}
184 			} 
185 		}
186     }
187     
188     private static void foo(int x) {}
189     
190     private static void foo1() {
191     	try {
192     		char c = 'c';
193     	} finally {
194     		
195     	}
196     }
197     
198 }