Java Code Examples for com.sun.tools.javac.code.Type#getKind()

The following examples show how to use com.sun.tools.javac.code.Type#getKind() . 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: LambdaToMethod.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Erasure destroys the implementation parameter subtype
 * relationship for intersection types
 */
boolean interfaceParameterIsIntersectionType() {
    List<Type> tl = tree.getDescriptorType(types).getParameterTypes();
    if (tree.kind == ReferenceKind.UNBOUND) {
        tl = tl.tail;
    }
    for (; tl.nonEmpty(); tl = tl.tail) {
        Type pt = tl.head;
        if (pt.getKind() == TypeKind.TYPEVAR) {
            TypeVar tv = (TypeVar) pt;
            if (tv.bound.getKind() == TypeKind.INTERSECTION) {
                return true;
            }
        }
    }
    return false;
}
 
Example 2
Source File: LambdaToMethod.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Erasure destroys the implementation parameter subtype
 * relationship for intersection types
 */
boolean interfaceParameterIsIntersectionType() {
    List<Type> tl = tree.getDescriptorType(types).getParameterTypes();
    if (tree.kind == ReferenceKind.UNBOUND) {
        tl = tl.tail;
    }
    for (; tl.nonEmpty(); tl = tl.tail) {
        Type pt = tl.head;
        if (pt.getKind() == TypeKind.TYPEVAR) {
            TypeVar tv = (TypeVar) pt;
            if (tv.bound.getKind() == TypeKind.INTERSECTION) {
                return true;
            }
        }
    }
    return false;
}
 
Example 3
Source File: JNIWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private String getJvmPrimitiveSignature(Type t) {
    switch (t.getKind()) {
        case VOID:      return SIG_VOID;
        case BOOLEAN:   return SIG_BOOLEAN;
        case BYTE:      return SIG_BYTE;
        case CHAR:      return SIG_CHAR;
        case SHORT:     return SIG_SHORT;
        case INT:       return SIG_INT;
        case LONG:      return SIG_LONG;
        case FLOAT:     return SIG_FLOAT;
        case DOUBLE:    return SIG_DOUBLE;
        default:
            Assert.error("unknown type: should not happen");
    }
    return null;
}
 
Example 4
Source File: LambdaToMethod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Erasure destroys the implementation parameter subtype
 * relationship for intersection types
 */
boolean interfaceParameterIsIntersectionType() {
    List<Type> tl = tree.getDescriptorType(types).getParameterTypes();
    if (tree.kind == ReferenceKind.UNBOUND) {
        tl = tl.tail;
    }
    for (; tl.nonEmpty(); tl = tl.tail) {
        Type pt = tl.head;
        if (pt.getKind() == TypeKind.TYPEVAR) {
            TypeVar tv = (TypeVar) pt;
            if (tv.bound.getKind() == TypeKind.INTERSECTION) {
                return true;
            }
        }
    }
    return false;
}
 
Example 5
Source File: JNIWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private String getJvmPrimitiveSignature(Type t) {
    switch (t.getKind()) {
        case VOID:      return SIG_VOID;
        case BOOLEAN:   return SIG_BOOLEAN;
        case BYTE:      return SIG_BYTE;
        case CHAR:      return SIG_CHAR;
        case SHORT:     return SIG_SHORT;
        case INT:       return SIG_INT;
        case LONG:      return SIG_LONG;
        case FLOAT:     return SIG_FLOAT;
        case DOUBLE:    return SIG_DOUBLE;
        default:
            Assert.error("unknown type: should not happen");
    }
    return null;
}
 
Example 6
Source File: LambdaToMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Erasure destroys the implementation parameter subtype
 * relationship for intersection types
 */
boolean interfaceParameterIsIntersectionType() {
    List<Type> tl = tree.getDescriptorType(types).getParameterTypes();
    if (tree.kind == ReferenceKind.UNBOUND) {
        tl = tl.tail;
    }
    for (; tl.nonEmpty(); tl = tl.tail) {
        Type pt = tl.head;
        if (pt.getKind() == TypeKind.TYPEVAR) {
            TypeVar tv = (TypeVar) pt;
            if (tv.bound.getKind() == TypeKind.INTERSECTION) {
                return true;
            }
        }
    }
    return false;
}
 
Example 7
Source File: LambdaToMethod.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Erasure destroys the implementation parameter subtype
 * relationship for intersection types
 */
boolean interfaceParameterIsIntersectionType() {
    List<Type> tl = tree.getDescriptorType(types).getParameterTypes();
    if (tree.kind == ReferenceKind.UNBOUND) {
        tl = tl.tail;
    }
    for (; tl.nonEmpty(); tl = tl.tail) {
        Type pt = tl.head;
        if (pt.getKind() == TypeKind.TYPEVAR) {
            TypeVar tv = (TypeVar) pt;
            if (tv.bound.getKind() == TypeKind.INTERSECTION) {
                return true;
            }
        }
    }
    return false;
}
 
Example 8
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Erasure destroys the implementation parameter subtype
 * relationship for intersection types
 */
boolean interfaceParameterIsIntersectionType() {
    List<Type> tl = tree.getDescriptorType(types).getParameterTypes();
    for (; tl.nonEmpty(); tl = tl.tail) {
        Type pt = tl.head;
        if (pt.getKind() == TypeKind.TYPEVAR) {
            TypeVar tv = (TypeVar) pt;
            if (tv.bound.getKind() == TypeKind.INTERSECTION) {
                return true;
            }
        }
    }
    return false;
}
 
Example 9
Source File: TypeUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Find the type of the method descriptor associated to the functional interface.
 * 
 * @param origin functional interface type
 * @return associated method descriptor type or <code>null</code> if the <code>origin</code> is not a functional interface.
 * @since 0.112
 */
public ExecutableType getDescriptorType(DeclaredType origin) {
    Types types = Types.instance(info.impl.getJavacTask().getContext());
    if (types.isFunctionalInterface(((Type)origin).tsym)) {
        Type dt = types.findDescriptorType((Type)origin);
        if (dt != null && dt.getKind() == TypeKind.EXECUTABLE) {
            return (ExecutableType)dt;
        }
    }
    return null;
}
 
Example 10
Source File: LambdaToMethod.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Erasure destroys the implementation parameter subtype
 * relationship for intersection types
 */
boolean interfaceParameterIsIntersectionType() {
    List<Type> tl = tree.getDescriptorType(types).getParameterTypes();
    for (; tl.nonEmpty(); tl = tl.tail) {
        Type pt = tl.head;
        if (pt.getKind() == TypeKind.TYPEVAR) {
            TypeVar tv = (TypeVar) pt;
            if (tv.bound.getKind() == TypeKind.INTERSECTION) {
                return true;
            }
        }
    }
    return false;
}
 
Example 11
Source File: ExpressionToTypeInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private ExpressionInfo treeToInfo(TreePath tp) {
    if (tp != null) {
        Tree tree = tp.getLeaf();
        if (tree instanceof ExpressionTree) {
            ExpressionInfo ei = new ExpressionInfo();
            ei.tree = (ExpressionTree) tree;
            Type type = pathToType(tp, tree);
            if (type != null) {
                switch (type.getKind()) {
                    case VOID:
                    case NONE:
                    case ERROR:
                    case OTHER:
                        break;
                    case NULL:
                        ei.isNonVoid = true;
                        ei.typeName = OBJECT_TYPE_NAME;
                        break;
                    default: {
                        ei.isNonVoid = true;
                        ei.typeName = varTypeName(type);
                        if (ei.typeName == null) {
                            ei.typeName = OBJECT_TYPE_NAME;
                        }
                        break;
                    }
                }
            }
            return ei;
        }
    }
    return null;
}
 
Example 12
Source File: JVMNames.java    From annotation-tools with MIT License 5 votes vote down vote up
/**
 * Create a JVML string for a type.
 * Uses {@link Signatures#binaryNameToFieldDescriptor(String)}
 *
 * Array strings are built by recursively converting the component type.
 *
 * @param type the Type to convert to JVML
 * @return the JVML representation of type
 */
@SuppressWarnings("signature") // com.sun.tools.javac.code is not yet annotated
public static String typeToJvmlString(Type type) {
    if (type.getKind() == TypeKind.ARRAY) {
        return "[" + typeToJvmlString((Type) ((ArrayType) type).getComponentType());
    } else if (type.getKind() == TypeKind.INTERSECTION) {
        // replace w/erasure (== erasure of 1st conjunct)
        return typeToJvmlString(type.tsym.erasure_field);
    } else if (type.getKind() == TypeKind.VOID) {
        return "V";  // special case since UtilPlume doesn't handle void
    } else {
        return Signatures.binaryNameToFieldDescriptor(type.tsym.flatName().toString());
    }
}
 
Example 13
Source File: UTemplater.java    From Refaster with Apache License 2.0 5 votes vote down vote up
@Override
public UType visitType(Type type, Void v) {
  if (UPrimitiveType.isDeFactoPrimitive(type.getKind())) {
    return UPrimitiveType.create(type.getKind());
  } else {
    throw new IllegalArgumentException(
        "Refaster does not currently support syntax " + type.getKind());
  }
}
 
Example 14
Source File: InferredJARModelsHandler.java    From NullAway with MIT License 4 votes vote down vote up
private String getSimpleTypeName(Type typ) {
  if (typ.getKind() == TypeKind.TYPEVAR)
    return typ.getUpperBound().tsym.getSimpleName().toString();
  else return typ.tsym.getSimpleName().toString();
}
 
Example 15
Source File: JNIWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@SuppressWarnings("fallthrough")
protected final String jniType(Type t) {
    switch (t.getKind()) {
        case ARRAY: {
            Type ct = ((Type.ArrayType)t).getComponentType();
            switch (ct.getKind()) {
                case BOOLEAN:  return "jbooleanArray";
                case BYTE:     return "jbyteArray";
                case CHAR:     return "jcharArray";
                case SHORT:    return "jshortArray";
                case INT:      return "jintArray";
                case LONG:     return "jlongArray";
                case FLOAT:    return "jfloatArray";
                case DOUBLE:   return "jdoubleArray";
                case ARRAY:
                case DECLARED: return "jobjectArray";
                default: throw new Error(ct.toString());
            }
        }

        case VOID:     return "void";
        case BOOLEAN:  return "jboolean";
        case BYTE:     return "jbyte";
        case CHAR:     return "jchar";
        case SHORT:    return "jshort";
        case INT:      return "jint";
        case LONG:     return "jlong";
        case FLOAT:    return "jfloat";
        case DOUBLE:   return "jdouble";
        case DECLARED: {
            if (t.tsym.type == syms.stringType) {
                return "jstring";
            } else if (types.isAssignable(t, syms.throwableType)) {
                return "jthrowable";
            } else if (types.isAssignable(t, syms.classType)) {
                return "jclass";
            } else {
                return "jobject";
            }
        }
    }

    Assert.check(false, "jni unknown type");
    return null; /* dead code. */
}
 
Example 16
Source File: JNIWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
protected final String jniType(Type t) {
    switch (t.getKind()) {
        case ARRAY: {
            Type ct = ((Type.ArrayType)t).getComponentType();
            switch (ct.getKind()) {
                case BOOLEAN:  return "jbooleanArray";
                case BYTE:     return "jbyteArray";
                case CHAR:     return "jcharArray";
                case SHORT:    return "jshortArray";
                case INT:      return "jintArray";
                case LONG:     return "jlongArray";
                case FLOAT:    return "jfloatArray";
                case DOUBLE:   return "jdoubleArray";
                case ARRAY:
                case DECLARED: return "jobjectArray";
                default: throw new Error(ct.toString());
            }
        }

        case VOID:     return "void";
        case BOOLEAN:  return "jboolean";
        case BYTE:     return "jbyte";
        case CHAR:     return "jchar";
        case SHORT:    return "jshort";
        case INT:      return "jint";
        case LONG:     return "jlong";
        case FLOAT:    return "jfloat";
        case DOUBLE:   return "jdouble";
        case DECLARED: {
            if (t.tsym.type == syms.stringType) {
                return "jstring";
            } else if (types.isAssignable(t, syms.throwableType)) {
                return "jthrowable";
            } else if (types.isAssignable(t, syms.classType)) {
                return "jclass";
            } else {
                return "jobject";
            }
        }
    }

    Assert.check(false, "jni unknown type");
    return null; /* dead code. */
}
 
Example 17
Source File: ASTPathCriterion.java    From annotation-tools with MIT License 4 votes vote down vote up
private boolean checkReceiverType(int i, Type t) {
    if (t == null) { return false; }
    while (++i < astPath.size()) {
        ASTPath.ASTEntry entry = astPath.get(i);
        switch (entry.getTreeKind()) {
        case ANNOTATED_TYPE:
          break;
        case ARRAY_TYPE:
          if (t.getKind() != TypeKind.ARRAY) { return false; }
          t = ((Type.ArrayType) t).getComponentType();
          break;
        case MEMBER_SELECT:
          // TODO
          break;
        case PARAMETERIZED_TYPE:
          if (entry.childSelectorIs(ASTPath.TYPE_PARAMETER)) {
            if (!t.isParameterized()) { return false; }
            List<Type> args = t.getTypeArguments();
            int a = entry.getArgument();
            if (a >= args.size()) { return false; }
            t = args.get(a);
          } // else TYPE -- stay?
          break;
        case TYPE_PARAMETER:
          if (t.getKind() != TypeKind.WILDCARD) { return false; }
          t = t.getLowerBound();
          break;
        case EXTENDS_WILDCARD:
          if (t.getKind() != TypeKind.WILDCARD) { return false; }
          t = ((Type.WildcardType) t).getExtendsBound();
          break;
        case SUPER_WILDCARD:
          if (t.getKind() != TypeKind.WILDCARD) { return false; }
          t = ((Type.WildcardType) t).getSuperBound();
          break;
        case UNBOUNDED_WILDCARD:
          if (t.getKind() != TypeKind.WILDCARD) { return false; }
          t = t.getLowerBound();
          break;
        default:
          return false;
        }
        if (t == null) { return false; }
    }
    return true;
}