Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Objectteams » CFLOW like behaviour?
CFLOW like behaviour? [message #629570] Tue, 28 September 2010 18:11 Go to next message
Jan Marc Hoffmann is currently offline Jan Marc HoffmannFriend
Messages: 32
Registered: July 2009
Member
Hey guys,

how would I archieve AspectJ CFLOW like behaviour? My guess would be adding both roles into a team and work with a team field. Is there a more elegant way of doing this?

greetings

Jan Marc
Re: CFLOW like behaviour? [message #629576 is a reply to message #629570] Tue, 28 September 2010 18:34 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Hi,

That's funny, just today I implemented a team that does
exactly, what in AspectJ you would use a cflow for.

Assuming the two triggers are in different classes it is as easy as:

team class Outer {
    protected team class Interceptor1 playedBy Base1 {
        trigger1 <- replace baseMethod1;
        callin void trigger1() {
            within (this)
                base.trigger1();
        }
        protected class Interceptor2 playedBy Base2 {
            targetMethod <- before baseMethod2;
        }
    }
}
...
new Outer().activate();


The key here is that the nested team Interceptor1 is not active
by default but only while trigger1() is being executed.
I think everything is nicely kept local in one spot.

Would this work for your use cases?

best
Stephan

PS: I should definitely put this into the wiki.
Thanks for bringing this up.
Re: CFLOW like behaviour? [message #629723 is a reply to message #629570] Wed, 29 September 2010 11:28 Go to previous messageGo to next message
Jan Marc Hoffmann is currently offline Jan Marc HoffmannFriend
Messages: 32
Registered: July 2009
Member
Thanks, this helps. :=)

greetings

Jan Marc
Re: CFLOW like behaviour? [message #643663 is a reply to message #629570] Tue, 07 December 2010 18:58 Go to previous messageGo to next message
Jan Marc Hoffmann is currently offline Jan Marc HoffmannFriend
Messages: 32
Registered: July 2009
Member
This works nice for 1 trigger. But what about 2 or more trigger? No problem if they are from the same class... But what if they aren't? :=)
Re: CFLOW like behaviour? [message #643675 is a reply to message #643663] Tue, 07 December 2010 19:36 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Jan Marc Hoffmann wrote on Tue, 07 December 2010 19:58
This works nice for 1 trigger. But what about 2 or more trigger? No problem if they are from the same class... But what if they aren't? :=)


Well, it looks like you have to split the Interceptor1.
However, in order to make all those share a common
infrastructure, why not use inheritance:
team class Outer {
    protected team class AbstractInterceptor1 {
        callin void trigger1() {
            within (this)
                base.trigger1();
        }
        protected class Interceptor2 playedBy Base2 {
            targetMethod <- before baseMethod2;
        }
    }
    protected team class Interceptor1_1 extends AbstractInterceptor1 playedBy Base1_1 {
        trigger1 <- replace baseMethod1;
    }
    protected team class Interceptor1_2 extends AbstractInterceptor2 playedBy Base1_2 {
        trigger1 <- replace baseMethod1;
    }
}


any problems? Smile
Stephan
Re: CFLOW like behaviour? [message #643681 is a reply to message #629570] Tue, 07 December 2010 20:06 Go to previous messageGo to next message
Jan Marc Hoffmann is currently offline Jan Marc HoffmannFriend
Messages: 32
Registered: July 2009
Member
I really like it. The only problem are Exceptions ...

@SuppressWarnings("restriction")
public team class GOTScannerAdaptor {

	protected abstract team class Interceptor {

		protected class GOTScanner playedBy Scanner {

		}
		
		@SuppressWarnings("basecall")
		callin void trigger1() {
			within(this) {
				try {
					base.trigger1();
				} catch (Exception e) {
					// hmm not nice ... 
					e.printStackTrace();
				}
			}
		}
	}
	
	protected team class ScannerInterceptor1 extends Interceptor playedBy DeltaProcessor {
		@SuppressWarnings("decapsulation")
		trigger1 <- replace elementType;
	}
	
	protected team class ScannerInterceptor2 extends Interceptor playedBy CompilationUnit {
		void trigger1() <- replace org.eclipse.jdt.core.dom.CompilationUnit reconcile(int astLevel, int reconcileFlags, WorkingCopyOwner workingCopyOwner, IProgressMonitor monitor);
	}
}
Re: CFLOW like behaviour? [message #643688 is a reply to message #643681] Tue, 07 December 2010 20:40 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Jan Marc Hoffmann wrote on Tue, 07 December 2010 21:06
I really like it. The only problem are Exceptions ...



Why do you want to catch those exceptions?
"within" already takes care that activation is reverted
to the previous state regardless of exceptions.

do I miss anything?
Stephan
Re: CFLOW like behaviour? [message #643691 is a reply to message #629570] Tue, 07 December 2010 21:06 Go to previous message
Jan Marc Hoffmann is currently offline Jan Marc HoffmannFriend
Messages: 32
Registered: July 2009
Member
Without the try catch block I get the following error:

Unhandled exception type JavaModelException
at base.trigger1();

And what about the fragileCallin Binding warning at

trigger1 <- replace elementType;

and

void trigger1() <- replace org.eclipse.jdt.core.dom.CompilationUnit reconcile(int astLevel, int reconcileFlags, WorkingCopyOwner workingCopyOwner, IProgressMonitor monitor);

Hmm ;/....
Previous Topic:When it gets bigger... Teamactivation or base when or nothing?
Next Topic:Modifying Type Declaration
Goto Forum:
  


Current Time: Thu Mar 28 23:48:01 GMT 2024

Powered by FUDForum. Page generated in 0.03198 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top