Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/jshell/FileManagerTest.java
40931 views
1
/*
2
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test 8173845
26
* @summary test custom file managers
27
* @build KullaTesting TestingInputStream
28
* @run testng FileManagerTest
29
*/
30
31
32
import java.io.File;
33
import java.io.IOException;
34
35
import java.util.Set;
36
import javax.tools.ForwardingJavaFileManager;
37
import javax.tools.JavaFileObject;
38
import javax.tools.JavaFileObject.Kind;
39
import javax.tools.StandardJavaFileManager;
40
import org.testng.annotations.BeforeMethod;
41
import org.testng.annotations.Test;
42
43
import static org.testng.Assert.assertTrue;
44
45
@Test
46
public class FileManagerTest extends KullaTesting {
47
48
boolean encountered;
49
50
class MyFileManager extends ForwardingJavaFileManager<StandardJavaFileManager>
51
implements StandardJavaFileManager {
52
53
protected MyFileManager(StandardJavaFileManager fileManager) {
54
super(fileManager);
55
}
56
57
@Override
58
public Iterable<JavaFileObject> list(Location location,
59
String packageName,
60
Set<Kind> kinds,
61
boolean recurse)
62
throws IOException {
63
//System.out.printf("list(%s, %s, %s, %b)\n",
64
// location, packageName, kinds, recurse);
65
if (packageName.equals("java.lang.reflect")) {
66
encountered = true;
67
}
68
return fileManager.list(location, packageName, kinds, recurse);
69
}
70
71
@Override
72
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {
73
return fileManager.getJavaFileObjectsFromFiles(files);
74
}
75
76
@Override
77
public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
78
return fileManager.getJavaFileObjects(files);
79
}
80
81
@Override
82
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
83
return fileManager.getJavaFileObjectsFromStrings(names);
84
}
85
86
@Override
87
public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) {
88
return fileManager.getJavaFileObjects(names);
89
}
90
91
@Override
92
public void setLocation(Location location, Iterable<? extends File> files) throws IOException {
93
fileManager.setLocation(location, files);
94
}
95
96
@Override
97
public Iterable<? extends File> getLocation(Location location) {
98
return fileManager.getLocation(location);
99
}
100
101
}
102
103
@BeforeMethod
104
@Override
105
public void setUp() {
106
setUp(b -> b.fileManager(fm -> new MyFileManager(fm)));
107
}
108
109
public void testSnippetMemberAssignment() {
110
assertEval("java.lang.reflect.Array.get(new String[1], 0) == null");
111
assertTrue(encountered, "java.lang.reflect not encountered");
112
}
113
114
}
115
116