fix: should not ignore on first element of pattern

This commit is contained in:
zaaarf 2023-04-14 01:22:48 +02:00
parent 05c9f6c3a2
commit 8cc440017f
No known key found for this signature in database
GPG key ID: 82240E075E31FA4C
2 changed files with 7 additions and 5 deletions

View file

@ -58,7 +58,7 @@ public class InsnSequence extends InsnList {
index = Math.abs(index); index = Math.abs(index);
if(index > size()) if(index > size())
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
return this.toArray()[size() - index]; return super.get(size() - index);
} }
/** /**
@ -72,7 +72,7 @@ public class InsnSequence extends InsnList {
/** /**
* Wraps InsnList's add() to throw an exception * Wraps InsnList's add() to throw an exception
* when fed null values. * when given null values.
* @param node to add * @param node to add
*/ */
@Override @Override

View file

@ -84,9 +84,11 @@ public class PatternMatcher {
first = cur; first = cur;
last = cur; last = cur;
for(int match = 0; last != null && match < predicates.size(); last = reverse ? last.getPrevious() : last.getNext()) { for(int match = 0; last != null && match < predicates.size(); last = reverse ? last.getPrevious() : last.getNext()) {
if(ignoreLabels && cur.getType() == AbstractInsnNode.LABEL) continue; if(match != 0) {
if(ignoreFrames && cur.getType() == AbstractInsnNode.FRAME) continue; if(ignoreLabels && last.getType() == AbstractInsnNode.LABEL) continue;
if(ignoreLineNumbers && cur.getType() == AbstractInsnNode.LINE) continue; if(ignoreFrames && last.getType() == AbstractInsnNode.FRAME) continue;
if(ignoreLineNumbers && last.getType() == AbstractInsnNode.LINE) continue;
}
if(!predicates.get(match).test(last)) break; if(!predicates.get(match).test(last)) break;
if(match == predicates.size() - 1) { if(match == predicates.size() - 1) {
if(reverse) return new InsnSequence(last, first); //we are matching backwards if(reverse) return new InsnSequence(last, first); //we are matching backwards