use of org.bytedeco.javacpp.annotation.Const in project bigbluebutton by bigbluebutton.
the class Generator method adapterInformation.
AdapterInformation adapterInformation(boolean out, String valueTypeName, Annotation... annotations) {
AdapterInformation adapterInfo = null;
boolean constant = false;
String cast = "";
for (Annotation a : annotations) {
Adapter adapter = a instanceof Adapter ? (Adapter) a : a.annotationType().getAnnotation(Adapter.class);
if (adapter != null) {
adapterInfo = new AdapterInformation();
adapterInfo.name = adapter.value();
adapterInfo.argc = adapter.argc();
if (a != adapter) {
try {
Class cls = a.annotationType();
if (cls.isAnnotationPresent(Const.class)) {
constant = true;
}
try {
String value = cls.getDeclaredMethod("value").invoke(a).toString();
if (value != null && value.length() > 0) {
valueTypeName = value;
}
// else use inferred type
} catch (NoSuchMethodException e) {
// this adapter does not support a template type
valueTypeName = null;
}
Cast c = (Cast) cls.getAnnotation(Cast.class);
if (c != null && cast.length() == 0) {
cast = c.value()[0];
if (valueTypeName != null) {
cast += "< " + valueTypeName + " >";
}
if (c.value().length > 1) {
cast += c.value()[1];
}
}
} catch (Exception ex) {
logger.warn("Could not invoke the value() method on annotation \"" + a + "\": " + ex);
}
if (valueTypeName != null && valueTypeName.length() > 0) {
adapterInfo.name += "< " + valueTypeName + " >";
}
}
} else if (a instanceof Const) {
constant = true;
} else if (a instanceof Cast) {
Cast c = ((Cast) a);
if (c.value().length > 1) {
cast = c.value()[1];
}
}
}
if (adapterInfo != null) {
adapterInfo.cast = cast;
adapterInfo.constant = constant;
}
return out && constant ? null : adapterInfo;
}
use of org.bytedeco.javacpp.annotation.Const in project bigbluebutton by bigbluebutton.
the class Generator method cppAnnotationTypeName.
String[] cppAnnotationTypeName(Class<?> type, Annotation... annotations) {
String[] typeName = cppCastTypeName(type, annotations);
String prefix = typeName[0];
String suffix = typeName[1];
boolean casted = false;
for (Annotation a : annotations) {
if ((a instanceof Cast && ((Cast) a).value()[0].length() > 0) || a instanceof Const) {
casted = true;
break;
}
}
Annotation by = by(annotations);
if (by instanceof ByVal) {
prefix = constValueTypeName(typeName);
} else if (by instanceof ByRef) {
prefix = constValueTypeName(typeName) + "&";
} else if (by instanceof ByPtrPtr && !casted) {
prefix = prefix + "*";
} else if (by instanceof ByPtrRef) {
prefix = prefix + "&";
}
// else ByPtr
typeName[0] = prefix;
typeName[1] = suffix;
return typeName;
}
use of org.bytedeco.javacpp.annotation.Const in project bigbluebutton by bigbluebutton.
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 parenthesis = prefix.indexOf(')');
if (parenthesis > 0) {
suffix = prefix.substring(parenthesis).trim();
prefix = prefix.substring(0, parenthesis).trim();
}
typeName = prefix.length() > 0 ? new String[] { prefix, suffix } : null;
} else if (a instanceof Const) {
if (warning = typeName != null) {
// prioritize @Cast
continue;
}
typeName = cppTypeName(type);
boolean[] b = ((Const) a).value();
if (b.length > 1 && b[1]) {
typeName[0] = valueTypeName(typeName) + " const *";
}
if (b.length > 0 && b[0]) {
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;
}
use of org.bytedeco.javacpp.annotation.Const in project javacpp by bytedeco.
the class Generator method adapterInformation.
AdapterInformation adapterInformation(boolean out, String valueTypeName, Annotation... annotations) {
AdapterInformation adapterInfo = null;
boolean constant = false;
String cast = "", cast2 = "";
for (Annotation a : annotations) {
// allow overriding template type for const, etc
if (a instanceof Cast) {
Cast c = ((Cast) a);
if (c.value().length > 0 && c.value()[0].length() > 0) {
valueTypeName = constValueTypeName(c.value()[0]);
}
}
}
for (Annotation a : annotations) {
Adapter adapter = a instanceof Adapter ? (Adapter) a : a.annotationType().getAnnotation(Adapter.class);
if (adapter != null) {
adapterInfo = new AdapterInformation();
adapterInfo.name = adapter.value();
adapterInfo.argc = adapter.argc();
if (a != adapter) {
try {
Class cls = a.annotationType();
if (cls.isAnnotationPresent(Const.class)) {
constant = true;
}
try {
String value = cls.getDeclaredMethod("value").invoke(a).toString();
if (value != null && value.length() > 0) {
valueTypeName = value;
}
// else use inferred type
} catch (NoSuchMethodException e) {
// this adapter does not support a template type
valueTypeName = null;
}
Cast c = (Cast) cls.getAnnotation(Cast.class);
if (c != null && cast.length() == 0) {
cast = c.value()[0];
if (valueTypeName != null) {
cast += "< " + valueTypeName + " >";
}
if (c.value().length > 1) {
cast += c.value()[1];
}
if (c.value().length > 2) {
cast2 = c.value()[2];
}
}
} catch (Exception ex) {
logger.warn("Could not invoke the value() method on annotation \"" + a + "\": " + ex);
}
if (valueTypeName != null && valueTypeName.length() > 0) {
adapterInfo.name += "< " + valueTypeName + " >";
}
}
} else if (a instanceof Const) {
constant = true;
} else if (a instanceof Cast) {
Cast c = ((Cast) a);
if (c.value().length > 1) {
cast = c.value()[1];
}
if (c.value().length > 2) {
cast2 = c.value()[2];
}
}
}
if (adapterInfo != null) {
adapterInfo.cast = cast;
adapterInfo.cast2 = cast2;
adapterInfo.constant = constant;
}
return out && constant ? null : adapterInfo;
}
use of org.bytedeco.javacpp.annotation.Const in project javacpp by bytedeco.
the class Generator method cppAnnotationTypeName.
String[] cppAnnotationTypeName(Class<?> type, Annotation... annotations) {
String[] typeName = cppCastTypeName(type, annotations);
String prefix = typeName[0];
String suffix = typeName[1];
boolean casted = false;
for (Annotation a : annotations) {
if ((a instanceof Cast && ((Cast) a).value()[0].length() > 0) || a instanceof Const) {
casted = true;
break;
}
}
Annotation by = by(annotations);
if (by instanceof ByVal) {
prefix = constValueTypeName(typeName);
} else if (by instanceof ByRef) {
prefix = constValueTypeName(typeName) + "&";
} else if (by instanceof ByPtrPtr && !casted) {
prefix = prefix + "*";
} else if (by instanceof ByPtrRef) {
prefix = prefix + "&";
}
// else ByPtr
typeName[0] = prefix;
typeName[1] = suffix;
return typeName;
}
Aggregations