From 2fe517b9a2e1a680b50c7e1273897495800c5350 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Wed, 31 Mar 2010 16:08:54 +0200 Subject: implemented better logging using java.util.logging. --- src/java/com/sun/gluegen/JavaEmitter.java | 44 ++++++++++++++++--------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'src/java/com/sun/gluegen/JavaEmitter.java') diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java index 25aeb16..4e154d7 100644 --- a/src/java/com/sun/gluegen/JavaEmitter.java +++ b/src/java/com/sun/gluegen/JavaEmitter.java @@ -39,11 +39,20 @@ package com.sun.gluegen; +import java.beans.PropertyChangeEvent; import java.io.*; import java.util.*; import java.text.MessageFormat; import com.sun.gluegen.cgram.types.*; +import java.beans.PropertyChangeListener; +import java.util.logging.ConsoleHandler; +import java.util.logging.Filter; +import java.util.logging.LogManager; +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import javax.swing.plaf.basic.BasicComboBoxUI.PropertyChangeHandler; +import static java.util.logging.Level.*; // PROBLEMS: // - what if something returns 'const int *'? Could we @@ -89,6 +98,8 @@ public class JavaEmitter implements GlueEmitter { private MachineDescription machDesc32; private MachineDescription machDesc64; + protected final static Logger LOG = Logger.getLogger(JavaEmitter.class.getPackage().getName()); + public void readConfigurationFile(String filename) throws Exception { cfg = createConfig(); cfg.read(filename); @@ -406,16 +417,10 @@ public class JavaEmitter implements GlueEmitter { ArrayList funcsToBind = new ArrayList(funcsToBindSet); // sort functions to make them easier to find in native code - Collections.sort( - funcsToBind, - new Comparator() { - public int compare(FunctionSymbol o1, FunctionSymbol o2) { - return o1.getName().compareTo(o2.getName()); - } - @Override - public boolean equals(Object obj) { - return obj.getClass() == this.getClass(); - } + Collections.sort(funcsToBind, new Comparator() { + public int compare(FunctionSymbol o1, FunctionSymbol o2) { + return o1.getName().compareTo(o2.getName()); + } }); // Bind all the C funcs to Java methods @@ -787,7 +792,7 @@ public class JavaEmitter implements GlueEmitter { } if (name == null) { - System.err.println("WARNING: skipping emission of unnamed struct \"" + structType + "\""); + LOG.log(WARNING, "skipping emission of unnamed struct \"{0}\"", structType); return; } @@ -851,7 +856,6 @@ public class JavaEmitter implements GlueEmitter { String structClassPkg = cfg.packageForStruct(name); PrintWriter writer = null; - PrintWriter cWriter = null; try { writer = openFile( cfg.javaOutputDir() + File.separator + @@ -863,9 +867,9 @@ public class JavaEmitter implements GlueEmitter { if (cfg.nativeOutputUsesJavaHierarchy()) { nRoot += File.separator + CodeGenUtils.packageAsPath(cfg.packageName()); } - cWriter = openFile(nRoot + File.separator + containingTypeName + "_JNI.c"); - CodeGenUtils.emitAutogeneratedWarning(cWriter, this); - emitCHeader(cWriter, containingTypeName); + PrintWriter newCWriter = openFile(nRoot + File.separator + containingTypeName + "_JNI.c"); + CodeGenUtils.emitAutogeneratedWarning(newCWriter, this); + emitCHeader(newCWriter, containingTypeName); } } catch(Exception e) { throw new RuntimeException("Unable to open files for emission of struct class", e); @@ -1095,7 +1099,6 @@ public class JavaEmitter implements GlueEmitter { } catch (Exception e) { System.err.println("Error occurred while creating accessor for field \"" + field.getName() + "\" in type \"" + name + "\""); - e.printStackTrace(); throw(e); } if (externalJavaType.isPrimitive()) { @@ -1152,8 +1155,7 @@ public class JavaEmitter implements GlueEmitter { } } else { // FIXME - System.err.println("WARNING: Complicated fields (field \"" + field + "\" of type \"" + name + - "\") not implemented yet"); + LOG.log(WARNING, "Complicated fields (field \"{0}\" of type \"{1}\") not implemented yet", new Object[]{field, name}); // throw new RuntimeException("Complicated fields (field \"" + field + "\" of type \"" + t + // "\") not implemented yet"); } @@ -1240,7 +1242,7 @@ public class JavaEmitter implements GlueEmitter { // t is**, targetType is *, we need to get Type bottomType = targetType.asPointer().getTargetType(); - System.out.println("INFO: Opaque Type: "+t+", targetType: "+targetType+", bottomType: "+bottomType+" is ptr-ptr"); + LOG.log(INFO, "Opaque Type: {0}, targetType: {1}, bottomType: {2} is ptr-ptr", new Object[]{t, targetType, bottomType}); } } } @@ -1333,7 +1335,7 @@ public class JavaEmitter implements GlueEmitter { } else { // t is[][], targetType is [], we need to get bottomType = targetType.asArray().getElementType(); - System.out.println("WARNING: typeToJavaType(ptr-ptr): "+t+", targetType: "+targetType+", bottomType: "+bottomType+" -> Unhandled!"); + LOG.log(WARNING, "typeToJavaType(ptr-ptr): {0}, targetType: {1}, bottomType: {2} -> Unhandled!", new Object[]{t, targetType, bottomType}); } // Warning: The below code is not backed up by an implementation, @@ -1569,7 +1571,7 @@ public class JavaEmitter implements GlueEmitter { */ protected void emitCustomJavaCode(PrintWriter writer, String className) throws Exception { List code = cfg.customJavaCodeForClass(className); - if (code.size() == 0) + if (code.isEmpty()) return; writer.println(); -- cgit v1.2.3