use of org.bytedeco.javacpp.annotation.Const in project javacpp by bytedeco.
the class Generator method cppCastTypeName.
String[] cppCastTypeName(Class<?> type, Annotation... annotations) {
String[] typeName = null;
boolean warning = false, adapter = false;
for (Annotation a : annotations) {
if (a instanceof Cast) {
warning = typeName != null;
String prefix = ((Cast) a).value()[0], suffix = "";
int templateCount = 0;
for (int i = 0; i < prefix.length(); i++) {
int c = prefix.charAt(i);
if (c == '<') {
templateCount++;
} else if (c == '>') {
templateCount--;
} else if (templateCount == 0 && c == ')') {
suffix = prefix.substring(i).trim();
prefix = prefix.substring(0, i).trim();
break;
}
}
typeName = prefix.length() > 0 ? new String[] { prefix, suffix } : null;
} else if (a instanceof Const) {
boolean[] b = ((Const) a).value();
if ((b.length == 1 && !b[0]) || (b.length > 1 && !b[0] && !b[1])) {
// not interested in const members
continue;
}
if (warning = typeName != null) {
// prioritize @Cast
continue;
}
typeName = cppTypeName(type);
if (b.length > 1 && b[1] && !typeName[0].endsWith(" const *")) {
typeName[0] = valueTypeName(typeName) + " const *";
}
if (b.length > 0 && b[0] && !typeName[0].startsWith("const ")) {
typeName[0] = "const " + typeName[0];
}
Annotation by = by(annotations);
if (by instanceof ByPtrPtr) {
typeName[0] += "*";
} else if (by instanceof ByPtrRef) {
typeName[0] += "&";
}
} else if (a instanceof Adapter || a.annotationType().isAnnotationPresent(Adapter.class)) {
adapter = true;
}
}
if (warning && !adapter) {
logger.warn("Without \"Adapter\", \"Cast\" and \"Const\" annotations are mutually exclusive.");
}
if (typeName == null) {
typeName = cppTypeName(type);
}
return typeName;
}
Aggregations