author | jlahoda |
Thu, 09 Oct 2014 10:08:52 +0200 | |
changeset 26993 | 513b2cae81c3 |
parent 26100 | bb7dd001d190 |
child 27552 | 8a4b2d3639c1 |
permissions | -rw-r--r-- |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
1 |
/* |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
4 |
* |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
8 |
* |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
14 |
* |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
18 |
* |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
21 |
* questions. |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
22 |
*/ |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
23 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
24 |
/* |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
25 |
* @test |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
26 |
* @bug 8042261 |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
27 |
* @summary Checking that deprecated attribute does not apply to classes of deprecated package. |
26100 | 28 |
* @library /tools/lib /tools/javac/lib ../lib |
29 |
* @build ToolBox TestBase TestResult InMemoryFileManager |
|
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
30 |
* @run main DeprecatedPackageTest |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
31 |
*/ |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
32 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
33 |
import com.sun.tools.classfile.Attribute; |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
34 |
import com.sun.tools.classfile.ClassFile; |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
35 |
import com.sun.tools.classfile.Deprecated_attribute; |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
36 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
37 |
public class DeprecatedPackageTest extends TestResult { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
38 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
39 |
private static final String[] sourceTest = new String[]{ |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
40 |
"package deprecated;\n" |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
41 |
+ "public class notDeprecated{}", |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
42 |
"package deprecated;\n" |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
43 |
+ "public interface notDeprecated{}", |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
44 |
"package deprecated;\n" |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
45 |
+ "public @interface notDeprecated{}", |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
46 |
"package deprecated;\n" |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
47 |
+ "public enum notDeprecated{}" |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
48 |
}; |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
49 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
50 |
private static final String CLASS_NAME = "deprecated.notDeprecated"; |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
51 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
52 |
private static final String PACKAGE_INFO = |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
53 |
"@Deprecated\n" + |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
54 |
"package deprecated;"; |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
55 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
56 |
public static void main(String[] args) throws TestFailedException { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
57 |
new DeprecatedPackageTest().test(); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
58 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
59 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
60 |
private void test() throws TestFailedException { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
61 |
try { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
62 |
for (String src : sourceTest) { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
63 |
test(PACKAGE_INFO, src); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
64 |
test(PACKAGE_INFO.replaceAll("@Deprecated", "/** @deprecated */"), src); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
65 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
66 |
} catch (Exception e) { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
67 |
addFailure(e); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
68 |
} finally { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
69 |
checkStatus(); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
70 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
71 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
72 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
73 |
private void test(String package_info, String src) { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
74 |
addTestCase(src); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
75 |
printf("Testing test case: \n%s\n", src); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
76 |
try { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
77 |
ClassFile cf = ClassFile.read(compile( |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
78 |
new String[]{"package-info.java", package_info}, |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
79 |
new String[]{"notDeprecated.java", src}) |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
80 |
.getClasses().get(CLASS_NAME).openInputStream()); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
81 |
Deprecated_attribute attr = |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
82 |
(Deprecated_attribute) cf.getAttribute(Attribute.Deprecated); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
83 |
assertNull(attr, "Class can not have deprecated attribute : " + CLASS_NAME); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
84 |
} catch (Exception e) { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
85 |
addFailure(e); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
86 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
87 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff
changeset
|
88 |
} |