java-gobject-introspection r172 - in trunk: . src src/org/gnome/gir/compiler



Author: walters
Date: Sat Feb  7 02:05:47 2009
New Revision: 172
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=172&view=rev

Log:
Further work on documentation generation

Added:
   trunk/src/org/gnome/gir/compiler/jclass-decl-head.st
   trunk/src/org/gnome/gir/compiler/jclass-toplevel.st
Modified:
   trunk/.classpath
   trunk/Makefile
   trunk/src/jgir-docgen.in
   trunk/src/org/gnome/gir/compiler/DocFactory.java
   trunk/wscript

Modified: trunk/.classpath
==============================================================================
--- trunk/.classpath	(original)
+++ trunk/.classpath	Sat Feb  7 02:05:47 2009
@@ -10,5 +10,7 @@
 	<classpathentry kind="lib" path="/usr/share/java/objectweb-asm/asm-tree.jar"/>
 	<classpathentry kind="lib" path="/usr/share/java/objectweb-asm/asm-util.jar"/>
 	<classpathentry kind="lib" path="/usr/share/java/gnu-getopt.jar"/>
+	<classpathentry kind="lib" path="/usr/share/java/stringtemplate.jar"/>
+	<classpathentry kind="lib" path="/usr/share/java/antlr.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile	(original)
+++ trunk/Makefile	Sat Feb  7 02:05:47 2009
@@ -2,4 +2,7 @@
 	python ./waf build
 
 install: all
-	python ./waf install --destdir=$(DESTDIR)
\ No newline at end of file
+	python ./waf install --destdir=$(DESTDIR)
+	
+clean:
+	python ./waf clean
\ No newline at end of file

Modified: trunk/src/jgir-docgen.in
==============================================================================
--- trunk/src/jgir-docgen.in	(original)
+++ trunk/src/jgir-docgen.in	Sat Feb  7 02:05:47 2009
@@ -14,7 +14,4 @@
 args.extend(java_opts)
 args.extend(['-cp', classpath, 'org.gnome.gir.compiler.DocFactory'])
 args.extend(sys.argv[1:])
-subprocess.check_call(args,
-                      stdout=sys.stdout,
-                      stderr=sys.stderr,
-                      close_fds=True)
+os.execvp(args[0], args)
\ No newline at end of file

Modified: trunk/src/org/gnome/gir/compiler/DocFactory.java
==============================================================================
--- trunk/src/org/gnome/gir/compiler/DocFactory.java	(original)
+++ trunk/src/org/gnome/gir/compiler/DocFactory.java	Sat Feb  7 02:05:47 2009
@@ -21,6 +21,8 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
+import org.antlr.stringtemplate.StringTemplate;
+import org.antlr.stringtemplate.StringTemplateGroup;
 import org.gnome.gir.repository.Repository;
 import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.Attribute;
@@ -45,9 +47,11 @@
 	}
 
 	private final Repository repo;
+	private final StringTemplateGroup templates;
 
 	private DocFactory(Repository repo) {
 		this.repo = repo;
+		this.templates = new StringTemplateGroup("templates");
 	}
 	
 	public static String join(String sep, List<String> components) {
@@ -61,7 +65,11 @@
 				builder.append(sep);
 		}
 		return builder.toString();
-	}	
+	}
+	
+	private StringTemplate getTemplate(String name) {
+		return templates.getInstanceOf("org/gnome/gir/compiler/" + name);		
+	}
 	
     private static String strAccess(final int access) {
     	List<String> modifiers = new ArrayList<String>();
@@ -87,9 +95,6 @@
 		if ((access & Opcodes.ACC_VOLATILE) != 0) {
 			modifiers.add("volatile");
 		}
-		if ((access & Opcodes.ACC_TRANSIENT) != 0) {
-			modifiers.add("transient");
-		}
 		if ((access & Opcodes.ACC_NATIVE) != 0) {
 			modifiers.add("native");
 		}
@@ -105,59 +110,85 @@
     	boolean isInterface;
     	boolean isEnum;
     	boolean isInner;
+    	boolean isAnonStub;
+    	
     	String clsName;
     	
 		public ClassJavafier(Writer out) {
 			this.out = out;
 		}
+		
+		private boolean skip() {
+			return isAnonStub;
+		}
 
 		@Override
 		public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
 			isInner = name.contains("$");
+			
+			if (!isInner) {
+				StringTemplate clsToplevel = getTemplate("jclass-toplevel");
+				clsToplevel.setAttribute("package", getPackage(name));
+				try {
+					String value = clsToplevel.toString();
+					out.write(value);
+				} catch (IOException e) {
+					throw new RuntimeException(e);
+				}
+				isAnonStub = false;
+			} else {
+				isAnonStub = name.contains("AnonStub");
+			}
+			
+			if (skip())
+				return;
+			
 			isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
 			isEnum = (access & Opcodes.ACC_ENUM) != 0;
 			clsName = stripInternals(name);
-			try {
-				out.write("package ");
-				out.write(getPackage(name));
-				out.write(";\n\n");
-				out.write(strAccess(access)); 
-				if (isInterface)
-					out.write(" interface ");
-				else if (isEnum)
-					out.write(" enum ");
+			if (isInner)
+				clsName = inner1(clsName);
+			
+			StringTemplate clsHeader = getTemplate("jclass-decl-head");			
+			clsHeader.setAttribute("access", strAccess(access));
+			String clsType;
+			if (isInterface)
+				clsType = "interface";
+			else if (isEnum)
+				clsType = "enum";
+			else
+				clsType = "class";
+			
+			String iname = stripInternals(name);
+			int innerIdx = iname.indexOf('$');
+			if (innerIdx > 0)
+				iname = iname.substring(innerIdx + 1);			
+			
+			clsHeader.setAttribute("clsType", clsType);
+			clsHeader.setAttribute("clsName", iname);
+
+			if (!isInterface && !isEnum) {
+				clsHeader.setAttribute("extends", replaceInternals(superName));
+			}
+			if (interfaces != null && interfaces.length > 0) {
+				if (!isInterface)
+					clsHeader.setAttribute("implementsType", "implements");
 				else
-					out.write(" class ");
-				String iname = stripInternals(name);
-				int innerIdx = iname.indexOf('$');
-				if (innerIdx > 0)
-					iname = iname.substring(innerIdx + 1);
-				out.write(iname);
-				if (!isInterface && !isEnum) {
-					out.write(" extends ");
-					out.write(replaceInternals(superName));
-				}
-				if (interfaces != null && interfaces.length > 0) {
-					if (!isInterface)
-						out.write(" implements ");
-					else
-						out.write(" extends ");
-					List<String> ifaces = new ArrayList<String>();
-					for (String iface : Arrays.asList(interfaces)) {
-						ifaces.add(replaceInternals(iface));
-					}
-					out.write(join(",", ifaces));
-				}
-				out.write(" {\n");
-				
-				if (isEnum) {
-					out.write("FOO;\n\n");
-				}
+					clsHeader.setAttribute("implementsType", "extends");
+				List<String> ifaces = new ArrayList<String>();
+				for (String iface : Arrays.asList(interfaces)) {
+					ifaces.add(replaceInternals(iface));
+				}				
+				clsHeader.setAttribute("implements", ifaces);
+			}
+			try {
+				String value = clsHeader.toString();
+				out.write(value);
 			} catch (IOException e) {
 				throw new RuntimeException(e);
 			}
 		}
-
+		
 		@Override
 		public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) {
 			return null;
@@ -172,6 +203,8 @@
 		}
 		
 		public void close() {
+			if (skip())
+				return;
     		try {
 				out.write("\n}\n\n");
 			} catch (IOException e) {
@@ -192,6 +225,11 @@
 		public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
 			if (name.equals("<clinit>") || (access & Opcodes.ACC_PRIVATE) != 0)
 				return null;
+			if (skip())
+				return null;
+			/* Skip enum methods for now, a lot of the stuff is enum internals */
+			if (isEnum)
+				return null;
 			Type[] args = Type.getArgumentTypes(descriptor);
 			Type retType = Type.getReturnType(descriptor);
 			try {
@@ -262,14 +300,26 @@
     	return path.substring(0, idx).replace('/', '.');    	
     }
     
-    private static final String stripInternals(String path) {
-    	int idx = path.lastIndexOf('/');
-    	String name = path.substring(idx+1);
-    	idx = name.indexOf('$');
+    private static final String outerClass(String name) {
+    	int idx = name.indexOf('$');
     	if (idx < 0)
     		return name;
-    	
-    	return name.substring(idx+1);
+    	return name.substring(0, idx);	
+    }
+    
+    private static final String inner1(String name) {
+    	int idx = name.indexOf('$');
+    	if (idx < 0)
+    		return null;
+    	int nextIdx = name.indexOf('$', idx+1);
+    	if (nextIdx < 0)
+    		return name.substring(idx+1);
+    	return name.substring(idx+1, nextIdx);
+    }
+    
+    private static final String stripInternals(String path) {
+    	int idx = path.lastIndexOf('/');
+    	return path.substring(idx+1);
     }
     
     private static final String replaceInternals(String path) {
@@ -285,7 +335,8 @@
 		for (ZipEntry entry : entries) {
 			if (entry.getName().contains("$"))
 				continue;
-			String name = stripInternals(entry.getName().replace(".class", ""));			
+			String fullName = entry.getName().replace(".class", "");
+			String name = outerClass(stripInternals(fullName));
 			
 			File javaOutPath = new File(outpath, entry.getName().replace(".class", ".java"));
 			javaOutPath.getParentFile().mkdirs();
@@ -298,12 +349,16 @@
 			ClassJavafier visitor = new ClassJavafier(javaOut);
 
 			cv.accept(visitor, 0);
-			
-			String innerPrefix = name + "$";
+
 			/* Load its inner classes */
+			String innerPrefix = fullName + "$";
 			for (ZipEntry subEntry : entries) {
-				String innerName = stripInternals(subEntry.getName().replace(".class", ""));
-				if (!innerName.startsWith(innerPrefix))
+				if (!subEntry.getName().startsWith(innerPrefix))
+					continue;
+				System.err.println("write " + subEntry);
+				String innerStripped = stripInternals(subEntry.getName().replace(".class", ""));
+				String innerStrippedSuffix = innerStripped.substring(name.length()+1);
+				if (innerStrippedSuffix.contains("$"))
 					continue;
 				
 				InputStream innerInput = zf.getInputStream(subEntry);

Added: trunk/src/org/gnome/gir/compiler/jclass-decl-head.st
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/compiler/jclass-decl-head.st	Sat Feb  7 02:05:47 2009
@@ -0,0 +1,2 @@
+$access$ $clsType$ $clsName$ $if(extends)$extends $extends$$endif$ $if(implementsType)$$implementsType$ $implements; separator=", "$$endif$ {
+$\n$

Added: trunk/src/org/gnome/gir/compiler/jclass-toplevel.st
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/compiler/jclass-toplevel.st	Sat Feb  7 02:05:47 2009
@@ -0,0 +1,6 @@
+package $package$;
+
+import gobject.runtime.*;
+import com.sun.jna.*;
+$\n$
+$\n$

Modified: trunk/wscript
==============================================================================
--- trunk/wscript	(original)
+++ trunk/wscript	Sat Feb  7 02:05:47 2009
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 # -*- coding: utf-8; indent-tabs-mode: nil; python-indent: 2 -*-
 
-import os, glob, shutil
+import os, glob, shutil, re
 
 import Task,TaskGen,Node
 from TaskGen import *
@@ -72,15 +72,33 @@
   conf.find_jpackage_jar('jna')
   conf.find_jpackage_jar('junit')
   conf.find_jpackage_jar('gnu.getopt')
+  conf.find_jpackage_jar('stringtemplate')
+  conf.find_jpackage_jar('antlr')
   print "Using CLASSPATH: %r" % (conf.env['CLASSPATH'],)
 
+# feature('jar')
+# before('apply_java')
+#def create_jar(self, name, regexp='.*'):
+#  # see wafadmin/Tools/java.py line 81
+#  tsk = self.create_task('jar_create')
+#  r = re.compile(regexp)
+#  def acc(node, name):
+#    return r.search(name) > -1
+#  def prune(node, name):
+#    return False
+#  inputs = self.path.find_dir(self.source_root).find_iter_impl(dir=False, accept_name=acc, is_prune=prune)
+#  tsk.set_inputs(inputs)
+#  tsk.set_outputs(self.path.find_or_declare(name))
+
 def build(bld):
-  jsrc = bld.new_task_gen(features='java',
+  srcroot = bld.path.find_dir('src')
+  templates = ['jclass-toplevel.st', 'jclass-decl-head.st']
+  jsrc = bld.new_task_gen(features='java jar',
                           name='jsrc',
                           install_path = '${PREFIX}/share/java',
-                          source_root = 'src',
-                          jarname = 'jgir.jar')
-  bld.install_files('${PREFIX}/share/java', 'jgir.jar')
+                          jarname = 'jgir.jar',
+                          jaropts = '-C default/src . ' + ''.join([' -C ../src/ org/gnome/gir/compiler/' + x for x in templates]), 
+                          source_root = 'src')
 
   full_cp = bld.env['CLASSPATH'] + ':' + bld.env['PREFIX'] + '/share/java/jgir.jar'
   compscript = bld.new_task_gen('subst')
@@ -104,7 +122,9 @@
   compscript.source = 'src/jgir-docgen.in'
   compscript.target = 'jgir-docgen'
   compscript.dict = {'CLASSPATH': full_cp, 'PREFIX': bld.env['PREFIX'],
-                     'TYPELIBDIR': bld.env['typelibdir'], 'GIRDIR': bld.env['girdir']}  
+                     'TYPELIBDIR': bld.env['typelibdir'], 'GIRDIR': bld.env['girdir']}
+  
+  bld.install_files('${PREFIX}/share/java', 'jgir.jar')  
 
   #openjdkdir = glob.glob('/usr/share/javadoc/java-1.6*openjdk/api')[0]
   #jnadir = glob.glob('/usr/share/javadoc/jna-*')[0]



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]