本文整理匯總了Java中org.objectweb.asm.tree.LineNumberNode類的典型用法代碼示例。如果您正苦於以下問題:Java LineNumberNode類的具體用法?Java LineNumberNode怎麽用?Java LineNumberNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LineNumberNode類屬於org.objectweb.asm.tree包,在下文中一共展示了LineNumberNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getImportantList
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
public static InsnList getImportantList(InsnList list) {
if (list.size() == 0) {
return list;
}
HashMap<LabelNode, LabelNode> labels = new HashMap<>();
for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) {
if (insn instanceof LabelNode) {
labels.put((LabelNode) insn, (LabelNode) insn);
}
}
InsnList importantNodeList = new InsnList();
for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) {
if (insn instanceof LabelNode || insn instanceof LineNumberNode) {
continue;
}
importantNodeList.add(insn.clone(labels));
}
return importantNodeList;
}
示例2: run
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
@Override
public void run() {
try {
ListIterator<AbstractInsnNode> iterator = mn.instructions.iterator();
AbstractInsnNode next;
//TODO: implement stream
while (iterator.hasNext()) {
next = iterator.next();
if (next instanceof LineNumberNode)
iterator.set (
new LineNumberNode (
rand.nextInt(),
((LineNumberNode) next).start
)
);
}
} catch(Throwable t) {
}
}
示例3: findLineNumber
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
/**
* Finds the line number closest to the given node
*
* @param node the instruction node to get a line number for
* @return the closest line number, or -1 if not known
*/
public static int findLineNumber(@NonNull AbstractInsnNode node) {
AbstractInsnNode curr = node;
// First search backwards
while (curr != null) {
if (curr.getType() == AbstractInsnNode.LINE) {
return ((LineNumberNode) curr).line;
}
curr = curr.getPrevious();
}
// Then search forwards
curr = node;
while (curr != null) {
if (curr.getType() == AbstractInsnNode.LINE) {
return ((LineNumberNode) curr).line;
}
curr = curr.getNext();
}
return -1;
}
示例4: getImportantList
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
public static InsnList getImportantList(InsnList list) {
if (list.size() == 0) {
return list;
}
HashMap<LabelNode, LabelNode> labels = new HashMap<LabelNode, LabelNode>();
for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) {
if (insn instanceof LabelNode) {
labels.put((LabelNode) insn, (LabelNode) insn);
}
}
InsnList importantNodeList = new InsnList();
for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) {
if (insn instanceof LabelNode || insn instanceof LineNumberNode) {
continue;
}
importantNodeList.add(insn.clone(labels));
}
return importantNodeList;
}
示例5: visitEnd
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void visitEnd() {
MethodNode methodNode = (MethodNode) mv;
Iterator<AbstractInsnNode> nodeIter = methodNode.instructions.iterator();
while (nodeIter.hasNext()) {
AbstractInsnNode insnNode = nodeIter.next();
if (insnNode.getType() == AbstractInsnNode.LINE) {
currentLine = ((LineNumberNode) insnNode).line;
methodNode.instructions.insertBefore(insnNode, getLineNumberInstrumentation());
continue;
}
if ((insnNode.getType() == AbstractInsnNode.VAR_INSN)
|| (insnNode.getType() == AbstractInsnNode.FIELD_INSN)
|| (insnNode.getType() == AbstractInsnNode.IINC_INSN)
|| (insnNode.getType() == AbstractInsnNode.INT_INSN)
|| (insnNode.getType() == AbstractInsnNode.INSN)) {
methodNode.instructions.insert(insnNode, getInstrumentation(insnNode));
}
}
methodNode.accept(next);
}
示例6: findLineNumberForInstruction
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
/**
* Find line number associated with an instruction.
* @param insnList instruction list for method
* @param insnNode instruction within method being searched against
* @throws NullPointerException if any argument is {@code null} or contains {@code null}
* @throws IllegalArgumentException if arguments aren't all from the same method
* @return line number node associated with the instruction, or {@code null} if no line number exists
*/
public static LineNumberNode findLineNumberForInstruction(InsnList insnList, AbstractInsnNode insnNode) {
Validate.notNull(insnList);
Validate.notNull(insnNode);
int idx = insnList.indexOf(insnNode);
Validate.isTrue(idx != -1);
// Get index of labels and insnNode within method
ListIterator<AbstractInsnNode> insnIt = insnList.iterator(idx);
while (insnIt.hasPrevious()) {
AbstractInsnNode node = insnIt.previous();
if (node instanceof LineNumberNode) {
return (LineNumberNode) node;
}
}
return null;
}
示例7: scanForElse
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
/**
* <p>
* This method scans the instructions for 'else' and returns the node
* </p>
*
* @param ifTargetIndex
* Index of the target instruction of 'if'
* @param endIndex
* Index of the end instruction upto which scanner will work
* @param nestingLevel
* nesting level
* @return Node
*/
private AbstractInsnNode scanForElse(int ifTargetIndex, int endIndex) {
boolean lineNumberFound = false;
LabelNode ln = (LabelNode) this.insnArr[ifTargetIndex];
for (int i = ifTargetIndex + 1; i <= endIndex; i++) {
AbstractInsnNode ain = this.insnArr[i];
if (ain instanceof JumpInsnNode
&& InstrumentUtil.getJumpInsnOpcodesMap().containsKey(
ain.getOpcode())) {
if (!lineNumberFound) {
return ain;
}
} else if (ain instanceof LineNumberNode) {
LineNumberNode lnn = (LineNumberNode) ain;
// if the line does not belong to the label
if (lnn.start != ln) {
lineNumberFound = true;
return null;
}
}
}
return null;
}
示例8: getImportantList
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
public static InsnList getImportantList(InsnList list)
{
if(list.size() == 0)
return list;
HashMap<LabelNode, LabelNode> labels = new HashMap<LabelNode, LabelNode>();
for(AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext())
{
if(insn instanceof LabelNode)
labels.put((LabelNode)insn, (LabelNode)insn);
}
InsnList importantNodeList = new InsnList();
for(AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext())
{
if(insn instanceof LabelNode || insn instanceof LineNumberNode)
continue;
importantNodeList.add(insn.clone(labels));
}
return importantNodeList;
}
示例9: write
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
@Override
public void write(DoStmtToken token) {
expr.writeDefineVariables(token.getLocal());
LabelNode start = expr.writeLabel(node, token.getMeta().getStartLine());
LabelNode end = new LabelNode();
method.pushJump(end, start);
expr.write(token.getBody());
method.popJump();
expr.writeConditional(token.getCondition(), end);
add(new JumpInsnNode(GOTO, start));
add(end);
add(new LineNumberNode(token.getMeta().getEndLine(), end));
expr.writeUndefineVariables(token.getLocal());
}
示例10: writeBody
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
private void writeBody(IfStmtToken token) {
LabelNode end = new LabelNode();
LabelNode elseL = new LabelNode();
expr.writePopBoolean();
add(new JumpInsnNode(IFEQ, token.getElseBody() != null ? elseL : end));
expr.stackPop();
if (token.getBody() != null) {
expr.write(token.getBody());
}
if (token.getElseBody() != null){
add(new JumpInsnNode(GOTO, end));
add(elseL);
expr.write(token.getElseBody());
}
add(end);
add(new LineNumberNode(token.getMeta().getEndLine(), end));
}
示例11: write
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
@Override
public void write(WhileStmtToken token) {
expr.writeDefineVariables(token.getLocal());
LabelNode start = expr.writeLabel(node, token.getMeta().getStartLine());
LabelNode end = new LabelNode();
expr.writeConditional(token.getCondition(), end);
method.pushJump(end, start);
expr.write(BodyStmtToken.class, token.getBody());
method.popJump();
add(new JumpInsnNode(GOTO, start));
add(end);
add(new LineNumberNode(token.getMeta().getEndLine(), end));
expr.writeUndefineVariables(token.getLocal());
}
示例12: areNodesEqual
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
public static boolean areNodesEqual(AbstractInsnNode node, AbstractInsnNode node2) {
if (node.getClass() == node2.getClass() && node.getOpcode() == node2.getOpcode()) {
if (node instanceof MethodInsnNode) {
return ((MethodInsnNode) node).name.equals(((MethodInsnNode) node2).name)
&& ((MethodInsnNode) node).desc.equals(((MethodInsnNode) node2).desc)
&& ((MethodInsnNode) node).owner.equals(((MethodInsnNode) node2).owner);
} else if (node instanceof VarInsnNode) {
return ((VarInsnNode) node).var == ((VarInsnNode) node2).var;
} else if (node instanceof InsnNode) {
return true;
} else if (node instanceof TypeInsnNode) {
return ((TypeInsnNode) node).desc.equals(((TypeInsnNode) node2).desc);
} else if (node instanceof JumpInsnNode) {
return ((JumpInsnNode) node).label == ((JumpInsnNode) node2).label;
} else if (node instanceof LabelNode) {
return node == node2;
} else if (node instanceof LineNumberNode) {
return ((LineNumberNode) node).line == ((LineNumberNode) node2).line;
} else if (node instanceof FieldInsnNode) {
return ((FieldInsnNode) node).name.equals(((FieldInsnNode) node2).name)
&& ((FieldInsnNode) node).desc.equals(((FieldInsnNode) node2).desc)
&& ((FieldInsnNode) node).owner.equals(((FieldInsnNode) node2).owner);
} else if (node instanceof LdcInsnNode) {
return ((LdcInsnNode) node).cst.equals(((LdcInsnNode) node2).cst);
}
}
return false;
}
示例13: getNext
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
@SuppressWarnings("all")
private static AbstractInsnNode getNext(Iterator<AbstractInsnNode> it) {
while (it.hasNext()) {
final AbstractInsnNode in = it.next();
if (!(in instanceof LineNumberNode)) {
return in;
}
}
return null;
}
示例14: findLineNumbers
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
private static List<Integer> findLineNumbers(InsnList insnList) {
List<Integer> lineNumbers = new ArrayList<>();
insnList.iterator().forEachRemaining(i -> {
if (i instanceof LineNumberNode) {
lineNumbers.add(((LineNumberNode) i).line);
}
});
return lineNumbers;
}
示例15: transform
import org.objectweb.asm.tree.LineNumberNode; //導入依賴的package包/類
@Override
public boolean transform() throws Throwable {
classNodes().forEach(classNode -> {
classNode.methods.forEach(methodNode -> {
Iterator<AbstractInsnNode> it = methodNode.instructions.iterator();
while (it.hasNext()) {
if (it.next() instanceof LineNumberNode) {
it.remove();
}
}
});
});
return true;
}