本文整理汇总了Java中net.bytebuddy.description.field.FieldDescription.InDefinedShape方法的典型用法代码示例。如果您正苦于以下问题:Java FieldDescription.InDefinedShape方法的具体用法?Java FieldDescription.InDefinedShape怎么用?Java FieldDescription.InDefinedShape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.bytebuddy.description.field.FieldDescription
的用法示例。
在下文中一共展示了FieldDescription.InDefinedShape方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wrap
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
@Override
public ClassVisitor wrap(TypeDescription typeDescription, ClassVisitor cv, Context context, TypePool typePool,
FieldList<FieldDescription.InDefinedShape> fieldList, MethodList<?> methodList, int i, int i1)
{
// public void visit(int version, int modifiers, String name, String signature, String superName, String[] interfaces) {
cv.visit(ClassFileVersion.JAVA_V9.getMinorMajorVersion(), typeDescription.getModifiers(), typeDescription.getInternalName(), null,
typeDescription.getSuperClass().asErasure().getInternalName(), typeDescription.getInterfaces().asErasures().toInternalNames());
TypeDescription clazz = this.clazz;
String internalName = clazz.getInternalName();
String descriptor = clazz.getDescriptor();
MethodList<InDefinedShape> declaredMethods = clazz.getDeclaredMethods();
int methodsSize = declaredMethods.size();
String implName = GENERATED_PREFIX + "." + clazz.getName();
String internalImplName = GENERATED_PREFIX.replace('.', '/') + "/" + internalName;
String descriptorImplName = "L" + GENERATED_PREFIX.replace('.', '/') + "/" + internalName + ";";
FieldVisitor fv;
MethodVisitor mv;
AnnotationVisitor av0;
cv.visitEnd();
return cv;
}
示例2: testAccessorIsValid
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testAccessorIsValid() throws Exception {
TypeProxy typeProxy = new TypeProxy(mock(TypeDescription.class),
mock(Implementation.Target.class),
mock(TypeProxy.InvocationFactory.class),
false,
false);
TypeProxy.MethodCall methodCall = typeProxy.new MethodCall(mock(MethodAccessorFactory.class));
TypeDescription instrumentedType = mock(TypeDescription.class);
FieldList<FieldDescription.InDefinedShape> fieldList = mock(FieldList.class);
when(fieldList.filter(any(ElementMatcher.class))).thenReturn(fieldList);
when(fieldList.getOnly()).thenReturn(mock(FieldDescription.InDefinedShape.class));
when(instrumentedType.getDeclaredFields()).thenReturn(fieldList);
TypeProxy.MethodCall.Appender appender = methodCall.new Appender(instrumentedType);
Implementation.SpecialMethodInvocation specialMethodInvocation = mock(Implementation.SpecialMethodInvocation.class);
when(specialMethodInvocation.isValid()).thenReturn(true);
StackManipulation stackManipulation = appender.new AccessorMethodInvocation(mock(MethodDescription.class), specialMethodInvocation);
assertThat(stackManipulation.isValid(), is(true));
verify(specialMethodInvocation).isValid();
verifyNoMoreInteractions(specialMethodInvocation);
}
示例3: ModifierAdjustingClassVisitor
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
/**
* Creates a new modifier adjusting visitor.
*
* @param classVisitor The class visitor to delegate to.
* @param typeAdjustments A list of type modifier adjustments to apply.
* @param fieldAdjustments A list of field modifier adjustments to apply.
* @param methodAdjustments A list of method modifier adjustments to apply.
* @param instrumentedType The instrumented type.
* @param fields A mapping of field names and descriptors to their description.
* @param methods A mapping of method names and descriptors to their description.
*/
protected ModifierAdjustingClassVisitor(ClassVisitor classVisitor,
List<Adjustment<TypeDescription>> typeAdjustments,
List<Adjustment<FieldDescription.InDefinedShape>> fieldAdjustments,
List<Adjustment<MethodDescription>> methodAdjustments,
TypeDescription instrumentedType,
Map<String, FieldDescription.InDefinedShape> fields,
Map<String, MethodDescription> methods) {
super(Opcodes.ASM6, classVisitor);
this.typeAdjustments = typeAdjustments;
this.fieldAdjustments = fieldAdjustments;
this.methodAdjustments = methodAdjustments;
this.instrumentedType = instrumentedType;
this.fields = fields;
this.methods = methods;
}
示例4: testWithFieldOfInstrumentedTypeAsArray
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
@Test
public void testWithFieldOfInstrumentedTypeAsArray() throws Exception {
InstrumentedType instrumentedType = makePlainInstrumentedType();
assertThat(instrumentedType.getDeclaredFields().size(), is(0));
instrumentedType = instrumentedType.withField(new FieldDescription.Token(BAR, Opcodes.ACC_PUBLIC,
new TypeDescription.Generic.OfGenericArray.Latent(TargetType.DESCRIPTION.asGenericType(), new AnnotationSource.Explicit(annotationDescription))));
assertThat(instrumentedType.getDeclaredFields().size(), is(1));
FieldDescription.InDefinedShape fieldDescription = instrumentedType.getDeclaredFields().get(0);
assertThat(fieldDescription.getType().getSort(), is(TypeDefinition.Sort.NON_GENERIC));
assertThat(fieldDescription.getType().asErasure().isArray(), is(true));
assertThat(fieldDescription.getType().asErasure().getComponentType(), sameInstance((TypeDescription) instrumentedType));
assertThat(fieldDescription.getModifiers(), is(Opcodes.ACC_PUBLIC));
assertThat(fieldDescription.getName(), is(BAR));
assertThat(fieldDescription.getType().getDeclaredAnnotations().size(), is(1));
assertThat(fieldDescription.getType().getDeclaredAnnotations().getOnly(), is(annotationDescription));
assertThat(fieldDescription.getDeclaringType(), sameInstance((TypeDescription) instrumentedType));
}
示例5: wrap
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
@Override
public ClassVisitor wrap(TypeDescription instrumentedType,
ClassVisitor classVisitor,
Implementation.Context implementationContext,
TypePool typePool,
FieldList<FieldDescription.InDefinedShape> fields,
MethodList<?> methods,
int writerFlags,
int readerFlags) {
for (AsmVisitorWrapper asmVisitorWrapper : asmVisitorWrappers) {
classVisitor = asmVisitorWrapper.wrap(instrumentedType,
classVisitor,
implementationContext,
typePool,
fields,
methods,
writerFlags,
readerFlags);
}
return classVisitor;
}
示例6: validateClass
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
private <T> void validateClass(Class<T> entityClass) {
if (entityClass.isAnonymousClass() || entityClass.isLocalClass()) {
throw new IllegalArgumentException(entityClass.getName() + " is not publically accessable.");
}
if (!ClassUtils.isAnnotationPresent(entityClass, REntity.class)) {
throw new IllegalArgumentException("REntity annotation is missing from class type declaration.");
}
FieldList<FieldDescription.InDefinedShape> fieldsWithRIdAnnotation
= Introspectior.getFieldsWithAnnotation(entityClass, RId.class);
if (fieldsWithRIdAnnotation.size() == 0) {
throw new IllegalArgumentException("RId annotation is missing from class field declaration.");
}
if (fieldsWithRIdAnnotation.size() > 1) {
throw new IllegalArgumentException("Only one field with RId annotation is allowed in class field declaration.");
}
FieldDescription.InDefinedShape idFieldDescription = fieldsWithRIdAnnotation.getOnly();
String idFieldName = idFieldDescription.getName();
Field idField = null;
try {
idField = ClassUtils.getDeclaredField(entityClass, idFieldName);
} catch (Exception e) {
throw new IllegalStateException(e);
}
if (ClassUtils.isAnnotationPresent(idField.getType(), REntity.class)) {
throw new IllegalArgumentException("Field with RId annotation cannot be a type of which class is annotated with REntity.");
}
if (idField.getType().isAssignableFrom(RObject.class)) {
throw new IllegalArgumentException("Field with RId annotation cannot be a type of RObject");
}
}
示例7: getAllFields
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
public static FieldList<FieldDescription.InDefinedShape> getAllFields(Class<?> cls) {
List<Field> fields = new ArrayList<Field>();
for (Class<?> c = cls; c != null; c = c.getSuperclass()) {
Collections.addAll(fields, c.getDeclaredFields());
}
return new FieldList.ForLoadedFields(fields);
}
示例8: generateFieldInjection
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
public static int generateFieldInjection(ControllerClassData classData, ControllerFieldData<?> fieldData, MethodNode mv, int lineNumber,
PlaceholderType placeholderType)
{
AbstractInsnNode[] result = new AbstractInsnNode[2];
FieldDescription.InDefinedShape member = fieldData.getMember();
TypeDescription fieldType = member.getType().asErasure();
boolean isStatic = member.isStatic();
lineNumber = AsmUtils.printLineNumber(mv, lineNumber);
if (isStatic)
{
mv.visitInsn(ACONST_NULL);
}
else
{
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 0);
}
AsmUtils.storeInt(mv, classData.getIndex());
AsmUtils.storeInt(mv, fieldData.getIndex());
switch (placeholderType)
{
case INVALID:
case UNKNOWN:
default:
throw new IllegalStateException("Can't generate injection for invalid placeholders.");
case NONNULL:
mv.visitInsn(ICONST_1);
break;
case NULLABLE:
mv.visitInsn(ICONST_0);
break;
}
mv.visitMethodInsn(INVOKESTATIC, INJECTOR_CLASS, INJECTOR_FIELD, INJECTOR_FIELD_DESC, false);
return lineNumber;
}
示例9: wrap
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
@Override
public ClassVisitor wrap(TypeDescription instrumentedType,
ClassVisitor classVisitor,
Implementation.Context implementationContext,
TypePool typePool,
FieldList<FieldDescription.InDefinedShape> fields,
MethodList<?> methods,
int writerFlags,
int readerFlags) {
return new TypeValidator(classVisitor, modifiers, inner);
}
示例10: resolve
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
@Override
public Resolver resolve(FieldDescription.InDefinedShape fieldDescription, boolean writeAccess) {
for (Substitution substitution : substitutions) {
Resolver resolver = substitution.resolve(fieldDescription, writeAccess);
if (resolver.isResolved()) {
return resolver;
}
}
return Resolver.Unresolved.INSTANCE;
}
示例11: apply
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) {
StackManipulation preparation = targetMethod.isConstructor()
? new StackManipulation.Compound(TypeCreation.of(targetMethod.getDeclaringType().asErasure()), Duplication.SINGLE)
: StackManipulation.Trivial.INSTANCE;
List<StackManipulation> fieldAccess = new ArrayList<StackManipulation>(declaredFields.size() * 2 + 1);
for (FieldDescription.InDefinedShape fieldDescription : declaredFields) {
fieldAccess.add(MethodVariableAccess.loadThis());
fieldAccess.add(FieldAccess.forField(fieldDescription).read());
}
List<StackManipulation> parameterAccess = new ArrayList<StackManipulation>(instrumentedMethod.getParameters().size() * 2);
for (ParameterDescription parameterDescription : instrumentedMethod.getParameters()) {
parameterAccess.add(MethodVariableAccess.load(parameterDescription));
parameterAccess.add(Assigner.DEFAULT.assign(parameterDescription.getType(),
specializedLambdaMethod.getParameterTypes().get(parameterDescription.getIndex()).asGenericType(),
Assigner.Typing.DYNAMIC));
}
return new Size(new StackManipulation.Compound(
preparation,
new StackManipulation.Compound(fieldAccess),
new StackManipulation.Compound(parameterAccess),
MethodInvocation.invoke(targetMethod),
Assigner.DEFAULT.assign(targetMethod.isConstructor()
? targetMethod.getDeclaringType().asGenericType()
: targetMethod.getReturnType(),
specializedLambdaMethod.getReturnType().asGenericType(),
Assigner.Typing.DYNAMIC),
MethodReturn.of(specializedLambdaMethod.getReturnType())
).apply(methodVisitor, implementationContext).getMaximalSize(), instrumentedMethod.getStackSize());
}
示例12: appender
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
@Override
public ByteCodeAppender appender(Target implementationTarget) {
TypeDescription serializedLambda;
try {
serializedLambda = new TypeDescription.ForLoadedType(Class.forName("java.lang.invoke.SerializedLambda"));
} catch (ClassNotFoundException exception) {
throw new IllegalStateException("Cannot find class for lambda serialization", exception);
}
List<StackManipulation> lambdaArguments = new ArrayList<StackManipulation>(implementationTarget.getInstrumentedType().getDeclaredFields().size());
for (FieldDescription.InDefinedShape fieldDescription : implementationTarget.getInstrumentedType().getDeclaredFields()) {
lambdaArguments.add(new StackManipulation.Compound(MethodVariableAccess.loadThis(),
FieldAccess.forField(fieldDescription).read(),
Assigner.DEFAULT.assign(fieldDescription.getType(), TypeDescription.Generic.OBJECT, Assigner.Typing.STATIC)));
}
return new ByteCodeAppender.Simple(new StackManipulation.Compound(
TypeCreation.of(serializedLambda),
Duplication.SINGLE,
ClassConstant.of(targetType),
new TextConstant(lambdaType.getInternalName()),
new TextConstant(lambdaMethodName),
new TextConstant(lambdaMethod.getDescriptor()),
IntegerConstant.forValue(targetMethod.getHandleType().getIdentifier()),
new TextConstant(targetMethod.getOwnerType().getInternalName()),
new TextConstant(targetMethod.getName()),
new TextConstant(targetMethod.getDescriptor()),
new TextConstant(specializedMethod.getDescriptor()),
ArrayFactory.forType(TypeDescription.Generic.OBJECT).withValues(lambdaArguments),
MethodInvocation.invoke(serializedLambda.getDeclaredMethods().filter(isConstructor()).getOnly()),
MethodReturn.REFERENCE
));
}
示例13: registerClassInternal
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
private <T> void registerClassInternal(Class<T> entityClass) {
DynamicType.Builder<T> builder = new ByteBuddy()
.subclass(entityClass);
for (FieldDescription.InDefinedShape field
: Introspectior.getTypeDescription(LiveObjectTemplate.class)
.getDeclaredFields()) {
builder = builder.define(field);
}
Class<? extends T> proxied = builder.method(ElementMatchers.isDeclaredBy(
Introspectior.getTypeDescription(RLiveObject.class))
.and(ElementMatchers.isGetter().or(ElementMatchers.isSetter())
.or(ElementMatchers.named("isPhantom"))
.or(ElementMatchers.named("delete"))))
.intercept(MethodDelegation.withDefaultConfiguration()
.withBinders(FieldProxy.Binder
.install(LiveObjectInterceptor.Getter.class,
LiveObjectInterceptor.Setter.class))
.to(new LiveObjectInterceptor(redisson, codecProvider, entityClass,
getRIdFieldName(entityClass))))
.implement(RLiveObject.class)
.method(ElementMatchers.isAnnotatedWith(RFieldAccessor.class)
.and(ElementMatchers.named("get")
.or(ElementMatchers.named("set"))))
.intercept(MethodDelegation.to(FieldAccessorInterceptor.class))
.method(ElementMatchers.isDeclaredBy(RObject.class)
.or(ElementMatchers.isDeclaredBy(RObjectAsync.class)))
.intercept(MethodDelegation.to(RObjectInterceptor.class))
.implement(RObject.class)
.method(ElementMatchers.isDeclaredBy(RExpirable.class)
.or(ElementMatchers.isDeclaredBy(RExpirableAsync.class)))
.intercept(MethodDelegation.to(RExpirableInterceptor.class))
.implement(RExpirable.class)
.method(ElementMatchers.isDeclaredBy(Map.class)
.or(ElementMatchers.isDeclaredBy(ConcurrentMap.class))
.or(ElementMatchers.isDeclaredBy(RMapAsync.class))
.or(ElementMatchers.isDeclaredBy(RMap.class)))
.intercept(MethodDelegation.to(RMapInterceptor.class))
.implement(RMap.class)
.method(ElementMatchers.not(ElementMatchers.isDeclaredBy(Object.class))
.and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RLiveObject.class)))
.and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RExpirable.class)))
.and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RExpirableAsync.class)))
.and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RObject.class)))
.and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RObjectAsync.class)))
.and(ElementMatchers.not(ElementMatchers.isDeclaredBy(ConcurrentMap.class)))
.and(ElementMatchers.not(ElementMatchers.isDeclaredBy(Map.class)))
.and(ElementMatchers.isGetter()
.or(ElementMatchers.isSetter()))
.and(ElementMatchers.isPublic()
.or(ElementMatchers.isProtected()))
)
.intercept(MethodDelegation.to(
new AccessorInterceptor(redisson, objectBuilder)))
.make().load(getClass().getClassLoader(),
ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
classCache.putIfAbsent(entityClass, proxied);
}
示例14: getFieldsDescription
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
public static FieldList<FieldDescription.InDefinedShape> getFieldsDescription(Class<?> c) {
return getTypeDescription(c)
.getDeclaredFields();
}
示例15: getFieldsWithAnnotation
import net.bytebuddy.description.field.FieldDescription; //导入方法依赖的package包/类
public static FieldList<FieldDescription.InDefinedShape> getFieldsWithAnnotation(Class<?> c, Class<? extends Annotation> a) {
return getAllFields(c)
.filter(ElementMatchers.isAnnotatedWith(a));
}