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

ok, thanks.
I opened this ticket:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=349861

how complex is this fix?

-----Original Message----- From: Andy Clement
Sent: Tuesday, June 21, 2011 12:53 AM
To: AspectJ developer discussions
Subject: Re: [aspectj-dev] Getting source code positions for advice

On 20 June 2011 13:23, Yoav A. <yoav_@xxxxxxxxxxx> wrote:
What packages should I compile? I notice that getModel returns
IStructureModel which is an interface with no methods (at least in AJ 165).

You should treat the IStructureModel object as an AsmManager instance,
IStructureModel is a completely unfinished abstraction (empty - as you
noticed!).

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?

Parse it twice, not necessarily compile it twice.  I don't know what
you are up to so don't know if this is a problem for you.

Then I will have to somehow match
the BcelAdvice I have with the AST.

If you went down this route, yes you will need to match them up.
Advice has a robust name based on advice type, occurrence in the
aspect and hashcode of the pointcut text.

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.

I don't know what you want to do with the positions but working with
bytecode line number tables can be hit and miss.  If you need the
position of the closing curly brace you will always be out of luck
(you can guess relatively to the last instruction in the method but it
won't always be right).  And for the line where the actual declaration
is, well we added the methoddeclarationlinenumber attribute to the
advice methods so we know the declaration line rather than the line
with the first instruction on.  We've never added the same thing for
the end line, we haven't needed it.

I'd say use the structuremodel if you can, but it will only come out
if you drive compilation, not for pure weaving.

Andy

-----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
_______________________________________________
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