Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Getting source code positions for advice

What packages should I compile? I notice that getModel returns IStructureModel which is an interface with no methods (at least in AJ 165). I am trying to modify weaver back end code to collect this info during weave time (BcelWeaver.weave).

I will try to look into the running the parser. However, won't this mean that I compile every source file twice? Then I will have to somehow match the BcelAdvice I have with the AST.

I did consider using the LineNumberTable, it is already available at this stage using this code:

BcelMethod method = (BcelMethod) adv.getSignature();
LineNumberTable lnTable = method.getMethod().getLineNumberTable();

Then I try to fetch the last line using:

int length = lnTable.getLineNumberTable().length;
int elnr = lnTable.getLineNumberTable()[length-1].getLineNumber()+1;

However this does not work for advice that does not call return explicitly. The compiler adds a return instruction at the end of the method and adds it to the line number table at the last line. Now elnr is one line after the actual end of the advice.



-----Original Message----- From: Andy Clement
Sent: Monday, June 20, 2011 10:01 PM
To: AspectJ developer discussions
Subject: Re: [aspectj-dev] Getting source code positions for advice

If doing a full compile you can specify the option -emacssym and it
will be created inside the World object and accessible through
world.getModel().  If binary weaving (loadtime weaving), probably not,
as the compiler creates a lot of the up front pieces of the structure
- I'm not sure how you are operating the weaver in order to access the
internals.

You could look at the AJDT wiki article that talks about using the
parser standalone:

http://wiki.eclipse.org/Developer%27s_guide_to_building_tools_on_top_of_AJDT_and_AspectJ

(obviously an ast for the file would give you accurate positions).

Or you could access the bytecode and look at the line number table for
the advice method, the last entry will give you an indication of where
the last bit of code is in the advice.

cheers
Andy

On 20 June 2011 11:42, Yoav A. <yoav_@xxxxxxxxxxx> wrote:
is there some way to access this structure model from the weaver code?


-----Original Message----- From: Andy Clement
Sent: Monday, June 20, 2011 9:41 PM
To: AspectJ developer discussions
Subject: Re: [aspectj-dev] Getting source code positions for advice

Hi,

I doubt you are doing anything wrong.  We just never use the endline
(from BcelAdvice) for anything (as I recall) and so don't really
guarantee it is correct.  The structure model produced alongside the
compile is more likely to have correct information in it, as that is
used by AJDT.  Feel free to raise a bugzilla to sort out the
BcelAdvice end line if you like.

cheers
Andy

On 20 June 2011 11:25, Yoav A. <yoav_@xxxxxxxxxxx> wrote:

I'm trying to extract source file information during the weaving process.
I
wrote the following code to fetch the beginning and end of an advice:

public String getAdviceFormatString(BcelAdvice adv)
{
  ISourceLocation pos = adv.getSourceLocation(); int startLine =
pos.getLine();
  int endLine = pos.getEndLine(); // do the rest
}


I always get that startLine == endLine which correspond to the first line
of
the advice declaration. What am I doing wrong here?



_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


Back to the top