Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-dev] DOMs and ASTs (for metrics tool purpose)

Hi MichaƂ,

Nice work on figuring this out and stating your needs clearly--all of your
conclusions are correct.  While the ASM may be a convenient way of getting
some of your metrics, you'll need to tie into the AST visitor mechanism to
get finer-grained information.  You can do that in the exact same way that
the ASM does, by extending the AsmHierarchyBuilder which is a subclass of
the ASTVisitor that we get from the JDT.  For any additional information
that you need to collect you simply add the corresponding visit(..) method.
For example, to collect method calls you could do the following:

class ExtendedAsmHiearchyBuilder extends AsmHierarchyBuilder {
    public boolean visit(MessageSend messageSend, BlockScope scope) {
	  // do something interesting with calls...
    }
    public void endVisit(MessageSend messageSend, BlockScope scope) {
        stack.pop();
    } 
}

And register your custom builder by overriding the default one: 
AjBuildManager.setAsmHierarchyBuilder(new ExtendedAsmHierarchyBuilder());

I've put an example test into org.aspectj/docs/sandbox/api-clients which you
should check out as a project.  If you run
org.aspectj.samples.AsmHierarchyBuilderExtensionTest as a JUnit test you'll
notice that it outputs information about call sites.  

Happy hacking,

Mik

> -----Original Message-----
> From: aspectj-dev-bounces@xxxxxxxxxxx [mailto:aspectj-dev-
> bounces@xxxxxxxxxxx] On Behalf Of Michal Stochmialek
> Sent: Thursday, March 31, 2005 12:56 AM
> To: aspectj-dev@xxxxxxxxxxx
> Subject: [aspectj-dev] DOMs and ASTs (for metrics tool purpose)
> 
> Hello,
> 
> I'm on planning stage of development of metrics suite for aspectj
> programs. The suite will be consisted mainly of CK metrics.
> I've following requirements:
>  - suite should measure java and aj files
>  - suite should be aware of java5 new language constructs
>  - tool should be run from console (ant) without *running*
>    eclipse
> 
> 
> I would like to use AspectJ for this manner and I started
> look into AspectJ's source models and syntax trees.
> 
> JDT provides DOM for this kind of purposes, but after a while I
> find out, that AspectJ don't inherit it, and even modified JDT
> version will reject .aj files.
> 
> After digging a while in mail archives, I found out that AJDT
> provides ASM model for similar proposes. I found examples for it, and
> it looks quite nice, but... it can reach only to method/advice level.
> For computing method complexity or detecting aspect-object coupling
> this is not enough :|
> 
> At the end, I looked at AJDT ASTs, which inherit JDT ASTs. From
> developer docs (btw. a good one) I know that it provides statement
> level, so its granulity is that what I need.
> 
> Do you think AST will be good for my purposes?
> Where can I get some examples how to obtain AST for a file?
> 
> 
> best regards,
> --
> Michal Stochmialek <misto@xxxxxxxxxxxxxxxx>
> _______________________________________________
> aspectj-dev mailing list
> aspectj-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-dev



Back to the top