langtools/test/tools/javac/linenumbers/NestedLineNumberTest.java
author alundblad
Wed, 26 Aug 2015 09:02:02 +0200
changeset 32337 c9d3ab9f601c
parent 30846 2b3f379840f0
child 32338 8b2183276f84
permissions -rw-r--r--
8133671: langtools tests have bad license Summary: Dropped classpath exception from copyright notice in tests. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27230
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27230
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
27230
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
     4
 *
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32337
c9d3ab9f601c 8133671: langtools tests have bad license
alundblad
parents: 30846
diff changeset
     7
 * published by the Free Software Foundation.
27230
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
     8
 *
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    14
 *
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    18
 *
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    21
 * questions.
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    22
 */
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    23
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    24
/*
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    25
 * @test
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    26
 * @bug 8061778
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    27
 * @summary  Wrong LineNumberTable for default constructors
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    28
 * @modules jdk.jdeps/com.sun.tools.classfile
27230
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    29
 */
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    30
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    31
import com.sun.tools.classfile.ClassFile;
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    32
import com.sun.tools.classfile.ConstantPoolException;
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    33
import com.sun.tools.classfile.Method;
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    34
import com.sun.tools.classfile.Attribute;
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    35
import com.sun.tools.classfile.Code_attribute;
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    36
import com.sun.tools.classfile.LineNumberTable_attribute;
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    37
import com.sun.tools.classfile.LineNumberTable_attribute.Entry;
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    38
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    39
import java.io.IOException;
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    40
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    41
public class NestedLineNumberTest {
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    42
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    44
        Entry[] lines = findEntries();
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    45
        if (lines == null || lines.length != 1) {
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    46
            int found = lines == null ? 0 : lines.length;
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    47
            error(String.format("LineNumberTable contains wrong number of entries - expected %d, found %d", 1, found));
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    48
        }
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    49
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    50
        int line = lines[0].line_number;
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27230
diff changeset
    51
        if (line != 79) {
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27230
diff changeset
    52
            error(String.format("LineNumberTable contains wrong line number - expected %d, found %d", 79, line));
27230
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    53
        }
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    54
    }
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    55
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    56
    static Entry[] findEntries() throws IOException, ConstantPoolException {
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    57
        ClassFile self = ClassFile.read(NestedLineNumberTest.Test.class.getResourceAsStream("NestedLineNumberTest$Test.class"));
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    58
        for (Method m : self.methods) {
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    59
            if ("<init>".equals(m.getName(self.constant_pool))) {
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    60
                Code_attribute code_attribute = (Code_attribute)m.attributes.get(Attribute.Code);
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    61
                for (Attribute at : code_attribute.attributes) {
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    62
                    if (Attribute.LineNumberTable.equals(at.getName(self.constant_pool))) {
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    63
                        return ((LineNumberTable_attribute)at).line_number_table;
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    64
                    }
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    65
                }
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    66
            }
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    67
        }
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    68
        return null;
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    69
    }
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    70
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    71
    static void error(String msg) {
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    72
        throw new AssertionError(msg);
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    73
    }
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    74
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    75
    // The default constructor in this class should get only one LineNumberTable entry,
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    76
    // pointing to the first line of the declaration of class Test.
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    77
    static class Test {
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    78
        static class Empty { }
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    79
    }
361efbfa3079 8061778: Wrong LineNumberTable for default constructors
mcimadamore
parents:
diff changeset
    80
}