Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] AspectJ and RCP

I'm not quite an expert on that configuration but my initial reaction
is that maybe you want to use 'execution()' rather than the 'call()'
pointcut.

So:

 pointcut handlers() : execution(void *.execute(..));

The difference, and which you should us, kind of comes down to working
out which code the compiler can see when building your project.  If it
is being allowed to weave the code containing the method of interest,
use execution.  If the compiler can only see the code calling the
method of interest, use call.
With execution() the actual method itself is instrumented by AspectJ.
With call() the (possibly many) call sites are instrumented.  Hence
execution() is more efficient really.

If the callers of the method are only on the classpath, that doesn't
mean they are going to be woven.  Only source code in your project and
binaries on the inpath are candidates for weaving.

Andy


On 5 August 2012 10:35, Sopot Çela <sopotcela@xxxxxxxxx> wrote:
> Hi,
>
> I installed AJDT version 2.2.0e42x-RELEASE-20120703-2200.
> I created a sample plug-in project, converted it to AspectJ and created this
> aspect:
>
> public aspect MainAspect {
> pointcut handlers() : call (void *.execute(..));
> before() : handlers() {
> System.err.println("Hello aspectJ");
> }
>
> }
>
> Then I created a sample e4 app (which is a rcp app with default osgi bundles
> etc) which has the OpenHandler class with the execute method and exported
> the package. I added the e4 app plugin in the dependencies of the aspectj
> plugin project. I updated the run configurations and launched. THe app works
> fine, the execute method is called but the Hello AspectJ is nowhere to be
> found in the console.
>
> The manifest of the AspectJ project looks like this:
> Manifest-Version: 1.0
> Bundle-ManifestVersion: 2
> Bundle-Name: Aspectj
> Bundle-SymbolicName: e4.aspectj
> Bundle-Version: 1.0.0.qualifier
> Bundle-Activator: e4.aspectj.Activator
> Bundle-ActivationPolicy: lazy
> Bundle-RequiredExecutionEnvironment: JavaSE-1.7
> Import-Package: e4.test.aspects.handlers,
>  org.osgi.framework;version="1.3.0"
> Require-Bundle: org.aspectj.runtime;bundle-version="1.7.0",
>  org.aspectj.weaver;bundle-version="1.7.0",
>  org.eclipse.equinox.weaving.aspectj;bundle-version="1.0.100"
> Export-Package: e4.aspectj
>
> And the e4 project's manifest looks like this:
> Manifest-Version: 1.0
> Bundle-ManifestVersion: 2
> Bundle-Name: Aspects
> Bundle-SymbolicName: e4.test.aspects; singleton:=true
> Bundle-Version: 1.0.0.qualifier
> Bundle-Activator: e4.test.aspects.Activator
> Require-Bundle: javax.inject;bundle-version="1.0.0",
>  org.eclipse.core.runtime;bundle-version="3.8.0",
>  org.eclipse.swt;bundle-version="3.100.0",
>  org.eclipse.core.databinding;bundle-version="1.4.1",
>  org.eclipse.core.databinding.beans;bundle-version="1.2.200",
>  org.eclipse.jface;bundle-version="3.8.0",
>  org.eclipse.jface.databinding;bundle-version="1.6.0",
>  org.eclipse.e4.ui.services;bundle-version="0.10.1",
>  org.eclipse.e4.ui.workbench;bundle-version="0.10.2",
>  org.eclipse.e4.core.services;bundle-version="1.0.0",
>  org.eclipse.e4.core.di;bundle-version="1.1.0",
>  org.eclipse.e4.core.contexts;bundle-version="1.1.0",
>  org.eclipse.e4.ui.workbench.swt;bundle-version="0.10.1",
>  org.eclipse.core.databinding.property;bundle-version="1.4.100",
>  org.eclipse.e4.ui.css.core;bundle-version="0.10.1",
>  org.w3c.css.sac;bundle-version="1.3.1",
>  org.eclipse.e4.core.commands;bundle-version="0.10.1",
>  org.eclipse.e4.ui.bindings;bundle-version="0.10.1"
> Bundle-RequiredExecutionEnvironment: JavaSE-1.7
> Import-Package: org.osgi.framework;version="1.3.0"
> Bundle-ActivationPolicy: lazy
> Export-Package: e4.test.aspects.handlers
>
> OpenHandler class:
>
> package e4.test.aspects.handlers;
> import java.lang.reflect.InvocationTargetException;
> import javax.inject.Named;
> import org.eclipse.e4.core.contexts.IEclipseContext;
> import org.eclipse.e4.core.di.annotations.Execute;
> import org.eclipse.e4.ui.services.IServiceConstants;
> import org.eclipse.swt.widgets.FileDialog;
> import org.eclipse.swt.widgets.Shell;
>
> public class OpenHandler {
>
> @Execute
> public void execute(
> IEclipseContext context,
> @Named(IServiceConstants.ACTIVE_SHELL) Shell shell)
> throws InvocationTargetException, InterruptedException {
> FileDialog dialog = new FileDialog(shell);
> dialog.open();
> }
> }
>
>
> Worth noting that there is a warning "advice defined in e4.aspectj.MyAspect
> has not been applied [Xlint:adviceDidNotMatch]"
>
> What am I doing wrong? Consider I have just 2 hours experience in AspectJ.
>
> Thanks.
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top