下面列出了java.lang.reflect.Modifier#classModifiers ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void getModifiersTest() {
for (Class<?> c : classes) {
ResolvedJavaType type = metaAccess.lookupJavaType(c);
int mask = Modifier.classModifiers() & ~Modifier.STATIC;
int expected = c.getModifiers() & mask;
int actual = type.getModifiers() & mask;
Class<?> elementalType = c;
while (elementalType.isArray()) {
elementalType = elementalType.getComponentType();
}
if (elementalType.isMemberClass()) {
// member class get their modifiers from the inner-class attribute in the JVM and
// from the classfile header in jvmci
expected &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
actual &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
}
assertEquals(String.format("%s: 0x%x != 0x%x", type, expected, actual), expected, actual);
}
}
private static ClassCode newClass(ConstantPool constantPool, int access, String className, ClassSignature signature,
Type superClass, List<Type> interfaces, SourceInfo sourceInfo) {
if ((access & ~Modifier.classModifiers()) != 0) {
throw new IllegalArgumentException();
}
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cw.visit(JAVA_VERSION, access | Opcodes.ACC_SUPER, className, signature.toString(), superClass.internalName(),
toInternalNames(interfaces));
cw.visitSource(sourceInfo.getFileName(), sourceInfo.getSourceMap());
return new ClassCode(constantPool, className, cw);
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface},
* <code>@</code>{@code interface}, or {@code record} as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any,
* including informative bounds on the type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* For an array type, the string starts with the type name,
* followed by an angle-bracketed comma-separated list of the
* type's type parameters, if any, followed by a sequence of
* {@code []} characters, one set of brackets per dimension of
* the array.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
@SuppressWarnings("preview")
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
Class<?> component = this;
int arrayDepth = 0;
if (isArray()) {
do {
arrayDepth++;
component = component.getComponentType();
} while (component.isArray());
sb.append(component.getName());
} else {
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else if (isRecord())
sb.append("record");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
}
TypeVariable<?>[] typeparms = component.getTypeParameters();
if (typeparms.length > 0) {
sb.append(Arrays.stream(typeparms)
.map(Class::typeVarBounds)
.collect(Collectors.joining(",", "<", ">")));
}
if (arrayDepth > 0) sb.append("[]".repeat(arrayDepth));
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* For an array type, the string starts with the type name,
* followed by an angle-bracketed comma-separated list of the
* type's type parameters, if any, followed by a sequence of
* {@code []} characters, one set of brackets per dimension of
* the array.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
Class<?> component = this;
int arrayDepth = 0;
if (isArray()) {
do {
arrayDepth++;
component = component.getComponentType();
} while (component.isArray());
sb.append(component.getName());
} else {
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
}
TypeVariable<?>[] typeparms = component.getTypeParameters();
if (typeparms.length > 0) {
StringJoiner sj = new StringJoiner(",", "<", ">");
for(TypeVariable<?> typeparm: typeparms) {
sj.add(typeparm.getTypeName());
}
sb.append(sj.toString());
}
for (int i = 0; i < arrayDepth; i++)
sb.append("[]");
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}
/**
* Returns a string describing this {@code Class}, including
* information about modifiers and type parameters.
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
* and {@code class}, {@code enum}, {@code interface}, or
* <code>@</code>{@code interface}, as appropriate), followed
* by the type's name, followed by an angle-bracketed
* comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
* occur in canonical order. If there are no type parameters, the
* type parameter list is elided.
*
* <p>Note that since information about the runtime representation
* of a type is being generated, modifiers not present on the
* originating source code or illegal on the originating source
* code may be present.
*
* @return a string describing this {@code Class}, including
* information about modifiers and type parameters
*
* @since 1.8
*/
public String toGenericString() {
if (isPrimitive()) {
return toString();
} else {
StringBuilder sb = new StringBuilder();
// Class modifiers are a superset of interface modifiers
int modifiers = getModifiers() & Modifier.classModifiers();
if (modifiers != 0) {
sb.append(Modifier.toString(modifiers));
sb.append(' ');
}
if (isAnnotation()) {
sb.append('@');
}
if (isInterface()) { // Note: all annotation types are interfaces
sb.append("interface");
} else {
if (isEnum())
sb.append("enum");
else
sb.append("class");
}
sb.append(' ');
sb.append(getName());
TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) {
boolean first = true;
sb.append('<');
for(TypeVariable<?> typeparm: typeparms) {
if (!first)
sb.append(',');
sb.append(typeparm.getTypeName());
first = false;
}
sb.append('>');
}
return sb.toString();
}
}