summaryrefslogtreecommitdiffstats
path: root/src/java/com/sun
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/sun')
-rw-r--r--src/java/com/sun/gluegen/CodeGenUtils.java175
-rw-r--r--src/java/com/sun/gluegen/JavaEmitter.java15
-rw-r--r--src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java18
3 files changed, 105 insertions, 103 deletions
diff --git a/src/java/com/sun/gluegen/CodeGenUtils.java b/src/java/com/sun/gluegen/CodeGenUtils.java
index a558c66..ac2e033 100644
--- a/src/java/com/sun/gluegen/CodeGenUtils.java
+++ b/src/java/com/sun/gluegen/CodeGenUtils.java
@@ -36,110 +36,107 @@
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-
package com.sun.gluegen;
import java.io.*;
import java.util.*;
public class CodeGenUtils {
- /**
- * Given a java package name (e.g., "java.lang"), return the package as a
- * directory path (i.e., "java/lang").
- */
- public static String packageAsPath(String packageName) {
- String path = packageName.replace('.', File.separatorChar);
- //System.out.println("Converted package [" + packageName + "] to path [" + path +"]");
- return path;
- }
- /**
- * @param generator the object that is emitting the autogenerated code. If
- * null, the generator will not be mentioned in the warning message.
- */
- public static void emitAutogeneratedWarning(PrintWriter w, Object generator) {
- w.print("/* !---- DO NOT EDIT: This file autogenerated ");
- if (generator != null) {
- w.print("by ");
- w.print(packageAsPath(generator.getClass().getName()));
- w.print(".java ");
+ /**
+ * Given a java package name (e.g., "java.lang"), return the package as a
+ * directory path (i.e., "java/lang").
+ */
+ public static String packageAsPath(String packageName) {
+ String path = packageName.replace('.', File.separatorChar);
+ //System.out.println("Converted package [" + packageName + "] to path [" + path +"]");
+ return path;
}
- w.print("on ");
- w.print((new Date()).toString());
- w.println(" ----! */");
- w.println();
- }
-
- /**
- * Emit the opening headers for one java class/interface file.
- */
- public static void emitJavaHeaders( PrintWriter w,
- String packageName,
- String className,
- String gluegenRuntimePackage,
- boolean isClassNotInterface,
- String[] imports,
- String[] accessModifiers,
- String[] interfaces,
- String classExtended,
- EmissionCallback classDocComment) throws IOException {
- w.println("package " + packageName + ";");
- w.println();
- for (int i = 0; imports != null && i < imports.length; ++i) {
- w.print("import ");
- w.print(imports[i]);
- w.println(';');
+ /**
+ * @param generator the object that is emitting the autogenerated code. If
+ * null, the generator will not be mentioned in the warning message.
+ */
+ public static void emitAutogeneratedWarning(PrintWriter w, Object generator) {
+ w.print("/* !---- DO NOT EDIT: This file autogenerated ");
+ if (generator != null) {
+ w.print("by ");
+ w.print(packageAsPath(generator.getClass().getName()));
+ w.print(".java ");
+ }
+ w.print("on ");
+ w.print((new Date()).toString());
+ w.println(" ----! */");
+ w.println();
}
- w.println("import " + gluegenRuntimePackage + ".*;");
- w.println();
+ /**
+ * Emit the opening headers for one java class/interface file.
+ */
+ public static void emitJavaHeaders(PrintWriter w,
+ String packageName,
+ String className,
+ boolean isClassNotInterface,
+ List<String> imports,
+ String[] accessModifiers,
+ String[] interfaces,
+ String classExtended,
+ EmissionCallback classDocComment) throws IOException {
+ w.println("package " + packageName + ";");
+ w.println();
- if (classDocComment != null)
- {
- classDocComment.emit(w);
- }
-
- for (int i = 0; accessModifiers != null && i < accessModifiers.length; ++i) {
- w.print(accessModifiers[i]);
- w.print(' ');
- }
+ for (String imp : imports) {
+ w.print("import ");
+ w.print(imp);
+ w.println(';');
+ }
- if (isClassNotInterface) {
- w.print("class ");
- w.print(className);
- w.print(' ');
- if (classExtended != null) {
- w.print("extends ");
- w.print(classExtended);
- }
- }
- else {
- if (classExtended != null) {
- throw new IllegalArgumentException(
- "Autogenerated interface class " + className +
- " cannot extend class " + classExtended);
- }
- w.print("interface ");
- w.print(className);
- w.print(' ');
- }
+ w.println();
- for (int i = 0; interfaces != null && i < interfaces.length; ++i) {
- if (i == 0) { w.print(isClassNotInterface ? "implements " : "extends "); }
- w.print(interfaces[i]);
- if (i < interfaces.length-1) { w.print(", "); }
- }
+ if (classDocComment != null) {
+ classDocComment.emit(w);
+ }
+
+ for (int i = 0; accessModifiers != null && i < accessModifiers.length; ++i) {
+ w.print(accessModifiers[i]);
+ w.print(' ');
+ }
+
+ if (isClassNotInterface) {
+ w.print("class ");
+ w.print(className);
+ w.print(' ');
+ if (classExtended != null) {
+ w.print("extends ");
+ w.print(classExtended);
+ }
+ } else {
+ if (classExtended != null) {
+ throw new IllegalArgumentException("Autogenerated interface class " + className + " cannot extend class " + classExtended);
+ }
+ w.print("interface ");
+ w.print(className);
+ w.print(' ');
+ }
- w.println();
- w.println('{');
- }
+ for (int i = 0; interfaces != null && i < interfaces.length; ++i) {
+ if (i == 0) {
+ w.print(isClassNotInterface ? "implements " : "extends ");
+ }
+ w.print(interfaces[i]);
+ if (i < interfaces.length - 1) {
+ w.print(", ");
+ }
+ }
- //-----------------------------------------
+ w.println('{');
+ }
+
+ //-----------------------------------------
+ /** A class that emits source code of some time when activated. */
+ public interface EmissionCallback {
- /** A class that emits source code of some time when activated. */
- public interface EmissionCallback {
- /** Emit appropriate source code through the given writer. */
- public void emit(PrintWriter output);
- }
+ /** Emit appropriate source code through the given writer. */
+ public void emit(PrintWriter output);
+ }
}
diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java
index fc8ab34..240bb55 100644
--- a/src/java/com/sun/gluegen/JavaEmitter.java
+++ b/src/java/com/sun/gluegen/JavaEmitter.java
@@ -870,6 +870,7 @@ public class JavaEmitter implements GlueEmitter {
writer.println();
writer.println("import java.nio.*;");
writer.println();
+
writer.println("import " + cfg.gluegenRuntimePackage() + ".*;");
writer.println("import " + DynamicLookupHelper.class.getPackage().getName() + ".*;");
writer.println("import " + Buffers.class.getPackage().getName() + ".*;");
@@ -905,6 +906,7 @@ public class JavaEmitter implements GlueEmitter {
writer.println(" StructAccessor accessor;");
writer.println();
}
+
writer.println(" public static int size() {");
if (doBaseClass) {
writer.println(" if (Platform.is32Bit()) {");
@@ -1582,7 +1584,13 @@ public class JavaEmitter implements GlueEmitter {
*/
protected void emitAllFileHeaders() throws IOException {
try {
+ List<String> imports = new ArrayList<String>(cfg.imports());
+ imports.add(cfg.gluegenRuntimePackage()+".*");
+ imports.add(DynamicLookupHelper.class.getPackage().getName()+".*");
+ imports.add(Buffers.class.getPackage().getName()+".*");
+
if (cfg.allStatic() || cfg.emitInterface()) {
+
String[] interfaces;
List<String> userSpecifiedInterfaces = null;
if (cfg.emitInterface()) {
@@ -1614,8 +1622,8 @@ public class JavaEmitter implements GlueEmitter {
javaWriter,
cfg.packageName(),
cfg.className(),
- cfg.gluegenRuntimePackage(),
- cfg.allStatic() ? true : false, cfg.imports().toArray(new String[] {}),
+ cfg.allStatic() ? true : false,
+ imports,
accessModifiers,
interfaces,
cfg.extendedParentClass(cfg.className()),
@@ -1657,9 +1665,8 @@ public class JavaEmitter implements GlueEmitter {
javaImplWriter,
cfg.implPackageName(),
cfg.implClassName(),
- cfg.gluegenRuntimePackage(),
true,
- cfg.imports().toArray(new String[] {}),
+ imports,
accessModifiers,
interfaces,
cfg.extendedParentClass(cfg.implClassName()),
diff --git a/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java b/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java
index 9750c13..54aa759 100644
--- a/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java
+++ b/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java
@@ -43,6 +43,7 @@ import com.sun.gluegen.*;
import java.lang.reflect.*;
import java.io.*;
import java.util.*;
+import java.util.ArrayList;
public class BuildComposablePipeline {
@@ -348,22 +349,19 @@ public class BuildComposablePipeline {
clazzList.add(prologClassOpt);
}
- String[] importNames = new String[clazzList.size() + 2];
- {
- int i = 0;
- importNames[i++] = "java.io.*";
- importNames[i++] = "javax.media.opengl.*";
- for (Iterator<Class<?>> iter = clazzList.iterator(); iter.hasNext();) {
- importNames[i++] = iter.next().getName();
- }
+ ArrayList<String> imports = new ArrayList<String>();
+ imports.add("java.io.*");
+ imports.add("javax.media.opengl.*");
+ imports.add("com.jogamp.gluegen.runtime.*");
+ for (Class<?> clasS : clazzList) {
+ imports.add(clasS.getName());
}
CodeGenUtils.emitJavaHeaders(output,
outputPackage,
outputClassName,
- "com.jogamp.gluegen.runtime", // FIXME: should make configurable
true,
- importNames,
+ imports,
new String[]{"public"},
ifNames,
null,