< prev index next >
jaxws/src/jdk.xml.bind/share/classes/com/sun/codemodel/internal/JCodeModel.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 37,47 ****
import java.util.Map;
import com.sun.codemodel.internal.writer.FileCodeWriter;
import com.sun.codemodel.internal.writer.ProgressCodeWriter;
-
/**
* Root of the code DOM.
*
* <p>
* Here's your typical CodeModel application.
--- 37,46 ----
*** 78,91 ****
* See {@link #_class(String, ClassType)}.
*/
public final class JCodeModel {
/** The packages that this JCodeWriter contains. */
! private HashMap<String,JPackage> packages = new HashMap<String,JPackage>();
/** All JReferencedClasses are pooled here. */
! private final HashMap<Class<?>,JReferencedClass> refClasses = new HashMap<Class<?>,JReferencedClass>();
/** Obtains a reference to the special "null" type. */
public final JNullType NULL = new JNullType(this);
// primitive types
--- 77,93 ----
* See {@link #_class(String, ClassType)}.
*/
public final class JCodeModel {
/** The packages that this JCodeWriter contains. */
! private final HashMap<String,JPackage> packages = new HashMap<>();
!
! /** Java module in {@code module-info.java} file. */
! private JModule module;
/** All JReferencedClasses are pooled here. */
! private final HashMap<Class<?>,JReferencedClass> refClasses = new HashMap<>();
/** Obtains a reference to the special "null" type. */
public final JNullType NULL = new JNullType(this);
// primitive types
*** 119,129 ****
public JCodeModel() {}
/**
! * Add a package to the list of packages to be generated
*
* @param name
* Name of the package. Use "" to indicate the root package.
*
* @return Newly generated package
--- 121,131 ----
public JCodeModel() {}
/**
! * Add a package to the list of packages to be generated.
*
* @param name
* Name of the package. Use "" to indicate the root package.
*
* @return Newly generated package
*** 135,144 ****
--- 137,190 ----
packages.put(name, p);
}
return p;
}
+ /**
+ * Creates and returns Java module to be generated.
+ * @param name The Name of Java module.
+ * @return New Java module.
+ */
+ public JModule _moduleInfo(final String name) {
+ return module = new JModule(name);
+ }
+
+ /**
+ * Returns existing Java module to be generated.
+ * @return Java module or {@code null} if Java module was not created yet.
+ */
+ public JModule _getModuleInfo() {
+ return module;
+ }
+
+ /**
+ * Creates Java module instance and adds existing packages with classes to the Java module info.
+ * Used to initialize and build Java module instance with existing packages content.
+ * @param name The Name of Java module.
+ * @param requires Requires directives to add.
+ * @throws IllegalStateException when Java module instance was not initialized.
+ */
+ public void _prepareModuleInfo(final String name, final String ...requires) {
+ _moduleInfo(name);
+ _updateModuleInfo(requires);
+ }
+
+ /**
+ * Adds existing packages with classes to the Java module info.
+ * Java module instance must exist before calling this method.
+ * Used to update Java module instance with existing packages content after it was prepared on client side.
+ * @param requires Requires directives to add.
+ * @throws IllegalStateException when Java module instance was not initialized.
+ */
+ public void _updateModuleInfo(final String ...requires) {
+ if (module == null) {
+ throw new IllegalStateException("Java module instance was not initialized yet.");
+ }
+ module._exports(packages.values(), false);
+ module._requires(requires);
+ }
+
public final JPackage rootPackage() {
return _package("");
}
/**
*** 290,301 ****
* Generates Java source code.
*/
public void build( CodeWriter source, CodeWriter resource ) throws IOException {
JPackage[] pkgs = packages.values().toArray(new JPackage[packages.size()]);
// avoid concurrent modification exception
! for( JPackage pkg : pkgs )
pkg.build(source,resource);
source.close();
resource.close();
}
/**
--- 336,351 ----
* Generates Java source code.
*/
public void build( CodeWriter source, CodeWriter resource ) throws IOException {
JPackage[] pkgs = packages.values().toArray(new JPackage[packages.size()]);
// avoid concurrent modification exception
! for( JPackage pkg : pkgs ) {
pkg.build(source,resource);
+ }
+ if (module != null) {
+ module.build(source);
+ }
source.close();
resource.close();
}
/**
< prev index next >