java-gobject-introspection r173 - trunk/src/org/gnome/gir/compiler



Author: walters
Date: Sat Feb  7 03:56:56 2009
New Revision: 173
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=173&view=rev

Log:
Append underscore to methods with illegal identifier

Modified:
   trunk/src/org/gnome/gir/compiler/CodeFactory.java

Modified: trunk/src/org/gnome/gir/compiler/CodeFactory.java
==============================================================================
--- trunk/src/org/gnome/gir/compiler/CodeFactory.java	(original)
+++ trunk/src/org/gnome/gir/compiler/CodeFactory.java	Sat Feb  7 03:56:56 2009
@@ -152,6 +152,14 @@
 			add("unref");
 		}
 	};
+	
+	// http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html
+	private static final Set<String> javaIdentifierBlacklist = new HashSet<String>(Arrays.asList(new String[] { "abstract", "continue", "for", "new", "switch", "assert",
+			"default", "goto", "package", "synchronized", "boolean", "do", "if", "private", "this", "break", "double",
+			"implements", "protected", "throw", "byte", "else", "import", "public", "throws", "case", "enum",
+			"instanceof", "return", "transient", "catch", "extends", "int", "short", "try", "char", "final",
+			"interface", "static", "void", "class", "finally", "long", "strictfp", "volatile", "const", "float",
+			"native", "super", "while", "true", "false", "null" }));
 
 	private final Repository repo;
 	private final Set<String> alreadyCompiled = new HashSet<String>();
@@ -1235,6 +1243,14 @@
 				}
 			}
 		}
+		
+		ctx.name = NameMap.ucaseToCamel(si.getName());
+		// Callables are allowed to be named "new", we handle that specially
+		if (javaIdentifierBlacklist.contains(ctx.name) && !ctx.name.equals("new")) {
+			logger.warning(String.format("Callable %s has illegal identifer as name", si.getIdentifier()));
+			ctx.name = ctx.name + "_";
+		}
+		
 		if (ctx.returnType == null) {
 			logger.warning("Skipping callable with unhandled return signature: " + si.getIdentifier());
 			return null;
@@ -1328,8 +1344,6 @@
 
 		ctx.argTypes = filteredTypes;
 
-		ctx.name = NameMap.ucaseToCamel(si.getName());
-
 		if (seenSignatures != null) {
 			String signature = TypeMap.getUniqueSignature(ctx.name, ctx.returnType, ctx.argTypes);
 			if (seenSignatures.contains(signature)) {



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