String fieldName = fieldDescription.getName(); if (!fieldSignatureTokens.add(fieldDescription.asSignatureToken())) { throw new IllegalStateException("Duplicate field definition for " + fieldDescription); } else if (!isValidIdentifier(fieldName)) { throw new IllegalStateException("Illegal field name for " + fieldDescription); } else if ((fieldDescription.getModifiers() & ~ModifierContributor.ForField.MASK) != EMPTY_MASK) { throw new IllegalStateException("Illegal field modifiers " + fieldDescription.getModifiers() + " for " + fieldDescription); Generic fieldType = fieldDescription.getType(); if (!fieldType.accept(Generic.Visitor.Validator.FIELD)) { throw new IllegalStateException("Illegal field type " + fieldType + " for " + fieldDescription); } else if (!fieldType.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) { throw new IllegalStateException("Illegal type annotations on " + fieldType + " for " + this); } else if (!fieldDescription.isSynthetic() && !fieldType.asErasure().isVisibleTo(this)) { throw new IllegalStateException("Invisible field type " + fieldDescription.getType() + " for " + fieldDescription); for (AnnotationDescription annotationDescription : fieldDescription.getDeclaredAnnotations()) { if (!annotationDescription.getElementTypes().contains(ElementType.FIELD)) { throw new IllegalStateException("Cannot add " + annotationDescription + " on " + fieldDescription);
switch (opcode) { case Opcodes.PUTFIELD: parameters = new TypeList.Generic.Explicit(candidates.getOnly().getDeclaringType(), candidates.getOnly().getType()); result = TypeDescription.Generic.VOID; break; case Opcodes.PUTSTATIC: parameters = new TypeList.Generic.Explicit(candidates.getOnly().getType()); result = TypeDescription.Generic.VOID; break; case Opcodes.GETFIELD: parameters = new TypeList.Generic.Explicit(candidates.getOnly().getDeclaringType()); result = candidates.getOnly().getType(); break; case Opcodes.GETSTATIC: parameters = new TypeList.Generic.Empty(); result = candidates.getOnly().getType(); break; default:
/** * {@inheritDoc} */ public void drain(TypeInitializer.Drain drain, ClassVisitor classVisitor, AnnotationValueFilter.Factory annotationValueFilterFactory) { fieldCacheCanAppendEntries = false; TypeInitializer typeInitializer = this.typeInitializer; for (Map.Entry<FieldCacheEntry, FieldDescription.InDefinedShape> entry : registeredFieldCacheEntries.entrySet()) { FieldVisitor fieldVisitor = classVisitor.visitField(entry.getValue().getModifiers(), entry.getValue().getInternalName(), entry.getValue().getDescriptor(), entry.getValue().getGenericSignature(), FieldDescription.NO_DEFAULT_VALUE); if (fieldVisitor != null) { fieldVisitor.visitEnd(); typeInitializer = typeInitializer.expandWith(entry.getKey().storeIn(entry.getValue())); } } drain.apply(classVisitor, typeInitializer, this); for (TypeWriter.MethodPool.Record record : registeredAccessorMethods.values()) { record.apply(classVisitor, this, annotationValueFilterFactory); } for (TypeWriter.MethodPool.Record record : registeredGetters.values()) { record.apply(classVisitor, this, annotationValueFilterFactory); } for (TypeWriter.MethodPool.Record record : registeredSetters.values()) { record.apply(classVisitor, this, annotationValueFilterFactory); } }
Object object = ClassUtils.getField(detachedObject, field.getName()); if (object == null) { continue; RObject rObject = commandExecutor.getObjectBuilder().createObject(id, detachedObject.getClass(), object.getClass(), field.getName(), redisson); if (rObject != null) { commandExecutor.getObjectBuilder().store(rObject, field.getName(), liveMap); if (rObject instanceof SortedSet) { ((RSortedSet)rObject).trySetComparator(((SortedSet)object).comparator()); Object persisted = alreadyPersisted.get(obj); if (persisted == null) { if (checkCascade(detachedObject, type, field.getName())) { persisted = persist(obj, alreadyPersisted, type); Object persisted = alreadyPersisted.get(key); if (persisted == null) { if (checkCascade(detachedObject, type, field.getName())) { persisted = persist(key, alreadyPersisted, type); Object persisted = alreadyPersisted.get(value); if (persisted == null) { if (checkCascade(detachedObject, type, field.getName())) { persisted = persist(value, alreadyPersisted, type); excludedFields.add(field.getName()); } else if (ClassUtils.isAnnotationPresent(object.getClass(), REntity.class)) { Object persisted = alreadyPersisted.get(object); if (persisted == null) {
Implementation.Context implementationContext, MethodDescription instrumentedMethod) { TypeDescription dispatcherType = persistentFieldAsDefined.getType().isPrimitive() ? persistentFieldAsDefined.getType().asErasure() : TypeDescription.OBJECT; methodVisitor.visitLdcInsn( persistentFieldAsDefined.getName() ); methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 ); fieldRead( methodVisitor ); methodVisitor.visitTypeInsn( Opcodes.CHECKCAST, persistentFieldAsDefined.getType().asErasure().getInternalName() ); methodVisitor.visitTypeInsn( Opcodes.CHECKCAST, persistentFieldAsDefined.getType().asErasure().getInternalName() ); return new Size( 4 + 2 * persistentFieldAsDefined.getType().getStackSize().getSize(), instrumentedMethod.getStackSize() );
methodVisitor.visitVarInsn( Type.getType( persistentField.getType().asErasure().getDescriptor() ).getOpcode( Opcodes.ILOAD ), 1 ); methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 ); if ( persistentField.getDeclaringType().asErasure().equals( managedCtClass ) ) { methodVisitor.visitFieldInsn( Opcodes.GETFIELD, persistentField.getDeclaringType().asErasure().getInternalName(), persistentField.getName(), persistentField.getDescriptor() ); methodVisitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, persistentField.getDeclaringType().asErasure().getInternalName(), EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX + persistentField.getName(), Type.getMethodDescriptor( Type.getType( persistentField.getDescriptor() ) ), false ); if ( persistentField.getType().isPrimitive() ) { if ( persistentField.getType().represents( long.class ) ) { methodVisitor.visitInsn( Opcodes.LCMP ); else if ( persistentField.getType().represents( float.class ) ) { methodVisitor.visitInsn( Opcodes.FCMPL ); else if ( persistentField.getType().represents( double.class ) ) { methodVisitor.visitInsn( Opcodes.DCMPL ); methodVisitor.visitLdcInsn( persistentField.getName() );
Implementation.Context implementationContext, MethodDescription instrumentedMethod) { TypeDescription dispatcherType = persistentFieldAsDefined.getType().isPrimitive() ? persistentFieldAsDefined.getType().asErasure() : TypeDescription.OBJECT; methodVisitor.visitLdcInsn( persistentFieldAsDefined.getName() ); methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 ); fieldRead( methodVisitor ); methodVisitor.visitTypeInsn( Opcodes.CHECKCAST, persistentFieldAsDefined.getType().asErasure().getInternalName() ); fieldRead( methodVisitor ); if ( !persistentField.getType().isPrimitive() && !persistentField.getType().asErasure().getInternalName().equals( persistentFieldAsDefined.getType().asErasure().getInternalName() ) ) { methodVisitor.visitTypeInsn( Opcodes.CHECKCAST, persistentField.getType().asErasure().getInternalName() ); methodVisitor.visitInsn( Type.getType( persistentFieldAsDefined.getType().asErasure().getDescriptor() ).getOpcode( Opcodes.IRETURN ) ); return new Size( 4 + persistentFieldAsDefined.getType().getStackSize().getSize(), instrumentedMethod.getStackSize() );
RBatch batch = redisson.createBatch(); for (InDefinedShape field : fields) { String fieldName = field.getName(); Object value = map.get(fieldName); NamingScheme namingScheme = objectBuilder.getNamingScheme(me.getClass().getSuperclass());
ElementMatchers.anyOf(Map.class, Collection.class, RObject.class)))); for (InDefinedShape field : fields) { throw new IllegalArgumentException("RIndex annotation couldn't be defined for field '" + field.getName() + "' with type '" + field.getType() + "'"); String idFieldName = idFieldDescription.getName(); Field idField = null; try {
String name = Introspectior .getFieldsWithAnnotation(rEntity, RId.class) .getOnly().getName(); Class<?> type = ClassUtils.getDeclaredField(rEntity, name).getType();
@Override public final StackManipulationToken stackManipulationToken() { return new SmtCombined( new SmtStatic( new TextConstant(", ") ), new SmtArray( new TypeDescription.ForLoadedType(CharSequence.class), List.of(type) .flatMap(TypeDescription::getDeclaredFields) .filter(f -> !f.isStatic()) .<StackManipulationToken>map(SmtAtomFieldToString::new) .prepend(new SmtAtomTypeToString(type)) .toJavaArray(i -> new StackManipulationToken[i]) ), new SmtInvokeMethod( new TypeDescription.ForLoadedType(String.class), new ConjunctionMatcher<>( ElementMatchers.named("join"), ElementMatchers.takesArguments(2), ElementMatchers.takesArgument(0, CharSequence.class), ElementMatchers.takesArgument(1, CharSequence[].class), ElementMatchers.returns(String.class) ) ) ); } }
private void visitFields(Set<Class<?>> types, AnnotationCache cache, TypeDescription typeDescription, boolean inheriting) { typeDescription.getDeclaredFields().forEach(f -> { Consumer<Annotation> addToCache = a -> types.forEach(t -> cache.addFieldAnnotation(t, f.getName(), a)); // Regular field annotations f.getDeclaredAnnotations() .forEach(a -> cacheSupportedAnnotations(a, types, cache, addToCache, inheriting)); // Type-use annotations f.getType().getDeclaredAnnotations() .forEach(a -> cacheSupportedAnnotations(a, types, cache, addToCache, inheriting)); }); typeDescription.getDeclaredMethods() .filter(m -> m.getName().startsWith("get") && m.getName().length() > 3) .forEach(m -> { String methodName = m.getName(); String correspondingFieldName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4); Consumer<Annotation> addToCache = a -> types.forEach(t -> cache.addFieldAnnotation(t, correspondingFieldName, a)); m.getDeclaredAnnotations() .forEach(a -> cacheSupportedAnnotations(a, types, cache, addToCache, inheriting)); }); }
@Override public final StackManipulationToken stackManipulationToken() { NaturalJavaAtom naturalMatcher = new NaturalJavaAtom(); return new SmtArray( List.of(type) .flatMap(TypeDescription::getDeclaredFields) .filter(f -> !f.isStatic()) .filter(f -> naturalMatcher.matches(f.getType().asErasure())) .map(f -> new SmtLoadField(f)) .toJavaArray(SmtLoadField.class) ); } }
@Override public final StackManipulationToken stackManipulationToken() { NaturalJavaAtom naturalMatcher = new NaturalJavaAtom(); return new SmtArray( List.of(type) .flatMap(TypeDescription::getDeclaredFields) .filter(f -> !f.isStatic()) .filter(f -> !naturalMatcher.matches(f.getType().asErasure())) .map(f -> new SmtLoadField(f)) .toJavaArray(SmtLoadField.class) ); } }
@Override protected void fieldRead(MethodVisitor methodVisitor) { methodVisitor.visitMethodInsn( Opcodes.INVOKESPECIAL, managedCtClass.getSuperClass().asErasure().getInternalName(), EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX + persistentFieldAsDefined.getName(), Type.getMethodDescriptor( Type.getType( persistentFieldAsDefined.getType().asErasure().getDescriptor() ) ), false ); }
@Override protected void fieldWrite(MethodVisitor methodVisitor) { methodVisitor.visitMethodInsn( Opcodes.INVOKESPECIAL, managedCtClass.getSuperClass().asErasure().getInternalName(), EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + persistentFieldAsDefined.getName(), Type.getMethodDescriptor( Type.getType( void.class ), Type.getType( persistentFieldAsDefined.getType().asErasure().getDescriptor() ) ), false ); } }
private String getRIdFieldName(Class<?> cls) { return Introspectior.getFieldsWithAnnotation(cls, RId.class) .getOnly() .getName(); }
@Override public final boolean matches(final TypeDescription target) { return target.getDeclaredFields() .filter(not(isSynthetic())) .filter(f -> f.getType().isArray()) .isEmpty(); } }
@Override protected void fieldWrite(MethodVisitor methodVisitor) { methodVisitor.visitFieldInsn( Opcodes.PUTFIELD, persistentFieldAsDefined.getDeclaringType().asErasure().getInternalName(), persistentFieldAsDefined.getInternalName(), persistentFieldAsDefined.getDescriptor() ); } }
private static String getREntityIdFieldName(Object o) throws Exception { return Introspectior .getFieldsWithAnnotation(o.getClass().getSuperclass(), RId.class) .getOnly() .getName(); }