Java Code Examples for net.bytebuddy.description.type.TypeDescription#Generic

The following examples show how to use net.bytebuddy.description.type.TypeDescription#Generic . 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: Controller.java    From Diorite with MIT License 6 votes vote down vote up
static String fixName(TypeDescription.Generic type, String currentName)
{
    if (type.asErasure().equals(PROVIDER))
    {
        String name = currentName.toLowerCase();
        int providerIndex = name.indexOf("provider");
        if (providerIndex != - 1)
        {
            name = currentName.substring(0, providerIndex);
        }
        else
        {
            name = currentName;
        }
        return name;
    }
    else
    {
        return currentName;
    }
}
 
Example 2
Source File: EqualsMethodOtherTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testEnumerationTypeComparatorRightEnumeration() {
    Comparator<FieldDescription.InDefinedShape> comparator = EqualsMethod.TypePropertyComparator.FOR_ENUMERATION_TYPES;
    FieldDescription.InDefinedShape left = mock(FieldDescription.InDefinedShape.class), right = mock(FieldDescription.InDefinedShape.class);
    TypeDescription.Generic leftType = mock(TypeDescription.Generic.class), rightType = mock(TypeDescription.Generic.class);
    when(left.getType()).thenReturn(leftType);
    when(right.getType()).thenReturn(rightType);
    when(rightType.isEnum()).thenReturn(true);
    assertThat(comparator.compare(left, right), is(1));
}
 
Example 3
Source File: GenericTypeAwareAssigner.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Boolean onTypeVariable(TypeDescription.Generic typeVariable) {
    if (typeVariable.getTypeVariableSource().isInferrable()) {
        throw new UnsupportedOperationException("Assignability checks for type variables declared by methods arel not currently supported");
    } else {
        return false;
    }
}
 
Example 4
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public StackManipulation resolve(TypeDescription targetType,
                                 ByteCodeElement target,
                                 TypeList.Generic parameters,
                                 TypeDescription.Generic result,
                                 int freeOffset) {
    FieldDescription fieldDescription = fieldResolver.resolve(targetType, target, parameters, result);
    if (!fieldDescription.isAccessibleTo(instrumentedType)) {
        throw new IllegalStateException(instrumentedType + " cannot access " + fieldDescription);
    } else if (result.represents(void.class)) {
        if (parameters.size() != (fieldDescription.isStatic() ? 1 : 2)) {
            throw new IllegalStateException("Cannot set " + fieldDescription + " with " + parameters);
        } else if (!fieldDescription.isStatic() && !parameters.get(0).asErasure().isAssignableTo(fieldDescription.getDeclaringType().asErasure())) {
            throw new IllegalStateException("Cannot set " + fieldDescription + " on " + parameters.get(0));
        } else if (!parameters.get(fieldDescription.isStatic() ? 0 : 1).asErasure().isAssignableTo(fieldDescription.getType().asErasure())) {
            throw new IllegalStateException("Cannot set " + fieldDescription + " to " + parameters.get(fieldDescription.isStatic() ? 0 : 1));
        }
        return FieldAccess.forField(fieldDescription).write();
    } else {
        if (parameters.size() != (fieldDescription.isStatic() ? 0 : 1)) {
            throw new IllegalStateException("Cannot set " + fieldDescription + " with " + parameters);
        } else if (!fieldDescription.isStatic() && !parameters.get(0).asErasure().isAssignableTo(fieldDescription.getDeclaringType().asErasure())) {
            throw new IllegalStateException("Cannot get " + fieldDescription + " on " + parameters.get(0));
        } else if (!fieldDescription.getType().asErasure().isAssignableTo(result.asErasure())) {
            throw new IllegalStateException("Cannot get " + fieldDescription + " as " + result);
        }
        return FieldAccess.forField(fieldDescription).read();
    }
}
 
Example 5
Source File: MethodDescription.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Token accept(TypeDescription.Generic.Visitor<? extends TypeDescription.Generic> visitor) {
    return new Token(name,
            modifiers,
            getTypeVariableTokens().accept(visitor),
            returnType.accept(visitor),
            getParameterTokens().accept(visitor),
            getExceptionTypes().accept(visitor),
            annotations,
            defaultValue,
            receiverType == null
                    ? TypeDescription.Generic.UNDEFINED
                    : receiverType.accept(visitor));
}
 
Example 6
Source File: AnnotationAppender.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public AnnotationAppender onGenericArray(TypeDescription.Generic genericArray) {
    return genericArray.getComponentType().accept(new ForTypeAnnotations(apply(genericArray, typePath),
            annotationValueFilter,
            typeReference,
            typePath + COMPONENT_TYPE_PATH));
}
 
Example 7
Source File: MethodDescription.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public TypeDescription.Generic getReceiverType() {
    if (TypeDescription.AbstractBase.RAW_TYPES) {
        return super.getReceiverType();
    }
    TypeDescription.Generic receiverType = TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveReceiverType(method);
    return receiverType == null
            ? super.getReceiverType()
            : receiverType;
}
 
Example 8
Source File: ParameterDescription.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new type substituting parameter.
 *
 * @param declaringMethod      The method that declares this type-substituted parameter.
 * @param parameterDescription The represented parameter.
 * @param visitor              A visitor that is applied to the parameter type.
 */
public TypeSubstituting(MethodDescription.InGenericShape declaringMethod,
                        ParameterDescription parameterDescription,
                        TypeDescription.Generic.Visitor<? extends TypeDescription.Generic> visitor) {
    this.declaringMethod = declaringMethod;
    this.parameterDescription = parameterDescription;
    this.visitor = visitor;
}
 
Example 9
Source File: FieldDescription.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new latent field description. All provided types are attached to this instance before they are returned.
 *
 * @param declaringType       The declaring type of the field.
 * @param name           The name of the field.
 * @param fieldType           The field's modifiers.
 * @param modifiers           The type of the field.
 * @param declaredAnnotations The annotations of this field.
 */
public Latent(TypeDescription declaringType,
              String name,
              int modifiers,
              TypeDescription.Generic fieldType,
              List<? extends AnnotationDescription> declaredAnnotations) {
    this.declaringType = declaringType;
    this.name = name;
    this.modifiers = modifiers;
    this.fieldType = fieldType;
    this.declaredAnnotations = declaredAnnotations;
}
 
Example 10
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public StackManipulation resolve(TypeDescription targetType,
                                 ByteCodeElement target,
                                 TypeList.Generic parameters,
                                 TypeDescription.Generic result,
                                 int freeOffset) {
    List<StackManipulation> stackManipulations = new ArrayList<StackManipulation>(1
            + parameters.size()
            + steps.size() * 2
            + (result.represents(void.class) ? 0 : 2));
    Map<Integer, Integer> offsets = new HashMap<Integer, Integer>();
    for (int index = parameters.size() - 1; index >= 0; index--) {
        stackManipulations.add(MethodVariableAccess.of(parameters.get(index)).storeAt(freeOffset));
        offsets.put(index, freeOffset);
        freeOffset += parameters.get(index).getStackSize().getSize();
    }
    stackManipulations.add(DefaultValue.of(result));
    TypeDescription.Generic current = result;
    for (Step step : steps) {
        Step.Resolution resulution = step.resolve(targetType,
                target,
                parameters,
                current,
                offsets,
                freeOffset);
        stackManipulations.add(resulution.getStackManipulation());
        current = resulution.getResultType();
    }
    stackManipulations.add(assigner.assign(current, result, typing));
    return new StackManipulation.Compound(stackManipulations);
}
 
Example 11
Source File: ParameterDescription.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The implicit field type casting is not understood by Findbugs")
public TypeDescription.Generic getType() {
    if (TypeDescription.AbstractBase.RAW_TYPES) {
        return TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(executable.getParameterTypes()[index]);
    }
    return new TypeDescription.Generic.LazyProjection.OfConstructorParameter(executable, index, executable.getParameterTypes());
}
 
Example 12
Source File: BiDirectionalAssociationHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static TypeDescription entityType(TypeDescription.Generic type) {
	if ( type.getSort().isParameterized() ) {
		if ( type.asErasure().isAssignableTo( Collection.class ) ) {
			return type.getTypeArguments().get( 0 ).asErasure();
		}
		if ( type.asErasure().isAssignableTo( Map.class ) ) {
			return type.getTypeArguments().get( 1 ).asErasure();
		}
	}

	return type.asErasure();
}
 
Example 13
Source File: TypePoolDefaultTypeDescriptionSuperClassLoadingTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
protected TypeDescription.Generic describeType(Field field) {
    return describe(field.getDeclaringClass()).getDeclaredFields().filter(is(field)).getOnly().getType();
}
 
Example 14
Source File: BinderValueData.java    From Diorite with MIT License 4 votes vote down vote up
BinderValueData(Predicate<TypeDescription.Generic> typePredicate, Collection<QualifierPattern> qualifiers)
{
    this.typePredicate = typePredicate;
    this.qualifiers = qualifiers;
}
 
Example 15
Source File: AnnotationAppender.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public AnnotationAppender onTypeVariable(TypeDescription.Generic typeVariable) {
    return apply(typeVariable, typePath);
}
 
Example 16
Source File: DecoratingDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public DynamicType.Builder<T> transform(ElementMatcher<? super TypeDescription.Generic> matcher, Transformer<TypeVariableToken> transformer) {
    throw new UnsupportedOperationException("Cannot transform decorated type: " + instrumentedType);
}
 
Example 17
Source File: GenericTypeAwareAssigner.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Boolean onParameterizedType(TypeDescription.Generic parameterizedType) {
    return typeDescription.accept(new OfParameterizedType(parameterizedType, polymorphic));
}
 
Example 18
Source File: ElementMatchers.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Matches any Java bean getter method which returns an value with a type matches the supplied matcher.
 *
 * @param matcher A matcher to be allied to a getter method's argument type.
 * @param <T>     The type of the matched object.
 * @return A matcher that matches a getter method with a return type that matches the supplied matcher.
 */
public static <T extends MethodDescription> ElementMatcher.Junction<T> isGenericGetter(ElementMatcher<? super TypeDescription.Generic> matcher) {
    return isGetter().and(returnsGeneric(matcher));
}
 
Example 19
Source File: ParameterDescription.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the type of this parameter.
 *
 * @return The type of this parameter.
 */
TypeDescription.Generic getType();
 
Example 20
Source File: ElementMatchers.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Matches any virtual method with a signature that is compatible to a method that is declared by a type that matches the supplied matcher.
 *
 * @param matcher A matcher for a method's declaring type that needs to be matched if that type declares a method with the same signature
 *                as the matched method.
 * @param <T>     The type of the matched object.
 * @return A matcher that checks a method's signature equality for any method declared by the declaring type.
 */
public static <T extends MethodDescription> ElementMatcher.Junction<T> isOverriddenFromGeneric(ElementMatcher<? super TypeDescription.Generic> matcher) {
    return new MethodOverrideMatcher<T>(matcher);
}