Search in sources :

Example 1 with Adapter

use of org.bytedeco.javacpp.annotation.Adapter 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;
}
Also used : Cast(org.bytedeco.javacpp.annotation.Cast) Const(org.bytedeco.javacpp.annotation.Const) Adapter(org.bytedeco.javacpp.annotation.Adapter) Annotation(java.lang.annotation.Annotation) FileNotFoundException(java.io.FileNotFoundException) NoException(org.bytedeco.javacpp.annotation.NoException)

Example 2 with Adapter

use of org.bytedeco.javacpp.annotation.Adapter 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;
}
Also used : Cast(org.bytedeco.javacpp.annotation.Cast) ByPtrRef(org.bytedeco.javacpp.annotation.ByPtrRef) Const(org.bytedeco.javacpp.annotation.Const) Adapter(org.bytedeco.javacpp.annotation.Adapter) ByPtrPtr(org.bytedeco.javacpp.annotation.ByPtrPtr) Annotation(java.lang.annotation.Annotation)

Aggregations

Annotation (java.lang.annotation.Annotation)2 Adapter (org.bytedeco.javacpp.annotation.Adapter)2 Cast (org.bytedeco.javacpp.annotation.Cast)2 Const (org.bytedeco.javacpp.annotation.Const)2 FileNotFoundException (java.io.FileNotFoundException)1 ByPtrPtr (org.bytedeco.javacpp.annotation.ByPtrPtr)1 ByPtrRef (org.bytedeco.javacpp.annotation.ByPtrRef)1 NoException (org.bytedeco.javacpp.annotation.NoException)1