/******************************************************************************* * Copyright (c) 2009 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ aspect UnfoldSynchronized { /* if the method is declared synchronized, strip away the synchronized qualifier and surround the * body of the method with a synchronized block * * for a static method, we need to synchronize on A.class, where A is the host type of the method; * for an instance method, we need to synchronize on this */ public void MethodDecl.unfoldSynchronized() { if(!this.isSynchronized() || !this.hasBlock()) return; getModifiers().removeModifier("synchronized"); if(this.isStatic()) { Stmt stmt = new SynchronizedStmt(new AbstractDot(hostType().createLockedAccess(), new ClassAccess()), getBlock()); setBlock(new Block(new List().add(stmt))); } else { Stmt stmt = new SynchronizedStmt(new ThisAccess("this"), getBlock()); setBlock(new Block(new List().add(stmt))); } } }