Java Code Examples for com.squareup.javapoet.TypeName.LONG

The following are Jave code examples for showing how to use LONG of the com.squareup.javapoet.TypeName class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: BindingSet.java   View Source Code Vote up 6 votes
private static TypeName bestGuess(String type) {
  switch (type) {
    case "void": return TypeName.VOID;
    case "boolean": return TypeName.BOOLEAN;
    case "byte": return TypeName.BYTE;
    case "char": return TypeName.CHAR;
    case "double": return TypeName.DOUBLE;
    case "float": return TypeName.FLOAT;
    case "int": return TypeName.INT;
    case "long": return TypeName.LONG;
    case "short": return TypeName.SHORT;
    default:
      int left = type.indexOf('<');
      if (left != -1) {
        ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
        List<TypeName> typeArguments = new ArrayList<>();
        do {
          typeArguments.add(WildcardTypeName.subtypeOf(Object.class));
          left = type.indexOf('<', left + 1);
        } while (left != -1);
        return ParameterizedTypeName.get(typeClassName,
            typeArguments.toArray(new TypeName[typeArguments.size()]));
      }
      return ClassName.bestGuess(type);
  }
}
 
Example 2
Project: auto-value-json   File: AutoValueJsonExtension.java   View Source Code Vote up 6 votes
private String defaultValue(JsonProperty property, TypeName type) {
  if (property.defaultValue != null) {
    return property.defaultValue;
  }
  if (type == TypeName.BOOLEAN) {
    return "false";
  } else if (type == TypeName.BYTE) {
    return "(byte) 0";
  } else if (type == TypeName.SHORT) {
    return "0";
  } else if (type == TypeName.INT) {
    return "0";
  } else if (type == TypeName.LONG) {
    return "0L";
  } else if (type == TypeName.CHAR) {
    return "'\0'";
  } else if (type == TypeName.FLOAT) {
    return "0.0f";
  } else if (type == TypeName.DOUBLE) {
    return "0.0d";
  } else {
    return "null";
  }
}
 
Example 3
Project: D-Router   File: RouterProcessor.java   View Source Code Vote up 6 votes
private static TypeName convertClass(String originClazz) {
    switch (originClazz) {
        case "int":
            return TypeName.INT;
        case "long":
            return TypeName.LONG;
        case "float":
            return TypeName.FLOAT;
        case "double":
            return TypeName.DOUBLE;
        case "short":
            return TypeName.SHORT;
        case "boolean":
            return TypeName.BOOLEAN;
        case "char":
            return TypeName.CHAR;
        default:
            return ClassName.bestGuess(originClazz);
    }
}
 
Example 4
Project: slimorm   File: SlimOrmProcessor.java   View Source Code Vote up 6 votes
private String mapTypeToCursorGetMethod(TypeName typeName) {
    if (typeName == TypeName.BOOLEAN) {
        return "getInt";
    } else if (typeName == TypeName.SHORT) {
        return "getShort";
    } else if (typeName == TypeName.INT) {
        return "getInt";
    } else if (typeName == TypeName.LONG) {
        return "getLong";
    } else if (typeName == TypeName.FLOAT) {
        return "getFloat";
    } else if (typeName == TypeName.DOUBLE) {
        return "getDouble";
    }
    return "";
}
 
Example 5
Project: raml-java-tools   File: Scalars.java   View Source Code Vote up 5 votes
public static TypeName classToTypeName(Class scalar) {
    if (scalar.isPrimitive()) {
        switch (scalar.getSimpleName()) {
            case "int":
                return TypeName.INT;

            case "boolean":
                return TypeName.BOOLEAN;

            case "double":
                return TypeName.DOUBLE;

            case "float":
                return TypeName.FLOAT;

            case "byte":
                return TypeName.BYTE;

            case "char":
                return TypeName.CHAR;

            case "short":
                return TypeName.SHORT;

            case "long":
                return TypeName.LONG;

            case "void":
                return TypeName.VOID; // ?

            default:
                throw new GenerationException("can't handle type: " + scalar);
        }
    } else {
        return ClassName.get(scalar);
    }
}
 
Example 6
Project: RxAndroidOrm   File: ProcessUtils.java   View Source Code Vote up 5 votes
public static String getFieldType(VariableElement variableElement) {
    TypeName typeName = getFieldClass(variableElement);
    if (typeName == TypeName.INT || typeName == TypeName.BOOLEAN || typeName == TypeName.BYTE) {
        return "Int";
    } else if (typeName == TypeName.LONG) {
        return "Long";
    } else if (typeName == TypeName.FLOAT) {
        return "Float";
    } else if (typeName == TypeName.DOUBLE) {
        return "Double";
    } else if (ClassName.get(String.class).equals(typeName)) {
        return "String";
    }
    return "";
}
 
Example 7
Project: RxAndroidOrm   File: ProcessUtils.java   View Source Code Vote up 5 votes
public static String getFieldTableType(Element variableElement) {
    TypeName typeName = getFieldClass(variableElement);
    if (typeName == TypeName.INT
        || typeName == TypeName.BOOLEAN
        || typeName == TypeName.LONG
        || typeName == TypeName.BYTE) {
        return "integer";
    }
    if (typeName == TypeName.FLOAT) {
        return "real";
    } else if (ClassName.get(String.class).equals(typeName) || isDate(typeName)) {
        return "text";
    }
    return null;
}
 
Example 8
Project: RapidRouter   File: EasyType.java   View Source Code Vote up 5 votes
public static TypeName bestGuess(String type) {
    switch (type) {
        case "void":
            return TypeName.VOID;
        case "boolean":
            return TypeName.BOOLEAN;
        case "byte":
            return TypeName.BYTE;
        case "char":
            return TypeName.CHAR;
        case "double":
            return TypeName.DOUBLE;
        case "float":
            return TypeName.FLOAT;
        case "int":
            return TypeName.INT;
        case "long":
            return TypeName.LONG;
        case "short":
            return TypeName.SHORT;
        default:
            int left = type.indexOf('<');
            if (left != -1) {
                ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
                List<TypeName> typeArguments = new ArrayList<>();
                do {
                    typeArguments.add(WildcardTypeName.subtypeOf(Object.class));
                    left = type.indexOf('<', left + 1);
                } while (left != -1);
                return ParameterizedTypeName.get(typeClassName,
                        typeArguments.toArray(new TypeName[typeArguments.size()]));
            }
            return ClassName.bestGuess(type);
    }
}
 
Example 9
Project: RapidRouter   File: EasyType.java   View Source Code Vote up 5 votes
/**
 * @param type
 * @return
 */
public static TypeName bestGuessDeep(String type) {
    switch (type) {
        case "void":
            return TypeName.VOID;
        case "boolean":
            return TypeName.BOOLEAN;
        case "byte":
            return TypeName.BYTE;
        case "char":
            return TypeName.CHAR;
        case "double":
            return TypeName.DOUBLE;
        case "float":
            return TypeName.FLOAT;
        case "int":
            return TypeName.INT;
        case "long":
            return TypeName.LONG;
        case "short":
            return TypeName.SHORT;
        default:
            int left = type.indexOf('<');
            int right = type.indexOf('>');
            if (-1 != left && -1 != right) {
                ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
                List<TypeName> typeArguments = new ArrayList<>();
                do {
                    typeArguments.add(WildcardTypeName.subtypeOf(bestGuess(type.substring(left + 1, right))));
                    left = type.indexOf('<', left + 1);
                    right = type.indexOf('>', right - 1);
                } while (left != -1);
                return ParameterizedTypeName.get(typeClassName,
                        typeArguments.toArray(new TypeName[typeArguments.size()]));
            }
            return ClassName.bestGuess(type);
    }
}
 
Example 10
Project: data-mediator   File: TypeUtils.java   View Source Code Vote up 5 votes
public static TypeName getTypeName(String type){
    switch (type){
        case NAME_int:
            return TypeName.INT;

        case NAME_long:
            return TypeName.LONG;

        case NAME_short:
            return TypeName.SHORT;

        case NAME_byte:
            return TypeName.BYTE;

        case NAME_boolean:
            return TypeName.BOOLEAN;

        case NAME_float:
            return TypeName.FLOAT;

        case NAME_double:
            return TypeName.DOUBLE;

        case NAME_char:
            return TypeName.CHAR;

        case NAME_void:
            return TypeName.VOID;
    }
    return ClassName.bestGuess(type);
}
 
Example 11
Project: butterknife-parent   File: BindingSet.java   View Source Code Vote up 5 votes
private static TypeName bestGuess(String type) {
    switch (type) {
        case "void":
            return TypeName.VOID;
        case "boolean":
            return TypeName.BOOLEAN;
        case "byte":
            return TypeName.BYTE;
        case "char":
            return TypeName.CHAR;
        case "double":
            return TypeName.DOUBLE;
        case "float":
            return TypeName.FLOAT;
        case "int":
            return TypeName.INT;
        case "long":
            return TypeName.LONG;
        case "short":
            return TypeName.SHORT;
        default:
            int left = type.indexOf('<');
            if (left != -1) {
                ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
                List<TypeName> typeArguments = new ArrayList<>();
                do {
                    typeArguments.add(WildcardTypeName.subtypeOf(Object.class));
                    left = type.indexOf('<', left + 1);
                } while (left != -1);
                return ParameterizedTypeName.get(typeClassName,
                        typeArguments.toArray(new TypeName[typeArguments.size()]));
            }
            return ClassName.bestGuess(type);
    }
}
 
Example 12
Project: arez   File: ComponentDescriptor.java   View Source Code Vote up 5 votes
@Nonnull
private TypeName getIdType()
{
  return null == _componentId ?
         TypeName.LONG :
         TypeName.get( _componentId.getReturnType() );
}
 
Example 13
Project: GitHub   File: LongFieldType.java   View Source Code Vote up 4 votes
@Override
public TypeName getTypeName() {
    return (isPrimitive ? TypeName.LONG : ClassName.get(Long.class));
}