001: package com.puppycrawl.tools.checkstyle;
002:
003: /**
004: * Describe class InputMagicNumber
005: * @author Rick Giles
006: * @version 6-May-2003
007: */
008: public class InputMagicNumber {
009: public void magicMethod() {
010: //constants, ignore
011: final int INT_CONST = 101;
012: final long LONG_CONST1 = 100L;
013: final long LONG_CONST2 = 100l;
014: final float FLOAT_CONST1 = 1.5F;
015: final float FLOAT_CONST2 = 1.5f;
016: final double DOUBLE_CONST1 = 1.5D;
017: final double DOUBLE_CONST2 = 1.5d;
018: final double DOUBLE_CONST3 = 1.5;
019:
020: //ignore by default
021: int int_var1 = 1;
022: int int_var2 = (2);
023: long long_var1 = 0L;
024: long long_var2 = 0l;
025: double double_var1 = 0D;
026: double double_var2 = 0d;
027:
028: int[] int_array = new int[2];
029:
030: int_var1 = 1 + 2;
031: int_var1 += 1;
032: double_var1 = 1.0 + 2.0;
033:
034: for (int i = 0; i < 2; i++)
035: ;
036:
037: if (1 < 2)
038: ;
039:
040: if (1.0 < 2.0)
041: ;
042:
043: //magic numbers
044: int int_magic1 = 3;
045: double double_magic1 = 1.5;
046: int int_magic2 = (3 + 4);
047:
048: int_array = new int[3];
049:
050: int_magic1 += 3;
051: double_magic1 *= 1.5;
052:
053: for (int j = 3; j < 5; j += 3) {
054: int_magic1++;
055: }
056:
057: if (int_magic1 < 3) {
058: int_magic1 = int_magic1 + 3;
059: }
060:
061: //octal
062: int octalVar0 = 00;
063: int octalVar8 = 010;
064: int octalVar9 = 011;
065:
066: long longOctalVar8 = 010L;
067: long longOctalVar9 = 011l;
068:
069: //hex
070: int hexVar0 = 0x0;
071: int hexVar16 = 0x10;
072: int hexVar17 = 0X011;
073: long longHexVar0 = 0x0L;
074: long longHexVar16 = 0x10L;
075: long longHexVar17 = 0X11l;
076: }
077: }
078:
079: interface Blah {
080: int LOW = 5;
081: int HIGH = 78;
082: }
083:
084: class ArrayMagicTest {
085: private static final int[] NONMAGIC = { 3 };
086: private int[] magic = { 3 };
087: private static final int[][] NONMAGIC2 = { { 1 }, { 2 }, { 3 } };
088: }
089:
090: /** test long hex */
091: class LongHex {
092: long l = 0xffffffffL;
093: }
094:
095: /** test signed values */
096: class Signed {
097: public static final int CONST_PLUS_THREE = +3;
098: public static final int CONST_MINUS_TWO = -2;
099: private int mPlusThree = +3;
100: private int mMinusTwo = -2;
101: private double mPlusDecimal = +3.5;
102: private double mMinusDecimal = -2.5;
103: }
104:
105: /** test octal and hex negative values */
106: class NegativeOctalHex {
107: private int hexIntMinusOne = 0xffffffff;
108: private long hexLongMinusOne = 0xffffffffffffffffL;
109: private long hexIntMinValue = 0x80000000;
110: private long hexLongMinValue = 0x8000000000000000L;
111: private int octalIntMinusOne = 037777777777;
112: private long octalLongMinusOne = 01777777777777777777777L;
113: private long octalIntMinValue = 020000000000;
114: private long octalLongMinValue = 01000000000000000000000L;
115: }
116:
117: class Cast {
118: public static final int TESTINTVAL = (byte) 0x80;
119: }
120:
121: class ComplexAndFlagged {
122: public static final java.util.List MYLIST = new java.util.ArrayList() {
123: public int size() {
124: // should be flagged although technically inside const definition
125: return 378;
126: }
127: };
128: }
129:
130: class ComplexButNotFlagged {
131: // according to user feedback this is typical code that should not be flagged
132: // (at least in the default configuration of MagicNumberCheck)
133: public static final Integer DEFAULT_INT = new Integer(27);
134: public static final int SECS_PER_DAY = 24 * 60 * 60;
135: public static final javax.swing.border.Border STD_BORDER = javax.swing.BorderFactory
136: .createEmptyBorder(3, 3, 3, 3);
137: }
138:
139: enum MyEnum {
140: A(3), B(54);
141:
142: private MyEnum(int value) {
143:
144: }
145: }
|