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

The following examples show how to use javax.lang.model.type.TypeKind#CHAR . 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: TypeTag.java    From openjdk-jdk8u-backup 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 2
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 3
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 4
Source File: TypeTag.java    From openjdk-jdk8u 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 lua-for-android with BSD 3-Clause "New" or "Revised" License 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: 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 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: MalformedFormatString.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Unbox a wrapper type into a TypeKind. Some additional types are mapped to TypeKinds which cannot really appear in 
 * expressions (at least I hope)
 * 
 * @param tm
 * @return 
 */
private static TypeKind unboxBoxed(TypeMirror tm) {
    TypeElement te = (TypeElement)((DeclaredType)tm).asElement();
    String qn = te.getQualifiedName().toString();
    if (!qn.startsWith("java.lang.")) { // NO18N
        if (qn.equals("java.math.BigInteger")) { // NOI18N
            return TypeKind.WILDCARD;
        }
        return null;
    }
    switch (qn.substring(10)) {
        case "Short": return TypeKind.SHORT; // NOI18N
        case "Long": return TypeKind.LONG; // NOI18N
        case "Byte": return TypeKind.BYTE; // NOI18N
        case "Integer": return TypeKind.INT; // NOI18N
        case "Double": return TypeKind.DOUBLE; // NOI18N
        case "Float": return TypeKind.FLOAT; // NOI18N
        case "Character": return TypeKind.CHAR; // NOI18N
        case "String": return TypeKind.OTHER; // NOI18N
        case "Object": return TypeKind.PACKAGE; // NOI18N
    }
    return null;
}
 
Example 9
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 10
Source File: StringBufferCharConstructor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@TriggerPatterns({
    @TriggerPattern(value = "new java.lang.StringBuffer($x)", constraints = @ConstraintVariableType(variable = "$x", type = "char")),
    @TriggerPattern(value = "new java.lang.StringBuilder($x)", constraints = @ConstraintVariableType(variable = "$x", type = "char"))
})
public static ErrorDescription run(HintContext ctx) {
    TreePath p = ctx.getPath();
    
    TypeMirror paramType = ctx.getInfo().getTrees().getTypeMirror(ctx.getVariables().get("$x")); // NOI18N
    if (paramType.getKind() != TypeKind.CHAR) {
        if (paramType.getKind() != TypeKind.DECLARED) {
            return null;
        }
        Element el = ((DeclaredType)paramType).asElement();
        if (el == null || el.getKind() != ElementKind.CLASS) {
            return null;
        }
        if (!((TypeElement)el).getQualifiedName().contentEquals("java.lang.Character")) {
            return null;
        }
    }
    
    TypeMirror tm = ctx.getInfo().getTrees().getTypeMirror(p);
    CharSequence tname = ctx.getInfo().getTypeUtilities().getTypeName(tm);
    
    return ErrorDescriptionFactory.forTree(ctx, p, Bundle.TEXT_StringBufferCharConstructor(tname), 
            new NewAndAppendFix(TreePathHandle.create(p, ctx.getInfo()), tname.toString()).toEditorFix());
}
 
Example 11
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 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 = makeQualIdent(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 13
Source File: Autoboxer.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Override
public void endVisit(CastExpression node) {
  TypeMirror castType = node.getTypeMirror();
  Expression expr = node.getExpression();
  TypeMirror exprType = expr.getTypeMirror();
  if (castType.getKind().isPrimitive() && !exprType.getKind().isPrimitive()) {
    if (typeUtil.isAssignable(exprType, typeUtil.getJavaNumber().asType())) {
      // Casting a Number object to a primitive, convert to value method.
      unbox(expr, (PrimitiveType) castType);
    } else if (exprType == typeUtil.boxedClass(typeUtil.getChar()).asType()) {
      // Unboxing and casting Character, which does not have number value functions.
      unbox(expr);
      if (castType.getKind() != TypeKind.CHAR) {
        // If the resulting type is not char - keep the cast, to preserve type information in
        // case of reboxing.
        CastExpression castExpr = new CastExpression(castType, null);
        Expression unboxedExpression = node.getExpression();
        unboxedExpression.replaceWith(castExpr);
        castExpr.setExpression(unboxedExpression);
      }
    } else {
      // Casting an object to a primitive. Convert the cast type to the wrapper
      // so that we do a proper cast check, as Java would.
      castType = typeUtil.boxedClass((PrimitiveType) castType).asType();
      node.setType(Type.newType(castType));
      boxOrUnboxExpression(expr, castType);
    }
  } else {
    boxOrUnboxExpression(expr, castType);
  }
  Expression newExpr = node.getExpression();
  if (newExpr != expr) {
    TreeNode parent = node.getParent();
    if (parent instanceof ParenthesizedExpression) {
      parent.replaceWith(TreeUtil.remove(newExpr));
    } else {
      node.replaceWith(TreeUtil.remove(newExpr));
    }
  }
}
 
Example 14
Source File: ArithmeticUtilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Object visitTypeCast(TypeCastTree node, Void p) {
    Object op = scan(node.getExpression(), p);
    if (op == null) {
        return null;
    }
    Object result = null;
    TypeMirror tm = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getType()));
    if (!Utilities.isValidType(tm)) {
        return null;
    }
    // casting to some non-char primitive type, perform unary numeric promotion JLS 5.6.1
    if (tm.getKind() != TypeKind.CHAR && op instanceof Character) {
        op = Integer.valueOf(((Character)op).charValue());
    }
    // accept unboxing conversion, primitive conversion
    switch (tm.getKind()) {
        case BOOLEAN:
            if (op instanceof Boolean) result = op;
            break;
        case BYTE:
            if (op instanceof Number)  result = ((Number)op).byteValue();
            break;
        case CHAR:
            if (op instanceof Character) result = op;
            if (op instanceof Number)  result = Character.valueOf((char)((Number)op).intValue());
            break;
        case DOUBLE:
            if (op instanceof Number)  result = ((Number)op).doubleValue();
            break;
        case FLOAT:
            if (op instanceof Number)  result = ((Number)op).floatValue();
            break;
        case INT:
            if (op instanceof Number)  result = ((Number)op).intValue();
            break;
        case LONG:
            if (op instanceof Number)  result = ((Number)op).longValue();
            break;
        case SHORT:
            if (op instanceof Number)  result = ((Number)op).shortValue();
            break;
        default:
            return resolveTypeCast(node, tm, op, p);
            
    }
    return result;
}
 
Example 15
Source File: ValueAttribute.java    From immutables with Apache License 2.0 4 votes vote down vote up
public boolean isChar() {
  return returnType.getKind() == TypeKind.CHAR;
}
 
Example 16
Source File: TypeDeclaration.java    From doma with Apache License 2.0 4 votes vote down vote up
public boolean isTextType() {
  return type.getKind() == TypeKind.CHAR
      || ctx.getMoreTypes().isSameTypeWithErasure(type, String.class)
      || ctx.getMoreTypes().isSameTypeWithErasure(type, Character.class);
}
 
Example 17
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 18
Source File: CriteriaModel.java    From immutables with Apache License 2.0 4 votes vote down vote up
public boolean isNumber() {
  return type.getKind().isPrimitive() && !isBoolean() && type.getKind() != TypeKind.CHAR || isSubtypeOf(Number.class);
}
 
Example 19
Source File: FromEntityBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static String getConversionFromString(TypeMirror idType, int index, String keyType) {
    String param = index == -1 ? "value" : "values["+index+"]";
    if (TypeKind.BOOLEAN == idType.getKind()) {
        return "Boolean.parseBoolean("+param+")";
    } else if (TypeKind.BYTE == idType.getKind()) {
        return "Byte.parseByte("+param+")";
    } else if (TypeKind.CHAR == idType.getKind()) {
        return param+".charAt(0)";
    } else if (TypeKind.DOUBLE == idType.getKind()) {
        return "Double.parseDouble("+param+")";
    } else if (TypeKind.FLOAT == idType.getKind()) {
        return "Float.parseFloat("+param+")";
    } else if (TypeKind.INT == idType.getKind()) {
        return "Integer.parseInt("+param+")";
    } else if (TypeKind.LONG == idType.getKind()) {
        return "Long.parseLong("+param+")";
    } else if (TypeKind.SHORT == idType.getKind()) {
        return "Short.parseShort("+param+")";
    } else if (TypeKind.DECLARED == idType.getKind()) {
        if ("Boolean".equals(idType.toString()) || "java.lang.Boolean".equals(idType.toString())) {
            return "Boolean.valueOf("+param+")";
        } else if ("Byte".equals(idType.toString()) || "java.lang.Byte".equals(idType.toString())) {
            return "Byte.valueOf("+param+")";
        } else if ("Character".equals(idType.toString()) || "java.lang.Character".equals(idType.toString())) {
            return "new Character("+param+".charAt(0))";
        } else if ("Double".equals(idType.toString()) || "java.lang.Double".equals(idType.toString())) {
            return "Double.valueOf("+param+")";
        } else if ("Float".equals(idType.toString()) || "java.lang.Float".equals(idType.toString())) {
            return "Float.valueOf("+param+")";
        } else if ("Integer".equals(idType.toString()) || "java.lang.Integer".equals(idType.toString())) {
            return "Integer.valueOf("+param+")";
        } else if ("Long".equals(idType.toString()) || "java.lang.Long".equals(idType.toString())) {
            return "Long.valueOf("+param+")";
        } else if ("Short".equals(idType.toString()) || "java.lang.Short".equals(idType.toString())) {
            return "Short.valueOf("+param+")";
        } else if ("BigDecimal".equals(idType.toString()) || "java.math.BigDecimal".equals(idType.toString())) {
            return "new java.math.BigDecimal("+param+")";
        } else if ("Date".equals(idType.toString()) || "java.util.Date".equals(idType.toString())) {
            return "java.sql.Date.valueOf("+param+")";
        }
    }
    return param;
}
 
Example 20
Source File: ValueAttribute.java    From immutables with Apache License 2.0 4 votes vote down vote up
public boolean isNumberType() {
  TypeKind kind = returnType.getKind();
  return kind.isPrimitive()
      && kind != TypeKind.CHAR
      && kind != TypeKind.BOOLEAN;
}