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

The following examples show how to use javax.lang.model.type.TypeKind#DOUBLE . 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 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: 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 3
Source File: TypeTag.java    From openjdk-8 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 4
Source File: OperatorRewriter.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Some operator functions are given a suffix indicating the promotion type of
 * the operands according to JLS 5.6.2.
 */
private static String getPromotionSuffix(Assignment node) {
  if (!needsPromotionSuffix(node.getOperator())) {
    return "";
  }
  TypeKind lhsKind = node.getLeftHandSide().getTypeMirror().getKind();
  TypeKind rhsKind = node.getRightHandSide().getTypeMirror().getKind();
  if (lhsKind == TypeKind.DOUBLE || rhsKind == TypeKind.DOUBLE) {
    return "D";
  }
  if (lhsKind == TypeKind.FLOAT || rhsKind == TypeKind.FLOAT) {
    return "F";
  }
  if (lhsKind == TypeKind.LONG || rhsKind == TypeKind.LONG) {
    return "J";
  }
  return "I";
}
 
Example 5
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 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: Type.java    From java-n-IDE-for-Android with Apache License 2.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 8
Source File: JCTree.java    From java-n-IDE-for-Android with Apache License 2.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 9
Source File: TurbineTypeMirror.java    From turbine with Apache License 2.0 6 votes vote down vote up
@Override
public TypeKind getKind() {
  switch (type.primkind()) {
    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 BYTE:
      return TypeKind.BYTE;
    case NULL:
      return TypeKind.NULL;
    case STRING:
  }
  throw new AssertionError(type.primkind());
}
 
Example 10
Source File: TypeTag.java    From TencentKona-8 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 11
Source File: LLNI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private int doTwoWordFields(FieldDefsRes res, TypeElement clazz,
                            int offset, String cname, boolean padWord) {
    boolean first = true;
    List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());

    for (VariableElement field: fields) {
        TypeKind tk = field.asType().getKind();
        boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);
        if (twoWords && doField(res, field, cname, first && padWord)) {
            offset += 8; first = false;
        }
    }
    return offset;
}
 
Example 12
Source File: LLNI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private int doTwoWordFields(FieldDefsRes res, TypeElement clazz,
                            int offset, String cname, boolean padWord) {
    boolean first = true;
    List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());

    for (VariableElement field: fields) {
        TypeKind tk = field.asType().getKind();
        boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);
        if (twoWords && doField(res, field, cname, first && padWord)) {
            offset += 8; first = false;
        }
    }
    return offset;
}
 
Example 13
Source File: LLNI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private int doTwoWordFields(FieldDefsRes res, TypeElement clazz,
                            int offset, String cname, boolean padWord) {
    boolean first = true;
    List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());

    for (VariableElement field: fields) {
        TypeKind tk = field.asType().getKind();
        boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);
        if (twoWords && doField(res, field, cname, first && padWord)) {
            offset += 8; first = false;
        }
    }
    return offset;
}
 
Example 14
Source File: LLNI.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private int doTwoWordFields(FieldDefsRes res, TypeElement clazz,
                            int offset, String cname, boolean padWord) {
    boolean first = true;
    List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());

    for (VariableElement field: fields) {
        TypeKind tk = field.asType().getKind();
        boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);
        if (twoWords && doField(res, field, cname, first && padWord)) {
            offset += 8; first = false;
        }
    }
    return offset;
}
 
Example 15
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 16
Source File: LLNI.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
FieldDefsRes fieldDefs(TypeElement clazz, String cname,
                                 boolean bottomMost){
    FieldDefsRes res;
    int offset;
    boolean didTwoWordFields = false;

    TypeElement superclazz = (TypeElement) types.asElement(clazz.getSuperclass());

    if (superclazz != null) {
        String supername = superclazz.getQualifiedName().toString();
        res = new FieldDefsRes(clazz,
                               fieldDefs(superclazz, cname, false),
                               bottomMost);
        offset = res.parent.byteSize;
    } else {
        res = new FieldDefsRes(clazz, null, bottomMost);
        offset = 0;
    }

    List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());

    for (VariableElement field: fields) {

        if (doubleAlign && !didTwoWordFields && (offset % 8) == 0) {
            offset = doTwoWordFields(res, clazz, offset, cname, false);
            didTwoWordFields = true;
        }

        TypeKind tk = field.asType().getKind();
        boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);

        if (!doubleAlign || !twoWords) {
            if (doField(res, field, cname, false)) offset += 4;
        }

    }

    if (doubleAlign && !didTwoWordFields) {
        if ((offset % 8) != 0) offset += 4;
        offset = doTwoWordFields(res, clazz, offset, cname, true);
    }

    res.byteSize = offset;
    return res;
}
 
Example 17
Source File: LLNI.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
FieldDefsRes fieldDefs(TypeElement clazz, String cname,
                                 boolean bottomMost){
    FieldDefsRes res;
    int offset;
    boolean didTwoWordFields = false;

    TypeElement superclazz = (TypeElement) types.asElement(clazz.getSuperclass());

    if (superclazz != null) {
        String supername = superclazz.getQualifiedName().toString();
        res = new FieldDefsRes(clazz,
                               fieldDefs(superclazz, cname, false),
                               bottomMost);
        offset = res.parent.byteSize;
    } else {
        res = new FieldDefsRes(clazz, null, bottomMost);
        offset = 0;
    }

    List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());

    for (VariableElement field: fields) {

        if (doubleAlign && !didTwoWordFields && (offset % 8) == 0) {
            offset = doTwoWordFields(res, clazz, offset, cname, false);
            didTwoWordFields = true;
        }

        TypeKind tk = field.asType().getKind();
        boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);

        if (!doubleAlign || !twoWords) {
            if (doField(res, field, cname, false)) offset += 4;
        }

    }

    if (doubleAlign && !didTwoWordFields) {
        if ((offset % 8) != 0) offset += 4;
        offset = doTwoWordFields(res, clazz, offset, cname, true);
    }

    res.byteSize = offset;
    return res;
}
 
Example 18
Source File: Marshallers.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public boolean matches(PrimitiveType type) {
  return type.getKind() == TypeKind.DOUBLE;
}
 
Example 19
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 20
Source File: TypeUtils.java    From ig-json-parser with MIT License 4 votes vote down vote up
public ParseType getParseType(
    TypeMirror typeMirror, @Nullable Class<? extends Annotation> typeAnnotationClass) {
  if (typeMirror == null) {
    return ParseType.UNSUPPORTED;
  } else if (JAVA_LANG_STRING.equals(typeMirror.toString())) {
    return ParseType.STRING;
  } else if (typeMirror.getKind() == TypeKind.BOOLEAN) {
    return ParseType.BOOLEAN;
  } else if (JAVA_LANG_BOOLEAN.equals(typeMirror.toString())) {
    return ParseType.BOOLEAN_OBJECT;
  } else if (typeMirror.getKind() == TypeKind.INT) {
    return ParseType.INTEGER;
  } else if (JAVA_LANG_INTEGER.equals(typeMirror.toString())) {
    return ParseType.INTEGER_OBJECT;
  } else if (typeMirror.getKind() == TypeKind.LONG) {
    return ParseType.LONG;
  } else if (JAVA_LANG_LONG.equals(typeMirror.toString())) {
    return ParseType.LONG_OBJECT;
  } else if (typeMirror.getKind() == TypeKind.FLOAT) {
    return ParseType.FLOAT;
  } else if (JAVA_LANG_FLOAT.equals(typeMirror.toString())) {
    return ParseType.FLOAT_OBJECT;
  } else if (typeMirror.getKind() == TypeKind.DOUBLE) {
    return ParseType.DOUBLE;
  } else if (JAVA_LANG_DOUBLE.equals(typeMirror.toString())) {
    return ParseType.DOUBLE_OBJECT;
  } else if (typeMirror instanceof DeclaredType) {
    DeclaredType type = (DeclaredType) typeMirror;
    Element element = type.asElement();

    Annotation annotation =
        typeAnnotationClass != null ? element.getAnnotation(typeAnnotationClass) : null;
    if (annotation != null && EnumSet.of(CLASS, INTERFACE).contains(element.getKind())) {
      return ParseType.PARSABLE_OBJECT;
    }

    // is it an enum?
    if (element instanceof TypeElement) {
      TypeElement typeElement = (TypeElement) element;
      TypeMirror superclass = typeElement.getSuperclass();
      if (superclass instanceof DeclaredType) {
        DeclaredType superclassDeclaredType = (DeclaredType) superclass;

        if (JAVA_LANG_ENUM.equals(getCanonicalTypeName(superclassDeclaredType))) {
          return ParseType.ENUM_OBJECT;
        }
      }
    }
  }

  return ParseType.UNSUPPORTED;
}