Here you can find the source of getSourceLine(InstructionHandle ih)
public static int getSourceLine(InstructionHandle ih)
//package com.java2s; /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). * All rights reserved. /* w w w .j a v a 2 s .c om*/ * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v1.0 * which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * PARC initial implementation * ******************************************************************/ import java.util.Iterator; import org.aspectj.apache.bcel.generic.InstructionHandle; import org.aspectj.apache.bcel.generic.InstructionTargeter; import org.aspectj.apache.bcel.generic.LineNumberTag; public class Main { /** returns -1 if no source line attribute */ // this naive version overruns the JVM stack size, if only Java understood // tail recursion... // public static int getSourceLine(InstructionHandle ih) { // if (ih == null) return -1; // // InstructionTargeter[] ts = ih.getTargeters(); // if (ts != null) { // for (int j = ts.length - 1; j >= 0; j--) { // InstructionTargeter t = ts[j]; // if (t instanceof LineNumberTag) { // return ((LineNumberTag)t).getLineNumber(); // } // } // } // return getSourceLine(ih.getNext()); // } public static int getSourceLine(InstructionHandle ih) {// ,boolean // goforwards) { int lookahead = 0; // arbitrary rule that we will never lookahead more than 100 // instructions for a line # while (lookahead++ < 100) { if (ih == null) { return -1; } Iterator<InstructionTargeter> tIter = ih.getTargeters().iterator(); while (tIter.hasNext()) { InstructionTargeter t = tIter.next(); if (t instanceof LineNumberTag) { return ((LineNumberTag) t).getLineNumber(); } } // if (goforwards) ih=ih.getNext(); else ih = ih.getPrev(); } // System.err.println("no line information available for: " + ih); return -1; } }