The report of JavaOne2011 about groovy

6,046 views
6,282 views

Published on

Published in: Technology, Education
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,046
On SlideShare
0
From Embeds
0
Number of Embeds
3,578
Actions
Shares
0
Downloads
12
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

The report of JavaOne2011 about groovy

  1. 1. 1 201http://www.flickr.com/photos/compujeramey
  2. 2. $ time groovy -e println "Hello, world!";Hello, world!real 0m1.177suser 0m1.321ssys 0m0.171s$ time groovyclient -e println "Hello,world!";Hello, world!real 0m0.029suser 0m0.001ssys 0m0.002s
  3. 3. http://jira.codehaus.org/browse/GROOVY-5101
  4. 4. https://github.com/downloads/kobo/groovyserv/ groovyserv-0.10-SNAPSHOT-21eda1f.jar
  5. 5. http://gihyo.jp/book/2011/978-4-7741-4727-7
  6. 6. http://www.flickr.com/photos/yto/
  7. 7. // this pipe generated by kiyotakadef url = http://pipes.yahoo.com/pipes/pipe.run?_id=081f8f5039194af0f25909129d6d007d&_render=rssdef items = new XmlParser().parse(url).channel.itemdef cols = pubDate title description.tokenize()groovy.swing.SwingBuilder.build { frame(id:f, title: Japanese Groovy Blogs, visible:true) { scrollPane { table { tableModel(list: items) { cols.each { col -> closureColumn header: col, read: { it[col].text() } } } } } } f.pack()}
  8. 8. http://www.flickr.com/photos/luilainez
  9. 9. http://www.flickr.com/photos/taniasaiz !! New
  10. 10. invite “You” to javaone
  11. 11. invite(“You”).to(javaone)
  12. 12. def invite(subject) { [ to : { target -> target.add(subject) } ]}def javaone = []invite(“You”).to(javaone)assert javaone == ["Nakano”, "<Your Name>"]
  13. 13. def invite(subject) { [ to : { target -> target.add(subject) } ]}def javaone = []invite(“You”).to(javaone)assert javaone == ["Nakano”, "<Your Name>"]
  14. 14. def invite(subject) { [ to : { target -> target.add(subject) } ]}def javaone = []invite(“You”).to(javaone)assert javaone == ["Nakano”, "<Your Name>"]
  15. 15. def invite(subject) { [ to : { target -> target.add(subject) } ]}def javaone = []invite(“You”).to(javaone)assert javaone == ["Nakano”, "<Your Name>"]
  16. 16. def invite(subject) { [ to : { target -> target.add(subject) } ]}def javaone = []invite(“You”).to(javaone)assert javaone == ["Nakano”, "<Your Name>"] javaone.add(“You”)
  17. 17. invite “You” to javaone
  18. 18. http://www.flickr.com/photos/larsjuh
  19. 19. http://www.flickr.com/photos/eiriknewth
  20. 20. !! Newhttp://www.flickr.com/photos/striatic
  21. 21. @groovy.util.logging.Logclass Foo { def method() { log.info(info message) log.fine(fine message) log.severe(severe message) }}new Foo().method()$ groovy astLog.groovyNov 9, 2011 1:09:10 PM java_util_logging_Logger$info callINFO: info messageNov 9, 2011 1:09:10 PM java_util_logging_Logger$severe callSEVERE: severe message
  22. 22. @Immutableclass Foo { int x Date date = new Date(1000)}def a = new Foo(x:1)assert a.x == 1assert a.date.getTime() == 1000a.date.setTime(2000)assert a.date.getTime() == 1000a.x = 3
  23. 23. @Singletonclass Foo { def hello() { "hello" }}assert Foo.instance.hello() == "hello"// => Caught: java.lang.RuntimeException:// Cant instantiate singleton Foo. Use Foo.instancenew Foo()
  24. 24. class StringList { @Delegate List<String> list = new ArrayList<String>()}def stringList = new StringList()stringList.add("A")stringList.add("B")assert stringList == ["A", "B"]stringList.each { print it }// => AB
  25. 25. @HelloWorldx$ groovy sample.groovyHello, World!
  26. 26. @GroovyASTTransformationClass("org.jggug.kobo.gastah.HelloWorldASTTransformation")@Retention(RetentionPolicy.RUNTIME)public @interface HelloWorld { String value()}@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)class HelloWorldASTTransformation extends ClassCodeVisitorSupport implements ASTTransformation { SourceUnit sourceUnit // forced to override by super class public void visit(ASTNode[] nodes, SourceUnit source) { AnnotatedNode target = (AnnotatedNode) nodes[1] AnnotationNode includeAnnotation = (AnnotationNode) nodes[0] def additionNode = new AstBuilder().buildFromCode({ println "Hello, World!" })[0] def statements = additionNode.statements // source.getAST().getStatementBlock().getStatements().clear() source.getAST().getStatementBlock().getStatements().addAll(0, statements) }} https://github.com/nobeans/jggug-20110617
  27. 27. ld ! Ohttp://www.flickr.com/photos/solarbotics
  28. 28. ld !O

×