jodd-proxetta/src/main/java/jodd/proxetta/asm/ProxyAspectData.java
private void readAdviceData() {
		if (ready) {
			return;
		}

		adviceClassReader.accept(new EmptyClassVisitor() {

			/**
			 * Stores advice reference.
			 */
			@Override
			public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) {
				adviceReference = name;
				super.visit(version, access, name, signature, superName, interfaces);
			}

			/**
			 * Prevents advice to have inner classes.
			 */
			@Override
			public void visitInnerClass(final String name, final String outerName, final String innerName, final int access) {
				if (outerName.equals(adviceReference)) {
					throw new ProxettaException("Proxetta doesn't allow inner classes in/for advice: " + advice.getName());
				}
				super.visitInnerClass(name, outerName, innerName, access);
			}

			/**
			 * Clones advices fields to destination.
			 */
			@Override
			public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
				wd.dest.visitField(access, adviceFieldName(name, aspectIndex), desc, signature, value);     // [A5]
				return super.visitField(access, name, desc, signature, value);
			}

			/**
			 * Copies advices methods to destination.
			 */
			@Override
			public MethodVisitor visitMethod(int access, String name, final String desc, final String signature, final String[] exceptions) {
				if (name.equals(CLINIT)) {              // [A6]
					if (!desc.equals(DESC_VOID)) {
						throw new ProxettaException("Invalid static initialization block description for advice: " + advice.getName());
					}
					name = ProxettaNames.clinitMethodName + ProxettaNames.methodDivider + aspectIndex;
					access |= AsmUtil.ACC_PRIVATE | AsmUtil.ACC_FINAL;
					wd.addAdviceClinitMethod(name);
					return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {

						@Override
						public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) {
						}

						@Override
						public void visitLineNumber(final int line, final Label start) {
						}

						@Override
						public void visitMethodInsn(final int opcode, String owner, String name, final String desc, final boolean isInterface) {
							if (opcode == INVOKESTATIC) {
								if (owner.equals(adviceReference)) {
									owner = wd.thisReference;
									name = adviceMethodName(name, aspectIndex);
								}
							}
							super.visitMethodInsn(opcode, owner, name, desc, isInterface);
						}

						@Override
						public void visitFieldInsn(final int opcode, String owner, String name, final String desc) { // [F6]
							if (owner.equals(adviceReference)) {
								owner = wd.thisReference;              // [F5]
								name = adviceFieldName(name, aspectIndex);
							}
							super.visitFieldInsn(opcode, owner, name, desc);
						}
					};
				} else

				if (name.equals(INIT)) { // [A7]
					if (!desc.equals(DESC_VOID)) {
						throw new ProxettaException("Advices can have only default constructors. Invalid advice: " + advice.getName());
					}

					name = ProxettaNames.initMethodName + ProxettaNames.methodDivider + aspectIndex;
					access = ProxettaAsmUtil.makePrivateFinalAccess(access);
					wd.addAdviceInitMethod(name);
					return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {
						@Override
						public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) {
						}

						@Override
						public void visitLineNumber(final int line, final Label start) {
						}

						int state; // used to detect and to ignore the first super call()

						@Override
						public void visitVarInsn(final int opcode, final int var) {                      // [F7]
							if ((state == 0) && (opcode == ALOAD) && (var == 0)) {
								state++;
								return;
							}
							super.visitVarInsn(opcode, var);
						}

						@Override
						public void visitMethodInsn(final int opcode, String owner, String name, final String desc, final boolean isInterface) {
							if ((state == 1) && (opcode == INVOKESPECIAL)) {
							    state++;
								return;
							}
							if ((opcode == INVOKEVIRTUAL) || (opcode == INVOKEINTERFACE)) {
								if (owner.equals(adviceReference)) {
									owner = wd.thisReference;
									name = adviceMethodName(name, aspectIndex);
								}
							} else

							if (opcode == INVOKESTATIC) {
								if (owner.equals(adviceReference)) {
									owner = wd.thisReference;
									name = adviceMethodName(name, aspectIndex);
								}
							}
							super.visitMethodInsn(opcode, owner, name, desc, isInterface);
						}

						@Override
						public void visitFieldInsn(final int opcode, String owner, String name, final String desc) { // [F7]
							if (owner.equals(adviceReference)) {
								owner = wd.thisReference;              // [F5]
								name = adviceFieldName(name, aspectIndex);
							}
							super.visitFieldInsn(opcode, owner, name, desc);
						}
					};

				} else

				// other methods
				if (!name.equals(ProxettaNames.executeMethodName)) {
					name = adviceMethodName(name, aspectIndex);
					return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {

						@Override
						public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) {
						}

						@Override
						public void visitLineNumber(final int line, final Label start) {
						}

						@Override
						public void visitMethodInsn(final int opcode, String owner, String name, final String desc, final boolean isInterface) {
							if ((opcode == INVOKEVIRTUAL) || (opcode == INVOKEINTERFACE)) {
								if (owner.equals(adviceReference)) {
									owner = wd.thisReference;
									name = adviceMethodName(name, aspectIndex);
								}
							} else

							if (opcode == INVOKESTATIC || opcode == INVOKESPECIAL) {
								if (owner.equals(adviceReference)) {
									owner = wd.thisReference;
									name = adviceMethodName(name, aspectIndex);
								}
							}
							super.visitMethodInsn(opcode, owner, name, desc, isInterface);
						}

						@Override
						public void visitFieldInsn(final int opcode, String owner, String name, final String desc) {        // replace field references
							if (owner.equals(adviceReference)) {
								owner = wd.thisReference;
								name = adviceFieldName(name, aspectIndex);
							}
							super.visitFieldInsn(opcode, owner, name, desc);
						}
					};
				}

				// Parse EXECUTE method, just to gather some info, real parsing will come later
				//return new MethodAdapter(new EmptyMethodVisitor()) {		// toask may we replace this with the following code?
				return new EmptyMethodVisitor() {
					@Override
					public void visitVarInsn(final int opcode, final int var) {
						if (isStoreOpcode(opcode)) {
							if (var > maxLocalVarOffset) {
								maxLocalVarOffset = var;          // find max local var offset
							}
						}
						super.visitVarInsn(opcode, var);
					}
				};
//					return super.visitMethod(access, name, desc, signature, exceptions);
			}
		}, 0);
		maxLocalVarOffset += 2;       // increment offset by 2 because var on last index may be a dword value
		ready = true;
	}
private void readAdviceData() {
		if (ready) {
			return;
		}

		adviceClassReader.accept(new EmptyClassVisitor() {

			/**
			 * Stores advice reference.
			 */
			@Override
			public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) {
				adviceReference = name;
				super.visit(version, access, name, signature, superName, interfaces);
			}

			/**
			 * Prevents advice to have inner classes.
			 */
			@Override
			public void visitInnerClass(final String name, final String outerName, final String innerName, final int access) {
				if (outerName.equals(adviceReference)) {
					throw new ProxettaException("Proxetta doesn't allow inner classes in/for advice: " + advice.getName());
				}
				super.visitInnerClass(name, outerName, innerName, access);
			}

			/**
			 * Clones advices fields to destination.
			 */
			@Override
			public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
				wd.dest.visitField(access, adviceFieldName(name, aspectIndex), desc, signature, value);     // [A5]
				return super.visitField(access, name, desc, signature, value);
			}

			/**
			 * Copies advices methods to destination.
			 */
			@Override
			public MethodVisitor visitMethod(int access, String name, final String desc, final String signature, final String[] exceptions) {
				if (name.equals(CLINIT)) {              // [A6]
					if (!desc.equals(DESC_VOID)) {
						throw new ProxettaException("Invalid static initialization block description for advice: " + advice.getName());
					}
					name = ProxettaNames.clinitMethodName + ProxettaNames.methodDivider + aspectIndex;
					access |= AsmUtil.ACC_PRIVATE | AsmUtil.ACC_FINAL;
					wd.addAdviceClinitMethod(name);
					return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {

						@Override
						public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) {
						}

						@Override
						public void visitLineNumber(final int line, final Label start) {
						}

						@Override
						public void visitMethodInsn(final int opcode, String owner, String name, final String desc, final boolean isInterface) {
							if (opcode == INVOKESTATIC) {
								if (owner.equals(adviceReference)) {
									owner = wd.thisReference;
									name = adviceMethodName(name, aspectIndex);
								}
							}
							super.visitMethodInsn(opcode, owner, name, desc, isInterface);
						}

						@Override
						public void visitFieldInsn(final int opcode, String owner, String name, final String desc) { // [F6]
							if (owner.equals(adviceReference)) {
								owner = wd.thisReference;              // [F5]
								name = adviceFieldName(name, aspectIndex);
							}
							super.visitFieldInsn(opcode, owner, name, desc);
						}
					};
				} else

				if (name.equals(INIT)) { // [A7]
					if (!desc.equals(DESC_VOID)) {
						throw new ProxettaException("Advices can have only default constructors. Invalid advice: " + advice.getName());
					}

					name = ProxettaNames.initMethodName + ProxettaNames.methodDivider + aspectIndex;
					access = ProxettaAsmUtil.makePrivateFinalAccess(access);
					wd.addAdviceInitMethod(name);
					return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {
						@Override
						public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) {
						}

						@Override
						public void visitLineNumber(final int line, final Label start) {
						}

						int state; // used to detect and to ignore the first super call()

						@Override
						public void visitVarInsn(final int opcode, final int var) {                      // [F7]
							if ((state == 0) && (opcode == ALOAD) && (var == 0)) {
								state++;
								return;
							}
							super.visitVarInsn(opcode, var);
						}

						@Override
						public void visitMethodInsn(final int opcode, String owner, String name, final String desc, final boolean isInterface) {
							if ((state == 1) && (opcode == INVOKESPECIAL)) {
							    state++;
								return;
							}
							if ((opcode == INVOKEVIRTUAL) || (opcode == INVOKEINTERFACE)) {
								if (owner.equals(adviceReference)) {
									owner = wd.thisReference;
									name = adviceMethodName(name, aspectIndex);
								}
							} else

							if (opcode == INVOKESTATIC) {
								if (owner.equals(adviceReference)) {
									owner = wd.thisReference;
									name = adviceMethodName(name, aspectIndex);
								}
							}
							super.visitMethodInsn(opcode, owner, name, desc, isInterface);
						}

						@Override
						public void visitFieldInsn(final int opcode, String owner, String name, final String desc) { // [F7]
							if (owner.equals(adviceReference)) {
								owner = wd.thisReference;              // [F5]
								name = adviceFieldName(name, aspectIndex);
							}
							super.visitFieldInsn(opcode, owner, name, desc);
						}
					};

				} else

				// other methods
				if (!name.equals(ProxettaNames.executeMethodName)) {
					name = adviceMethodName(name, aspectIndex);
					return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {

						@Override
						public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) {
						}

						@Override
						public void visitLineNumber(final int line, final Label start) {
						}

						@Override
						public void visitMethodInsn(final int opcode, String owner, String name, final String desc, final boolean isInterface) {
							if ((opcode == INVOKEVIRTUAL) || (opcode == INVOKEINTERFACE)) {
								if (owner.equals(adviceReference)) {
									owner = wd.thisReference;
									name = adviceMethodName(name, aspectIndex);
								}
							} else

							if (opcode == INVOKESTATIC || opcode == INVOKESPECIAL) {
								if (owner.equals(adviceReference)) {
									owner = wd.thisReference;
									name = adviceMethodName(name, aspectIndex);
								}
							}
							super.visitMethodInsn(opcode, owner, name, desc, isInterface);
						}

						@Override
						public void visitFieldInsn(final int opcode, String owner, String name, final String desc) {        // replace field references
							if (owner.equals(adviceReference)) {
								owner = wd.thisReference;
								name = adviceFieldName(name, aspectIndex);
							}
							super.visitFieldInsn(opcode, owner, name, desc);
						}
					};
				}

				// Parse EXECUTE method, just to gather some info, real parsing will come later
				//return new MethodAdapter(new EmptyMethodVisitor()) {		// toask may we replace this with the following code?
				return new EmptyMethodVisitor() {
					@Override
					public void visitVarInsn(final int opcode, final int var) {
						if (isStoreOpcode(opcode)) {
							if (var > maxLocalVarOffset) {
								maxLocalVarOffset = var;          // find max local var offset
							}
						}
						super.visitVarInsn(opcode, var);
					}
				};
//					return super.visitMethod(access, name, desc, signature, exceptions);
			}
		}, 0);
		maxLocalVarOffset += 2;       // increment offset by 2 because var on last index may be a dword value
		ready = true;
	}
private void readAdviceData ( ) { if ( ready ) { return ; } adviceClassReader . accept ( new EmptyClassVisitor ( ) { /**
			 * Stores advice reference.
			 */ @ Override public void visit ( final int version , final int access , final String name , final String signature , final String superName , final String [ ] interfaces ) { adviceReference = name ; super . visit ( version , access , name , signature , superName , interfaces ) ; } /**
			 * Prevents advice to have inner classes.
			 */ @ Override public void visitInnerClass ( final String name , final String outerName , final String innerName , final int access ) { if ( outerName . equals ( adviceReference ) ) { throw new ProxettaException ( "Proxetta doesn't allow inner classes in/for advice: " + advice . getName ( ) ) ; } super . visitInnerClass ( name , outerName , innerName , access ) ; } /**
			 * Clones advices fields to destination.
			 */ @ Override public FieldVisitor visitField ( final int access , final String name , final String desc , final String signature , final Object value ) { wd . dest . visitField ( access , adviceFieldName ( name , aspectIndex ) , desc , signature , value ) ; // [A5] return super . visitField ( access , name , desc , signature , value ) ; } /**
			 * Copies advices methods to destination.
			 */ @ Override public MethodVisitor visitMethod ( int access , String name , final String desc , final String signature , final String [ ] exceptions ) { if ( name . equals ( CLINIT ) ) { // [A6] if ( ! desc . equals ( DESC_VOID ) ) { throw new ProxettaException ( "Invalid static initialization block description for advice: " + advice . getName ( ) ) ; } name = ProxettaNames . clinitMethodName + ProxettaNames . methodDivider + aspectIndex ; access |= AsmUtil . ACC_PRIVATE | AsmUtil . ACC_FINAL ; wd . addAdviceClinitMethod ( name ) ; return new MethodAdapter ( wd . dest . visitMethod ( access , name , desc , signature , exceptions ) ) { @ Override public void visitLocalVariable ( final String name , final String desc , final String signature , final Label start , final Label end , final int index ) { } @ Override public void visitLineNumber ( final int line , final Label start ) { } @ Override public void visitMethodInsn ( final int opcode , String owner , String name , final String desc , final boolean isInterface ) { if ( opcode == INVOKESTATIC ) { if ( owner . equals ( adviceReference ) ) { owner = wd . thisReference ; name = adviceMethodName ( name , aspectIndex ) ; } } super . visitMethodInsn ( opcode , owner , name , desc , isInterface ) ; } @ Override public void visitFieldInsn ( final int opcode , String owner , String name , final String desc ) { // [F6] if ( owner . equals ( adviceReference ) ) { owner = wd . thisReference ; // [F5] name = adviceFieldName ( name , aspectIndex ) ; } super . visitFieldInsn ( opcode , owner , name , desc ) ; } } ; } else if ( name . equals ( INIT ) ) { // [A7] if ( ! desc . equals ( DESC_VOID ) ) { throw new ProxettaException ( "Advices can have only default constructors. Invalid advice: " + advice . getName ( ) ) ; } name = ProxettaNames . initMethodName + ProxettaNames . methodDivider + aspectIndex ; access = ProxettaAsmUtil . makePrivateFinalAccess ( access ) ; wd . addAdviceInitMethod ( name ) ; return new MethodAdapter ( wd . dest . visitMethod ( access , name , desc , signature , exceptions ) ) { @ Override public void visitLocalVariable ( final String name , final String desc , final String signature , final Label start , final Label end , final int index ) { } @ Override public void visitLineNumber ( final int line , final Label start ) { } int state ; // used to detect and to ignore the first super call() @ Override public void visitVarInsn ( final int opcode , final int var ) { // [F7] if ( ( state == 0 ) && ( opcode == ALOAD ) && ( var == 0 ) ) { state ++ ; return ; } super . visitVarInsn ( opcode , var ) ; } @ Override public void visitMethodInsn ( final int opcode , String owner , String name , final String desc , final boolean isInterface ) { if ( ( state == 1 ) && ( opcode == INVOKESPECIAL ) ) { state ++ ; return ; } if ( ( opcode == INVOKEVIRTUAL ) || ( opcode == INVOKEINTERFACE ) ) { if ( owner . equals ( adviceReference ) ) { owner = wd . thisReference ; name = adviceMethodName ( name , aspectIndex ) ; } } else if ( opcode == INVOKESTATIC ) { if ( owner . equals ( adviceReference ) ) { owner = wd . thisReference ; name = adviceMethodName ( name , aspectIndex ) ; } } super . visitMethodInsn ( opcode , owner , name , desc , isInterface ) ; } @ Override public void visitFieldInsn ( final int opcode , String owner , String name , final String desc ) { // [F7] if ( owner . equals ( adviceReference ) ) { owner = wd . thisReference ; // [F5] name = adviceFieldName ( name , aspectIndex ) ; } super . visitFieldInsn ( opcode , owner , name , desc ) ; } } ; } else // other methods if ( ! name . equals ( ProxettaNames . executeMethodName ) ) { name = adviceMethodName ( name , aspectIndex ) ; return new MethodAdapter ( wd . dest . visitMethod ( access , name , desc , signature , exceptions ) ) { @ Override public void visitLocalVariable ( final String name , final String desc , final String signature , final Label start , final Label end , final int index ) { } @ Override public void visitLineNumber ( final int line , final Label start ) { } @ Override public void visitMethodInsn ( final int opcode , String owner , String name , final String desc , final boolean isInterface ) { if ( ( opcode == INVOKEVIRTUAL ) || ( opcode == INVOKEINTERFACE ) ) { if ( owner . equals ( adviceReference ) ) { owner = wd . thisReference ; name = adviceMethodName ( name , aspectIndex ) ; } } else if ( opcode == INVOKESTATIC || opcode == INVOKESPECIAL ) { if ( owner . equals ( adviceReference ) ) { owner = wd . thisReference ; name = adviceMethodName ( name , aspectIndex ) ; } } super . visitMethodInsn ( opcode , owner , name , desc , isInterface ) ; } @ Override public void visitFieldInsn ( final int opcode , String owner , String name , final String desc ) { // replace field references if ( owner . equals ( adviceReference ) ) { owner = wd . thisReference ; name = adviceFieldName ( name , aspectIndex ) ; } super . visitFieldInsn ( opcode , owner , name , desc ) ; } } ; } // Parse EXECUTE method, just to gather some info, real parsing will come later //return new MethodAdapter(new EmptyMethodVisitor()) {		// toask may we replace this with the following code? return new EmptyMethodVisitor ( ) { @ Override public void visitVarInsn ( final int opcode , final int var ) { if ( isStoreOpcode ( opcode ) ) { if ( var > maxLocalVarOffset ) { maxLocalVarOffset = var ; // find max local var offset } } super . visitVarInsn ( opcode , var ) ; } } ; //					return super.visitMethod(access, name, desc, signature, exceptions); } } , 0 ) ; maxLocalVarOffset += 2 ; // increment offset by 2 because var on last index may be a dword value ready = true ; }
Parse advice class to gather some advice data. Should be called before any advice use.
Must be called only *once* per advice.
Parse advice class to gather some advice data . Should be called before any advice use . Must be called only * once * per advice .