1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 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 }