All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.taobao.arthas.bytekit.asm.location.LineLocationMatcher Maven / Gradle / Ivy

The newest version!
package com.taobao.arthas.bytekit.asm.location;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode;
import com.alibaba.arthas.deps.org.objectweb.asm.tree.LineNumberNode;

import com.taobao.arthas.bytekit.asm.MethodProcessor;
import com.taobao.arthas.bytekit.asm.location.Location.LineLocation;

public class LineLocationMatcher implements LocationMatcher {

    private List targetLines = Collections.emptyList();

    public LineLocationMatcher(int... targetLines) {
        if (targetLines != null) {
            ArrayList result = new ArrayList(targetLines.length);
            for (int targetLine : targetLines) {
                result.add(targetLine);
            }
            this.targetLines = result;
        }
    }

    public LineLocationMatcher(List targetLines) {
        this.targetLines = targetLines;
    }

    @Override
    public List match(MethodProcessor methodProcessor) {
        List locations = new ArrayList();
        AbstractInsnNode insnNode = methodProcessor.getEnterInsnNode();
        while (insnNode != null) {
            if (insnNode instanceof LineNumberNode) {
                LineNumberNode lineNumberNode = (LineNumberNode) insnNode;
                if (match(lineNumberNode.line)) {
                    locations.add(new LineLocation(lineNumberNode, lineNumberNode.line));
                }
            }
            insnNode = insnNode.getNext();
        }

        return locations;
    }

    private boolean match(int line) {
        for (int targetLine : targetLines) {
            if (targetLine == -1) {
                return true;
            } else if (line == targetLine) {
                return true;
            }

        }
        return false;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy