Java Code Examples for com.squareup.javapoet.TypeName#BOOLEAN

The following examples show how to use com.squareup.javapoet.TypeName#BOOLEAN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeUtility.java    From kripton with Apache License 2.0 6 votes vote down vote up
public static String getDefaultValue(TypeName value) {
	if (!isTypePrimitive(value)) {
		return null;
	} else {
		if (value == TypeName.BOOLEAN) {
			return "false";
		} else if (value == TypeName.BYTE) {
			return "(byte)0";
		} else if (value == TypeName.CHAR) {
			return "(char)0";
		} else if (value == TypeName.DOUBLE) {
			return "0.0";
		} else if (value == TypeName.FLOAT) {
			return "0.0f";
		} else if (value == TypeName.INT) {
			return "0";
		} else if (value == TypeName.LONG) {
			return "0";
		} else if (value == TypeName.SHORT) {
			return "(short)0";
		} else {
			return "0";
		}
	}
}
 
Example 2
Source File: ParameAnnotationClass.java    From EasyRouter with Apache License 2.0 6 votes vote down vote up
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 3
Source File: TypeUtil.java    From Intimate with Apache License 2.0 6 votes vote down vote up
public static String typeDefaultReturnCode(CName cName) {

        if (cName.isPrimitive) {
            if (cName.typeName == TypeName.VOID) return "";
            if (cName.typeName == TypeName.BOOLEAN) return "return false;";
            if (cName.typeName == TypeName.BYTE) return "return 0;";
            if (cName.typeName == TypeName.SHORT) return "return 0;";
            if (cName.typeName == TypeName.INT) return "return 0;";
            if (cName.typeName == TypeName.LONG) return "return 0;";
            if (cName.typeName == TypeName.CHAR) return "return 0;";
            if (cName.typeName == TypeName.FLOAT) return "return 0;";
            if (cName.typeName == TypeName.DOUBLE) return "return 0;";
        } else if (cName.fullName.equals("void")) {
            return "";
        }
        return "return null;";
    }
 
Example 4
Source File: PsiTypeUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
private static TypeName getPrimitiveTypeName(PsiPrimitiveType type) {
  switch (type.getCanonicalText()) {
    case "void":
      return TypeName.VOID;
    case "boolean":
      return TypeName.BOOLEAN;
    case "byte":
      return TypeName.BYTE;
    case "short":
      return TypeName.SHORT;
    case "int":
      return TypeName.INT;
    case "long":
      return TypeName.LONG;
    case "char":
      return TypeName.CHAR;
    case "float":
      return TypeName.FLOAT;
    case "double":
      return TypeName.DOUBLE;
    default:
      throw new UnsupportedOperationException(
          "Unknown primitive type: " + type.getCanonicalText());
  }
}
 
Example 5
Source File: BindingSet.java    From butterknife with Apache License 2.0 6 votes vote down vote up
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 6
Source File: JTypeName.java    From gwt-jackson with Apache License 2.0 6 votes vote down vote up
private TypeName primitiveName( JPrimitiveType type, boolean boxed ) {
    if ( "boolean".equals( type.getSimpleSourceName() ) ) {
        return boxed ? BOOLEAN_NAME : TypeName.BOOLEAN;
    } else if ( "byte".equals( type.getSimpleSourceName() ) ) {
        return boxed ? BYTE_NAME : TypeName.BYTE;
    } else if ( "short".equals( type.getSimpleSourceName() ) ) {
        return boxed ? SHORT_NAME : TypeName.SHORT;
    } else if ( "int".equals( type.getSimpleSourceName() ) ) {
        return boxed ? INTEGER_NAME : TypeName.INT;
    } else if ( "long".equals( type.getSimpleSourceName() ) ) {
        return boxed ? LONG_NAME : TypeName.LONG;
    } else if ( "char".equals( type.getSimpleSourceName() ) ) {
        return boxed ? CHARACTER_NAME : TypeName.CHAR;
    } else if ( "float".equals( type.getSimpleSourceName() ) ) {
        return boxed ? FLOAT_NAME : TypeName.FLOAT;
    } else if ( "double".equals( type.getSimpleSourceName() ) ) {
        return boxed ? DOUBLE_NAME : TypeName.DOUBLE;
    } else {
        return boxed ? VOID_NAME : TypeName.VOID;
    }
}
 
Example 7
Source File: ProcessUtils.java    From RxAndroidOrm with Apache License 2.0 5 votes vote down vote up
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 8
Source File: ProcessUtils.java    From Freezer with Apache License 2.0 5 votes vote down vote up
public static String getQueryCast(VariableElement variableElement) {
    TypeName typeName = getFieldClass(variableElement);
    if (ClassName.get(String.class).equals(typeName)) {
        return "$L";
    } else if (typeName == TypeName.BOOLEAN || typeName.equals(TypeName.get(Boolean.class))) {
        return "String.valueOf($L ? 1 : 0)";
    } else {
        return "String.valueOf($L)";
    }
}
 
Example 9
Source File: ProcessUtils.java    From Freezer with Apache License 2.0 5 votes vote down vote up
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 10
Source File: ProcessUtils.java    From Freezer with Apache License 2.0 5 votes vote down vote up
public static String getFieldCast(VariableElement variableElement) {
    TypeName typeName = getFieldClass(variableElement);
    if (typeName == TypeName.BOOLEAN) {
        return "(1 == %s)";
    }
    return "%s";
}
 
Example 11
Source File: ProcessUtils.java    From RxAndroidOrm with Apache License 2.0 5 votes vote down vote up
public static String getQueryCast(VariableElement variableElement) {
    TypeName typeName = getFieldClass(variableElement);
    if (ClassName.get(String.class).equals(typeName)) {
        return "$L";
    } else if (typeName == TypeName.BOOLEAN || typeName.equals(TypeName.get(Boolean.class))) {
        return "String.valueOf($L ? 1 : 0)";
    } else {
        return "String.valueOf($L)";
    }
}
 
Example 12
Source File: ProcessUtils.java    From RxAndroidOrm with Apache License 2.0 5 votes vote down vote up
public static String getFieldCast(VariableElement variableElement) {
    TypeName typeName = getFieldClass(variableElement);
    if (typeName == TypeName.BOOLEAN) {
        return "(1 == %s)";
    }
    return "%s";
}
 
Example 13
Source File: Scalars.java    From raml-java-tools with Apache License 2.0 5 votes vote down vote up
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 14
Source File: EasyType.java    From RapidORM with Apache License 2.0 5 votes vote down vote up
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 15
Source File: TypeNameUtils.java    From componentrouter with Apache License 2.0 5 votes vote down vote up
public static String getDefaultValue(String fullClassName) {
    TypeName typeName = getTypeName(fullClassName);
    if (typeName == TypeName.SHORT || typeName == TypeName.INT || typeName == TypeName.LONG || typeName == TypeName.FLOAT || typeName == TypeName.DOUBLE || typeName == TypeName.CHAR || typeName == TypeName.BYTE) {
        return String.format("(%s)0", typeName.toString());
    }
    if (typeName == TypeName.BOOLEAN) {
        return "false";
    }
    return String.format("(%s)null", typeName.toString());
}
 
Example 16
Source File: Names.java    From featured with Apache License 2.0 5 votes vote down vote up
public TypeName getTypeNameByKind(VariableElement param) {
    switch (param.asType().getKind()) {

        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;

        case DECLARED:
            TypeMirror type = param.asType();
            TypeName typeName = ClassName.get(type);
            typeName = applyAnnotations(typeName, param);
            return typeName;

        case ARRAY:
            ArrayType arrayType = (ArrayType) param.asType();
            TypeName arrayTypeName = ArrayTypeName.get(arrayType);
            arrayTypeName = applyAnnotations(arrayTypeName, param);
            return arrayTypeName;

        default:
            throw new IllegalStateException("unsupported kind: " + param.asType().getKind());
    }
}
 
Example 17
Source File: JsonBoolean.java    From json2java4idea with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public TypeName getType() {
    return TypeName.BOOLEAN;
}
 
Example 18
Source File: ClassNameModel.java    From nalu with Apache License 2.0 4 votes vote down vote up
public TypeName getTypeName() {
  switch (className) {
    case "void":
      return TypeName.VOID;
    case "boolean":
      return TypeName.BOOLEAN;
    case "byte":
      return TypeName.BYTE;
    case "short":
      return TypeName.SHORT;
    case "int":
      return TypeName.INT;
    case "long":
      return TypeName.LONG;
    case "char":
      return TypeName.CHAR;
    case "float":
      return TypeName.FLOAT;
    case "double":
      return TypeName.DOUBLE;
    case "Object":
      return TypeName.OBJECT;
    case "Void":
      return ClassName.get("java.lang",
                           "Void");
    case "Boolean":
      return ClassName.get("java.lang",
                           "Boolean");
    case "Byte":
      return ClassName.get("java.lang",
                           "Byte");
    case "Short":
      return ClassName.get("java.lang",
                           "Short");
    case "Integer":
      return ClassName.get("java.lang",
                           "Integer");
    case "Long":
      return ClassName.get("java.lang",
                           "Long");
    case "Character":
      return ClassName.get("java.lang",
                           "Character");
    case "Float":
      return ClassName.get("java.lang",
                           "Float");
    case "Double":
      return ClassName.get("java.lang",
                           "Double");
    default:
      return ClassName.get(this.getPackage(),
                           this.getSimpleName());
  }
}
 
Example 19
Source File: AbstractConfigProviderGenerator.java    From aircon with MIT License 4 votes vote down vote up
protected static String getGetterMethodPrefix(TypeName typeName) {
	return typeName == TypeName.BOOLEAN ? Consts.PREDICATE_METHOD_PREFIX : Consts.GETTER_METHOD_PREFIX;
}
 
Example 20
Source File: BeanUtils.java    From fastjgame with Apache License 2.0 2 votes vote down vote up
/**
 * 是否是基本类型的boolean
 *
 * @param typeName 类型描述名
 * @return 如果boolean类型或Boolean则返回true
 */
public static boolean isPrimitiveBoolean(TypeName typeName) {
    return typeName == TypeName.BOOLEAN;
}