Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3b0b80954b0802bd150edfa8f633bc1ecd1d5ae5 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*******************************************************************************
 * Copyright (c) 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.tools.internal;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Properties;

public class MetaData {
	
	Properties data;

public MetaData(Properties data) {
	this.data = data;
}

public ClassData getMetaData(Class clazz) {
	String key = JNIGenerator.toC(clazz.getName());
	String value = getMetaData(key, "");
	return new ClassData(clazz, value);
}

public FieldData getMetaData(Field field) {
	String className = JNIGenerator.getClassName(field.getDeclaringClass());
	String key = className + "_" + field.getName();
	String value = getMetaData(key, "");
	return new FieldData(field, value);
}

boolean convertTo32Bit(Class[] paramTypes) {
	boolean changed = false;
	for (int i = 0; i < paramTypes.length; i++) {
		Class paramType = paramTypes[i];
		if (paramType == Long.TYPE) {
			paramTypes[i] = Integer.TYPE;
			changed = true;
		}
		if (paramType == long[].class) {
			paramTypes[i] = int[].class;
			changed = true;
		}
	}
	return changed;	
}

public MethodData getMetaData(Method method) {
	String className = JNIGenerator.getClassName(method.getDeclaringClass());
	String key = className + "_" + JNIGenerator.getFunctionName(method);
	String value = getMetaData(key, null);
	if (value == null) {
		key = className + "_" + method.getName();
		value = getMetaData(key, null);
	}
	/*
	* Support for 64 bit port.
	*/
	if (value == null) {
		Class[] paramTypes = method.getParameterTypes();
		if (convertTo32Bit(paramTypes)) {
			key = className + "_" + JNIGenerator.getFunctionName(method, paramTypes);
			value = getMetaData(key, null);
		}
	}	
	if (value == null) value = "";	
	return new MethodData(method, value);
}

public ParameterData getMetaData(Method method, int parameter) {
	String className = JNIGenerator.getClassName(method.getDeclaringClass());
	String key = className + "_" + JNIGenerator.getFunctionName(method) + "_" + parameter;
	String value = getMetaData(key, null);
	if (value == null) {
		key = className + "_" + method.getName() + "_" + parameter;
		value = getMetaData(key, null);
	}	
	/*
	* Support for 64 bit port.
	*/
	if (value == null) {
		Class[] paramTypes = method.getParameterTypes();
		if (convertTo32Bit(paramTypes)) {
			key = className + "_" + JNIGenerator.getFunctionName(method, paramTypes) + "_" + parameter;
			value = getMetaData(key, null);
		}
	}	
	if (value == null) value = "";
	
	return new ParameterData(method, parameter, value);
}

public String getMetaData(String key, String defaultValue) {
	return data.getProperty(key, defaultValue);
}

public void setMetaData(Class clazz, ClassData value) {
	String key = JNIGenerator.toC(clazz.getName());
	setMetaData(key, value.toString());
}

public void setMetaData(Field field, FieldData value) {
	String className = JNIGenerator.getClassName(field.getDeclaringClass());
	String key = className + "_" + field.getName();
	setMetaData(key, value.toString());
}

public void setMetaData(Method method, MethodData value) {
	String key;
	String className = JNIGenerator.getClassName(method.getDeclaringClass());
	if (JNIGenerator.isUnique(method, Modifier.NATIVE)) {
		key = className + "_" + method.getName ();
	} else {
		key = className + "_" + JNIGenerator.getFunctionName(method);
	}
	setMetaData(key, value.toString());
}

public void setMetaData(Method method, int arg, ParameterData value) {
	String key;
	String className = JNIGenerator.getClassName(method.getDeclaringClass());
	if (JNIGenerator.isUnique(method, Modifier.NATIVE)) {
		key = className + "_" + method.getName () + "_" + arg;
	} else {
		key = className + "_" + JNIGenerator.getFunctionName(method) + "_" + arg;
	}
	setMetaData(key, value.toString());
}

public void setMetaData(String key, String value) {
	data.setProperty(key, value);
}

}

Back to the top