View Javadoc
1   /*
2   VariableDeclarationUsageDistance
3   allowedDistance = 1
4   ignoreVariablePattern = (default)
5   validateBetweenScopes = true
6   ignoreFinal = (default)true
7   
8   
9   */
10  
11  package com.puppycrawl.tools.checkstyle.checks.coding.variabledeclarationusagedistance;
12  
13  import java.util.*;
14  
15  public class InputVariableDeclarationUsageDistanceFinal {
16  
17      private static int test1 = 0;
18  
19      static {
20          int b = 0;
21          int d = 0;
22          {
23              d = ++b;
24          }
25      }
26  
27      static {
28          int c = 0;
29          int a = 3;
30          int b = 2;
31          {
32              a = a + b;
33              c = b;
34          }
35          {
36              c--;
37          }
38          a = 7;
39      }
40  
41      static {
42          int a = -1; // violation 'Distance between .* declaration and its first usage is 2.'
43          int b = 2;
44          b++;
45          int c = --b;
46          a = b; // DECLARATION OF VARIABLE 'a' SHOULD BE HERE (distance = 2)
47      }
48  
49      public InputVariableDeclarationUsageDistanceFinal(int test1) {
50          int temp = -1; // violation 'Distance between .* declaration and its first usage is 2.'
51          this.test1 = test1;
52          temp = test1; // DECLARATION OF VARIABLE 'temp' SHOULD BE HERE (distance = 2)
53      }
54  
55      public boolean testMethod() {
56          int temp = 7; // violation 'Distance between .* declaration and its first usage is 2.'
57          new InputVariableDeclarationUsageDistanceFinal(2);
58          String.valueOf(temp); // DECLARATION OF VARIABLE 'temp' SHOULD BE HERE (distance = 2)
59          boolean result = false;
60          String str = "";
61          if (test1 > 1) {
62              str = "123";
63              result = true;
64          }
65          return result;
66      }
67  
68      public void testMethod2() {
69          int count; // violation 'Distance between .* declaration and its first usage is 2.'
70          int a = 3;
71          int b = 2;
72          {
73              a = a
74                      + b
75                      - 5
76                      + 2
77                      * a;
78              count = b; // DECLARATION OF VARIABLE 'count' SHOULD BE HERE (distance = 2)
79          }
80      }
81  
82      public void testMethod3() {
83          int count; // violation 'Distance between .* declaration and its first usage is 4.'
84          int a = 3;
85          int b = 3;
86          a = a + b;
87          b = a + a;
88          testMethod2();
89          count = b; // DECLARATION OF VARIABLE 'count' SHOULD BE HERE (distance = 4)
90      }
91  
92      public void testMethod4(int arg) {
93          int d = 0;
94          for (int i = 0; i < 10; i++) {
95              d++;
96              if (i > 5) {
97                  d += arg;
98              }
99          }
100 
101         String ar[] = { "1", "2" };
102         for (String st : ar) {
103             System.identityHashCode(st);
104         }
105     }
106 
107     public void testMethod5() {
108         int arg = 7; // violation 'Distance between .* declaration and its first usage is 2.'
109         boolean b = true;
110         boolean bb = false;
111         if (b)
112             if (!bb)
113                 b = false;
114         testMethod4(arg); // DECLARATION OF VARIABLE 'arg' SHOULD BE HERE (distance = 2)
115     }
116 
117     public void testMethod6() {
118         int blockNumWithSimilarVar = 3;
119         int dist = 0;
120         int index = 0;
121         int block = 0;
122 
123         if (blockNumWithSimilarVar <= 1) {
124             do {
125                 dist++;
126                 if (block > 4) {
127                     break;
128                 }
129                 index++;
130                 block++;
131             } while (index < 7);
132         } else {
133             while (index < 8) {
134                 dist += block;
135                 index++;
136                 block++;
137             }
138         }
139     }
140 
141     public boolean testMethod7(int a) {
142         boolean res;
143         switch (a) {
144         case 1:
145             res = true;
146             break;
147         default:
148             res = false;
149         }
150         return res;
151     }
152 
153     public void testMethod8() {
154         int b = 0;
155         int c = 0;
156         int m = 0; // violation 'Distance between .* declaration and its first usage is 3.'
157         int n = 0; // violation 'Distance between .* declaration and its first usage is 2.'
158         {
159             c++;
160             b++;
161         }
162         {
163             n++; // DECLARATION OF VARIABLE 'n' SHOULD BE HERE (distance = 2)
164             m++; // DECLARATION OF VARIABLE 'm' SHOULD BE HERE (distance = 3)
165             b++;
166         }
167     }
168 
169     public void testMethod9() {
170         boolean result = false;
171         boolean b1 = true;
172         boolean b2 = false;
173         if (b1) {
174             if (!b2) {
175                 result = true;
176             }
177             result = true;
178         }
179     }
180 
181     public boolean testMethod10() {
182         boolean result;
183         try {
184             result = true;
185         } catch (Exception e) {
186             result = false;
187         } finally {
188             result = false;
189         }
190         return result;
191     }
192 
193     public void testMethod11() {
194         int a = 0;
195         int b = 10;
196         boolean result; // violation 'Distance between .* declaration and its first usage is 2.'
197         try {
198             b--;
199         } catch (Exception e) {
200             b++;
201             result = false; // DECLARATION OF VARIABLE 'result' SHOULD BE HERE (distance = 2)
202         } finally {
203             a++;
204         }
205     }
206 
207     public void testMethod12() {
208         boolean result = false;
209         boolean b3 = true;
210         boolean b1 = true;
211         boolean b2 = false;
212         if (b1) {
213             if (b3) {
214                 if (!b2) {
215                     result = true;
216                 }
217                 result = true;
218             }
219         }
220     }
221 
222     public void testMethod13() {
223         int i = 9;
224         int j = 6;
225         int g = i + 8;
226         int k = j + 10;
227     }
228 
229     public void testMethod14() {
230         Session s = openSession();
231         Transaction t = s.beginTransaction(); // violation 'Distance .* is 5.'
232         A a = new A();
233         E d1 = new E();
234         C1 c = new C1(); // violation 'Distance between .* declaration and its first usage is 3.'
235         E d2 = new E(); // violation 'Distance between .* declaration and its first usage is 3.'
236         a.setForward(d1);
237         d1.setReverse(a);
238         c.setForward(d2); // DECLARATION OF VARIABLE 'c' SHOULD BE HERE (distance = 3)
239                             // DECLARATION OF VARIABLE 'd2' SHOULD BE HERE (distance = 3)
240         d2.setReverse(c);
241         Serializable aid = s.save(a);
242         Serializable d2id = s.save(d2);
243         t.commit(); // DECLARATION OF VARIABLE 't' SHOULD BE HERE (distance = 5)
244         s.close();
245     }
246 
247     public boolean isCheckBoxEnabled(int path) {
248         String model = "";
249         if (true) {
250             for (int index = 0; index < path; ++index) {
251                 int nodeIndex = model.codePointAt(path);
252                 if (model.contains("")) {
253                     return false;
254                 }
255             }
256         } else {
257             int nodeIndex = model.codePointAt(path);
258             if (model.contains("")) {
259                 return false;
260             }
261         }
262         return true;
263     }
264 
265     public Object readObject(String in) throws Exception {
266         String startDay = new String("");
267         String endDay = new String("");
268         return new String(startDay + endDay);
269     }
270 
271     public int[] getSelectedIndices() {
272         int[] sel = new int[5]; // violation 'Distance .* is 2.'
273         String model = ""; // violation 'Distance .* is 2.'
274         int a = 0;
275         a++;
276         for (int index = 0; index < 5; ++index) {
277             sel[index] = Integer.parseInt(model.valueOf(a)); // 'sel' SHOULD BE HERE (distance = 2)
278                                     // DECLARATION OF VARIABLE 'model' SHOULD BE HERE (distance = 2)
279         }
280         return sel;
281     }
282 
283     public void testMethod15() {
284         String confDebug = "";
285         if (!confDebug.equals("") && !confDebug.equals("null")) {
286             LogLog.warn("The \"" + "\" attribute is deprecated.");
287             LogLog.warn("Use the \"" + "\" attribute instead.");
288             LogLog.setInternalDebugging(confDebug, true);
289         }
290 
291         int i = 0;
292         int k = 7;
293         boolean b = false;
294         for (; i < k; i++) {
295             b = true;
296             k++;
297         }
298 
299         int sw; // violation 'Distance between .* declaration and its first usage is 2.'
300         switch (i) {
301         case 0:
302             k++;
303             sw = 0; // DECLARATION OF VARIABLE 'sw' SHOULD BE HERE (distance = 2)
304             break;
305         case 1:
306             b = false;
307             break;
308         default:
309             b = true;
310         }
311 
312         int wh = 0; // violation 'Distance .* is 2.'
313         b = true;
314         do {
315             k--;
316             i++;
317         } while (wh > 0); // DECLARATION OF VARIABLE 'wh' SHOULD BE HERE (distance = 2)
318 
319         if (wh > 0) {
320             k++;
321         } else if (!b) {
322             i++;
323         } else {
324             i--;
325         }
326     }
327 
328     public void testMethod16() {
329         int wh = 1, i = 4, k = 0;
330         if (i > 0) {
331             k++;
332         } else if (wh > 0) {
333             i++;
334         } else {
335             i--;
336         }
337     }
338 
339     protected JMenuItem createSubMenuItem(LogLevel level) {
340         final JMenuItem result = new JMenuItem(level.toString());
341         final LogLevel logLevel = level;
342         result.setMnemonic(level.toString().charAt(0));
343         result.addActionListener(new ActionListener() {
344           public void actionPerformed(ActionEvent e) {
345             showLogLevelColorChangeDialog(result, logLevel);//'logLevel' SHOULD BE HERE (distance=2)
346           }
347         });
348 
349         return result;
350 
351       }
352 
353     public static Color darker(Color color, double fraction) {
354         int red = (int) Math.round(color.getRed() * (1.0 - fraction));
355         int green = (int) Math.round(color.getGreen() * (1.0 - fraction)); // violation '.* is 2.'
356         int blue = (int) Math.round(color.getBlue() * (1.0 - fraction)); // violation '.* 3.'
357 
358         if (red < 0) {
359             red = 0;
360         } else if (red > 255) {
361             red = 255;
362         }
363         if (green < 0) { // DECLARATION OF VARIABLE 'green' SHOULD BE HERE (distance = 2)
364             green = 0;
365         } else if (green > 255) {
366             green = 255;
367         }
368         if (blue < 0) { // DECLARATION OF VARIABLE 'blue' SHOULD BE HERE (distance = 3)
369             // blue = 0;
370         }
371 
372         int alpha = color.getAlpha();
373 
374         return new Color(red, green, blue, alpha);
375     }
376 
377     public void testFinal() {
378         AuthUpdateTask task = null;
379         final long intervalMs = 30 * 60000L; // 30 min
380         Object authCheckUrl = null, authInfo = null;
381         task = new AuthUpdateTask(authCheckUrl, authInfo, new IAuthListener() {
382             @Override
383             public void authTokenChanged(String cookie, String token) {
384                 fireAuthTokenChanged(cookie, token);
385             }
386         });
387 
388         Timer timer = new Timer("Auth Guard", true);
389         timer.schedule(task, intervalMs / 2, intervalMs);//'intervalMs' SHOULD BE HERE(distance = 2)
390     }
391 
392     public void testForCycle() {
393         int filterCount = 0;
394         for (int i = 0; i < 10; i++, filterCount++) {
395             int abc = 0;
396             System.identityHashCode(abc);
397 
398             for (int j = 0; j < 10; j++) {
399                 abc = filterCount;
400                 System.identityHashCode(abc);
401             }
402         }
403     }
404 
405     public void testIssue32_1()
406     {
407         Option srcDdlFile = OptionBuilder.create("f");
408         Option logDdlFile = OptionBuilder.create("o");
409         Option help = OptionBuilder.create("h");
410 
411         Options options = new Options();
412         options.something();
413         options.something();
414         options.something();
415         options.something();
416         options.addOption(srcDdlFile, logDdlFile, help); // distance=1
417     }
418 
419     public void testIssue32_2()
420     {
421         int mm = Integer.parseInt("2");
422         long timeNow = 0;
423         Calendar cal = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
424         cal.setTimeInMillis(timeNow);
425         cal.set(Calendar.SECOND, 0);
426         cal.set(Calendar.MILLISECOND, 0);
427         cal.set(Calendar.HOUR_OF_DAY, mm);
428         cal.set(Calendar.MINUTE, mm); // distance=1
429     }
430 
431     public void testIssue32_3(MyObject[] objects) {
432         Calendar cal = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
433         for(int i=0; i<objects.length; i++) {
434             objects[i].setEnabled(true);
435             objects[i].setColor(0x121212);
436             objects[i].setUrl("http://google.com");
437             objects[i].setSize(789);
438             objects[i].setCalendar(cal); // distance=1
439         }
440     }
441 
442     public String testIssue32_4(boolean flag) {
443         StringBuilder builder = new StringBuilder();
444         builder.append("flag is ");
445         builder.append(flag);
446         final String line = "";
447         if(flag) {
448             builder.append("line of AST is:");
449             builder.append("\n");
450             builder.append(String.valueOf(line)); //distance=1
451             builder.append("\n");
452         }
453         return builder.toString();
454     }
455 
456     public void testIssue32_5() {
457         Option a = null;
458         Option b = null;
459         Option c = null;
460         boolean isCNull = isNull(c); // distance=1
461         boolean isBNull = isNull(b); // distance=1
462         boolean isANull = isNull(a); // distance=1
463     }
464 
465     public void testIssue32_6() {
466         Option aOpt = null; // violation 'Distance .* is 3.'
467         Option bOpt = null; // violation 'Distance .* is 2.'
468         Option cOpt = null;
469         isNull(cOpt); // distance = 1
470         isNull(bOpt); // distance = 2
471         isNull(aOpt); // distance = 3
472     }
473 
474     public void testIssue32_7() {
475         String line = "abc";
476         otherWriter.write(line);
477         line.charAt(1);
478         builder.append(line);
479         test(line, line, line);
480     }
481 
482     public void testIssue32_8(Writer w1, Writer w2, Writer w3) {
483         String l1="1", l2="2", l3="3"; // 2 violations
484         w1.write(l3); //distance=1
485         w2.write(l2); //distance=2
486         w3.write(l1); //distance=3
487     }
488 
489     public void testIssue32_9() {
490         Options options = new Options();
491         Option myOption = null; // violation 'Distance .* is 7.'
492         options.addBindFile(null);
493         options.addBindFile(null);
494         options.addBindFile(null);
495         options.addBindFile(null);
496         options.addBindFile(null);
497         System.identityHashCode("message");
498         myOption.setArgName("abc"); // distance=7
499     }
500 
501     public void testIssue32_10() {
502         Options options = new Options();
503         Option myOption = null; // violation 'Distance .* is 6.'
504         options.addBindFile(null);
505         options.addBindFile(null);
506         options.addBindFile(null);
507         options.addBindFile(null);
508         options.addBindFile(null);
509         myOption.setArgName("q"); // distance=6
510     }
511 
512 
513     public int testIssue32_11(String toDir)
514             throws Exception
515     {
516         int count = 0; // violation 'Distance between .* declaration and its first usage is 4.'
517         String[] files = {}; // violation 'Distance .* is 2.'
518 
519         System.identityHashCode("Data archival started");
520         files.notify();
521         System.identityHashCode("sss");
522 
523         if (files == null || files.length == 0) {
524             System.identityHashCode("No files on a remote site");
525         }
526         else {
527             System.identityHashCode("Files on remote site: " + files.length);
528 
529             for (String ftpFile : files) {
530                 if (files.length == 0) {
531                     "".concat("");
532                     ftpFile.concat(files[2]);
533                     count++;
534                 }
535             }
536         }
537 
538         System.lineSeparator();
539 
540         return count;
541     }
542 
543     //////////////////////////////////////////////////
544     // False positive. Will be fixed in the future.
545     //////////////////////////////////////////////////
546     private TreeMapNode buildTree(Object[][] tree)
547     {
548         int k = 0;
549         tree.notify();
550         TreeMapNode root = null;
551         for (Object[] s : tree) {
552             Integer id = (Integer) s[0]; // violation 'Distance .* is 2.'
553             String label = (String) s[1];
554             Integer parentId = (Integer) s[2]; // violation 'Distance .* is 3.'
555             Number weight = (Number) s[3];
556             Number value = (Number) s[4];
557             Integer childCount = (Integer) s[5];
558             TreeMapNode node;
559             if (childCount == 0) {
560                 node = new TreeMapNode(label,
561                         weight != null ? weight.doubleValue() : 0.0,
562                         new DefaultValue(value != null ? value.doubleValue()
563                                 : 0.0));
564             }
565             else {
566                 node = new TreeMapNode(label);
567             }
568             System.identityHashCode(id.toString() + node);
569             System.identityHashCode(node.toString() + id);
570             if (parentId == null || parentId == -1) { ///!!!!!!!
571                 root = node;
572             }
573             else {
574                 System.identityHashCode(parentId.toString() +node);
575             }
576         }
577         return root;
578     }
579 
580     private Session openSession() {
581         return null;
582 
583     }
584 
585     class Session {
586 
587         public Transaction beginTransaction() {
588             return null;
589         }
590 
591         public void close() {
592         }
593 
594         public Serializable save(E d2) {
595             return null;
596         }
597 
598         public Serializable save(A a) {
599             return null;
600         }
601 
602     }
603 
604     class Transaction {
605 
606         public void commit() {
607 
608         }
609 
610     }
611 
612     class A {
613 
614         public void setForward(E d1) {
615 
616         }
617 
618     }
619 
620     class E {
621 
622         public void setReverse(C1 c) {
623 
624         }
625 
626         public void setReverse(A a) {
627 
628         }
629 
630     }
631 
632     class C1 {
633 
634         public void setForward(E d2) {
635 
636         }
637 
638     }
639 
640     class Serializable {
641 
642     }
643 
644     class JMenuItem {
645 
646         public JMenuItem(String string) {
647         }
648 
649         public void addActionListener(ActionListener actionListener) {
650 
651         }
652 
653         public void setMnemonic(char charAt) {
654 
655         }
656 
657     }
658 
659     class LogLevel {
660 
661     }
662 
663     class ActionListener {
664 
665     }
666 
667     class ActionEvent {
668 
669     }
670 
671     private void showLogLevelColorChangeDialog(JMenuItem j, LogLevel l) {   }
672 
673     static class Color {
674 
675         public Color(int red, int green, int blue, int alpha) {
676         }
677 
678         public double getRed() {
679             return 0;
680         }
681 
682         public int getAlpha() {
683             return 0;
684         }
685 
686         public double getBlue() {
687             return 0;
688         }
689 
690         public double getGreen() {
691             return 0;
692         }
693 
694     }
695 
696     class AuthUpdateTask {
697 
698         public AuthUpdateTask(Object authCheckUrl, Object authInfo,
699                 IAuthListener iAuthListener) {
700         }
701 
702     }
703 
704     interface IAuthListener {
705 
706         void authTokenChanged(String cookie, String token);
707 
708     }
709 
710     void fireAuthTokenChanged(String s, String s1) {}
711 
712     class Timer {
713 
714         public Timer(String string, boolean b) {
715         }
716 
717         public void schedule(AuthUpdateTask authUpdateTask, long l,
718                 long intervalMs) {
719         }
720 
721     }
722 
723     class Option {
724 
725         public void setArgName(String string) {
726         }
727 
728     }
729 
730     boolean isNull(Option o) {
731         return false;}
732 
733     class Writer {
734 
735         public void write(String l3) {
736 
737         }
738 
739     }
740 
741     class Options {
742 
743         public void addBindFile(Object object) {
744 
745         }
746 
747         public void
748                 addOption(Option srcDdlFile, Option logDdlFile, Option help)
749         {
750 
751         }
752 
753         public void something()
754         {
755 
756         }
757 
758     }
759 
760     class TreeMapNode {
761 
762         public TreeMapNode(String label, double d, DefaultValue defaultValue) {
763         }
764 
765         public TreeMapNode(String label) {
766         }
767 
768     }
769 
770     class DefaultValue {
771 
772         public DefaultValue(double d) {
773         }
774 
775     }
776 
777     static class LogLog {
778 
779         public static void warn(String string)
780         {
781 
782         }
783 
784         public static void setInternalDebugging(String confDebug, boolean b)
785         {
786 
787         }
788 
789     }
790 
791     static class OptionBuilder {
792 
793         public static Option create(String string)
794         {
795             return null;
796         }
797 
798     }
799 
800     class MyObject {
801 
802         public void setEnabled(boolean b)
803         {
804 
805         }
806 
807         public void setCalendar(Calendar cal)
808         {
809 
810         }
811 
812         public void setSize(int i)
813         {
814 
815         }
816 
817         public void setUrl(String string)
818         {
819 
820         }
821 
822         public void setColor(int i)
823         {
824 
825         }
826 
827     }
828 
829     static class otherWriter {
830 
831         public static void write(String line)
832         {
833 
834         }
835 
836     }
837 
838     void test(String s, String s1, String s2) {
839 
840     }
841 
842     static class builder {
843 
844         public static void append(String line)
845         {
846 
847         }
848 
849     }
850 
851 }
852 
853 class New5 {
854     void a() {
855         int a = 1;
856         System.lineSeparator();
857         System.lineSeparator();
858         System.lineSeparator();
859         System.lineSeparator();
860         while (true) {
861             System.lineSeparator();
862             System.identityHashCode(a);
863         }
864     }
865 
866     void b() {
867         int a = 1;
868         System.lineSeparator();
869         System.lineSeparator();
870         System.lineSeparator();
871         System.lineSeparator();
872         do {
873             System.lineSeparator();
874             System.identityHashCode(a);
875         } while (true);
876     }
877 
878     void c() {
879         int a = 1;
880         System.lineSeparator();
881         System.lineSeparator();
882         System.lineSeparator();
883         System.lineSeparator();
884         for (;;) {
885             System.lineSeparator();
886             System.identityHashCode(a);
887         }
888     }
889 
890     void d() {
891         int a = 1;
892         System.lineSeparator();
893         System.lineSeparator();
894         System.lineSeparator();
895         System.lineSeparator();
896         for (int i: new int[]{1,2,3}) {
897             System.lineSeparator();
898             System.identityHashCode(a);
899         }
900     }
901 
902     void f() {
903         int a = 1; // violation 'Distance between .* declaration and its first usage is 4.'
904         System.lineSeparator();
905         System.lineSeparator();
906         System.lineSeparator();
907         System.lineSeparator();
908         while (true)
909             System.identityHashCode(a);
910     }
911 
912     void h() {
913         int a = 1; // violation 'Distance between .* declaration and its first usage is 4.'
914         System.lineSeparator();
915         System.lineSeparator();
916         System.lineSeparator();
917         System.lineSeparator();
918         while (true)
919             while (true)
920                 a++;
921     }
922 
923     void i() {
924         int a = 1;
925         switch (Math.max(1, 2)) {
926         case 1:
927             System.lineSeparator();
928             break;
929         case 2:
930             System.lineSeparator();
931             break;
932         }
933 
934         switch (Math.max(1, 2)) {
935         case 1:
936             System.identityHashCode(a);
937             break;
938         case 2:
939             System.identityHashCode(a);
940             break;
941         }
942     }
943 
944     void k() {
945         int a = 1;
946         System.lineSeparator();
947         System.lineSeparator();
948         System.lineSeparator();
949         System.lineSeparator();
950         while (true) {
951             System.lineSeparator();
952             if (true) {
953                 System.lineSeparator();
954             } else if (true) {
955                 System.identityHashCode(a);
956             } else {
957                 System.lineSeparator();
958             }
959         }
960     }
961 
962     void l() {
963         int a = 1;
964 
965         while (true) {
966             switch (hashCode()){}
967             switch (Math.max(1, 2)) {
968             case 1:
969                 System.identityHashCode(a);
970                 break;
971             case 2:
972                 System.identityHashCode(a);
973                 break;
974             }
975         }
976     }
977 
978     void tryWithoutFinally() {
979         int a = 1; // violation 'Distance between .* declaration and its first usage is 4.'
980         System.lineSeparator();
981         System.lineSeparator();
982         System.lineSeparator();
983         try {
984             a = 2;
985         }
986         catch(Exception e){}
987     }
988 
989     void m() {
990         final int a = 1;
991         int b = 0;
992 
993         if (b == 1) {
994             System.lineSeparator();
995         }
996 
997         final int c = a + 1;
998     }
999 
1000     void test() {
1001         int a = 0; // violation 'Distance between .* declaration and its first usage is 3.'
1002 
1003         System.lineSeparator();
1004         System.lineSeparator();
1005         System.lineSeparator();
1006         for (int i = 0; i < 10; i++) {
1007             if (true) {
1008                 System.identityHashCode(a);
1009             }
1010             else {
1011                 System.identityHashCode(a);
1012             }
1013         }
1014 
1015         int b = 0;
1016         try {
1017             for (int i = 0; i < 10; i++) {
1018                 if (true) {
1019                     System.lineSeparator();
1020                     System.lineSeparator();
1021                     System.lineSeparator();
1022                     b = i;
1023                 }
1024             }
1025 
1026             System.lineSeparator();
1027             System.lineSeparator();
1028         }
1029         catch (Exception e) {
1030             System.lineSeparator();
1031         }
1032         finally {
1033             System.identityHashCode(b);
1034         }
1035 
1036         int c = 0; // violation 'Distance between .* declaration and its first usage is 3.'
1037         System.lineSeparator();
1038         System.lineSeparator();
1039         System.lineSeparator();
1040 
1041         if (false) {
1042 
1043         }
1044         else if (c == 1) {
1045             if (c != 2) {
1046                 System.lineSeparator();
1047             }
1048 
1049             System.identityHashCode(c);
1050         }
1051         else if (c == 2) {
1052             System.identityHashCode(c);
1053         }
1054     }
1055 
1056     private void launch(Integer number ) {
1057         String myInt = ( number.toString() + '\0' );
1058         boolean result = false;
1059         if (number == 123)
1060             result = true;
1061     }
1062 
1063     static int field;
1064 
1065     private void n() {
1066         long a = 0; // violation 'Distance between .* declaration and its first usage is 4.'
1067 
1068         New5.field = 1;
1069         New5.field = 2;
1070         New5.field = 3;
1071         New5.field = (int)a;
1072     }
1073 
1074 }