Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GIR java-gnome WIP - week 30
diff --git a/configure b/configure
index 0d1b791..17fd71c 100755
--- a/configure
+++ b/configure
@@ -971,6 +971,7 @@ if ($os eq "gentoo") {
"/usr/share/gir-1.0/Gio-2.0.gir",
"/usr/share/gir-1.0/GLib-2.0.gir",
"/usr/share/gir-1.0/Gtk-3.0.gir",
+ "/usr/share/gir-1.0/GtkSource-3.0.gir",
"/usr/share/gir-1.0/Notify-0.7.gir",
"/usr/share/gir-1.0/Pango-1.0.gir",
"/usr/share/gir-1.0/Rsvg-2.0.gir");
diff --git a/src/bindings/org/gnome/gdk/DragAction.java b/src/bindings/org/gnome/gdk/DragAction.java
index a55d704..3b068d9 100644
--- a/src/bindings/org/gnome/gdk/DragAction.java
+++ b/src/bindings/org/gnome/gdk/DragAction.java
@@ -32,7 +32,7 @@
*/
package org.gnome.gdk;
-import org.freedesktop.bindings.Constant;
+import org.freedesktop.bindings.Flag;
/*
* FIXME this is a placeholder stub for what will become the public API for
@@ -42,7 +42,7 @@ import org.freedesktop.bindings.Constant;
* are made about this class until it has been reviewed by a hacker and this
* comment has been replaced.
*/
-public final class DragAction extends Constant
+public final class DragAction extends Flag
{
private DragAction(int ordinal, String nickname) {
super(ordinal, nickname);
diff --git a/src/bindings/org/gnome/gtk/JunctionSides.java b/src/bindings/org/gnome/gtk/JunctionSides.java
index 0e917f1..f150f2b 100644
--- a/src/bindings/org/gnome/gtk/JunctionSides.java
+++ b/src/bindings/org/gnome/gtk/JunctionSides.java
@@ -1,7 +1,7 @@
/*
* java-gnome, a UI library for writing GTK and GNOME programs from Java!
*
- * Copyright © 2011 Operational Dynamics Consulting, Pty Ltd and Others
+ * Copyright © 2011-2013 Operational Dynamics Consulting, Pty Ltd and Others
*
* The code in this file, and the program it is a part of, is made available
* to you by its authors as open source software: you can redistribute it
@@ -32,7 +32,7 @@
*/
package org.gnome.gtk;
-import org.freedesktop.bindings.Constant;
+import org.freedesktop.bindings.Flag;
/**
* Constants that describe how a rendered element connects to adjacent
@@ -41,7 +41,7 @@ import org.freedesktop.bindings.Constant;
* @author Guillaume Mazoyer
* @since 4.1.2
*/
-public final class JunctionSides extends Constant
+public final class JunctionSides extends Flag
{
public JunctionSides(int ordinal, String nickname) {
super(ordinal, nickname);
diff --git a/src/bindings/org/gnome/gtk/RegionFlags.java b/src/bindings/org/gnome/gtk/RegionFlags.java
index d5d0f4a..3283ffc 100644
--- a/src/bindings/org/gnome/gtk/RegionFlags.java
+++ b/src/bindings/org/gnome/gtk/RegionFlags.java
@@ -1,7 +1,7 @@
/*
* java-gnome, a UI library for writing GTK and GNOME programs from Java!
*
- * Copyright © 2011 Operational Dynamics Consulting, Pty Ltd and Others
+ * Copyright © 2011-2013 Operational Dynamics Consulting, Pty Ltd and Others
*
* The code in this file, and the program it is a part of, is made available
* to you by its authors as open source software: you can redistribute it
@@ -32,7 +32,7 @@
*/
package org.gnome.gtk;
-import org.freedesktop.bindings.Constant;
+import org.freedesktop.bindings.Flag;
/**
* Describe a region within a widget.
@@ -40,7 +40,7 @@ import org.freedesktop.bindings.Constant;
* @author Guillaume Mazoyer
* @since 4.1.2
*/
-public final class RegionFlags extends Constant
+public final class RegionFlags extends Flag
{
protected RegionFlags(int ordinal, String nickname) {
super(ordinal, nickname);
diff --git a/src/bindings/org/gnome/gtk/Unit.java b/src/bindings/org/gnome/gtk/Unit.java
index 92c8a93..73272c4 100644
--- a/src/bindings/org/gnome/gtk/Unit.java
+++ b/src/bindings/org/gnome/gtk/Unit.java
@@ -81,9 +81,4 @@ public final class Unit extends Constant
* are, obviously, completely baseless.</i>
*/
public static final Unit INCH = new Unit(GtkUnit.INCH, "INCH");
-
- /*
- * What good is this?
- */
- public static final Unit PIXEL = new Unit(GtkUnit.PIXEL, "PIXEL");
}
diff --git a/src/bindings/org/gnome/pango/Engine.java b/src/bindings/org/gnome/pango/Engine.java
index 0889475..d5637ce 100644
--- a/src/bindings/org/gnome/pango/Engine.java
+++ b/src/bindings/org/gnome/pango/Engine.java
@@ -32,7 +32,7 @@
*/
package org.gnome.pango;
-import org.gnome.glib.Object;
+import org.gnome.glib.Boxed;
/*
* FIXME this is a placeholder stub for what will become the public API for
@@ -42,9 +42,14 @@ import org.gnome.glib.Object;
* are made about this class until it has been reviewed by a hacker and this
* comment has been replaced.
*/
-public class Engine extends Object
+public class Engine extends Boxed
{
protected Engine(long pointer) {
super(pointer);
}
+
+ @Override
+ protected void release() {
+ // TODO Auto-generated method stub
+ }
}
diff --git a/src/generator/com/operationaldynamics/defsparser/IntrospectionParser.java b/src/generator/com/operationaldynamics/defsparser/IntrospectionParser.java
index 82a30f0..b39e08a 100644
--- a/src/generator/com/operationaldynamics/defsparser/IntrospectionParser.java
+++ b/src/generator/com/operationaldynamics/defsparser/IntrospectionParser.java
@@ -1,5 +1,3 @@
-package com.operationaldynamics.defsparser;
-
/*
* java-gnome, a UI library for writing GTK and GNOME programs from Java!
*
@@ -18,6 +16,7 @@ package com.operationaldynamics.defsparser;
* see http://www.gnu.org/licenses/. The authors of this program may be
* contacted through http://java-gnome.sourceforge.net/.
*/
+package com.operationaldynamics.defsparser;
/*
* This code started life as prototype written during the Google Summer of Code
@@ -26,9 +25,10 @@ package com.operationaldynamics.defsparser;
* .defs parser being used by java-gnome for several years.
*/
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -43,6 +43,7 @@ import nu.xom.Elements;
import nu.xom.ParsingException;
import nu.xom.ValidityException;
+import com.operationaldynamics.codegen.Thing;
import com.operationaldynamics.driver.DefsFile;
import com.operationaldynamics.driver.ImproperDefsFileException;
@@ -66,6 +67,10 @@ public class IntrospectionParser
private static final Properties packageOverrides;
+ private static final Properties nameOverrides;
+
+ private static final List<String> blacklist;
+
private File introspectionFile;
static {
@@ -76,11 +81,18 @@ public class IntrospectionParser
packageOverrides = new Properties();
try {
packageOverrides.load(new FileInputStream("src/generator/packages-override.properties"));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
} catch (IOException e) {
- e.printStackTrace();
+ System.err.println("How come we can't open a file for reading?\n" + e);
+ }
+
+ nameOverrides = new Properties();
+ try {
+ nameOverrides.load(new FileInputStream("src/generator/names-override.properties"));
+ } catch (IOException e) {
+ System.err.println("How come we can't open a file for reading?\n" + e);
}
+
+ blacklist = new ArrayList<String>();
}
/**
@@ -95,6 +107,135 @@ public class IntrospectionParser
}
/**
+ * Load the whitelist of objects/enumerations/flags/boxeds/interfaces that
+ * we want to use.
+ */
+ private static final List<String> loadWhitelist() {
+ final List<String> whitelist;
+ final BufferedReader reader;
+ String line;
+
+ whitelist = new ArrayList<String>();
+
+ try {
+ reader = new BufferedReader(new FileReader("src/generator/whitelist.txt"));
+
+ while ((line = reader.readLine()) != null) {
+ whitelist.add(line);
+ }
+
+ reader.close();
+ } catch (IOException e) {
+ System.err.println("How come we can't open a file for reading?\n" + e);
+ }
+
+ return whitelist;
+ }
+
+ /**
+ * Browse all the Introspection data to find gtypes to blacklist (because
+ * we don't handle them yet).
+ *
+ * @param namespaces
+ * the Introspection namespaces to browse.
+ */
+ private static final void loadBlacklist(Elements namespaces) {
+ final List<String> whitelist;
+
+ whitelist = loadWhitelist();
+
+ for (int namespaceIndex = 0; namespaceIndex < namespaces.size(); namespaceIndex++) {
+ final Element namespace;
+ final Elements objects, interfaces, enumerations, flags, boxeds;
+
+ namespace = namespaces.get(namespaceIndex);
+ objects = namespace.getChildElements("class", CORE_NAMESPACE);
+ interfaces = namespace.getChildElements("interface", CORE_NAMESPACE);
+ enumerations = namespace.getChildElements("enumeration", CORE_NAMESPACE);
+ flags = namespace.getChildElements("bitfield", CORE_NAMESPACE);
+ boxeds = namespace.getChildElements("record", CORE_NAMESPACE);
+
+ for (int objectIndex = 0; objectIndex < objects.size(); objectIndex++) {
+ final Element object;
+ final String cName;
+
+ object = objects.get(objectIndex);
+ cName = object.getAttributeValue("type", C_NAMESPACE) == null ? object.getAttributeValue(
+ "type-name", GLIB_NAMESPACE) : object.getAttributeValue("type", C_NAMESPACE);
+
+ if (!whitelist.contains(cName)) {
+ blacklist.add(cName);
+ continue;
+ }
+ }
+
+ for (int interfaceIndex = 0; interfaceIndex < interfaces.size(); interfaceIndex++) {
+ final Element interfaze;
+ final String cName;
+
+ interfaze = interfaces.get(interfaceIndex);
+ cName = interfaze.getAttributeValue("type", C_NAMESPACE);
+
+ if (!whitelist.contains(cName)) {
+ blacklist.add(cName);
+ continue;
+ }
+
+ }
+
+ for (int enumerationIndex = 0; enumerationIndex < enumerations.size(); enumerationIndex++) {
+ final Element enumeration;
+ final String cName;
+
+ enumeration = enumerations.get(enumerationIndex);
+ cName = enumeration.getAttributeValue("type", C_NAMESPACE);
+
+ if (!whitelist.contains(cName)) {
+ blacklist.add(cName);
+ continue;
+ }
+ }
+
+ for (int flagIndex = 0; flagIndex < flags.size(); flagIndex++) {
+ final Element flag;
+ final String cName;
+
+ flag = flags.get(flagIndex);
+ cName = flag.getAttributeValue("type", C_NAMESPACE);
+
+ if (!whitelist.contains(cName)) {
+ blacklist.add(cName);
+ continue;
+ }
+ }
+
+ for (int boxedIndex = 0; boxedIndex < boxeds.size(); boxedIndex++) {
+ final Element boxed;
+ final String cName;
+
+ boxed = boxeds.get(boxedIndex);
+ cName = boxed.getAttributeValue("type", C_NAMESPACE);
+
+ if (!whitelist.contains(cName)) {
+ blacklist.add(cName);
+ continue;
+ }
+ }
+ }
+ }
+
+ /**
+ * Return whether the given C type is blacklisted.
+ *
+ * @param gtype
+ * the C type of the object.
+ * @return true if the C type is blacklisted.
+ */
+ private static final boolean isBlacklisted(String gtype) {
+ return blacklist.contains(gtype);
+ }
+
+ /**
* Return the Java package name to use for the given namespace.
*
* @param introspectionNamespace
@@ -110,6 +251,21 @@ public class IntrospectionParser
}
/**
+ * Return the Java name to use for the given object name.
+ *
+ * @param name
+ * the GObject name.
+ * @return the Java name to use.
+ */
+ private static final String getActualJavaName(String name) {
+ final String javaName;
+
+ javaName = nameOverrides.getProperty(name);
+
+ return ((javaName == null) ? name : javaName);
+ }
+
+ /**
* Return a String representation of the parent of the given object.
*
* @param object
@@ -196,6 +352,15 @@ public class IntrospectionParser
typeString = "none";
}
+ /*
+ * FIXME: this is ugly.
+ */
+
+ if (typeString.startsWith("GList") || typeString.startsWith("GSList")) {
+ typeString = typeString.replace("*", "") + "-"
+ + type.getChildElements().get(0).getAttributeValue("name");
+ }
+
return new String[] {
"return-type",
typeString.replace(" ", "-")
@@ -262,9 +427,8 @@ public class IntrospectionParser
for (int parameterIndex = 0; parameterIndex < list.size(); parameterIndex++) {
final Element parameter;
- final String name;
Element type;
- String typeString;
+ String name, typeString, realType;
parameter = list.get(parameterIndex);
name = parameter.getAttributeValue("name");
@@ -295,6 +459,43 @@ public class IntrospectionParser
}
/*
+ * Remove all modifiers to keep the real type and check if we
+ * can use it.
+ */
+
+ realType = typeString.replace("const-", "").replaceAll("\\*", "");
+
+ /*
+ * FIXME: this is ugly.
+ */
+
+ if (typeString.startsWith("GList") || typeString.startsWith("GSList")) {
+ typeString = typeString.replace("*", "") + "-"
+ + type.getChildElements().get(0).getAttributeValue("name");
+ }
+
+ /*
+ * Prevent from working with methods and signals that we
+ * cannot handle parameters.
+ */
+
+ /*
+ * if ((Thing.lookup(realType) == null) &&
+ * isBlacklisted(realType)) { return null; }
+ */
+
+ /*
+ * FIXME: In signal we already use the "handler" and "result"
+ * variables so we need to generate another name (basically we
+ * just append the parameter number).
+ */
+
+ if ((function.getQualifiedName().equals("virtual-method") || function.getQualifiedName()
+ .equals("signal")) && (name.equals("handler") || name.equals("result"))) {
+ name += parameterIndex;
+ }
+
+ /*
* Add the parameter to the parameters list and tell if 'null'
* can be used.
*/
@@ -371,18 +572,33 @@ public class IntrospectionParser
boxeds = namespace.getChildElements("record", CORE_NAMESPACE);
/*
+ * First pass, blacklist what need to be blacklisted.
+ */
+
+ loadBlacklist(namespaces);
+
+ /*
* Examine each class.
*/
for (int objectIndex = 0; objectIndex < objects.size(); objectIndex++) {
final Element object;
- final Elements constructors, methods, signals;
+ final Elements constructors, methods, functions, virtuals, signals;
final List<Block> blocks;
final List<String[]> characteristics;
+ final List<String> signalNames;
+ final String cName;
object = objects.get(objectIndex);
blocks = new ArrayList<Block>();
characteristics = new ArrayList<String[]>();
+ signalNames = new ArrayList<String>();
+ cName = object.getAttributeValue("type", C_NAMESPACE) == null ? object.getAttributeValue(
+ "type-name", GLIB_NAMESPACE) : object.getAttributeValue("type", C_NAMESPACE);
+
+ if (isBlacklisted(cName)) {
+ continue;
+ }
/*
* Retrieve constructors, methods and signals.
@@ -390,7 +606,9 @@ public class IntrospectionParser
constructors = object.getChildElements("constructor", CORE_NAMESPACE);
methods = object.getChildElements("method", CORE_NAMESPACE);
- signals = object.getChildElements("virtual-method", CORE_NAMESPACE);
+ functions = object.getChildElements("function", CORE_NAMESPACE);
+ virtuals = object.getChildElements("virtual-method", CORE_NAMESPACE);
+ signals = object.getChildElements("signal", GLIB_NAMESPACE);
/*
* Get object first characteristics: module it belongs to and
@@ -407,8 +625,7 @@ public class IntrospectionParser
});
characteristics.add(new String[] {
"c-name",
- object.getAttributeValue("type", C_NAMESPACE) == null ? object.getAttributeValue(
- "type-name", GLIB_NAMESPACE) : object.getAttributeValue("type", C_NAMESPACE)
+ cName
});
/*
@@ -421,7 +638,8 @@ public class IntrospectionParser
* Build the object blocks based on the info we have.
*/
- blocks.add(new ObjectBlock(object.getAttributeValue("name"), characteristics, null));
+ blocks.add(new ObjectBlock(getActualJavaName(object.getAttributeValue("name")),
+ characteristics, null));
/*
* Parse all constructors data.
@@ -429,7 +647,7 @@ public class IntrospectionParser
for (int constructorIndex = 0; constructorIndex < constructors.size(); constructorIndex++) {
final Element constructor;
- final List<String[]> constructorCharacteristics;
+ final List<String[]> constructorCharacteristics, constructorParameters;
final String[] callerOwnsReturn;
constructor = constructors.get(constructorIndex);
@@ -455,6 +673,11 @@ public class IntrospectionParser
constructorCharacteristics.add(getReturnType(constructor));
callerOwnsReturn = getCallerOwnsReturn(constructor);
+ constructorParameters = getParameters(constructor);
+
+ if (constructorParameters == null) {
+ continue;
+ }
if (callerOwnsReturn != null) {
constructorCharacteristics.add(callerOwnsReturn);
@@ -469,7 +692,7 @@ public class IntrospectionParser
blocks.add(new FunctionBlock(
constructor.getAttributeValue("identifier", C_NAMESPACE),
- constructorCharacteristics, getParameters(constructor)));
+ constructorCharacteristics, constructorParameters));
}
/*
@@ -478,7 +701,7 @@ public class IntrospectionParser
for (int methodIndex = 0; methodIndex < methods.size(); methodIndex++) {
final Element method;
- final List<String[]> methodCharacteristics;
+ final List<String[]> methodCharacteristics, methodParameters;
final String[] callerOwnsReturn;
String ofObject;
@@ -511,6 +734,11 @@ public class IntrospectionParser
methodCharacteristics.add(getReturnType(method));
callerOwnsReturn = getCallerOwnsReturn(method);
+ methodParameters = getParameters(method);
+
+ if (methodParameters == null) {
+ continue;
+ }
if (callerOwnsReturn != null) {
methodCharacteristics.add(callerOwnsReturn);
@@ -524,7 +752,104 @@ public class IntrospectionParser
}
blocks.add(new MethodBlock(method.getAttributeValue("name"), methodCharacteristics,
- getParameters(method)));
+ methodParameters));
+ }
+
+ /*
+ * Parse all functions data.
+ */
+
+ for (int functionIndex = 0; functionIndex < functions.size(); functionIndex++) {
+ final Element function;
+ final List<String[]> functionCharacteristics, functionParameters;
+ final String[] callerOwnsReturn;
+
+ function = functions.get(functionIndex);
+ functionCharacteristics = new ArrayList<String[]>();
+
+ /*
+ * Get the class that this method belongs to and the C
+ * name of this method.
+ */
+
+ functionCharacteristics.add(new String[] {
+ "of-object",
+ object.getAttributeValue("type", C_NAMESPACE)
+ });
+ functionCharacteristics.add(new String[] {
+ "c-name",
+ function.getAttributeValue("identifier", C_NAMESPACE)
+ });
+
+ /*
+ * Handle return value and its owner.
+ */
+
+ functionCharacteristics.add(getReturnType(function));
+ callerOwnsReturn = getCallerOwnsReturn(function);
+ functionParameters = getParameters(function);
+
+ if (functionParameters == null) {
+ continue;
+ }
+
+ if (callerOwnsReturn != null) {
+ functionCharacteristics.add(callerOwnsReturn);
+ }
+
+ if (hasVarArgs(function)) {
+ functionCharacteristics.add(new String[] {
+ "varargs",
+ "#t"
+ });
+ }
+
+ blocks.add(new FunctionBlock(function.getAttributeValue("name"),
+ functionCharacteristics, functionParameters));
+ }
+
+ /*
+ * Parse all virtuals data.
+ */
+
+ for (int virtualIndex = 0; virtualIndex < virtuals.size(); virtualIndex++) {
+ final Element virtual;
+ final List<String[]> virtualCharacteristics, virtualParameters;
+ final String virtualName;
+
+ virtual = virtuals.get(virtualIndex);
+ virtualName = virtual.getAttributeValue("name").replace("-", "_");
+ virtualCharacteristics = new ArrayList<String[]>();
+
+ /*
+ * We need a list of signals names to avoid duplicates
+ * between signals and virtuals.
+ */
+
+ signalNames.add(virtualName);
+
+ /*
+ * Get the class that this method belongs to.
+ */
+
+ virtualCharacteristics.add(new String[] {
+ "of-object",
+ object.getAttributeValue("type", C_NAMESPACE)
+ });
+
+ /*
+ * Handle return value.
+ */
+
+ virtualCharacteristics.add(getReturnType(virtual));
+
+ virtualParameters = getParameters(virtual);
+
+ if (virtualParameters == null) {
+ continue;
+ }
+
+ blocks.add(new VirtualBlock(virtualName, virtualCharacteristics, virtualParameters));
}
/*
@@ -533,12 +858,22 @@ public class IntrospectionParser
for (int signalIndex = 0; signalIndex < signals.size(); signalIndex++) {
final Element signal;
- final List<String[]> signalCharacteristics;
+ final List<String[]> signalCharacteristics, signalParameters;
+ final String signalName;
signal = signals.get(signalIndex);
+ signalName = signal.getAttributeValue("name").replace("-", "_");
signalCharacteristics = new ArrayList<String[]>();
/*
+ * Signal already handled with a virtual method.
+ */
+
+ if (signalNames.contains(signalName)) {
+ continue;
+ }
+
+ /*
* Get the class that this method belongs to.
*/
@@ -553,8 +888,13 @@ public class IntrospectionParser
signalCharacteristics.add(getReturnType(signal));
- blocks.add(new VirtualBlock(signal.getAttributeValue("name").replace("-", "_"),
- signalCharacteristics, getParameters(signal)));
+ signalParameters = getParameters(signal);
+
+ if (signalParameters == null) {
+ continue;
+ }
+
+ blocks.add(new VirtualBlock(signalName, signalCharacteristics, signalParameters));
}
try {
@@ -562,7 +902,7 @@ public class IntrospectionParser
* Generate the defs file definition for the given object.
*/
- defs.put(object.getAttributeValue("name"),
+ defs.put(getActualJavaName(object.getAttributeValue("name")),
new DefsFile(blocks.toArray(new Block[0])));
} catch (ImproperDefsFileException e) {
e.printStackTrace();
@@ -575,20 +915,30 @@ public class IntrospectionParser
for (int interfaceIndex = 0; interfaceIndex < interfaces.size(); interfaceIndex++) {
final Element interfaze;
- final Elements methods, signals;
+ final Elements methods, functions, virtuals, signals;
final List<Block> blocks;
final List<String[]> characteristics;
+ final List<String> signalNames;
+ final String cName;
interfaze = interfaces.get(interfaceIndex);
blocks = new ArrayList<Block>();
characteristics = new ArrayList<String[]>();
+ signalNames = new ArrayList<String>();
+ cName = interfaze.getAttributeValue("type", C_NAMESPACE);
+
+ if (isBlacklisted(cName)) {
+ continue;
+ }
/*
* Retrieve constructors, methods and signals.
*/
methods = interfaze.getChildElements("method", CORE_NAMESPACE);
- signals = interfaze.getChildElements("virtual-method", CORE_NAMESPACE);
+ functions = interfaze.getChildElements("function", CORE_NAMESPACE);
+ virtuals = interfaze.getChildElements("virtual-method", CORE_NAMESPACE);
+ signals = interfaze.getChildElements("signal", GLIB_NAMESPACE);
/*
* Get object first characteristics: module it belongs to and
@@ -601,14 +951,15 @@ public class IntrospectionParser
});
characteristics.add(new String[] {
"c-name",
- interfaze.getAttributeValue("type", C_NAMESPACE)
+ cName
});
/*
* Build the object blocks based on the info we have.
*/
- blocks.add(new InterfaceBlock(interfaze.getAttributeValue("name"), characteristics));
+ blocks.add(new InterfaceBlock(getActualJavaName(interfaze.getAttributeValue("name")),
+ characteristics));
/*
* Parse all methods data.
@@ -616,7 +967,7 @@ public class IntrospectionParser
for (int methodIndex = 0; methodIndex < methods.size(); methodIndex++) {
final Element method;
- final List<String[]> methodCharacteristics;
+ final List<String[]> methodCharacteristics, methodParameters;
final String[] callerOwnsReturn;
method = methods.get(methodIndex);
@@ -642,6 +993,11 @@ public class IntrospectionParser
methodCharacteristics.add(getReturnType(method));
callerOwnsReturn = getCallerOwnsReturn(method);
+ methodParameters = getParameters(method);
+
+ if (methodParameters == null) {
+ continue;
+ }
if (callerOwnsReturn != null) {
methodCharacteristics.add(callerOwnsReturn);
@@ -655,7 +1011,104 @@ public class IntrospectionParser
}
blocks.add(new MethodBlock(method.getAttributeValue("name"), methodCharacteristics,
- getParameters(method)));
+ methodParameters));
+ }
+
+ /*
+ * Parse all functions data.
+ */
+
+ for (int functionIndex = 0; functionIndex < functions.size(); functionIndex++) {
+ final Element function;
+ final List<String[]> functionCharacteristics, functionParameters;
+ final String[] callerOwnsReturn;
+
+ function = functions.get(functionIndex);
+ functionCharacteristics = new ArrayList<String[]>();
+
+ /*
+ * Get the class that this method belongs to and the C
+ * name of this method.
+ */
+
+ functionCharacteristics.add(new String[] {
+ "of-object",
+ interfaze.getAttributeValue("type", C_NAMESPACE)
+ });
+ functionCharacteristics.add(new String[] {
+ "c-name",
+ function.getAttributeValue("identifier", C_NAMESPACE)
+ });
+
+ /*
+ * Handle return value and its owner.
+ */
+
+ functionCharacteristics.add(getReturnType(function));
+ callerOwnsReturn = getCallerOwnsReturn(function);
+ functionParameters = getParameters(function);
+
+ if (functionParameters == null) {
+ continue;
+ }
+
+ if (callerOwnsReturn != null) {
+ functionCharacteristics.add(callerOwnsReturn);
+ }
+
+ if (hasVarArgs(function)) {
+ functionCharacteristics.add(new String[] {
+ "varargs",
+ "#t"
+ });
+ }
+
+ blocks.add(new FunctionBlock(function.getAttributeValue("name"),
+ functionCharacteristics, functionParameters));
+ }
+
+ /*
+ * Parse all virtuals data.
+ */
+
+ for (int virtualIndex = 0; virtualIndex < virtuals.size(); virtualIndex++) {
+ final Element virtual;
+ final List<String[]> virtualCharacteristics, virtualParameters;
+ final String virtualName;
+
+ virtual = virtuals.get(virtualIndex);
+ virtualName = virtual.getAttributeValue("name").replace("-", "_");
+ virtualCharacteristics = new ArrayList<String[]>();
+
+ /*
+ * We need a list of signals names to avoid duplicates
+ * between signals and virtuals.
+ */
+
+ signalNames.add(virtualName);
+
+ /*
+ * Get the class that this method belongs to.
+ */
+
+ virtualCharacteristics.add(new String[] {
+ "of-object",
+ interfaze.getAttributeValue("type", C_NAMESPACE)
+ });
+
+ /*
+ * Handle return value.
+ */
+
+ virtualCharacteristics.add(getReturnType(virtual));
+
+ virtualParameters = getParameters(virtual);
+
+ if (virtualParameters == null) {
+ continue;
+ }
+
+ blocks.add(new VirtualBlock(virtualName, virtualCharacteristics, virtualParameters));
}
/*
@@ -664,12 +1117,22 @@ public class IntrospectionParser
for (int signalIndex = 0; signalIndex < signals.size(); signalIndex++) {
final Element signal;
- final List<String[]> signalCharacteristics;
+ final List<String[]> signalCharacteristics, signalParameters;
+ final String signalName;
signal = signals.get(signalIndex);
+ signalName = signal.getAttributeValue("name").replace("-", "_");
signalCharacteristics = new ArrayList<String[]>();
/*
+ * Signal already handled with a virtual method.
+ */
+
+ if (signalNames.contains(signalName)) {
+ continue;
+ }
+
+ /*
* Get the class that this method belongs to.
*/
@@ -684,8 +1147,13 @@ public class IntrospectionParser
signalCharacteristics.add(getReturnType(signal));
- blocks.add(new VirtualBlock(signal.getAttributeValue("name").replace("-", "_"),
- signalCharacteristics, getParameters(signal)));
+ signalParameters = getParameters(signal);
+
+ if (signalParameters == null) {
+ continue;
+ }
+
+ blocks.add(new VirtualBlock(signalName, signalCharacteristics, signalParameters));
}
try {
@@ -693,7 +1161,7 @@ public class IntrospectionParser
* Generate the defs file definition for the given object.
*/
- defs.put(interfaze.getAttributeValue("name"),
+ defs.put(getActualJavaName(interfaze.getAttributeValue("name")),
new DefsFile(blocks.toArray(new Block[0])));
} catch (ImproperDefsFileException e) {
e.printStackTrace();
@@ -709,12 +1177,18 @@ public class IntrospectionParser
final Elements valuesList;
final List<Block> blocks;
final List<String[]> characteristics, values;
+ final String cName;
enumeration = enumerations.get(enumerationIndex);
valuesList = enumeration.getChildElements("member", CORE_NAMESPACE);
blocks = new ArrayList<Block>();
characteristics = new ArrayList<String[]>();
values = new ArrayList<String[]>();
+ cName = enumeration.getAttributeValue("type", C_NAMESPACE);
+
+ if (isBlacklisted(cName)) {
+ continue;
+ }
/*
* Get object first characteristics: module it belongs to and
@@ -727,7 +1201,7 @@ public class IntrospectionParser
});
characteristics.add(new String[] {
"c-name",
- enumeration.getAttributeValue("type", C_NAMESPACE)
+ cName
});
for (int valueIndex = 0; valueIndex < valuesList.size(); valueIndex++) {
@@ -758,15 +1232,16 @@ public class IntrospectionParser
});
}
- blocks.add(new EnumBlock(enumeration.getAttributeValue("name"), characteristics, values));
+ blocks.add(new EnumBlock(getActualJavaName(enumeration.getAttributeValue("name")),
+ characteristics, values));
try {
/*
* Generate the defs file definition for the given object.
*/
- defs.put(enumeration.getAttributeValue("name"),
- new DefsFile(blocks.toArray(new Block[0])));
+ defs.put(getActualJavaName(enumeration.getAttributeValue("name")), new DefsFile(
+ blocks.toArray(new Block[0])));
} catch (ImproperDefsFileException e) {
e.printStackTrace();
}
@@ -781,12 +1256,18 @@ public class IntrospectionParser
final Elements valuesList;
final List<Block> blocks;
final List<String[]> characteristics, values;
+ final String cName;
flag = flags.get(flagIndex);
valuesList = flag.getChildElements("member", CORE_NAMESPACE);
blocks = new ArrayList<Block>();
characteristics = new ArrayList<String[]>();
values = new ArrayList<String[]>();
+ cName = flag.getAttributeValue("type", C_NAMESPACE);
+
+ if (isBlacklisted(cName)) {
+ continue;
+ }
/*
* Get object first characteristics: module it belongs to and
@@ -799,7 +1280,7 @@ public class IntrospectionParser
});
characteristics.add(new String[] {
"c-name",
- flag.getAttributeValue("type", C_NAMESPACE)
+ cName
});
for (int valueIndex = 0; valueIndex < valuesList.size(); valueIndex++) {
@@ -824,7 +1305,8 @@ public class IntrospectionParser
}
if (values.size() > 0) {
- blocks.add(new FlagsBlock(flag.getAttributeValue("name"), characteristics, values));
+ blocks.add(new FlagsBlock(getActualJavaName(flag.getAttributeValue("name")),
+ characteristics, values));
try {
/*
@@ -832,7 +1314,7 @@ public class IntrospectionParser
* object.
*/
- defs.put(flag.getAttributeValue("name"),
+ defs.put(getActualJavaName(flag.getAttributeValue("name")),
new DefsFile(blocks.toArray(new Block[0])));
} catch (ImproperDefsFileException e) {
e.printStackTrace();
@@ -846,22 +1328,32 @@ public class IntrospectionParser
for (int boxedIndex = 0; boxedIndex < boxeds.size(); boxedIndex++) {
final Element boxed;
- final Elements methods;
+ final Elements fields, constructors, methods;
final List<Block> blocks;
final List<String[]> characteristics;
- final String boxedName;
+ final String boxedName, cName;
+ final BoxedBlock boxedBlock;
boxed = boxeds.get(boxedIndex);
boxedName = boxed.getAttributeValue("name");
+ cName = boxed.getAttributeValue("type", C_NAMESPACE);
/*
- * If this boxed thing is internal just ignore it.
+ * If this boxed thing is internal or must be skipped just
+ * ignore it.
*/
- if (boxedName.endsWith("Class") || boxedName.endsWith("Private")) {
+ if (boxedName.startsWith("_") || boxedName.endsWith("Class")
+ || boxedName.endsWith("Private")) {
+ continue;
+ }
+
+ if (isBlacklisted(cName)) {
continue;
}
+ fields = boxed.getChildElements("field", CORE_NAMESPACE);
+ constructors = boxed.getChildElements("constructor", CORE_NAMESPACE);
methods = boxed.getChildElements("method", CORE_NAMESPACE);
blocks = new ArrayList<Block>();
characteristics = new ArrayList<String[]>();
@@ -877,10 +1369,106 @@ public class IntrospectionParser
});
characteristics.add(new String[] {
"c-name",
- boxed.getAttributeValue("type", C_NAMESPACE)
+ cName
});
- blocks.add(new BoxedBlock(boxedName, characteristics));
+ boxedBlock = new BoxedBlock(getActualJavaName(boxedName), characteristics);
+ blocks.add(boxedBlock);
+
+ /*
+ * Parse all fields.
+ */
+
+ for (int fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++) {
+ final Element field;
+ final String name;
+ final boolean writable;
+ String type;
+
+ field = fields.get(fieldIndex);
+ type = field.getChildElements().get(0).getAttributeValue("type", C_NAMESPACE);
+ name = field.getAttributeValue("name");
+ writable = (field.getAttributeValue("writable") != null)
+ && field.getAttributeValue("writable").equals("1");
+
+ /*
+ * No C type just a name.
+ */
+
+ if (type == null) {
+ type = getActualJavaPackage(namespaceName)
+ + field.getChildElements().get(0).getAttributeValue("name");
+ }
+
+ /*
+ * Generate block to read the field.
+ */
+
+ blocks.add(new GetterBlock(boxedBlock, type, name));
+
+ /*
+ * If the field is also writable, generate the block to
+ * write it.
+ */
+
+ if (writable) {
+ blocks.add(new SetterBlock(boxedBlock, type, name));
+ }
+ }
+
+ /*
+ * Parse all constructors data.
+ */
+
+ for (int constructorIndex = 0; constructorIndex < constructors.size(); constructorIndex++) {
+ final Element constructor;
+ final List<String[]> constructorCharacteristics, constructorParameters;
+ final String[] callerOwnsReturn;
+
+ constructor = constructors.get(constructorIndex);
+ constructorCharacteristics = new ArrayList<String[]>();
+
+ /*
+ * Get the class that this constructor belongs to and the
+ * C name of this constructor.
+ */
+
+ constructorCharacteristics.add(new String[] {
+ "is-constructor-of",
+ boxed.getAttributeValue("type", C_NAMESPACE)
+ });
+ constructorCharacteristics.add(new String[] {
+ "c-name",
+ constructor.getAttributeValue("identifier", C_NAMESPACE)
+ });
+
+ /*
+ * Handle return value and its owner.
+ */
+
+ constructorCharacteristics.add(getReturnType(constructor));
+ callerOwnsReturn = getCallerOwnsReturn(constructor);
+ constructorParameters = getParameters(constructor);
+
+ if (constructorParameters == null) {
+ continue;
+ }
+
+ if (callerOwnsReturn != null) {
+ constructorCharacteristics.add(callerOwnsReturn);
+ }
+
+ if (hasVarArgs(constructor)) {
+ constructorCharacteristics.add(new String[] {
+ "varargs",
+ "#t"
+ });
+ }
+
+ blocks.add(new FunctionBlock(
+ constructor.getAttributeValue("identifier", C_NAMESPACE),
+ constructorCharacteristics, constructorParameters));
+ }
/*
* Retrieve all info about methods.
@@ -888,13 +1476,31 @@ public class IntrospectionParser
for (int methodIndex = 0; methodIndex < methods.size(); methodIndex++) {
final Element method;
- final List<String[]> methodCharacteristics;
+ final List<String[]> methodCharacteristics, methodParameters;
final String[] callerOwnsReturn;
method = methods.get(methodIndex);
methodCharacteristics = new ArrayList<String[]>();
/*
+ * Handle specials methods to copy and release resources.
+ */
+
+ if (method.getAttributeValue("name").equals("copy")) {
+ characteristics.add(new String[] {
+ "copy-func",
+ method.getAttributeValue("identifier", C_NAMESPACE)
+ });
+ }
+
+ if (method.getAttributeValue("name").equals("free")) {
+ characteristics.add(new String[] {
+ "release-func",
+ method.getAttributeValue("identifier", C_NAMESPACE)
+ });
+ }
+
+ /*
* Get the boxed that this method belongs to and the C
* name of this method.
*/
@@ -914,6 +1520,11 @@ public class IntrospectionParser
methodCharacteristics.add(getReturnType(method));
callerOwnsReturn = getCallerOwnsReturn(method);
+ methodParameters = getParameters(method);
+
+ if (methodParameters == null) {
+ continue;
+ }
if (callerOwnsReturn != null) {
methodCharacteristics.add(callerOwnsReturn);
@@ -927,7 +1538,7 @@ public class IntrospectionParser
}
blocks.add(new MethodBlock(method.getAttributeValue("name"), methodCharacteristics,
- getParameters(method)));
+ methodParameters));
}
try {
@@ -935,7 +1546,7 @@ public class IntrospectionParser
* Generate the defs file definition for the given boxed.
*/
- defs.put(boxedName, new DefsFile(blocks.toArray(new Block[0])));
+ defs.put(getActualJavaName(boxedName), new DefsFile(blocks.toArray(new Block[0])));
} catch (ImproperDefsFileException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment