langtools/test/tools/javac/literals/BadUnderscoreLiterals.java
author ssides
Wed, 09 Jul 2014 15:14:06 +0400
changeset 25760 7955db32d6b0
parent 7335 8b390fd27190
child 30716 1bbdff43424d
permissions -rw-r--r--
8046597: fix doclint issues in swing classes, part 4 of 4 Reviewed-by: pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3895
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     1
/*
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     2
 * @test /nodynamiccopyright/
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     3
 * @bug 6860973
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     4
 * @summary Project Coin: underscores in literals
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     5
 *
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     6
 * @compile/fail BadUnderscoreLiterals.java
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     7
 * @compile/fail/ref=BadUnderscoreLiterals.7.out -XDrawDiagnostics BadUnderscoreLiterals.java
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     8
 *
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
     9
 * @compile/fail -source 6 BadUnderscoreLiterals.java
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 3895
diff changeset
    10
 * @compile/fail/ref=BadUnderscoreLiterals.6.out -XDrawDiagnostics -source 6 -Xlint:-options BadUnderscoreLiterals.java
3895
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    11
 */
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    12
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    13
public class BadUnderscoreLiterals {
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    14
    int valid = 1_1;            // valid literal; illegal in -source 6
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    15
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    16
    // test zero
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    17
    int z1 = _0;                // valid (but undefined) variable
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    18
    int z2 = 0_;                // trailing underscore
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    19
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    20
    // test simple (decimal) integers
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    21
    int i1 = _1_2_3;            // valid (but undefined) variable
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    22
    int i2 = 1_2_3_;            // trailing underscore
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    23
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    24
    // test binary integers
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    25
    int b1 = 0b_0;              // leading underscore after radix
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    26
    int b2 = 0b0_;              // trailing underscore
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    27
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    28
    // test hexadecimal integers
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    29
    int x1 = 0x_0;              // leading underscore after radix
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    30
    int x2 = 0x0_;              // trailing underscore
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    31
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    32
    // test floating point numbers
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    33
    float f1 = 0_.1;            // trailing underscore before decimal point
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    34
    float f2 = 0._1;            // leading underscore after decimal point
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    35
    float f3 = 0.1_;            // trailing underscore
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    36
    float f4 = 0.1_e0;          // trailing underscore before exponent
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    37
    float f5 = 0e_1;            // leading underscore in exponent
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    38
    float f6 = 0e1_;            // trailing underscore in exponent
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    39
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    40
    // hexadecimal floating point
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    41
    float xf1 = 0x_0.1p0;       // leading underscore after radix
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    42
    float xf2 = 0x0_.1p0;       // trailing underscore before decimal point
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    43
    float xf3 = 0x0._1p0;       // leading underscore after decimal point
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    44
    float xf4 = 0x0.1_p0;       // trailing underscore before exponent
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    45
    float xf5 = 0x0p_1;         // leading underscore after exponent
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    46
    float xf6 = 0x0p1_;         // trailing underscore
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    47
}
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents:
diff changeset
    48