MCPcopy
hub / github.com/apache/groovy / Java9

Class Java9

src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java:59–1653  ·  view source on GitHub ↗

@deprecated Use org.codehaus.groovy.vmplugin.v17.Java17 instead. Groovy 6.0 requires JDK 17+.

Source from the content-addressed store, hash-verified

57 * @deprecated Use {@link org.codehaus.groovy.vmplugin.v17.Java17} instead. Groovy 6.0 requires JDK 17+.
58 */
59@Deprecated(since = "6.0.0", forRemoval = true)
60@SuppressWarnings("removal")
61public class Java9 extends Java8 {
62
63 /** {@inheritDoc} */
64 @Override
65 public int getVersion() {
66 return 9;
67 }
68
69 /** {@inheritDoc} */
70 @Override
71 public Class<?>[] getPluginDefaultGroovyMethods() {
72 Class<?>[] answer = super.getPluginDefaultGroovyMethods();
73
74 final int n = answer.length;
75 answer = Arrays.copyOf(answer, n + 1);
76 answer[n] = PluginDefaultGroovyMethods.class;
77
78 return answer;
79 }
80
81 /** {@inheritDoc} */
82 @Override
83 public Map<String, Set<String>> getDefaultImportClasses(final String[] packageNames) {
84 List<String> javaPackages = new ArrayList<>(4);
85 List<String> groovyPackages = new ArrayList<>(4);
86 for (String prefix : packageNames) {
87 String pn = prefix.substring(0, prefix.length() - 1).replace('.', '/');
88 if (pn.startsWith("java/")) {
89 javaPackages.add(pn);
90 } else if (pn.startsWith("groovy/")) {
91 groovyPackages.add(pn);
92 } else {
93 throw new GroovyBugError("unexpected package: " + pn);
94 }
95 }
96
97 Map<String, Set<String>> result = new LinkedHashMap<>(2048);
98 try (GroovyClassLoader gcl = new GroovyClassLoader(this.getClass().getClassLoader())) {
99 try {
100 // groovy-core (Java source)
101 URI gcjLocation = DefaultGroovyMethods.getLocation(gcl.loadClass("groovy.lang.GroovySystem")).toURI();
102 result.putAll(doFindClasses(gcjLocation, "groovy", groovyPackages));
103
104 // in production environment, groovy-core classes, e.g. `GroovySystem`(java class) and `ListenerLister`(groovy class) are all packaged in the groovy-core jar file,
105 // but in Groovy development environment, groovy-core classes are distributed in different directories
106 URI gcgLocation = DefaultGroovyMethods.getLocation(gcl.loadClass("groovy.beans.ListenerList")).toURI();
107 if (!gcjLocation.equals(gcgLocation)) {
108 result.putAll(doFindClasses(gcgLocation, "groovy", groovyPackages));
109 }
110 } finally {
111 result.putAll(doFindClasses(URI.create("jrt:/modules/java.base/"), "java", javaPackages));
112 }
113 } catch (Throwable ignore) {
114 Logger logger = Logger.getLogger(getClass().getName());
115 if (logger.isLoggable(Level.FINEST)) {
116 logger.finest("[WARNING] Failed to find default imported classes:\n" + DefaultGroovyMethods.asString(ignore));

Callers

nothing calls this directly

Calls 12

JAVA8_PACKAGESMethod · 0.95
isOpenMethod · 0.95
isExportedMethod · 0.95
forEachMethod · 0.80
mapMethod · 0.65
streamMethod · 0.65
getMethod · 0.65
addMethod · 0.65
nameMethod · 0.65
findAllMethod · 0.45
putIfAbsentMethod · 0.45
computeIfAbsentMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…