Search in sources :

Example 6 with ObjectiveCName

use of com.google.j2objc.annotations.ObjectiveCName in project j2objc by google.

the class Types method appendGenericType.

@ObjectiveCName("appendGenericType:type:")
public static void appendGenericType(StringBuilder out, Type type) {
    if (type instanceof TypeVariable) {
        out.append(((TypeVariable) type).getName());
    } else if (type instanceof ParameterizedType) {
        out.append(type.toString());
    } else if (type instanceof GenericArrayType) {
        Type simplified = ((GenericArrayType) type).getGenericComponentType();
        appendGenericType(out, simplified);
        out.append("[]");
    } else if (type instanceof Class) {
        Class c = (Class<?>) type;
        if (c.isArray()) {
            String[] as = c.getName().split("\\[");
            int len = as.length - 1;
            if (as[len].length() > 1) {
                out.append(as[len].substring(1, as[len].length() - 1));
            } else {
                char ch = as[len].charAt(0);
                if (ch == 'I') {
                    out.append("int");
                } else if (ch == 'B') {
                    out.append("byte");
                } else if (ch == 'J') {
                    out.append("long");
                } else if (ch == 'F') {
                    out.append("float");
                } else if (ch == 'D') {
                    out.append("double");
                } else if (ch == 'S') {
                    out.append("short");
                } else if (ch == 'C') {
                    out.append("char");
                } else if (ch == 'Z') {
                    out.append("boolean");
                } else if (ch == 'V') {
                    out.append("void");
                }
            }
            for (int i = 0; i < len; i++) {
                out.append("[]");
            }
        } else {
            out.append(c.getName());
        }
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) GenericArrayType(java.lang.reflect.GenericArrayType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) TypeVariable(java.lang.reflect.TypeVariable) GenericArrayType(java.lang.reflect.GenericArrayType) ObjectiveCName(com.google.j2objc.annotations.ObjectiveCName)

Example 7 with ObjectiveCName

use of com.google.j2objc.annotations.ObjectiveCName in project j2objc by google.

the class InputFilePreprocessor method extractPackagePrefix.

private void extractPackagePrefix(InputFile file, CompilationUnit unit) {
    // We should only reach here if it's a package-info.java file.
    assert file.getUnitName().endsWith("package-info.java");
    List<Annotation> annotations = (List<Annotation>) unit.getPackage().getAnnotations();
    for (Annotation annotation : annotations) {
        // getFullyQualifiedName() might not actually return a fully qualified name.
        String name = annotation.getTypeName().getFullyQualifiedName();
        if (name.endsWith("ObjectiveCName")) {
            // Per Eclipse docs, binding resolution can be a resource hog.
            if (TypeUtil.getQualifiedName(annotation.getAnnotationMirror().getAnnotationType()).equals(ObjectiveCName.class.getCanonicalName())) {
                String key = unit.getPackage().getName().getFullyQualifiedName();
                String val = (String) ((SingleMemberAnnotation) annotation).getValue().getConstantValue();
                options.getPackagePrefixes().addPrefix(key, val);
            }
        }
    }
}
Also used : ObjectiveCName(com.google.j2objc.annotations.ObjectiveCName) SingleMemberAnnotation(com.google.devtools.j2objc.ast.SingleMemberAnnotation) List(java.util.List) Annotation(com.google.devtools.j2objc.ast.Annotation) SingleMemberAnnotation(com.google.devtools.j2objc.ast.SingleMemberAnnotation)

Example 8 with ObjectiveCName

use of com.google.j2objc.annotations.ObjectiveCName in project actor-platform by actorapp.

the class IntlEngine method areSameDays.

@ObjectiveCName("areSameDaysWithA:withB:")
public boolean areSameDays(long a, long b) {
    Date date1 = new Date(a);
    int y1 = date1.getYear();
    int m1 = date1.getMonth();
    int d1 = date1.getDate();
    Date date2 = new Date(b);
    int y2 = date2.getYear();
    int m2 = date2.getMonth();
    int d2 = date2.getDate();
    return y1 == y2 && m1 == m2 && d1 == d2;
}
Also used : Date(java.util.Date) ObjectiveCName(com.google.j2objc.annotations.ObjectiveCName)

Example 9 with ObjectiveCName

use of com.google.j2objc.annotations.ObjectiveCName in project actor-platform by actorapp.

the class GroupPermissions method setShowJoinLeaveMessages.

@ObjectiveCName("setShowJoinLeaveMessages:")
public void setShowJoinLeaveMessages(boolean showJoinLeaveMessages) {
    SparseArray<Object> unmapped = settings.getUnmappedObjects();
    settings = new ApiAdminSettings(settings.showAdminsToMembers(), settings.canMembersInvite(), settings.canMembersEditGroupInfo(), settings.canAdminsEditGroupInfo(), showJoinLeaveMessages);
    settings.setUnmappedObjects(unmapped);
}
Also used : ApiAdminSettings(im.actor.core.api.ApiAdminSettings) ObjectiveCName(com.google.j2objc.annotations.ObjectiveCName)

Example 10 with ObjectiveCName

use of com.google.j2objc.annotations.ObjectiveCName in project actor-platform by actorapp.

the class I18nEngine method formatErrorText.

@ObjectiveCName("formatErrorTextWithError:")
public String formatErrorText(Object o) {
    if (o instanceof RpcException) {
        RpcException e = (RpcException) o;
        String res = Errors.mapError(e.getTag(), null);
        if (res != null) {
            return get(res);
        } else {
            if (e.getMessage().equals("")) {
                return e.getTag();
            } else {
                return e.getMessage();
            }
        }
    } else if (o instanceof Exception) {
        return ((Exception) o).getMessage();
    } else {
        return "" + o;
    }
}
Also used : RpcException(im.actor.core.network.RpcException) JSONException(im.actor.runtime.json.JSONException) RpcException(im.actor.core.network.RpcException) ObjectiveCName(com.google.j2objc.annotations.ObjectiveCName)

Aggregations

ObjectiveCName (com.google.j2objc.annotations.ObjectiveCName)11 ApiAdminSettings (im.actor.core.api.ApiAdminSettings)5 Date (java.util.Date)2 Annotation (com.google.devtools.j2objc.ast.Annotation)1 SingleMemberAnnotation (com.google.devtools.j2objc.ast.SingleMemberAnnotation)1 Message (im.actor.core.entity.Message)1 TextContent (im.actor.core.entity.content.TextContent)1 RpcException (im.actor.core.network.RpcException)1 JSONException (im.actor.runtime.json.JSONException)1 GenericArrayType (java.lang.reflect.GenericArrayType)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 TypeVariable (java.lang.reflect.TypeVariable)1 List (java.util.List)1