Here you can find the source of copyInstruction(Instruction i)
public static Instruction copyInstruction(Instruction i)
//package com.java2s; /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). * All rights reserved. /*ww w . j ava 2 s.co m*/ * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v1.0 * which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * PARC initial implementation * ******************************************************************/ import org.aspectj.apache.bcel.generic.Instruction; import org.aspectj.apache.bcel.generic.InstructionHandle; import org.aspectj.apache.bcel.generic.InstructionSelect; import org.aspectj.apache.bcel.generic.SwitchBuilder; public class Main { /** * Fix for Bugzilla #39479, #40109 patch contributed by Andy Clement * * Need to manually copy Select instructions - if we rely on the the 'fresh' object created by copy(), the InstructionHandle * array 'targets' inside the Select object will not have been deep copied, so modifying targets in fresh will modify the * original Select - not what we want ! (It is a bug in BCEL to do with cloning Select objects). * * <pre> * declare error: * call(* Instruction.copy()) && within(org.aspectj.weaver) * && !withincode(* Utility.copyInstruction(Instruction)): * "use Utility.copyInstruction to work-around bug in Select.copy()"; * </pre> */ public static Instruction copyInstruction(Instruction i) { if (i instanceof InstructionSelect) { InstructionSelect freshSelect = (InstructionSelect) i; // Create a new targets array that looks just like the existing one InstructionHandle[] targets = new InstructionHandle[freshSelect.getTargets().length]; for (int ii = 0; ii < targets.length; ii++) { targets[ii] = freshSelect.getTargets()[ii]; } // Create a new select statement with the new targets array return new SwitchBuilder(freshSelect.getMatchs(), targets, freshSelect.getTarget()).getInstruction(); } else { return i.copy(); // Use clone for shallow copy... } } }