8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.generic; 23 24 /** 25 * Equality of instructions isn't clearly to be defined. You might 26 * wish, for example, to compare whether instructions have the same 27 * meaning. E.g., whether two INVOKEVIRTUALs describe the same 28 * call.<br>The DEFAULT comparator however, considers two instructions 29 * to be equal if they have same opcode and point to the same indexes 30 * (if any) in the constant pool or the same local variable index. Branch 31 * instructions must have the same target. 32 * 33 * @see Instruction 34 * @version $Id$ 35 */ 36 public interface InstructionComparator { 37 38 InstructionComparator DEFAULT = new InstructionComparator() { 39 40 @Override 41 public boolean equals( final Instruction i1, final Instruction i2 ) { 42 if (i1.getOpcode() == i2.getOpcode()) { 43 if (i1 instanceof BranchInstruction) { 44 // BIs are never equal to make targeters work correctly (BCEL-195) 45 return false; 46 // } else if (i1 == i2) { TODO consider adding this shortcut 47 // return true; // this must be AFTER the BI test 48 } else if (i1 instanceof ConstantPushInstruction) { 49 return ((ConstantPushInstruction) i1).getValue().equals( 50 ((ConstantPushInstruction) i2).getValue()); 51 } else if (i1 instanceof IndexedInstruction) { 52 return ((IndexedInstruction) i1).getIndex() == ((IndexedInstruction) i2) 53 .getIndex(); 54 } else if (i1 instanceof NEWARRAY) { 55 return ((NEWARRAY) i1).getTypecode() == ((NEWARRAY) i2).getTypecode(); 56 } else { 57 return true; 58 } 59 } 60 return false; 61 } 62 }; 63 64 65 boolean equals( Instruction i1, Instruction i2 ); 66 } | 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.generic; 23 24 /** 25 * Equality of instructions isn't clearly to be defined. You might 26 * wish, for example, to compare whether instructions have the same 27 * meaning. E.g., whether two INVOKEVIRTUALs describe the same 28 * call. 29 * <p> 30 * The DEFAULT comparator however, considers two instructions 31 * to be equal if they have same opcode and point to the same indexes 32 * (if any) in the constant pool or the same local variable index. Branch 33 * instructions must have the same target. 34 * </p> 35 * 36 * @see Instruction 37 */ 38 public interface InstructionComparator { 39 40 InstructionComparator DEFAULT = (i1, i2) -> { 41 if (i1.getOpcode() == i2.getOpcode()) { 42 if (i1 instanceof BranchInstruction) { 43 // BIs are never equal to make targeters work correctly (BCEL-195) 44 return false; 45 // } else if (i1 == i2) { TODO consider adding this shortcut 46 // return true; // this must be AFTER the BI test 47 } else if (i1 instanceof ConstantPushInstruction) { 48 return ((ConstantPushInstruction) i1).getValue().equals( 49 ((ConstantPushInstruction) i2).getValue()); 50 } else if (i1 instanceof IndexedInstruction) { 51 return ((IndexedInstruction) i1).getIndex() == ((IndexedInstruction) i2) 52 .getIndex(); 53 } else if (i1 instanceof NEWARRAY) { 54 return ((NEWARRAY) i1).getTypecode() == ((NEWARRAY) i2).getTypecode(); 55 } else { 56 return true; 57 } 58 } 59 return false; 60 }; 61 62 63 boolean equals( Instruction i1, Instruction i2 ); 64 } |