Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 44f58a34d1e477e8525880a9de0dcaea34a71356 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*******************************************************************************
 * Copyright (c) 2004, 2017 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.tools.internal;

import java.lang.reflect.*;

public class MetaDataGenerator extends JNIGenerator {

@Override
public void generateCopyright() {
	generateMetaData("swt_properties_copyright");
}

@Override
public void generate(JNIClass clazz) {
	output(toC(clazz.getName()));
	output("=");
	output(((AbstractItem)clazz).flatten());
	outputln();
	JNIField[] fields = clazz.getDeclaredFields();
	generate(fields);
	JNIMethod[] methods = clazz.getDeclaredMethods();
	generate(methods);
	outputln();
}

public void generate(JNIField[] fields) {
	for (int i = 0; i < fields.length; i++) {
		JNIField field = fields[i];
		int mods = field.getModifiers();
		if ((mods & Modifier.PUBLIC) == 0) continue;
		if ((mods & Modifier.FINAL) != 0) continue;
		if ((mods & Modifier.STATIC) != 0) continue;
		generate(field);
		outputln();
	}
}

public void generate(JNIField field) {
	output(field.getDeclaringClass().getSimpleName());
	output("_");
	output(field.getName());
	output("=");
	output(((AbstractItem)field).flatten());
}

public void generate(JNIMethod[] methods) {
	sort(methods);
	for (int i = 0; i < methods.length; i++) {
		JNIMethod method = methods[i];
		if ((method.getModifiers() & Modifier.NATIVE) == 0) continue;
		generate(method);
		outputln();
		if (progress != null) progress.step();
	}
}

public void generate(JNIMethod method) {
	StringBuilder buffer = new StringBuilder();
	buffer.append(method.getDeclaringClass().getSimpleName());
	buffer.append("_");
	if (method.isNativeUnique()) {
		buffer.append(method.getName());
	} else {
		buffer.append(getFunctionName(method));
	}
	String key = buffer.toString();
	output(key);
	output("=");
	output(((AbstractItem)method).flatten());
	outputln();
	JNIParameter[] params = method.getParameters();
	for (int i = 0; i < params.length; i++) {
		output(key);
		output("_");
		output(i + "=");
		output(((AbstractItem)params[i]).flatten());
		outputln();		
	}
}

@Override
public String getExtension() {
	return ".properties";
}

@Override
protected boolean getGenerate(JNIItem item) {
	return true;
}

@Override
public String getOutputName() {
	return getMainClass().getName();
}

protected boolean getGenerate() {
	return true;
}

}

Back to the top