Java Code Examples for javax.lang.model.type.TypeKind#BYTE

The following examples show how to use javax.lang.model.type.TypeKind#BYTE . 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: Type.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public TypeKind getKind() {
    switch (tag) {
    case BYTE:      return TypeKind.BYTE;
    case CHAR:      return TypeKind.CHAR;
    case SHORT:     return TypeKind.SHORT;
    case INT:       return TypeKind.INT;
    case LONG:      return TypeKind.LONG;
    case FLOAT:     return TypeKind.FLOAT;
    case DOUBLE:    return TypeKind.DOUBLE;
    case BOOLEAN:   return TypeKind.BOOLEAN;
    case VOID:      return TypeKind.VOID;
    case BOT:       return TypeKind.NULL;
    case NONE:      return TypeKind.NONE;
    default:        return TypeKind.OTHER;
    }
}
 
Example 2
Source File: JCTree.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public TypeKind getPrimitiveTypeKind() {
    switch (typetag) {
        case TypeTags.BOOLEAN:
            return TypeKind.BOOLEAN;
        case TypeTags.BYTE:
            return TypeKind.BYTE;
        case TypeTags.SHORT:
            return TypeKind.SHORT;
        case TypeTags.INT:
            return TypeKind.INT;
        case TypeTags.LONG:
            return TypeKind.LONG;
        case TypeTags.CHAR:
            return TypeKind.CHAR;
        case TypeTags.FLOAT:
            return TypeKind.FLOAT;
        case TypeTags.DOUBLE:
            return TypeKind.DOUBLE;
        case TypeTags.VOID:
            return TypeKind.VOID;
        default:
            throw new AssertionError("unknown primitive type " + this);
    }
}
 
Example 3
Source File: PrimitiveTypeImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static TypeKind getKind(BaseTypeBinding binding) {
	switch (binding.id) {
	case TypeIds.T_boolean:
		return TypeKind.BOOLEAN;
	case TypeIds.T_byte:
		return TypeKind.BYTE;
	case TypeIds.T_char:
		return TypeKind.CHAR;
	case TypeIds.T_double:
		return TypeKind.DOUBLE;
	case TypeIds.T_float:
		return TypeKind.FLOAT;
	case TypeIds.T_int:
		return TypeKind.INT;
	case TypeIds.T_long:
		return TypeKind.LONG;
	case TypeIds.T_short:
		return TypeKind.SHORT;
	default:
		throw new IllegalArgumentException("BaseTypeBinding of unexpected id " + binding.id); //$NON-NLS-1$
	}
}
 
Example 4
Source File: TypeTag.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public TypeKind getPrimitiveTypeKind() {
    switch (this) {
    case BOOLEAN:
        return TypeKind.BOOLEAN;
    case BYTE:
        return TypeKind.BYTE;
    case SHORT:
        return TypeKind.SHORT;
    case INT:
        return TypeKind.INT;
    case LONG:
        return TypeKind.LONG;
    case CHAR:
        return TypeKind.CHAR;
    case FLOAT:
        return TypeKind.FLOAT;
    case DOUBLE:
        return TypeKind.DOUBLE;
    case VOID:
        return TypeKind.VOID;
    default:
        throw new AssertionError("unknown primitive type " + this);
    }
}
 
Example 5
Source File: TypeTag.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public TypeKind getPrimitiveTypeKind() {
    switch (this) {
    case BOOLEAN:
        return TypeKind.BOOLEAN;
    case BYTE:
        return TypeKind.BYTE;
    case SHORT:
        return TypeKind.SHORT;
    case INT:
        return TypeKind.INT;
    case LONG:
        return TypeKind.LONG;
    case CHAR:
        return TypeKind.CHAR;
    case FLOAT:
        return TypeKind.FLOAT;
    case DOUBLE:
        return TypeKind.DOUBLE;
    case VOID:
        return TypeKind.VOID;
    default:
        throw new AssertionError("unknown primitive type " + this);
    }
}
 
Example 6
Source File: AddWsOperationHelper.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String getMethodBody(Tree returnType) {
    String body = null;
    if (Kind.PRIMITIVE_TYPE == returnType.getKind()) {
        TypeKind type = ((PrimitiveTypeTree)returnType).getPrimitiveTypeKind();
        if (TypeKind.VOID == type) body = ""; //NOI18N
        else if (TypeKind.BOOLEAN == type) body = "return false;"; // NOI18N
        else if (TypeKind.INT == type) body = "return 0;"; // NOI18N
        else if (TypeKind.LONG == type) body = "return 0;"; // NOI18N
        else if (TypeKind.FLOAT == type) body = "return 0.0;"; // NOI18N
        else if (TypeKind.DOUBLE == type) body = "return 0.0;"; // NOI18N
        else if (TypeKind.BYTE == type) body = "return 0;"; // NOI18N
        else if (TypeKind.SHORT == type) body = "return 0;"; // NOI18N
        else if (TypeKind.CHAR == type) body = "return ' ';"; // NOI18N
        else body = "return null"; //NOI18N
    } else
        body = "return null"; //NOI18N
    return "{\n\t\t"+NbBundle.getMessage(AddWsOperationHelper.class, "TXT_TodoComment")+"\n"+body+"\n}";
}
 
Example 7
Source File: TypeTag.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public TypeKind getPrimitiveTypeKind() {
    switch (this) {
    case BOOLEAN:
        return TypeKind.BOOLEAN;
    case BYTE:
        return TypeKind.BYTE;
    case SHORT:
        return TypeKind.SHORT;
    case INT:
        return TypeKind.INT;
    case LONG:
        return TypeKind.LONG;
    case CHAR:
        return TypeKind.CHAR;
    case FLOAT:
        return TypeKind.FLOAT;
    case DOUBLE:
        return TypeKind.DOUBLE;
    case VOID:
        return TypeKind.VOID;
    default:
        throw new AssertionError("unknown primitive type " + this);
    }
}
 
Example 8
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if assignment looses precision.
 * Works only for primitive types, false for references.
 * 
 * @param from the assigned value type
 * @param to the target type
 * @return true, if precision is lost
 */
public static boolean loosesPrecision(TypeMirror from, TypeMirror to) {
    if (!from.getKind().isPrimitive() || !to.getKind().isPrimitive()) {
        return false;
    }
    if (to.getKind() == TypeKind.CHAR) {
        return true;
    } else if (from.getKind() == TypeKind.CHAR) {
        return to.getKind() == TypeKind.BYTE || to.getKind() == TypeKind.SHORT;
    }
    return to.getKind().ordinal() < from.getKind().ordinal();
}
 
Example 9
Source File: GenerationUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Tree createType(String typeName, TypeElement scope) {
    TreeMaker make = getTreeMaker();
    TypeKind primitiveTypeKind = null;
    if ("boolean".equals(typeName)) {           // NOI18N
        primitiveTypeKind = TypeKind.BOOLEAN;
    } else if ("byte".equals(typeName)) {       // NOI18N
        primitiveTypeKind = TypeKind.BYTE;
    } else if ("short".equals(typeName)) {      // NOI18N
        primitiveTypeKind = TypeKind.SHORT;
    } else if ("int".equals(typeName)) {        // NOI18N
        primitiveTypeKind = TypeKind.INT;
    } else if ("long".equals(typeName)) {       // NOI18N
        primitiveTypeKind = TypeKind.LONG;
    } else if ("char".equals(typeName)) {       // NOI18N
        primitiveTypeKind = TypeKind.CHAR;
    } else if ("float".equals(typeName)) {      // NOI18N
        primitiveTypeKind = TypeKind.FLOAT;
    } else if ("double".equals(typeName)) {     // NOI18N
        primitiveTypeKind = TypeKind.DOUBLE;
    } else if ("void".equals(typeName)) {     // NOI18N
        primitiveTypeKind = TypeKind.VOID;
    }
    if (primitiveTypeKind != null) {
        return getTreeMaker().PrimitiveType(primitiveTypeKind);
    }
    Tree typeTree = tryCreateQualIdent(typeName);
    if (typeTree == null) {
        // XXX does not handle imports; temporary until issue 102149 is fixed
        TypeMirror typeMirror = copy.getTreeUtilities().parseType(typeName, scope);
        typeTree = make.Type(typeMirror);
    }
    return typeTree;
}
 
Example 10
Source File: AddWsOperationHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String getMethodBody(Tree returnType) {
    String body = null;
    if (Kind.PRIMITIVE_TYPE == returnType.getKind()) {
        TypeKind type = ((PrimitiveTypeTree)returnType).getPrimitiveTypeKind();
        if (TypeKind.VOID == type) {
            body = ""; //NOI18N
        }
        else if (TypeKind.BOOLEAN == type) {
            body = "return false;"; // NOI18N
        }
        else if (TypeKind.INT == type) {
            body = "return 0;"; // NOI18N
        }
        else if (TypeKind.LONG == type) {
            body = "return 0;"; // NOI18N
        }
        else if (TypeKind.FLOAT == type) {
            body = "return 0.0;"; // NOI18N
        }
        else if (TypeKind.DOUBLE == type) {
            body = "return 0.0;"; // NOI18N
        }
        else if (TypeKind.BYTE == type) {
            body = "return 0;"; // NOI18N
        }
        else if (TypeKind.SHORT == type) {
            body = "return 0;"; // NOI18N
        }
        else if (TypeKind.CHAR == type) {
            body = "return ' ';"; // NOI18N
        }
        else {
            body = "return null"; //NOI18N
        }
    } else
        body = "return null"; //NOI18N
    return "{\n\t\t"+NbBundle.getMessage(AddWsOperationHelper.class, "TXT_TodoComment")+"\n"+body+"\n}";
}
 
Example 11
Source File: MethodModelSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Tree getTypeTree(WorkingCopy workingCopy, String typeName) {
    TreeMaker make = workingCopy.getTreeMaker();
    TypeKind primitiveTypeKind = null;
    if ("boolean".equals(typeName)) {           // NOI18N
        primitiveTypeKind = TypeKind.BOOLEAN;
    } else if ("byte".equals(typeName)) {       // NOI18N
        primitiveTypeKind = TypeKind.BYTE;
    } else if ("short".equals(typeName)) {      // NOI18N
        primitiveTypeKind = TypeKind.SHORT;
    } else if ("int".equals(typeName)) {        // NOI18N
        primitiveTypeKind = TypeKind.INT;
    } else if ("long".equals(typeName)) {       // NOI18N
        primitiveTypeKind = TypeKind.LONG;
    } else if ("char".equals(typeName)) {       // NOI18N
        primitiveTypeKind = TypeKind.CHAR;
    } else if ("float".equals(typeName)) {      // NOI18N
        primitiveTypeKind = TypeKind.FLOAT;
    } else if ("double".equals(typeName)) {     // NOI18N
        primitiveTypeKind = TypeKind.DOUBLE;
    } else if ("void".equals(typeName)) {     // NOI18N
        primitiveTypeKind = TypeKind.VOID;
    }
    if (primitiveTypeKind != null) {
        return make.PrimitiveType(primitiveTypeKind);
    } else {
        return createQualIdent(workingCopy, typeName);
    }
}
 
Example 12
Source File: GenerationUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Tree createType(String typeName, TypeElement scope) {
    TreeMaker make = getTreeMaker();
    TypeKind primitiveTypeKind = null;
    if ("boolean".equals(typeName)) {           // NOI18N
        primitiveTypeKind = TypeKind.BOOLEAN;
    } else if ("byte".equals(typeName)) {       // NOI18N
        primitiveTypeKind = TypeKind.BYTE;
    } else if ("short".equals(typeName)) {      // NOI18N
        primitiveTypeKind = TypeKind.SHORT;
    } else if ("int".equals(typeName)) {        // NOI18N
        primitiveTypeKind = TypeKind.INT;
    } else if ("long".equals(typeName)) {       // NOI18N
        primitiveTypeKind = TypeKind.LONG;
    } else if ("char".equals(typeName)) {       // NOI18N
        primitiveTypeKind = TypeKind.CHAR;
    } else if ("float".equals(typeName)) {      // NOI18N
        primitiveTypeKind = TypeKind.FLOAT;
    } else if ("double".equals(typeName)) {     // NOI18N
        primitiveTypeKind = TypeKind.DOUBLE;
    } else if ("void".equals(typeName)) {     // NOI18N
        primitiveTypeKind = TypeKind.VOID;
    }
    if (primitiveTypeKind != null) {
        return getTreeMaker().PrimitiveType(primitiveTypeKind);
    }
    Tree typeTree = tryCreateQualIdent(typeName);
    if (typeTree == null) {
        // XXX does not handle imports; temporary until issue 102149 is fixed
        TypeMirror typeMirror = copy.getTreeUtilities().parseType(typeName, scope);
        if ( typeMirror == null || typeMirror.getKind() == TypeKind.ERROR ){
            typeTree = getTreeMaker().QualIdent( typeName );
        }
        else {
            typeTree = make.Type(typeMirror);
        }
    }
    return typeTree;
}
 
Example 13
Source File: CtTypes.java    From doma with Apache License 2.0 5 votes vote down vote up
@Override
public Class<?> visitArray(ArrayType t, Void p) {
  if (t.getComponentType().getKind() == TypeKind.BYTE) {
    return BytesWrapper.class;
  }
  return null;
}
 
Example 14
Source File: TypeUtil.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * If type is a byte TypeMirror, short TypeMirror, or char TypeMirror, an int TypeMirror is
 * returned. Otherwise, type is returned. See jls-5.6.1.
 * @param type a numeric type
 * @return the result of unary numeric promotion applied to type
 */
public TypeMirror unaryNumericPromotion(TypeMirror type) {
  TypeKind t = type.getKind();
  if (t == TypeKind.DECLARED) {
    type = javacTypes.unboxedType(type);
    t = type.getKind();
  }
  if (t == TypeKind.BYTE || t == TypeKind.SHORT || t == TypeKind.CHAR) {
    return getInt();
  } else {
    return type;
  }
}
 
Example 15
Source File: ArithmeticUtilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Object resolveTypeCast(TypeCastTree node, TypeMirror target, Object result, Void p) {
    if (target.getKind() != TypeKind.DECLARED) {
        return null;
    }
    DeclaredType dt = (DeclaredType)target;
    TypeElement e = (TypeElement)dt.asElement();
    if (enhanceProcessing) {
        // accept null constant typecasted to anything as null
        if (result == NULL) {
            return NULL;
        } else if (result == NOT_NULL) {
            // some unspecified reference type...
            return result;
        }
    }
    String qn = e.getQualifiedName().toString();
    // type casts to String are permitted by JLS 15.28
    if ("java.lang.String".equals(qn)) { // NOI18N
        return result instanceof String ? result : null;
    } else if (!enhanceProcessing) {
        // other typecasts are not lised in JLS 15.28
        return null;
    }
    TypeMirror castee = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getExpression()));
    if (!Utilities.isValidType(castee)) {
        return null;
    }
    if (info.getTypes().isAssignable(castee, target)) {
        return result;
    }
    // a constant of primitive type may be casted / wrapped to the wrapper type
    switch (qn) {
        case "java.lang.Boolean": // NOI18N
            if (result instanceof Boolean) return result;
            break;
        case "java.lang.Byte": // NOI18N
            // the casted expression may be typed as Byte or byte; 
            if (result instanceof Number && castee != null && castee.getKind() == TypeKind.BYTE) 
                return ((Number)result).byteValue();
            break;
        case "java.lang.Character": // NOI18N
            if (result instanceof Number && castee != null && castee.getKind() == TypeKind.CHAR) 
                return Character.valueOf((char)((Number)result).intValue());
            break;
        case "java.lang.Double": // NOI18N
            if (result instanceof Number && castee != null && castee.getKind() == TypeKind.DOUBLE) 
                return ((Number)result).doubleValue();
            break;
        case "java.lang.Float": // NOI18N
            if (result instanceof Number && castee != null && castee.getKind() == TypeKind.FLOAT) 
                return ((Number)result).floatValue();
            break;
        case "java.lang.Integer": // NOI18N
            if (result instanceof Number && castee != null && castee.getKind() == TypeKind.INT) 
                return ((Number)result).intValue();
            break;
        case "java.lang.Long": // NOI18N
            if (result instanceof Number && castee != null && castee.getKind() == TypeKind.LONG) 
                return ((Number)result).longValue();
            break;
        case "java.lang.Short": // NOI18N
            if (result instanceof Number && castee != null && castee.getKind() == TypeKind.SHORT) 
                return ((Number)result).shortValue();
            break;
    }
    return null;
}
 
Example 16
Source File: JpaControllerUtil.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static Tree createType(WorkingCopy wc, TypeInfo type) {
    if(type == null) {
        return null;
    }
    String rawType = type.getRawType();
    
    TreeMaker make = wc.getTreeMaker();
    if (rawType.endsWith("[]")) { // NOI18N
        String rawTypeName = rawType.substring(0, rawType.length()-2);
        TypeInfo scalarTypeInfo = new TypeInfo(rawTypeName, type.getDeclaredTypeParameters());
        return make.ArrayType(createType(wc, scalarTypeInfo));
    }
    
    TypeKind primitiveTypeKind = null;
    if ("boolean".equals(rawType)) {           // NOI18N
        primitiveTypeKind = TypeKind.BOOLEAN;
    } else if ("byte".equals(rawType)) {       // NOI18N
        primitiveTypeKind = TypeKind.BYTE;
    } else if ("short".equals(rawType)) {      // NOI18N
        primitiveTypeKind = TypeKind.SHORT;
    } else if ("int".equals(rawType)) {        // NOI18N
        primitiveTypeKind = TypeKind.INT;
    } else if ("long".equals(rawType)) {       // NOI18N
        primitiveTypeKind = TypeKind.LONG;
    } else if ("char".equals(rawType)) {       // NOI18N
        primitiveTypeKind = TypeKind.CHAR;
    } else if ("float".equals(rawType)) {      // NOI18N
        primitiveTypeKind = TypeKind.FLOAT;
    } else if ("double".equals(rawType)) {     // NOI18N
        primitiveTypeKind = TypeKind.DOUBLE;
    } else if ("void".equals(rawType)) {
        primitiveTypeKind = TypeKind.VOID;
    }
    if (primitiveTypeKind != null) {
        return make.PrimitiveType(primitiveTypeKind);
    }
    
    TypeInfo[] declaredTypeParameters = type.getDeclaredTypeParameters();
    if (declaredTypeParameters == null || declaredTypeParameters.length == 0) {
        TypeElement typeElement = wc.getElements().getTypeElement(rawType);
        if (typeElement == null) {
            throw new IllegalArgumentException("Type " + rawType + " cannot be found"); // NOI18N
        }
        return make.QualIdent(typeElement);
    }
    else {
        TypeMirror typeMirror = getTypeMirror(wc, type);
        return make.Type(typeMirror);
    }
}
 
Example 17
Source File: FieldCodeFactory.java    From sqlbrite-dao with Apache License 2.0 4 votes vote down vote up
public static CodeGenerator get(ColumnAnnotatedField field) throws ProcessingException {


    VariableElement element = field.getField();
    switch (element.asType().getKind()) {

      case INT:
        return new FieldCodeGenerator(field, "getInt");

      case FLOAT:
        return new FieldCodeGenerator(field, "getFloat");

      case DOUBLE:
        return new FieldCodeGenerator(field, "getDouble");

      case LONG:
        return new FieldCodeGenerator(field, "getLong");

      case SHORT:
        return new FieldCodeGenerator(field, "getShort");

      case BOOLEAN:
        return new BooleanFieldCodeGenerator(field);

      case ARRAY:
        ArrayType arrayType = (ArrayType) element.asType();
        if (arrayType.getComponentType().getKind() == TypeKind.BYTE) {
          return new FieldCodeGenerator(field, "getBlob");
        }
        break;

      case DECLARED:
        String varType = element.asType().toString();
        if (varType.equals(String.class.getCanonicalName())) {
          return new FieldCodeGenerator(field, "getString");
        }

        if (varType.equals(Date.class.getCanonicalName())) {
          return new DateFieldCodeGenerator(field);
        }
        break;
    }

    throw new ProcessingException(element,
        "Unsupported type for field %s in class %s annotated with @%s. Don't know how to read the type %s",
        field.getElementName(), field.getQualifiedSurroundingClassName(), Column.class.getSimpleName(),
        element.asType().toString());
  }
 
Example 18
Source File: TypeUtils.java    From alchemy with Apache License 2.0 4 votes vote down vote up
boolean isByteArray(TypeMirror type) {
    return TypeKind.ARRAY == type.getKind() && TypeKind.BYTE == ((ArrayType) type).getComponentType().getKind();
}
 
Example 19
Source File: ValueAttribute.java    From immutables with Apache License 2.0 4 votes vote down vote up
public boolean isByte() {
  return returnType.getKind() == TypeKind.BYTE;
}
 
Example 20
Source File: MethodCodeFactory.java    From sqlbrite-dao with Apache License 2.0 4 votes vote down vote up
public static CodeGenerator get(ColumnAnnotatedMethod method) throws ProcessingException {

    ExecutableElement element = method.getMethod();
    TypeMirror parameter =element.getParameters().get(0).asType();

    switch (parameter.getKind()) {

      case INT:
        return new MethodCodeGenerator(method, "getInt");

      case FLOAT:
        return new MethodCodeGenerator(method, "getFloat");

      case DOUBLE:
        return new MethodCodeGenerator(method, "getDouble");

      case LONG:
        return new MethodCodeGenerator(method, "getLong");

      case SHORT:
        return new MethodCodeGenerator(method, "getShort");

      case BOOLEAN:
        return new BooleanMethodCodeGenerator(method);
      case ARRAY:
        ArrayType parameterArrayType = (ArrayType) parameter;
        if (parameterArrayType.getComponentType().getKind() == TypeKind.BYTE) {
          return new MethodCodeGenerator(method, "getBlob");
        }
        break;

      case DECLARED:
        String parameterType = parameter.toString();
        if (parameterType.equals(String.class.getCanonicalName())) {
          return new MethodCodeGenerator(method, "getString");
        }

        if (parameterType.equals(Date.class.getCanonicalName())) {
          return new DateMethodCodeGenerator(method);
        }
        break;
    }

    throw new ProcessingException(element,
        "Unsupported type %s as parameter in method %s() in class %s annotated with @%s.",
        parameter, method.getMethod(),
        method.getQualifiedSurroundingClassName(), Column.class.getSimpleName());
  }