Created
April 5, 2013 13:21
-
-
Save melix/5319224 to your computer and use it in GitHub Desktop.
Prevents usage of synchronized methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.codehaus.groovy.control.CompilerConfiguration | |
import org.codehaus.groovy.syntax.SyntaxException | |
import org.codehaus.groovy.ast.ClassNode | |
import org.codehaus.groovy.control.SourceUnit | |
import org.codehaus.groovy.classgen.GeneratorContext | |
class SynchronizedRemover extends org.codehaus.groovy.control.customizers.CompilationCustomizer { | |
SynchronizedRemover() { | |
super(org.codehaus.groovy.control.CompilePhase.CONVERSION) | |
} | |
void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) { | |
classNode.methods.each { mn -> | |
if (mn.modifiers & 0x0020) { // 0x0020 is for synchronized | |
source.addError(new SyntaxException("Synchronized is not allowed", mn.lineNumber, mn.columnNumber)) | |
} | |
} | |
} | |
} | |
def config = new CompilerConfiguration() | |
config.addCompilationCustomizers(new SynchronizedRemover()) | |
def shell = new GroovyShell(config) | |
shell.evaluate ''' | |
class Foo { public synchronized void foo() { println 'bar' } } | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment