1
/*******************************************************************************
2
* Copyright (c) 2009 Progress Software, Inc.
3
* Copyright (c) 2004 IBM Corporation and others.
5
* All rights reserved. This program and the accompanying materials
6
* are made available under the terms of the Eclipse Public License v1.0
7
* which accompanies this distribution, and is available at
8
* http://www.eclipse.org/legal/epl-v10.html
10
*******************************************************************************/
11
package org.fusesource.hawtjni.generator;
13
import java.lang.reflect.Modifier;
14
import java.util.List;
16
import org.fusesource.hawtjni.generator.model.JNIClass;
17
import org.fusesource.hawtjni.generator.model.JNIField;
18
import org.fusesource.hawtjni.generator.model.JNIType;
19
import org.fusesource.hawtjni.generator.model.ReflectClass;
23
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
25
public class ConstantsGenerator extends JNIGenerator {
27
public void generate(JNIClass clazz) {
28
List<JNIField> fields = clazz.getDeclaredFields();
32
public void generate(List<JNIField> fields) {
34
outputln("int main() {");
35
for (JNIField field : fields) {
36
if ((field.getModifiers() & Modifier.FINAL) == 0)
43
public void generate(JNIField field) {
44
JNIType type = field.getType();
45
output("\tprintf(\"public static final ");
46
output(field.getType().getTypeSignature3(false));
48
output(field.getName());
50
if (type.isType("java.lang.String") || type.isType("[B"))
55
output(field.getName());
59
public static void main(String[] args) {
60
if (args.length < 1) {
61
System.out.println("Usage: java ConstantsGenerator <className1> <className2>");
65
ConstantsGenerator gen = new ConstantsGenerator();
66
for (String clazzName : args) {
67
Class<?> clazz = Class.forName(clazzName);
68
gen.generate(new ReflectClass(clazz));
70
} catch (Exception e) {
71
System.out.println("Problem");
72
e.printStackTrace(System.out);