<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"
>

<channel>
	<title>acidum.de &#187; Metaprogramming</title>
	<atom:link href="http://www.acidum.de/tag/metaprogramming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.acidum.de</link>
	<description></description>
	<lastBuildDate>Sun, 08 Nov 2009 20:12:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Groovy Meta Programmierung</title>
		<link>http://www.acidum.de/2008/10/07/groovy-meta-programmierung/</link>
		<comments>http://www.acidum.de/2008/10/07/groovy-meta-programmierung/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 07:42:06 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Metaprogramming]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=146</guid>
		<description><![CDATA[Im Rahmen des Seminars Meta-Programmierung haben Lars Blumberg, Arvid Heise und ich eine Ausarbeitung erstellt, welche die Metaprogrammierung von Groovy untersucht.
Abstract:
Der Name der Programmiersprache ist Programm. Dass Groovy als noch junge Sprache viele neue und interessante Sprachkonzepte mitbringt, möchten wir im ersten Teil dieses Papers aufzeigen. Ein weiteres Highlight des ersten Kapitels ist vielleicht die [...]]]></description>
			<content:encoded><![CDATA[<p>Im Rahmen des Seminars Meta-Programmierung haben <a title="Lars Blumberg Homepage" href="http://www.lars-blumberg.de/" target="_blank">Lars Blumberg</a>, Arvid Heise und ich eine Ausarbeitung erstellt, welche die Metaprogrammierung von Groovy untersucht.</p>
<p><strong>Abstract:</strong></p>
<p>Der Name der Programmiersprache ist Programm. Dass Groovy als noch junge Sprache viele neue und interessante Sprachkonzepte mitbringt, möchten wir im ersten Teil dieses Papers aufzeigen. Ein weiteres Highlight des ersten Kapitels ist vielleicht die Erkenntnis über die gelungene, nahtlos Integration mit der Java-Plattform. Im folgenden Hauptteil wird insbesondere die Möglichkeit der Meta-Programmierung mit Groovy beschrieben. Es wird auf die Umsetzung des Meta-Object-Protocols eingegangen und erläutert, wie die zugehörigen Konzepte mit Hilfe der Java Virtual Machine umgesetzt werden konnten. Im dritten und letzten Teil wird dem Leser eine implementierte Beispiel-Anwendung vorgestellt. Sie ist wie dieses Paper im Rahmen der Veranstaltung &#8220;Metaprogrammierung und Reflection&#8221; entstanden und demonstriert eindrucksvoll die Meta-Programmierung in Groovy.</p>
<p><strong>Keywords:</strong></p>
<p>Groovy, Metaprogramming</p>
<p><strong><strong><a title="Microsoft Visual Programming Language: End-User Perspektive" href="http://www.acidum.de/wp-content/uploads/2008/08/microsoft-visual-programming-language-paper.pdf" target="_blank"><strong><strong></strong></strong></a></strong></strong></p>
<p><strong><strong><a href="http://www.acidum.de/wp-content/uploads/2008/10/groovy-meta-programming-paper.pdf"><img title="Pfd" src="http://www.acidum.de/wp-content/themes/acidum/images/pdf.gif" alt="Pfd" width="29" height="29" />Groovy Meta Programming Paper</a></strong></strong></p>
<p><strong><strong><a href="http://www.acidum.de/wp-content/uploads/2008/10/groovy-meta-programming-slides.pdf"><img title="Pfd" src="http://www.acidum.de/wp-content/themes/acidum/images/pdf.gif" alt="Pfd" width="29" height="29" />Groovy Meta Programming Slides</a></strong></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2008/10/07/groovy-meta-programmierung/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy Programming Examples</title>
		<link>http://www.acidum.de/2008/09/11/groovy-programming-examples/</link>
		<comments>http://www.acidum.de/2008/09/11/groovy-programming-examples/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 13:16:03 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Code Examples]]></category>
		<category><![CDATA[Metaprogramming]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=154</guid>
		<description><![CDATA[Java Iteration Example

import java.util.Date;
&#160;
public class Foo &#123;
    public static void main&#40;String&#91;&#93; args&#41; &#123;
        int start = 1;
        int summe = 0;
&#160;
        for &#40;int i = start; i &#60;= 5; i++&#41; &#123;
 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Java Iteration Example</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Foo <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> start <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> summe <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> start<span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            summe <span style="color: #339933;">+=</span> i<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003399;">Date</span> now <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>now.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; Die Summe ist: &quot;</span> <span style="color: #339933;">+</span> summe<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Groovy Iteration Example within Groovy Shell</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
        start <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span>
        summe <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i in start..5<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            summe <span style="color: #339933;">+=</span> i
        <span style="color: #009900;">&#125;</span>
&nbsp;
        now <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        println <span style="color: #0000ff;">&quot;$now Die Summe ist: $summe&quot;</span></pre></div></div>

<p><strong>Groovy Map Handling with Closures</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">map <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1</span>, <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// inline closure</span>
map.<span style="color: #006633;">each</span> <span style="color: #009900;">&#123;</span> key, value <span style="color: #339933;">-&gt;</span>
    map<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> value<span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span>
<span style="color: #009900;">&#125;</span>
println map
&nbsp;
<span style="color: #666666; font-style: italic;">// extern closure</span>
doubler <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> key, value <span style="color: #339933;">-&gt;</span>
    map<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> value<span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span>
<span style="color: #009900;">&#125;</span>
map.<span style="color: #006633;">each</span><span style="color: #009900;">&#40;</span>doubler<span style="color: #009900;">&#41;</span>
println map</pre></div></div>

<p><strong>Groovy Beans</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> <span style="color: #003399;">Book</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">String</span> title
&nbsp;
    <span style="color: #003399;">Book</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> theTitle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        title <span style="color: #339933;">=</span> theTitle
    <span style="color: #009900;">&#125;</span>
    <span style="color: #003399;">Book</span> plus<span style="color: #009900;">&#40;</span><span style="color: #003399;">Book</span> anotherBook<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Book</span><span style="color: #009900;">&#40;</span>title <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;, &quot;</span> <span style="color: #339933;">+</span> anotherBook.<span style="color: #006633;">title</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003399;">Book</span> gina <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Book</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Groovy in Action&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #666666; font-style: italic;">// getters are generated automatically </span>
println gina.<span style="color: #006633;">getTitle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
println <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>gina <span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Book</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Groovy for Experts&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">title</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><strong>Groovy Duck Typing</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Dog <span style="color: #009900;">&#123;</span>
    def speak<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> println <span style="color: #0000ff;">&quot;wuff&quot;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">class</span> Cat <span style="color: #009900;">&#123;</span>
    def speak<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> println <span style="color: #0000ff;">&quot;miau&quot;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
def saySomething<span style="color: #009900;">&#40;</span>somewhat<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    somewhat.<span style="color: #006633;">speak</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
saySomething<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Dog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
saySomething<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Cat<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><strong>Simple XML Example:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> XmlBuilder <span style="color: #009900;">&#123;</span>
   def out
   XmlBuilder<span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">out</span> <span style="color: #339933;">=</span> out <span style="color: #009900;">&#125;</span>
   def invokeMethod<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name, args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       out <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000ff;">&quot;&lt;$name&gt;&quot;</span>
       <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">instanceof</span> Closure<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">delegate</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>
            args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">call</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#125;</span>
       <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
           out <span style="color: #339933;">&lt;&lt;</span> args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#125;</span>
       out <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000ff;">&quot;&lt;/$name&gt;&quot;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
def xml <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlBuilder<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
xml.<span style="color: #006633;">html</span> <span style="color: #009900;">&#123;</span>
    head <span style="color: #009900;">&#123;</span>
        title <span style="color: #0000ff;">&quot;Hello World&quot;</span>
    <span style="color: #009900;">&#125;</span>
    body <span style="color: #009900;">&#123;</span>
        p <span style="color: #0000ff;">&quot;Welcome!&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
println xml.<span style="color: #006633;">out</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2008/09/11/groovy-programming-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.848 seconds -->
