use of org.graalvm.nativeimage.c.struct.RawField in project graal by oracle.
the class InfoTreeBuilder method createRawStructInfo.
private void createRawStructInfo(ResolvedJavaType type) {
if (!validInterfaceDefinition(type, RawStructure.class)) {
return;
}
Map<String, List<AccessorInfo>> fieldAccessorInfos = new TreeMap<>();
List<AccessorInfo> structAccessorInfos = new ArrayList<>();
for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
String fieldName;
AccessorInfo accessorInfo;
RawField fieldAnnotation = getMethodAnnotation(method, RawField.class);
if (fieldAnnotation != null) {
if (method.getSignature().getReturnKind() == JavaKind.Void) {
accessorInfo = new AccessorInfo(method, AccessorKind.SETTER, false, hasLocationIdentityParameter(method), hasUniqueLocationIdentity(method));
} else {
accessorInfo = new AccessorInfo(method, AccessorKind.GETTER, false, hasLocationIdentityParameter(method), hasUniqueLocationIdentity(method));
}
fieldName = getStructFieldName(method, "", accessorInfo.getAccessorKind());
} else if (method.getSignature().getReturnType(method.getDeclaringClass()).equals(method.getDeclaringClass())) {
fieldName = null;
accessorInfo = new AccessorInfo(method, AccessorKind.ADDRESS, method.getSignature().getParameterCount(false) > 0, false, false);
} else {
nativeLibs.addError("Unexpected method without annotation", method);
continue;
}
if (accessorValid(accessorInfo)) {
if (fieldName == null) {
structAccessorInfos.add(accessorInfo);
} else {
Map<String, List<AccessorInfo>> map = fieldAccessorInfos;
List<AccessorInfo> accessorInfos = map.get(fieldName);
if (accessorInfos == null) {
accessorInfos = new ArrayList<>();
map.put(fieldName, accessorInfos);
}
accessorInfos.add(accessorInfo);
}
nativeLibs.registerElementInfo(method, accessorInfo);
}
}
String typeName = getStructName(type);
StructInfo structInfo = StructInfo.create(typeName, type);
structInfo.adoptChildren(structAccessorInfos);
for (Map.Entry<String, List<AccessorInfo>> entry : fieldAccessorInfos.entrySet()) {
StructFieldInfo fieldInfo = new StructFieldInfo(entry.getKey(), elementKind(entry.getValue()));
fieldInfo.adoptChildren(entry.getValue());
structInfo.adoptChild(fieldInfo);
}
nativeCodeInfo.adoptChild(structInfo);
nativeLibs.registerElementInfo(type, structInfo);
}
Aggregations