List of usage examples for java.lang Class getTypeParameters
@SuppressWarnings("unchecked") public TypeVariable<Class<T>>[] getTypeParameters()
From source file:org.broadinstitute.gatk.queue.extensions.gatk.GATKExtensionsGenerator.java
/** * Returns a string representing the type parameters for a class, or an empty string if there are no type parameters. * @param clazz The class to look for type parameters. * @return The type parameters or an empty string. *///w ww.j av a 2 s. co m private String getScalaTypeParams(Class<?> clazz) { TypeVariable[] typeParams = clazz.getTypeParameters(); if (typeParams.length == 0) return ""; return "[" + StringUtils.repeat("_", ",", typeParams.length) + "]"; }
From source file:org.datalorax.populace.core.util.TypeResolver.java
private Type resolveClass(final Class<?> type) { final TypeVariable<? extends Class<?>>[] typeParameters = type.getTypeParameters(); if (typeParameters.length == 0) { return type; }//from w w w .j a v a 2 s .c om final ParameterizedType parameterised = TypeUtils.parameterise(type, typeParameters); return resolveParameterisedType(parameterised); }
From source file:org.eclipse.wb.android.internal.model.property.event.AndroidEventProperty.java
/** * @return the name of listener type, including generic arguments. */// ww w .j av a2s.c o m private String getListenerTypeNameSource() { // simple case - no generics { Class<?> listenerType = m_listener.getListenerType(); if (listenerType.getTypeParameters().length == 0) { return listenerType.getCanonicalName(); } } // listener with generics Type listenerType = m_listener.getMethod().getGenericParameterTypes()[0]; GenericTypeResolver resolver_2 = m_listener.getResolver(); return GenericsUtils.getTypeName(resolver_2, listenerType); }
From source file:org.eclipse.wb.internal.swing.databinding.model.beans.BeanSupport.java
public List<ObserveInfo> createProperties(ObserveInfo parent, IGenericType objectType) { try {//from w w w. j av a 2s . c o m Class<?> objectClass = objectType.getRawType(); BeanDecorationInfo decorationInfo = DecorationUtils.getDecorationInfo(objectClass); IDecorationProvider decorationProvider = decorationInfo == null ? m_decorationProviderOverType : m_decorationProviderOverInfo; List<ObserveInfo> properties = Lists.newArrayList(); // handle generic TypeVariable<?> superTypeParameter = null; Type superTypeParameterClass = null; if (objectClass.getTypeParameters().length == 1 && objectType.getSubTypes().size() == 1) { superTypeParameter = objectClass.getTypeParameters()[0]; superTypeParameterClass = objectType.getSubTypes().get(0).getRawType(); } else if (objectClass.getGenericSuperclass() instanceof ParameterizedType) { ParameterizedType superType = (ParameterizedType) objectClass.getGenericSuperclass(); if (superType.getActualTypeArguments().length == 1 && superType.getActualTypeArguments()[0] instanceof Class<?> && superType.getRawType() instanceof Class<?>) { Class<?> superClass = (Class<?>) superType.getRawType(); if (superClass.getTypeParameters().length == 1) { superTypeParameter = superClass.getTypeParameters()[0]; superTypeParameterClass = superType.getActualTypeArguments()[0]; } } } // properties for (PropertyDescriptor descriptor : getLocalPropertyDescriptors(objectClass)) { String name = descriptor.getName(); IGenericType propertyType = GenericUtils.getObjectType(superTypeParameter, superTypeParameterClass, descriptor); properties.add(new BeanPropertyObserveInfo(this, parent, name, propertyType, new StringReferenceProvider(name), decorationProvider.getDecorator(decorationInfo, propertyType, name, descriptor))); } // Swing properties if (javax.swing.text.JTextComponent.class.isAssignableFrom(objectClass)) { replaceProperty(properties, "text", new PropertiesObserveInfo(this, parent, "text", ClassGenericType.STRING_CLASS, new StringReferenceProvider("text"), IObserveDecorator.BOLD, new String[] { "text", "text_ON_ACTION_OR_FOCUS_LOST", "text_ON_FOCUS_LOST" })); } else if (javax.swing.JTable.class.isAssignableFrom(objectClass)) { addElementProperties(properties, parent); Collections.sort(properties, ObserveComparator.INSTANCE); } else if (javax.swing.JSlider.class.isAssignableFrom(objectClass)) { replaceProperty(properties, "value", new PropertiesObserveInfo(this, parent, "value", ClassGenericType.INT_CLASS, new StringReferenceProvider("value"), IObserveDecorator.BOLD, new String[] { "value", "value_IGNORE_ADJUSTING" })); } else if (javax.swing.JList.class.isAssignableFrom(objectClass)) { addElementProperties(properties, parent); Collections.sort(properties, ObserveComparator.INSTANCE); } // EL property if (m_addELProperty && !objectClass.isPrimitive()) { properties.add(0, new ElPropertyObserveInfo(parent, objectType)); } // Object property if (m_addSelfProperty && (parent == null || !(parent instanceof BeanPropertyObserveInfo))) { properties.add(0, new ObjectPropertyObserveInfo(objectType)); } // return properties; } catch (Throwable e) { DesignerPlugin.log(e); return Collections.emptyList(); } }
From source file:org.evosuite.utils.generic.GenericAccessibleObject.java
/** * Maps type parameters in a type to their values. * // w w w . java 2 s .co m * @param toMapType * Type possibly containing type arguments * @param typeAndParams * must be either ParameterizedType, or (in case there are no * type arguments, or it's a raw type) Class * @return toMapType, but with type parameters from typeAndParams replaced. */ protected Type mapTypeParameters(Type toMapType, Type typeAndParams) { if (isMissingTypeParameters(typeAndParams)) { logger.debug("Is missing type parameters, so erasing types"); return GenericTypeReflector.erase(toMapType); } else { VarMap varMap = new VarMap(); Type handlingTypeAndParams = typeAndParams; while (handlingTypeAndParams instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) handlingTypeAndParams; Class<?> clazz = (Class<?>) pType.getRawType(); // getRawType should always be Class varMap.addAll(clazz.getTypeParameters(), pType.getActualTypeArguments()); handlingTypeAndParams = pType.getOwnerType(); } varMap.addAll(getTypeVariableMap()); return varMap.map(toMapType); } }
From source file:org.evosuite.utils.generic.GenericClass.java
protected static Type addTypeParameters(Class<?> clazz) { if (clazz.isArray()) { return GenericArrayTypeImpl.createArrayType(addTypeParameters(clazz.getComponentType())); } else if (isMissingTypeParameters(clazz)) { TypeVariable<?>[] vars = clazz.getTypeParameters(); // Type[] arguments = new Type[vars.length]; // Arrays.fill(arguments, UNBOUND_WILDCARD); Type owner = clazz.getDeclaringClass() == null ? null : addTypeParameters(clazz.getDeclaringClass()); return new ParameterizedTypeImpl(clazz, vars, owner); } else {//from ww w .ja v a 2s. c o m return clazz; } }
From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java
private void validateType(ModelType<?> type, ModelSchemaExtractionContext<?> extractionContext) { Class<?> typeClass = type.getConcreteClass(); if (!typeClass.isInterface() && !Modifier.isAbstract(typeClass.getModifiers())) { throw new InvalidManagedModelElementTypeException(extractionContext, "must be defined as an interface or an abstract class."); }/*from www . j a v a 2 s .c o m*/ if (typeClass.getTypeParameters().length > 0) { throw new InvalidManagedModelElementTypeException(extractionContext, "cannot be a parameterized type."); } Constructor<?> customConstructor = findCustomConstructor(typeClass); if (customConstructor != null) { throw invalidMethod(extractionContext, "custom constructors are not allowed", customConstructor); } ensureNoInstanceScopedFields(extractionContext, typeClass); ensureNoProtectedOrPrivateMethods(extractionContext, typeClass); }
From source file:org.gradle.model.internal.manage.schema.extraction.ModelSchemaExtractor.java
public <T> void validateType(Class<T> type) { if (!isManaged(type)) { throw invalid(type, String.format("must be annotated with %s", Managed.class.getName())); }//from w ww . java 2s. c om if (!type.isInterface()) { throw invalid(type, "must be defined as an interface"); } if (type.getInterfaces().length != 0) { throw invalid(type, "cannot extend other types"); } if (type.getTypeParameters().length != 0) { throw invalid(type, "cannot be a parameterized type"); } }
From source file:org.gradle.model.internal.manage.schema.ModelSchemaExtractor.java
public <T> void validateType(Class<T> type) { if (!type.isInterface()) { throw invalid(type, "must be defined as an interface"); }/* ww w . ja va 2 s . c om*/ if (type.getInterfaces().length != 0) { throw invalid(type, "cannot extend other types"); } if (type.getTypeParameters().length != 0) { throw invalid(type, "cannot be a parameterized type"); } }
From source file:org.gradle.model.internal.manage.schema.store.ModelSchemaExtractor.java
public <T> void validateType(ModelType<T> type) { Class<T> typeClass = type.getConcreteClass(); if (!isManaged(typeClass)) { throw invalid(type, String.format("must be annotated with %s", Managed.class.getName())); }//from ww w. java 2s. c o m if (!typeClass.isInterface()) { throw invalid(type, "must be defined as an interface"); } if (typeClass.getInterfaces().length > 0) { throw invalid(type, "cannot extend other types"); } if (typeClass.getTypeParameters().length > 0) { throw invalid(type, "cannot be a parameterized type"); } }