<html>
<head>
<style><!--
  body {background-color:#ffffff;}
  .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
  .pathname {font-family:monospace; float:right;}
  .fileheader {margin-bottom:.5em;}
  .diff {margin:0;}
  .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
  .tasklist ul {margin-top:0;margin-bottom:0;}
  tr.alt {background-color:#eeeeee}
  #added {background-color:#ddffdd;}
  #addedchars {background-color:#99ff99;font-weight:bolder;}
  tr.alt #added {background-color:#ccf7cc;}
  #removed {background-color:#ffdddd;}
  #removedchars {background-color:#ff9999;font-weight:bolder;}
  tr.alt #removed {background-color:#f7cccc;}
  #copied {background-color:#ccccff;}
  tr.alt #copied {background-color:#bbbbf7;}
  #info {color:#888888;}
  #context {background-color:#eeeeee;}
  td {padding-left:.3em;padding-right:.3em;}
  tr.head {border-bottom-width:1px;border-bottom-style:solid;}
  tr.head td {padding:0;padding-top:.2em;}
  .task {background-color:#ffff00;}
  .comment {white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;padding:4px;border:1px dashed #000000;background-color:#ffffdd}
  .error {color:red;}
  hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="5">Commit in <b><tt>metaas/trunk/src/main/java/uk/co/badgersinfoil/metaas/impl</tt></b></td></tr>
<tr><td><tt><a href="#file1">ModifierUtils.java</a></tt> </td><td></td><td align="right" id="added">+59</td><td align="right" id="removed">-68</td><td nowrap="nowrap" align="center">677 -&gt; 678</td></tr>
</table>
<pre class="comment">
data is better than code, as Grandma used to say
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname">metaas/trunk/src/main/java/uk/co/badgersinfoil/metaas/impl</span><br />
<div class="fileheader"><big><b>ModifierUtils.java</b></big> <small id="info">677 -&gt; 678</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/metaas/impl/ModifierUtils.java        2008-02-10 22:33:30 UTC (rev 677)
+++ trunk/src/main/java/uk/co/badgersinfoil/metaas/impl/ModifierUtils.java        2008-02-10 23:21:11 UTC (rev 678)
@@ -6,6 +6,8 @@
</small></pre><pre class="diff" id="context"> 
 package uk.co.badgersinfoil.metaas.impl;
 
</pre><pre class="diff" id="added">+import java.util.HashMap;
+import java.util.Map;
</pre><pre class="diff" id="context"> import org.asdt.core.internal.antlr.AS3Parser;
 import uk.co.badgersinfoil.metaas.dom.Visibility;
 import uk.co.badgersinfoil.metaas.impl.antlr.LinkedListToken;
</pre><pre class="diff"><small id="info">@@ -16,26 +18,59 @@
</small></pre><pre class="diff" id="context">  * Helpers for dealing with the modifiers list.
  */
 class ModifierUtils {
</pre><pre class="diff" id="added">+        
+        private static class ModInfo {
+                public int tokenType;
+                public Visibility vis;
+                public String keyword;
</pre><pre class="diff" id="context"> 
</pre><pre class="diff" id="added">+                public ModInfo(int tokenType, Visibility vis, String keyword) {
+                        this.tokenType = tokenType;
+                        this.vis = vis;
+                        this.keyword = keyword;
+                }
+        }
+        
+        private static Map modinfoByTokenType = new HashMap();
+        private static Map modinfoByVisibility = new HashMap();
+
+        static {
+                mapMod(AS3Parser.PRIVATE, Visibility.PRIVATE, "private");
+                mapMod(AS3Parser.PUBLIC, Visibility.PUBLIC, "public");
+                mapMod(AS3Parser.PROTECTED, Visibility.PROTECTED, "protected");
+                mapMod(AS3Parser.INTERNAL, Visibility.INTERNAL, "internal");
+                mapMod(Integer.MIN_VALUE, Visibility.DEFAULT, null);
+        }
+
+        private static void mapMod(int tokenType, Visibility vis, String keyword) {
+                ModInfo inf = new ModInfo(tokenType, vis, keyword);
+                modinfoByTokenType.put(new Integer(tokenType), inf);
+                modinfoByVisibility.put(vis, inf);
+        }
+        
+        private static ModInfo getModInfo(int tokenType) {
+                return (ModInfo)modinfoByTokenType.get(new Integer(tokenType));
+        }
+        
+        private static ModInfo getModInfo(Visibility vis) {
+                ModInfo result = (ModInfo)modinfoByVisibility.get(vis);
+                if (result == null) {
+                        throw new IllegalArgumentException("unknown kind of visibility: "+vis);
+                }
+                return result;
+        }
+
</pre><pre class="diff" id="context">         public static Visibility getVisibility(LinkedListTree modifiers) {
                 for (ASTIterator i=new ASTIterator(modifiers); i.hasNext(); ) {
                         LinkedListTree mod = i.next();
</pre><pre class="diff" id="removed">-                        if (mod.getType() == AS3Parser.PRIVATE) {
-                                return Visibility.PRIVATE;
</pre><pre class="diff" id="added">+                        ModInfo modInfo = getModInfo(mod.getType());
+                        if (modInfo != null) {
+                                return modInfo.vis;
</pre><pre class="diff" id="context">                         }
</pre><pre class="diff" id="removed">-                        if (mod.getType() == AS3Parser.PUBLIC) {
-                                return Visibility.PUBLIC;
-                        }
-                        if (mod.getType() == AS3Parser.PROTECTED) {
-                                return Visibility.PROTECTED;
-                        }
-                        if (mod.getType() == AS3Parser.INTERNAL) {
-                                return Visibility.INTERNAL;
-                        }
</pre><pre class="diff" id="context">                 }
                 return Visibility.DEFAULT;
         }
</pre><pre class="diff" id="removed">-        
</pre><pre class="diff" id="added">+
</pre><pre class="diff" id="context">         private static boolean hasModifierFlag(LinkedListTree modifiers, int type) {
                 for (ASTIterator i=new ASTIterator(modifiers); i.hasNext(); ) {
                         LinkedListTree mod = i.next();
</pre><pre class="diff"><small id="info">@@ -84,58 +119,29 @@
</small></pre><pre class="diff" id="context">         }
 
         public static void setVisibility(LinkedListTree modifiers, Visibility protection) {
</pre><pre class="diff" id="added">+                ModInfo modInfo = getModInfo(protection);
</pre><pre class="diff" id="context">                 for (ASTIterator i=new ASTIterator(modifiers); i.hasNext(); ) {
                         LinkedListTree mod = i.next();
                         if (isVisibilityKeyword(mod)) {
</pre><pre class="diff" id="removed">-                                if (Visibility.PRIVATE == protection) {
-                                        mod.token.setType(AS3Parser.PRIVATE);
-                                        mod.token.setText("private");
-                                } else if (Visibility.PUBLIC == protection) {
-                                        mod.token.setType(AS3Parser.PUBLIC);
-                                        mod.token.setText("public");
-                                } else if (Visibility.PROTECTED == protection) {
-                                        mod.token.setType(AS3Parser.PROTECTED);
-                                        mod.token.setText("protected");
-                                } else if (Visibility.INTERNAL == protection) {
-                                        mod.token.setType(AS3Parser.INTERNAL);
-                                        mod.token.setText("internal");
-                                } else if (Visibility.DEFAULT == protection) {
</pre><pre class="diff" id="added">+                                if (modInfo.keyword == null) {
</pre><pre class="diff" id="context">                                         i.remove();
                                         if (modifiers.getChildCount() == 0) {
                                                 deleteAllChildTokens(modifiers);
                                         }
                                 } else {
</pre><pre class="diff" id="removed">-                                        throw new IllegalArgumentException("unknown kind of visibility: "+protection);
</pre><pre class="diff" id="added">+                                        mod.token.setType(modInfo.tokenType);
+                                        mod.token.setText(modInfo.keyword);
</pre><pre class="diff" id="context">                                 }
                                 return;
                         }
                 }
</pre><pre class="diff" id="removed">-                if (Visibility.PRIVATE == protection) {
-                        LinkedListTree node = ASTUtils.newAST(AS3Parser.PRIVATE, "private");
-                        node.appendToken(TokenBuilder.newSpace());
-                        modifiers.addChildWithTokens(node);
-                } else if (Visibility.PUBLIC == protection) {
-                        LinkedListTree node = ASTUtils.newAST(AS3Parser.PUBLIC, "public");
-                        node.appendToken(TokenBuilder.newSpace());
-                        modifiers.addChildWithTokens(node);
-                } else if (Visibility.PROTECTED == protection) {
-                        LinkedListTree node = ASTUtils.newAST(AS3Parser.PROTECTED, "protected");
-                        node.appendToken(TokenBuilder.newSpace());
-                        modifiers.addChildWithTokens(node);
-                } else if (Visibility.INTERNAL == protection) {
-                        LinkedListTree node = ASTUtils.newAST(AS3Parser.INTERNAL, "internal");
-                        node.appendToken(TokenBuilder.newSpace());
-                        modifiers.addChildWithTokens(node);
-                } else {
-                        throw new IllegalArgumentException("unknown kind of visibility: "+protection);
-                }
</pre><pre class="diff" id="added">+                LinkedListTree mod = ASTUtils.newAST(modInfo.tokenType, modInfo.keyword);
+                mod.appendToken(TokenBuilder.newSpace());
+                modifiers.addChildWithTokens(mod);
</pre><pre class="diff" id="context">         }
 
         private static boolean isVisibilityKeyword(LinkedListTree mod) {
</pre><pre class="diff" id="removed">-                return mod.getType() == AS3Parser.PRIVATE
-                     ||mod.getType() == AS3Parser.PUBLIC
-                     ||mod.getType() == AS3Parser.PROTECTED
-                     ||mod.getType() == AS3Parser.INTERNAL;
</pre><pre class="diff" id="added">+                return getModInfo(mod.getType()) != null;
</pre><pre class="diff" id="context">         }
 
         private static void deleteAllChildTokens(LinkedListTree modifiers) {
</pre><pre class="diff"><small id="info">@@ -158,25 +164,10 @@
</small></pre><pre class="diff" id="context">                         return ASTUtils.newPlaceholderAST(AS3Parser.MODIFIERS);
                 }
                 LinkedListTree modifiers = ASTUtils.newImaginaryAST(AS3Parser.MODIFIERS);
</pre><pre class="diff" id="removed">-                if (Visibility.PUBLIC.equals(visibility)) {
-                        LinkedListTree modPublic = ASTUtils.newAST(AS3Parser.PUBLIC, "public");
-                        modPublic.appendToken(TokenBuilder.newSpace());
-                        modifiers.addChildWithTokens(modPublic);
-                } else if (Visibility.PRIVATE.equals(visibility)) {
-                        LinkedListTree modPrivate = ASTUtils.newAST(AS3Parser.PRIVATE, "private");
-                        modPrivate.appendToken(TokenBuilder.newSpace());
-                        modifiers.addChildWithTokens(modPrivate);
-                } else if (Visibility.PROTECTED.equals(visibility)) {
-                        LinkedListTree modProtected = ASTUtils.newAST(AS3Parser.PROTECTED, "protected");
-                        modProtected.appendToken(TokenBuilder.newSpace());
-                        modifiers.addChildWithTokens(modProtected);
-                } else if (Visibility.INTERNAL.equals(visibility)) {
-                        LinkedListTree modInternal = ASTUtils.newAST(AS3Parser.INTERNAL, "internal");
-                        modInternal.appendToken(TokenBuilder.newSpace());
-                        modifiers.addChildWithTokens(modInternal);
-                } else {
-                        throw new IllegalArgumentException("unknown kind of visibility: "+visibility);
-                }
</pre><pre class="diff" id="added">+                ModInfo modInfo = getModInfo(visibility);
+                LinkedListTree mod = ASTUtils.newAST(modInfo.tokenType, modInfo.keyword);
+                mod.appendToken(TokenBuilder.newSpace());
+                modifiers.addChildWithTokens(mod);
</pre><pre class="diff" id="context">                 return modifiers;
         }
 }
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.12</small></center>
</body></html>