You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by ma...@apache.org on 2006/07/24 16:58:51 UTC

svn commit: r425117 [13/14] - in /incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript: ./ javascript20parser/ javascriptcompiler/ obfuscator/ obfuscato...

Added: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/JSParserUtils.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/JSParserUtils.java?rev=425117&view=auto
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/JSParserUtils.java (added)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/JSParserUtils.java Mon Jul 24 09:58:43 2006
@@ -0,0 +1,378 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidadbuild.plugin.javascript.obfuscator.javascript15parser;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+
+public class JSParserUtils
+{
+  public JSParserUtils()
+  {
+  }
+
+  /**
+   *
+   * @param funcToken
+   * @param bodyStart
+   * @param bodyEnd
+   */
+  public static void tagEvalCalls(Token funcToken, Token bodyStart,
+                                  Token bodyEnd)
+  {
+    boolean hasEval = false;
+    Token token = bodyStart;
+
+    while (token != bodyEnd)
+    {
+      if ((token.kind == JSParser15Constants.IDENTIFIER) &&
+          token.image.equals("eval") && (token.next != null) &&
+          (token.next.kind == JSParser15Constants.LPAREN))
+      {
+        hasEval = true;
+
+        break;
+      }
+
+      token = token.next;
+    }
+
+    ((AnnotatedToken) funcToken).setFunctionUsesEval(hasEval);
+  }
+
+  /**
+   *
+   * @param contextStack
+   * @param token
+   */
+  public static void pushToken(ProgramContextStack contextStack,
+                               AnnotatedToken token)
+  {
+    ProgramContext context = (ProgramContext) contextStack.peek();
+    context.addToken(token.image, token);
+  }
+
+  /**
+   *
+   * @param contextStack
+   * @param v
+   */
+  public static void pushTokens(ProgramContextStack contextStack, Vector v)
+  {
+    for (Enumeration item = v.elements(); item.hasMoreElements(); )
+    {
+      AnnotatedToken t = (AnnotatedToken) item.nextElement();
+      pushToken(contextStack, t);
+    }
+  }
+
+  /**
+   *
+   * @param objToken
+   * @param end
+   */
+  public static void tagObjectIdentifier(Token objToken, Token end)
+  {
+    Token t = objToken.next;
+    Token suffixToken = null;
+
+    while (t != end)
+    {
+      if (t.kind == JSParser15Constants.DOT)
+      {
+        annotateToken(objToken, AnnotationConstants.OBJECT_IDENTIFIER,
+                      null, -1);
+        suffixToken = t.next;
+
+        if ((suffixToken != null) &&
+            (suffixToken.kind == JSParser15Constants.IDENTIFIER))
+        {
+          annotateToken(suffixToken,
+                        AnnotationConstants.OBJECT_FIELD_IDENTIFIER, null,
+                        -1);
+        }
+      }
+
+      if ((t.kind == JSParser15Constants.LPAREN) && (suffixToken != null))
+      {
+        annotateToken(suffixToken,
+                      AnnotationConstants.OBJECT_METHOD_IDENTIFIER, null,
+                      -1);
+      }
+
+      t = t.next;
+    }
+  }
+
+  /**
+   *
+   * @param contextStack
+   * @param start
+   * @param end
+   */
+  public static void tagMethodInvocation(ProgramContextStack contextStack,
+                                         AnnotatedToken start,
+                                         AnnotatedToken end)
+  {
+    if (tagAssertProfilerCalls(contextStack, start, end))
+    {
+      return;
+    }
+
+    tagLoggerCalls(contextStack, start, end);
+  }
+
+  /**
+   *
+   * @param contextStack
+   * @param start
+   * @param end
+   * @return
+   */
+  private static boolean tagAssertProfilerCalls(ProgramContextStack contextStack,
+                                                AnnotatedToken start,
+                                                AnnotatedToken end)
+  {
+    AnnotatedToken token = start;
+    boolean isSpecialType = false;
+    boolean isRemovable = false;
+
+    while (token != end)
+    {
+      // This checks for:
+      // "Profiler.xxx=...;"
+      // or "foo.<profiler method>;" where foo is a var of type Profiler
+      AnnotatedToken objToken = contextStack.getToken(token.image);
+
+      if ((token.isSpecialClassType() ||
+           ((objToken != null) && objToken.isSpecialObjectType())) &&
+          (token.getKind() == AnnotationConstants.OBJECT_IDENTIFIER))
+      {
+        isSpecialType = true;
+      }
+
+      if (isSpecialType &&
+          (token.getKind() == AnnotationConstants.OBJECT_METHOD_IDENTIFIER))
+      {
+        isRemovable = true;
+
+        break;
+      }
+
+      token = token.getNext();
+    }
+
+    if (isRemovable)
+    {
+      token = start;
+
+      while (token != end)
+      {
+        token.setRemovable(true);
+        token = token.getNext();
+      }
+
+      if (token.kind == JSParser15Constants.SEMICOLON)
+      {
+        token.setRemovable(true);
+      }
+    }
+
+    return isRemovable;
+  }
+
+  /**
+   *
+   * @param contextStack
+   * @param start
+   * @param end
+   * @return
+   */
+  private static boolean tagLoggerCalls(ProgramContextStack contextStack,
+                                        AnnotatedToken start,
+                                        AnnotatedToken end)
+  {
+    AnnotatedToken token = start;
+    boolean isSpecialType = false;
+    boolean isLOGGER = false;
+    boolean isRemovable = false;
+
+    while (token != end)
+    {
+      // This checks for:
+      // "Logger.LOGGER.<static method>"
+      if ((token.isSpecialClassType()) &&
+          (token.getKind() == AnnotationConstants.OBJECT_IDENTIFIER))
+      {
+        isSpecialType = true;
+      }
+
+      if (isSpecialType &&
+          (token.getKind() == AnnotationConstants.OBJECT_FIELD_IDENTIFIER) &&
+          token.image.equals("LOGGER"))
+      {
+        isLOGGER = true;
+      }
+
+      if (isLOGGER &&
+          (token.getKind() == AnnotationConstants.OBJECT_METHOD_IDENTIFIER))
+      {
+        isRemovable = true;
+
+        break;
+      }
+
+      token = token.getNext();
+    }
+
+    if (isRemovable)
+    {
+      token = start;
+
+      while (token != end)
+      {
+        token.setRemovable(true);
+        token = token.getNext();
+      }
+
+      if (token.kind == JSParser15Constants.SEMICOLON)
+      {
+        token.setRemovable(true);
+      }
+    }
+
+    return isRemovable;
+  }
+
+  /**
+   *
+   * @param contextStack
+   * @param lhs
+   * @param op
+   * @param rhs
+   * @param end
+   */
+  public static void tagAssignmentExpression(ProgramContextStack contextStack,
+                                             AnnotatedToken varToken,
+                                             AnnotatedToken lhs,
+                                             AnnotatedToken op,
+                                             AnnotatedToken rhs,
+                                             AnnotatedToken end)
+  {
+    AnnotatedToken token = (varToken != null)? varToken: lhs;
+    boolean isSpecialType = false;
+    boolean isRemovable = false;
+    ProgramContext context = (ProgramContext) contextStack.peek();
+
+    if (rhs.kind != JSParser15Constants.IDENTIFIER)
+    {
+      return;
+    }
+
+    while (token != end)
+    {
+      // This checks for:
+      // "var foo = Profiler.xxx=...;"
+      // or "var bar = foo.<profiler method>;"
+      AnnotatedToken objToken = contextStack.getToken(token.image);
+
+      if ((token.isSpecialClassType() ||
+           ((objToken != null) && objToken.isSpecialObjectType())) &&
+          (token.getKind() == AnnotationConstants.OBJECT_IDENTIFIER))
+      {
+        isSpecialType = true;
+      }
+
+      if (isSpecialType &&
+          (token.getKind() == AnnotationConstants.OBJECT_METHOD_IDENTIFIER))
+      {
+        isRemovable = true;
+
+        break;
+      }
+
+      token = token.getNext();
+    }
+
+    if (isRemovable)
+    {
+      token = (varToken != null)? varToken: lhs;
+
+      AnnotatedToken prevToken = lhs;
+
+      while (token != end)
+      {
+        token.setRemovable(true);
+
+        if (token.getNext().isSpecialClassType() &&
+            (token.kind == JSParser15Constants.ASSIGN))
+        {
+          // This saves the LHS var name "foo" to be removed later. It also assigns the LHS type
+          // "var foo = Profiler.xxx=...;"
+          prevToken.setType(token.next.image);
+          context.addToken(prevToken.image, prevToken);
+        }
+
+        prevToken = token;
+        token = token.getNext();
+      }
+    }
+  }
+
+  /**
+   *
+   * @param t
+   * @param annotationId
+   * @param annotationObject
+   * @param wsSensitive
+   */
+  public static void annotateToken(Token t, int annotationId,
+                                   Object annotationObject,
+                                   int wsSensitive)
+  {
+    AnnotatedToken annToken = (AnnotatedToken) t;
+    annToken.setAnnotationKind(annotationId);
+
+    if (annotationObject != null)
+    {
+      annToken.setAnnotationObject(annotationObject);
+    }
+
+    if (wsSensitive >= 0)
+    {
+      annToken.setWSSensitive(wsSensitive);
+    }
+  }
+
+  /**
+   *
+   * @param v
+   * @param annotationId
+   * @param annotationObject
+   * @param wsSensitive
+   */
+  public static void annotateTokens(Vector v, int annotationId,
+                                    Object annotationObject,
+                                    int wsSensitive)
+  {
+    for (Enumeration item = v.elements(); item.hasMoreElements(); )
+    {
+      Token t = (Token) item.nextElement();
+      annotateToken(t, annotationId, annotationObject, wsSensitive);
+    }
+  }
+}
\ No newline at end of file

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/JSParserUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/NameGen.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/NameGen.java?rev=425117&view=auto
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/NameGen.java (added)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/NameGen.java Mon Jul 24 09:58:43 2006
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidadbuild.plugin.javascript.obfuscator.javascript15parser;
+
+public class NameGen
+{
+  private int _nextId = 0;
+
+  public NameGen()
+  {
+  }
+
+  public String getName()
+  {
+    return "x" + _nextId++;
+  }
+}
\ No newline at end of file

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/NameGen.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/ProgramContext.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/ProgramContext.java?rev=425117&view=auto
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/ProgramContext.java (added)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/ProgramContext.java Mon Jul 24 09:58:43 2006
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.myfaces.trinidadbuild.plugin.javascript.obfuscator.javascript15parser;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import java.util.HashMap;
+
+//~--- classes ----------------------------------------------------------------
+
+public class ProgramContext
+{
+
+  // Table of symbol name, AnnotatedToken
+  protected HashMap _symbolTable = new HashMap();
+  protected String _name;
+  protected NameGen _nameGen;
+
+  //~--- constructors -------------------------------------------------------
+
+  public ProgramContext(String name)
+  {
+    this(name, new NameGen());
+  }
+
+  public ProgramContext(String name, NameGen nameGen)
+  {
+    _name = name;
+    _nameGen = nameGen;
+  }
+
+  //~--- methods ------------------------------------------------------------
+
+  public void addToken(String name, AnnotatedToken token)
+  {
+    _symbolTable.put(name, token);
+  }
+
+  public String generateSymbolName()
+  {
+    return _nameGen.getName();
+  }
+
+  //~--- get methods --------------------------------------------------------
+
+  public String getName()
+  {
+    return _name;
+  }
+
+  public NameGen getNameGen()
+  {
+    return _nameGen;
+  }
+
+  public AnnotatedToken getToken(String key)
+  {
+    return (AnnotatedToken) _symbolTable.get(key);
+  }
+
+  //~--- set methods --------------------------------------------------------
+
+  public void setName(String name)
+  {
+    _name = name;
+  }
+
+  public void setNameGen(NameGen nameGen)
+  {
+    _nameGen = nameGen;
+  }
+}
+
+
+//~ Formatted by Jindent --- http://www.jindent.com
\ No newline at end of file

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/ProgramContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/ProgramContextStack.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/ProgramContextStack.java?rev=425117&view=auto
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/ProgramContextStack.java (added)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/ProgramContextStack.java Mon Jul 24 09:58:43 2006
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.myfaces.trinidadbuild.plugin.javascript.obfuscator.javascript15parser;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import java.util.Stack;
+
+//~--- classes ----------------------------------------------------------------
+
+public class ProgramContextStack extends Stack {
+    public ProgramContextStack() {}
+
+    //~--- methods ------------------------------------------------------------
+
+    public ProgramContext popContext() {
+        return ((ProgramContext) pop());
+    }
+
+    public void pushContext(ProgramContext context) {
+        push(context);
+    }
+
+    //~--- get methods --------------------------------------------------------
+
+    public AnnotatedToken getToken(String name) {
+        AnnotatedToken token = null;
+
+        for (int i = size() - 1; i >= 0; i--) {
+            ProgramContext context = (ProgramContext) get(i);
+
+            if (null != (token = context.getToken(name))) {
+                break;
+            }
+        }
+
+        return token;
+    }
+
+    /**
+     *
+     * @param name
+     * @param depth
+     * @return
+     */
+    public AnnotatedToken getToken(String name, int depth) {
+        int end;
+
+        end = size() - depth;
+        end = Math.max(end, 0);
+
+        AnnotatedToken token = null;
+
+        for (int i = size() - 1; i >= end; i--) {
+            ProgramContext context = (ProgramContext) get(i);
+
+            if (null != (token = context.getToken(name))) {
+                break;
+            }
+        }
+
+        return token;
+    }
+}
+
+
+//~ Formatted by Jindent --- http://www.jindent.com
\ No newline at end of file

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/ProgramContextStack.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/Token.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/Token.java?rev=425117&view=auto
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/Token.java (added)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/Token.java Mon Jul 24 09:58:43 2006
@@ -0,0 +1,96 @@
+/*
+* Copyright 2006 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */
+package org.apache.myfaces.trinidadbuild.plugin.javascript.obfuscator.javascript15parser;
+
+/**
+ * Describes the input token stream.
+ */
+
+public class Token {
+
+  /**
+   * An integer that describes the kind of this token.  This numbering
+   * system is determined by JavaCCParser, and a table of these numbers is
+   * stored in the file ...Constants.java.
+   */
+  public int kind;
+
+  /**
+   * beginLine and beginColumn describe the position of the first character
+   * of this token; endLine and endColumn describe the position of the
+   * last character of this token.
+   */
+  public int beginLine, beginColumn, endLine, endColumn;
+
+  /**
+   * The string image of the token.
+   */
+  public String image;
+
+  /**
+   * A reference to the next regular (non-special) token from the input
+   * stream.  If this is the last token from the input stream, or if the
+   * token manager has not read tokens beyond this one, this field is
+   * set to null.  This is true only if this token is also a regular
+   * token.  Otherwise, see below for a description of the contents of
+   * this field.
+   */
+  public Token next;
+
+  /**
+   * This field is used to access special tokens that occur prior to this
+   * token, but after the immediately preceding regular (non-special) token.
+   * If there are no such special tokens, this field is set to null.
+   * When there are more than one such special token, this field refers
+   * to the last of these special tokens, which in turn refers to the next
+   * previous special token through its specialToken field, and so on
+   * until the first special token (whose specialToken field is null).
+   * The next fields of special tokens refer to other special tokens that
+   * immediately follow it (without an intervening regular token).  If there
+   * is no such token, this field is null.
+   */
+  public Token specialToken;
+
+  /**
+   * Returns the image.
+   */
+  public String toString()
+  {
+     return image;
+  }
+
+  /**
+   * Returns a new Token object, by default. However, if you want, you
+   * can create and return subclass objects based on the value of ofKind.
+   * Simply add the cases to the switch for all those special cases.
+   * For example, if you have a subclass of Token called IDToken that
+   * you want to create if ofKind is ID, simlpy add something like :
+   *
+   *    case MyParserConstants.ID : return new IDToken();
+   *
+   * to the following switch statement. Then you can cast matchedToken
+   * variable to the appropriate type and use it in your lexical actions.
+   */
+  public static final Token newToken(int ofKind)
+  {
+     switch(ofKind)
+     {
+       default : return new AnnotatedToken();
+     }
+  }
+
+}
\ No newline at end of file

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/Token.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/js1.5.jj
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/js1.5.jj?rev=425117&view=auto
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/js1.5.jj (added)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/js1.5.jj Mon Jul 24 09:58:43 2006
@@ -0,0 +1,1174 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+options {
+  STATIC=false;
+  DEBUG_TOKEN_MANAGER=false;
+  DEBUG_PARSER=false;
+}
+
+PARSER_BEGIN(JSParser15)
+package org.apache.myfaces.trinidadbuild.plugin.javascript.obfuscator.javascript15parser;
+import java.util.Vector;
+import java.io.IOException;
+public class JSParser15 
+{
+    // This is a stack of symbol tables for the JS file
+    protected ProgramContextStack _contextStack = new ProgramContextStack();
+    
+}
+
+PARSER_END(JSParser15)
+
+/////////////////////////////////////////////////////
+// LEXICAL RULES Section
+/////////////////////////////////////////////////////
+TOKEN_MGR_DECLS :
+{
+    private boolean isRegValid = true;
+    public void setRegInvalid()
+    {
+        isRegValid = false;
+    }
+    public void setRegValid()
+    {
+        isRegValid = true;
+    }
+}
+
+/////////////////////////////////////////////////////
+// WHITE SPACE 
+/////////////////////////////////////////////////////
+SPECIAL_TOKEN :
+{
+        <EOL:   (["\n","\r"])+ >
+    |   <WS:    ([" ","\t"])+ >
+}
+/////////////////////////////////////////////////////
+// COMMENTS 
+/////////////////////////////////////////////////////
+MORE :
+{
+        "//" : IN_SINGLE_LINE_COMMENT
+    |   "/*" : IN_MULTI_LINE_COMMENT
+}
+
+<IN_SINGLE_LINE_COMMENT>
+SPECIAL_TOKEN :
+{
+        < SINGLE_LINE_COMMENT: (~["\n","\r"])* ("\n"|"\r"|"\r\n")? >  : DEFAULT
+}
+
+<IN_MULTI_LINE_COMMENT>
+SPECIAL_TOKEN :
+{
+        <MULTI_LINE_COMMENT: "*/" > : DEFAULT
+}
+
+<IN_SINGLE_LINE_COMMENT, IN_MULTI_LINE_COMMENT>
+MORE :
+{
+        < ~[] >
+}
+/////////////////////////////////////////////////////
+// RESERVED WORDS AND LITERALS
+/////////////////////////////////////////////////////
+TOKEN :
+{
+        < BREAK:        "break" >
+    |   < CONTINUE:     "continue" >
+    |   < DELETE:       "delete" >
+    |   < ELSE:         "else" >
+    |   < FOR:          "for" >
+    |   < FUNCTION:     "function" >
+    |   < FUNCTION_:    "Function" >
+    |   < IF:           "if" >
+    |   < IN:           "in" >
+    |   < NEW:          "new" >
+    |   < RETURN:       "return" >
+    |   < THIS:         "this" >
+    |   < TYPEOF:       "typeof" >
+    |   < INSTANCEOF:   "instanceof" >
+    |   < VAR:          "var" >
+    |   < VOID:         "void" >
+    |   < WHILE:        "while" >
+    |   < WITH:         "with" >
+    |   < CASE:         "case" >
+    |   < CATCH:        "catch" >
+    |   < CLASS:        "class" >
+    |   < CONST:        "const" >
+    |   < DEBUGGER:     "debugger" >
+    |   < _DEFAULT:     "default" >
+    |   < DO:           "do" >
+    |   < ENUM:         "enum" >
+    |   < EXPORT:       "export" >
+    |   < EXTENDS:      "extends" >
+    |   < FINALLY:      "finally" >
+    |   < IMPORT:       "import" >
+    |   < SUPER:        "super" >
+    |   < SWITCH:       "switch" >
+    |   < THROW:        "throw" >
+    |   < TRY:          "try" >
+    |   < TRUE:         "true" >    // They are not supposed to be keywords
+    |   < FALSE:        "false" >   // They are not supposed to be keywords
+    |   < NULL:         "null" >    // They are not supposed to be keywords
+}
+/////////////////////////////////////////////////////
+// LITERALS 
+/////////////////////////////////////////////////////
+TOKEN :
+{
+        < DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
+    |   < HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
+    |   < OCTAL_LITERAL: "0" (["0"-"7"])* >
+    |   < FLOATING_POINT_LITERAL: (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? 
+                                |   "." (["0"-"9"])+ (<EXPONENT>)? 
+                                |   (["0"-"9"])+ (<EXPONENT>)? 
+        >
+    |   < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
+    |   < STRING_LITERAL:   "\""  
+                            ( (~["\"","\\","\n","\r"]) | <ESCAPE_SEQUENCE> )* 
+                            "\""
+                        |   "\"" 
+                            ( (~["\"", "\\"]) | "\\" ("\n" | "\r" | "\r\n") | <ESCAPE_SEQUENCE> )* 
+                            "\""  
+                        |   "'"
+                            ( (~["'","\\","\n","\r"]) | <ESCAPE_SEQUENCE> )*
+                            "'"
+        >
+    |   < #ESCAPE_SEQUENCE: 
+            "\\"
+            (       ["n","t","b","r","f","\\","'","\"","[","]"]
+                |   ["0"-"7"] ( ["0"-"7"] )?
+                |   ["0"-"3"] ["0"-"7"] ["0"-"7"]
+                |   ["x"] ["0"-"9","a"-"f","A"-"F"] ["0"-"9","a"-"f","A"-"F"]
+                |   ["u"] ["0"-"9","a"-"f","A"-"F"] ["0"-"9","a"-"f","A"-"F"] 
+                          ["0"-"9","a"-"f","A"-"F"] ["0"-"9","a"-"f","A"-"F"]
+            )
+        >
+    |   < UNTERMINATED_STRING_LITERAL:
+                "\"" ( <ESCAPE_SEQUENCE> | (~["\"","\\","\n","\r"]) )* ( ["\n","\r"] )?
+            |   "'"  ( <ESCAPE_SEQUENCE> | (~["'","\\","\n","\r"])  )* ( ["\n","\r"] )?
+        >
+}
+/////////////////////////////////////////////////////
+// REGULAR EXPRESSIONS 
+/////////////////////////////////////////////////////
+TOKEN :
+{ 
+        < #REGX_START_CHAR : ~["\r","\n","/","=","*"] | "\\/">
+    |   < #REGX_BODY_CHAR_EXCLUSION : ~["\r","\n","/"] >  
+    |   < #REGX_BODY_CHAR : ( <REGX_BODY_CHAR_EXCLUSION> | "\\/" ) >
+    |   < #REGEX_END_CHAR :     "i" 
+                            |   "g" 
+                            |   "m" 
+                            |   "ig" 
+                            |   "im" 
+                            |   "gi" 
+                            |   "gm" 
+                            |   "mi" 
+                            |   "mg" 
+                            |   "igm" 
+                            |   "img" 
+                            |   "gmi" 
+                            |   "gim" 
+                            |   "mig" 
+                            |   "mgi" 
+        >
+}
+
+TOKEN :
+{
+        <REGULAR_EXPRESSION : "/" <REGX_START_CHAR> (<REGX_BODY_CHAR>)* "/" (<REGEX_END_CHAR>)? >
+        {
+           try {
+                // Peek at the next character.
+                char nextCh = input_stream.readChar();
+                input_stream.backup(1);
+                if (isRegValid == false || nextCh == '/' || nextCh == '*') {
+                    //
+                    // Lexecal analyser thinks it is a RE
+                    // operator such as /...../
+                    // Put the everything to the first "/" back on the input stream
+                    //
+                    input_stream.backup(lengthOfMatch-1);
+                    //
+                    // And remove it from the token
+                    //
+                    matchedToken.image = matchedToken.image.substring(0, 1);
+                    image.delete(0, image.length() - 1);
+                    image.append('/');
+                    matchedToken.kind=SLASH;
+                }
+               } catch (IOException e) {
+                    throw new Error(e.toString());
+               }
+        }        
+
+}
+/////////////////////////////////////////////////////
+// IDENTIFIERS 
+/////////////////////////////////////////////////////
+TOKEN :
+{
+        < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* >
+    |   < #LETTER: ["a"-"z","A"-"Z","$","_"] >
+    |   < #DIGIT: ["0"-"9"]>
+}
+/////////////////////////////////////////////////////
+// SEPARATORS 
+/////////////////////////////////////////////////////
+TOKEN :
+{
+        < LPAREN:   "(" >
+    |   < RPAREN:   ")" >
+    |   < LBRACE:   "{" >
+    |   < RBRACE:   "}" >
+    |   < LBRACKET: "[" >
+    |   < RBRACKET: "]" >
+    |   < SEMICOLON: ";" >
+    |   < COMMA:    "," >
+    |   < DOT:      "." >
+}
+
+/////////////////////////////////////////////////////
+// OPERATORS 
+/////////////////////////////////////////////////////
+TOKEN :
+{
+        < ASSIGN:               "=" >
+    |   < GT:                   ">" >
+    |   < LT:                   "<" >
+    |   < BANG:                 "!" >
+    |   < TILDE:                "~" >
+    |   < HOOK:                 "?" >
+    |   < COLON:                ":" >
+    |   < EQ:                   "==" >
+    |   < LE:                   "<=" >
+    |   < GE:                   ">=" >
+    |   < NE:                   "!=" >
+    |   < SC_OR:                "||" >
+    |   < SC_AND:               "&&" >
+    |   < INCR:                 "++" >
+    |   < DECR:                 "--" >
+    |   < PLUS:                 "+" >
+    |   < MINUS:                "-" >
+    |   < STAR:                 "*" >
+    |   < SLASH:                "/" >
+    |   < BIT_AND:              "&" >
+    |   < BIT_OR:               "|" >
+    |   < XOR:                  "^" >
+    |   < REM:                  "%" >
+    |   < LSHIFT:               "<<" >
+    |   < RSIGNEDSHIFT:         ">>" >
+    |   < RUNSIGNEDSHIFT:       ">>>" >
+    |   < PLUSASSIGN:           "+=" >
+    |   < MINUSASSIGN:          "-=" >
+    |   < STARASSIGN:           "*=" >
+    |   < SLASHASSIGN:          "/=" >
+    |   < ANDASSIGN:            "&=" >
+    |   < ORASSIGN:             "|=" >
+    |   < XORASSIGN:            "^=" >
+    |   < REMASSIGN:            "%=" >
+    |   < LSHIFTASSIGN:         "<<=" >
+    |   < RSIGNEDSHIFTASSIGN:   ">>=" >
+    |   < RUNSIGNEDSHIFTASSIGN: ">>>=" >
+    |   < IDENTITYOPER:         "===" >
+    |   < NOTIDENTITYOPER:      "!==" >
+}
+///////////////////////////////////////////////////////////////////
+// GRAMMAR Section
+///////////////////////////////////////////////////////////////////
+
+void Literal():
+{}
+{
+        <DECIMAL_LITERAL> 
+    |   <OCTAL_LITERAL>
+    |   <HEX_LITERAL>
+    |   <FLOATING_POINT_LITERAL> 
+    |   <STRING_LITERAL> 
+    |   <TRUE> 
+    |   <FALSE>
+    |   <REGULAR_EXPRESSION> 
+    |   <NULL>
+}
+
+Token Identifier():
+{
+		Token t;
+}
+{
+    	t = <IDENTIFIER> {return t;}
+}
+
+void PrimaryExpression():
+{
+		Token prefixToken = null;	
+}
+{
+    (
+        prefixToken = <THIS>            (PrimarySuffix())*
+            {
+               JSParserUtils.tagObjectIdentifier(prefixToken, getToken(1));
+            }
+    |   prefixToken=Identifier()        (PrimarySuffix())*
+            {
+               JSParserUtils.tagObjectIdentifier(prefixToken, getToken(1));
+               JSParserUtils.tagMethodInvocation(_contextStack, 
+                                                 (AnnotatedToken)prefixToken, 
+                                                 (AnnotatedToken)getToken(1));
+            }
+    |   LOOKAHEAD(2)  <STRING_LITERAL>  (PrimarySuffix())*  
+    |   LOOKAHEAD(2)  <REGULAR_EXPRESSION>  (PrimarySuffix())*    
+    |   LOOKAHEAD(2)  Literal() 
+    |   FunctionLiteral()
+    |   NestedArrayLiteral()                (PrimarySuffix())*
+    |   ObjectLiteral() 
+    |   <LPAREN> Expression() <RPAREN>      (PrimarySuffix())* 
+    |   AllocationExpression()
+    )
+    {
+        token_source.setRegValid();
+    }
+}
+
+
+void PrimarySuffix():
+{}
+{
+        Arguments() 
+    |   {token_source.setRegInvalid();} <LBRACKET> Expression() <RBRACKET> 
+    |   {token_source.setRegInvalid();} <DOT> Identifier()
+}
+
+void Arguments():
+{}
+{
+        <LPAREN> {token_source.setRegValid();} [ArgumentList()] <RPAREN>
+}
+
+void ArgumentList():
+{}
+{
+        AssignmentExpression() (<COMMA> AssignmentExpression())*
+}
+
+void LiteralArgumentList():
+{}
+{
+        <STRING_LITERAL> (<COMMA> <STRING_LITERAL>)*
+}
+
+void NewSuffix():
+{}
+{
+        <DOT> Identifier()
+}
+
+void AllocationExpression():
+{
+        Token t;
+}
+{
+        LOOKAHEAD(2)  t=<NEW> <THIS>       (NewSuffix())* [Arguments()]
+            {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);}
+    |   LOOKAHEAD(2)  t=<NEW> Identifier() (NewSuffix())* [Arguments()]
+            {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);}
+    |   LOOKAHEAD(2)  t=<NEW> FunctionConstructor() (NewSuffix())*      [Arguments()]
+            {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);}
+}
+
+
+void PostfixOp():
+{}
+{
+        <INCR>
+    |   <DECR>
+}
+
+void PostfixExpression():
+{}
+{
+        PrimaryExpression() [PostfixOp()]
+}
+
+
+void UnaryOp():
+{
+        Token t;
+}
+{
+        t=<DELETE>
+            {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);}
+    |   t=<VOID>
+            {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);}
+    |   t=<TYPEOF>
+            {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);}
+    |   <INCR>
+    |   <DECR>
+    |   <PLUS>
+    |   <MINUS>
+    |   <TILDE>
+    |   <BANG>
+}
+
+void UnaryExpression():
+{}
+{
+        PostfixExpression()
+    |   UnaryOp() UnaryExpression()
+}
+
+void MulOp():
+{}
+{
+        <STAR>
+    |   <SLASH>
+    |   <REM> 
+}
+
+void MultiplicativeExpression():
+{}
+{
+        UnaryExpression() (MulOp() UnaryExpression())*
+} 
+
+void AddOp():
+{}
+{
+        <PLUS>
+    |   <MINUS>
+}
+
+void AdditiveExpression():
+{}
+{
+        MultiplicativeExpression() (AddOp() MultiplicativeExpression())*
+} 
+
+void ShiftOp():
+{}
+{
+        <LSHIFT>
+    |   <RSIGNEDSHIFT>
+    |   <RUNSIGNEDSHIFT>
+}
+
+void ShiftExpression():
+{}
+{
+        AdditiveExpression() (ShiftOp() AdditiveExpression())*
+}
+
+void RelOp():
+{}
+{
+        <LT>
+    |   <GT> 
+    |   <LE> 
+    |   <GE>
+}
+
+void RelationalExpression():
+{
+        Token t;
+}
+{
+        ShiftExpression() 
+            (LOOKAHEAD(3) (  RelOp() 
+                           | t=<INSTANCEOF> 
+                             {JSParserUtils.annotateToken(t, 
+                                                          AnnotationConstants.UNDEFINED, 
+                                                          null, 2);}
+                           | t=<IN> 
+                             {JSParserUtils.annotateToken(t,
+                                                          AnnotationConstants.UNDEFINED,
+                                                          null, 2);})
+             ShiftExpression())*
+}
+
+void RelationalExpressionNoIN():
+{
+        Token t;
+}
+{
+        ShiftExpression() 
+            ( (  RelOp() 
+               | t=<INSTANCEOF>  
+                 {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, 
+                                              null, 2);})
+              ShiftExpression())*
+}
+
+void EqualOp():
+{}
+{
+        <EQ> 
+    |   <NE> 
+    |   <IDENTITYOPER> 
+    |   <NOTIDENTITYOPER>
+}
+
+void EqualityExpression():
+{}
+{
+        RelationalExpression() (EqualOp() RelationalExpression())*
+}
+
+void EqualityExpressionNoIN():
+{}
+{
+        RelationalExpressionNoIN() (EqualOp() RelationalExpressionNoIN())*
+}
+
+
+void BitwiseANDOp():
+{}
+{
+        <BIT_AND>
+}
+
+void BitwiseANDExpression():
+{}
+{
+        EqualityExpression() (BitwiseANDOp() EqualityExpression())*
+}
+
+void BitwiseANDExpressionNoIN():
+{}
+{
+        EqualityExpressionNoIN() (BitwiseANDOp() EqualityExpressionNoIN())*
+}
+
+
+void BitwiseXOROp():
+{}
+{
+        <XOR>
+}
+
+void BitwiseXORExpression():
+{}
+{
+        BitwiseANDExpression() (BitwiseXOROp() BitwiseANDExpression())*
+}
+
+void BitwiseXORExpressionNoIN():
+{}
+{
+        BitwiseANDExpressionNoIN() (BitwiseXOROp() BitwiseANDExpressionNoIN())*
+}
+
+void BitwiseOROp():
+{}
+{
+        <BIT_OR>
+}
+
+void BitwiseORExpression():
+{}
+{
+        BitwiseXORExpression() (BitwiseOROp() BitwiseXORExpression())*
+}
+
+void BitwiseORExpressionNoIN():
+{}
+{
+        BitwiseXORExpressionNoIN() (BitwiseOROp() BitwiseXORExpressionNoIN())*
+}
+
+void LogicalANDExpression():
+{}
+{
+        BitwiseORExpression() (<SC_AND> BitwiseORExpression())*
+}
+
+void LogicalANDExpressionNoIN():
+{}
+{
+        BitwiseORExpressionNoIN() (<SC_AND> BitwiseORExpressionNoIN())*
+}
+
+void LogicalORExpression():
+{}
+{
+        LogicalANDExpression() (<SC_OR> LogicalANDExpression())*
+}
+
+void LogicalORExpressionNoIN():
+{}
+{
+        LogicalANDExpressionNoIN() (<SC_OR> LogicalANDExpressionNoIN())*
+}
+
+void ConditionalExpression():
+{}
+{
+        LogicalORExpression() [<HOOK> Expression() <COLON> ConditionalExpression()]
+}
+
+void ConditionalExpressionNoIN():
+{}
+{
+        LogicalORExpressionNoIN() [<HOOK> ExpressionNoIN() <COLON> ConditionalExpressionNoIN()]
+}
+
+Token AssignementOperator():
+{
+        Token t;
+}
+{
+        ( t=<ASSIGN>
+    |     t=<STARASSIGN>
+    |     t=<SLASHASSIGN> 
+    |     t=<REMASSIGN> 
+    |     t=<PLUSASSIGN>
+    |     t=<MINUSASSIGN> 
+    |     t=<LSHIFTASSIGN> 
+    |     t=<RSIGNEDSHIFTASSIGN>
+    |     t=<RUNSIGNEDSHIFTASSIGN>
+    |     t=<ANDASSIGN> 
+    |     t=<XORASSIGN> 
+    |     t=<ORASSIGN> )
+        { return t; } 
+}
+
+void AssignmentExpression():
+{
+        Token tLHS      = getToken(1); 
+		Token tOperator = null; 
+		Token tRHS      = null;
+		Token tEnd      = null;
+}
+{
+        ConditionalExpression() 
+            [ (AssignementOperator() 
+               {tRHS=getToken(1);}
+               AssignmentExpression())
+               {
+                  tEnd = getToken(1);
+                  JSParserUtils.tagAssignmentExpression(_contextStack, null, 
+                                                        (AnnotatedToken)tLHS, 
+                                                        (AnnotatedToken)tOperator,
+                                                        (AnnotatedToken)tRHS, 
+                                                        (AnnotatedToken)tEnd); 
+               }
+            ]
+}
+
+void AssignmentExpressionNoIN():
+{
+        Token tLHS      = getToken(1); 
+		Token tOperator = null; 
+		Token tRHS      = null;
+		Token tEnd      = null;
+}
+{
+        ConditionalExpressionNoIN() 
+            [ (AssignementOperator() {tRHS=getToken(1);}
+               AssignmentExpressionNoIN())
+               {
+                  tEnd = getToken(1);
+                  JSParserUtils.tagAssignmentExpression(_contextStack, null, 
+                                                        (AnnotatedToken)tLHS, 
+                                                        (AnnotatedToken)tOperator,
+                                                        (AnnotatedToken)tRHS, 
+                                                        (AnnotatedToken)tEnd); 
+               }
+            ]
+}
+
+
+void Expression()                     :
+{}
+{
+  AssignmentExpression() ( "," AssignmentExpression() )*
+}   
+
+void ExpressionNoIN()                     :
+{}
+{
+  AssignmentExpressionNoIN() ( "," AssignmentExpressionNoIN() )*
+}   
+
+
+void Statement():
+{}
+{
+        LOOKAHEAD(3)    Block(null)
+    |                   VariableStatement()
+    |                   EmptyStatement()
+    |                   ExpressionStatement()
+    |                   IfStatement()
+    |                   IterationStatement()
+    |                   ContinueStatement()
+    |                   BreakStatement()
+    |                   ReturnStatement()
+    |                   WithStatement()
+    |                   TryStatement()
+    |                   ThrowStatement()
+    |                   SwitchStatement()
+}
+ 
+void Block(ProgramContext context):
+{}
+{
+        LOOKAHEAD(3)    <LBRACE> <RBRACE>   
+    |                   <LBRACE> {
+                                     if (context == null) {
+                                        _contextStack.pushContext(new ProgramContext("block"));
+ 	                                 }
+                                 }
+                                 [StatementList()] 
+                                 <RBRACE>
+                                 {
+                                     _contextStack.popContext();
+                                 }
+}
+ 
+void VariableStatement():
+{
+        Token t;
+}
+{
+        t=<VAR> {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);}
+        VariableDeclarationList(t) Sc()
+}
+ 
+void VariableDeclarationList(Token varToken):
+{}
+{
+        VariableDeclaration(varToken) ( <COMMA> VariableDeclaration(varToken) )*
+}
+
+void VariableDeclaration(Token varToken):
+{
+        Token lhs      = null;
+        Token[] tArray = null;
+}
+{
+        lhs=Identifier() [Initializer()]
+        {
+            JSParserUtils.annotateToken(lhs, AnnotationConstants.VAR_IDENTIFIER, null, -1);
+            JSParserUtils.pushToken(_contextStack, (AnnotatedToken)lhs);      
+      
+            if(tArray != null) {
+      	       Token end = getToken(1);
+               JSParserUtils.tagAssignmentExpression(_contextStack, (AnnotatedToken)varToken, 
+                                                     (AnnotatedToken)lhs, (AnnotatedToken)tArray[0], 
+                                                     (AnnotatedToken)tArray[1], (AnnotatedToken)end); 
+            }
+        }
+}
+
+Token[] Initializer():
+{
+        Token[] tArray = new Token[2];
+}
+{
+        tArray[0]=<ASSIGN> {tArray[1]=getToken(1);} 
+        AssignmentExpression()
+        {return tArray;}
+}
+ 
+void EmptyStatement():
+{}
+{
+        <SEMICOLON>
+}
+
+void ExpressionStatement():
+{}
+{
+        Expression() Sc() 
+}
+
+JAVACODE
+  void Sc() {
+
+    Token tok = getToken(1);
+    if (tok.kind == SEMICOLON) {
+       tok = getNextToken();
+    } else if (tok.specialToken != null) {
+       if (!EolCommentSkipWs(tok.specialToken) && (tok.kind != EOF)) {
+          throw generateParseException();
+       }
+    } else if ((tok.kind != EOF) && (tok.kind!=RBRACE)) {
+         throw generateParseException();
+    }
+  }
+ 
+JAVACODE
+  boolean EolCommentSkipWs(Token t) {
+    boolean retVal = false;
+    Token specialToken = t;
+    while(specialToken != null) {
+      if(specialToken.kind == WS) {
+        specialToken = specialToken.specialToken;
+        continue;
+      }
+      else if(specialToken.kind == EOL  || 
+              specialToken.kind == SINGLE_LINE_COMMENT) {
+        retVal = true;
+        break;
+      }
+      else {
+        break;
+      }
+    }
+    return retVal;
+  }
+ 
+void IfStatement():
+{
+        Token t;
+}
+{
+        <IF> <LPAREN> Expression() <RPAREN> 
+            Statement() 
+            [ LOOKAHEAD(1) t=<ELSE> {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED,
+                                                                 null, 1);}
+              Statement()
+            ]
+}
+
+
+void IterationStatement():
+{}
+{
+                            WhileStatement()
+    |                       DoStatement()
+    |   LOOKAHEAD(<FOR> <LPAREN> Expression() <SEMICOLON>)                     
+                            ForStatement()
+    |   LOOKAHEAD(<FOR> <LPAREN> <SEMICOLON>)                                  
+                            ForStatement()
+    |   LOOKAHEAD(<FOR> <LPAREN> varToekn=<VAR> VariableDeclarationList(varToken) <SEMICOLON>)  
+                            ForVarStatement()
+    |   LOOKAHEAD(3)        ForInStatement()
+    |   LOOKAHEAD(3)        ForVarInStatement()
+}
+ 
+void DoStatement():
+{}
+{
+        <DO> Statement() <WHILE> <LPAREN> Expression() <RPAREN>
+}
+
+void WhileStatement():
+{}
+{
+        <WHILE> <LPAREN> Expression() <RPAREN> 
+            Statement()
+}
+ 
+void ForStatement():
+{}
+{
+        <FOR> <LPAREN>  [Expression()] <SEMICOLON> 
+                        [Expression()] <SEMICOLON> 
+                        [Expression()] <RPAREN> 
+            Statement()
+}
+
+void ForVarStatement():
+{
+        Token t;
+}
+{
+        <FOR> <LPAREN>  t=<VAR> {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, 
+                                                             null, 1);}
+                        VariableDeclarationList(t) <SEMICOLON> 
+                        [Expression()]  <SEMICOLON> 
+                        [Expression()]  <RPAREN> 
+            Statement()
+}
+
+void ForInStatement():
+{
+        Token t;
+}
+{
+        <FOR> <LPAREN>  ExpressionNoIN() 
+                        t=<IN> {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, 
+                                                            null, 2);}
+                        ExpressionNoIN() <RPAREN> 
+            Statement()
+}
+ 
+void ForVarInStatement():
+{
+        Token t;
+}
+{
+        <FOR> <LPAREN>  
+                t=<VAR> {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);}
+                t=Identifier() 
+                  {
+   	                  JSParserUtils.annotateToken(t, AnnotationConstants.VAR_IDENTIFIER, null, 1);
+   	                  JSParserUtils.pushToken(_contextStack, (AnnotatedToken)t);
+                  }
+                [Initializer()] 
+                t=<IN> {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 2);}
+                ExpressionNoIN() 
+              <RPAREN> 
+            Statement()
+}
+
+void ContinueStatement():
+{}
+{
+        <CONTINUE> Sc()
+}
+
+void BreakStatement():
+{}
+{
+        <BREAK> Sc()
+}
+ 
+void ReturnStatement():
+{
+        Token t;
+}
+{
+        t=<RETURN> {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);}
+        [Expression()] Sc()
+}
+
+void WithStatement():
+{}
+{
+        <WITH> <LPAREN> Expression() <RPAREN>
+            Statement()
+}
+
+void TryStatement():
+{}
+{
+        <TRY> Block(null)
+        (<CATCH> <LPAREN> Identifier() <RPAREN> Block(null))*
+        [<FINALLY> Block(null)]
+} 
+
+void ThrowStatement():
+{
+        Token t;
+}
+{
+        t=<THROW> {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);}
+        [Expression()] Sc()
+}
+
+void CaseGuard():
+{
+        Token t;
+}
+{
+        t=<CASE> {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);}
+        Expression() <COLON>
+    |   <_DEFAULT> <COLON>
+}
+
+void CaseGroup():
+{}
+{
+        CaseGuard() (Statement())*  
+}
+
+void SwitchStatement():
+{}
+{
+        <SWITCH>    <LPAREN> Expression() <RPAREN> 
+                    <LBRACE> (CaseGroup())* <RBRACE>
+}
+
+void NamedFunction():
+{
+        Token  tIdentifier = null;
+        Token  tFunction   = null;
+        Token  blockStart  = null;
+        Token  blockEnd    = null;
+        Vector params      = new Vector();
+}
+{
+        tFunction=<FUNCTION> 
+        tIdentifier=Identifier() 
+           { 
+              JSParserUtils.annotateToken(tIdentifier, AnnotationConstants.FUNCTION_NAME_IDENTIFIER, 
+                                          null, -1); 
+              ProgramContext context = new ProgramContext(tIdentifier.image);
+              _contextStack.pushContext(context);
+           }
+        <LPAREN> 
+           [params=FormalParameterList()] 
+              { 
+                  JSParserUtils.annotateTokens(params,
+                                               AnnotationConstants.FUNCTION_PARAM_IDENTIFIER,
+                                               null, -1); 
+                  JSParserUtils.annotateToken(tFunction, AnnotationConstants.NAMED_FUNCTION,
+                                              params, 1); 
+                  JSParserUtils.pushTokens(_contextStack, params);
+              } 
+
+        <RPAREN>
+        {blockStart = getToken(1);} 
+        Block(context)
+        {
+           blockEnd = getToken(1);
+           JSParserUtils.tagEvalCalls(tFunction, blockStart, blockEnd);
+        }
+}
+
+void AnonymousFunction():
+{
+        Token  tFunction  = null;
+        Token  blockStart = null;
+        Token  blockEnd   = null;
+        Vector params     = new Vector();
+}
+{
+        tFunction=<FUNCTION>
+           { 
+              ProgramContext context = new ProgramContext("anonymous");
+              _contextStack.pushContext(context);
+           } 
+        <LPAREN> 
+           [params=FormalParameterList()] 
+              { 
+                  JSParserUtils.annotateTokens(params,
+                                               AnnotationConstants.FUNCTION_PARAM_IDENTIFIER,
+                                               null, -1); 
+                  JSParserUtils.annotateToken(tFunction,
+                                              AnnotationConstants.ANONYMOUS_FUNCTION,
+                                              params, -1); 
+                  JSParserUtils.pushTokens(_contextStack, params);
+              } 
+        <RPAREN> 
+        {blockStart = getToken(1);}
+        Block(context)
+        {
+           blockEnd = getToken(1);
+           JSParserUtils.tagEvalCalls(tFunction, blockStart, blockEnd);
+        }
+}
+
+void FunctionConstructor():
+{}
+{    
+        <FUNCTION_> <LPAREN> ArgumentList() <RPAREN> 
+}
+
+void FunctionDeclaration():
+{}
+{
+        LOOKAHEAD(2) NamedFunction() 
+    |   LOOKAHEAD(2) AnonymousFunction()
+}           
+
+void FunctionLiteral():
+{}
+{
+        AnonymousFunction()
+}
+                          
+Vector FormalParameterList():
+{
+        Token  t = null;
+        Vector v = new Vector();
+}
+{
+        t=Identifier() {v.add(t);} 
+        (<COMMA> t=Identifier() {v.add(t);})*
+        {return v;}
+}
+
+void LiteralElement() :
+{}
+{
+        AssignmentExpression()
+}
+
+void ElementList():
+{}
+{
+        LiteralElement() (<COMMA> LiteralElement())*
+}
+
+void ArrayLiteral():
+{}
+{
+        LOOKAHEAD(2) <LBRACKET> <RBRACKET>
+    |   LOOKAHEAD(2) <LBRACKET> ElementList() <RBRACKET>
+}
+
+void NestedArrayLiteral():
+{}
+{
+        LOOKAHEAD(3) ArrayLiteral() 
+    |   LOOKAHEAD(3) <LBRACKET> NestedArrayLiteral() <RBRACKET>
+}
+
+void LiteralField():
+{
+        Token t = null;
+}
+{
+        t=Identifier()     <COLON> AssignmentExpression()
+        {JSParserUtils.annotateToken(t, AnnotationConstants.LITERAL_OBJECT_KEY_IDENTIFIER,null,-1); }
+   |    t=<STRING_LITERAL> <COLON> AssignmentExpression()
+        {JSParserUtils.annotateToken(t, AnnotationConstants.LITERAL_OBJECT_KEY_IDENTIFIER,null,-1); }
+}
+
+void FieldList():
+{}
+{
+        LiteralField() (<COMMA> LiteralField())*
+}
+
+void ObjectLiteral():
+{}
+{
+        LOOKAHEAD(2) <LBRACE> <RBRACE>
+    |   LOOKAHEAD(2) <LBRACE> FieldList() <RBRACE>  
+}
+
+
+Token Program():
+{
+        Token retval = getToken(1);
+}
+{
+        {_contextStack.pushContext(new ProgramContext("root"));}
+        (SourceElement())*  <EOF>
+        {
+            return retval;
+        }
+}
+
+void SourceElement():
+{}
+{
+        LOOKAHEAD(2)    Statement() 
+    |                   FunctionDeclaration()
+}
+
+void StatementList(): 
+{
+//        Token t;
+}
+{
+        (Statement())+
+}

Added: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Detokenizer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Detokenizer.java?rev=425117&view=auto
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Detokenizer.java (added)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Detokenizer.java Mon Jul 24 09:58:43 2006
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2000,2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidadbuild.plugin.javascript.uixtools;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.io.PrintWriter;
+
+/**
+ * Converts Token Objects into a JavaScript file
+ * @version $Name:  $ ($Revision$) $Date$
+ * @author Arjuna Wijeyekoon - arjuna.wijeyekoon@oracle.com
+ */
+public class Detokenizer
+{
+  private final PrintWriter _out;
+
+  /**
+   * @param out the file to write the output to.
+   */
+  public Detokenizer(PrintWriter out)
+  {
+    this._out = out;
+  }
+
+  /**
+   * Creates a new PrintWriter and calls the other constructor.
+   */
+  public Detokenizer(Writer out)
+  {
+    this(new PrintWriter(out));
+  }
+
+  /**
+   * decodes a token and writes the result
+   * @param tok the token to decode.
+   */
+  public void write(Token tok) throws IOException
+  {
+    int com = tok.code;
+    switch(com)
+      {
+      case Token.NEWLINE :
+        _out.println();
+        break;
+      case Token.WHITESPACE :
+        _out.print(' ');
+        break;
+      case Token.PERIOD :
+        _out.print('.');
+        break;
+      case Token.SEMICOLON :
+        _out.print(';');
+        break;
+      case Token.QUOTED :
+        {
+          char ch = tok.ch;
+          _out.print(ch+tok.string+ch);
+        }
+        break;
+      case Token.CONTROL :
+      case Token.LEFT_BRACE :
+      case Token.RIGHT_BRACE :
+        _out.print(tok.ch);
+        break;
+      case Token.NUMBER :
+      case Token.RESERVED :
+      case Token.NAME :
+        _out.print(tok.string);
+        break;
+      case Token.COMMENT :
+        _out.print("/*"+tok.string+"*/");
+        break;
+      case Token.REGULAR_EXP :
+        _out.print("/"+tok.string+"/");
+        break;
+      case Token.REGULAR_EXP_MODIFIER :
+        _out.print(tok.ch);
+        break;
+      case Token.EOF :
+        _out.close();
+        break;
+      default :
+        throw new RuntimeException("Unknown Token:"+tok);
+      }
+  }
+}
\ No newline at end of file

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Detokenizer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/FileProcessor.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/FileProcessor.java?rev=425117&view=auto
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/FileProcessor.java (added)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/FileProcessor.java Mon Jul 24 09:58:43 2006
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2000-2002,2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidadbuild.plugin.javascript.uixtools;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+/**
+ * This utility class can be used to perform some processing on input files,
+ * and write the results to corresponding output files. It supports recursing
+ * into subdirectories.
+ * @version $Name:  $ ($Revision$) $Date$
+ * @author Arjuna Wijeyekoon (arjuna.wijeyekoon@oracle.com) */
+public abstract class FileProcessor
+{
+  /**
+   * @param filenameExt the filename extension to accept. If null, all files
+   *  are accepted.
+   * @return a filter that only accepts files with names that end with the
+   *  specified extension. However, the filter accepts all subdirectories.
+   */
+  public static FilenameFilter getExtensionFilter(final String filenameExt)
+  {
+    return new FilenameFilter() {
+        public boolean accept(File dir, String name)
+        {
+          if ((filenameExt==null) || (name.endsWith(filenameExt))) return true;
+          File f = new File(dir, name);
+          return f.isDirectory();
+        }
+      };
+  }
+
+  /**
+   * @param filter used to select files and/or subdirectories.
+   * @param failFast if true, terminates at the first error (otherwise,
+   *  continues with the next file).
+   * @param overwrite if false, will not overwrite existing output files (That
+   *  particular input and output file will be skipped).
+   * @param verbose if true, generates verbose output.  */
+  public FileProcessor(FilenameFilter filter,
+                       boolean failFast, boolean overwrite, boolean verbose)
+  {
+    _filter = filter;
+    _failFast = failFast;
+    _dontOverwrite = !overwrite;
+    isVerbose = verbose;
+  }
+
+  /**
+   * Creates a Fileprocessor that overwrites all output files, and does not
+   * fail fast.
+   * @param filter used to select files and/or subdirectories.  */
+  public FileProcessor(FilenameFilter filter, boolean verbosity)
+  {
+    this(filter, false, true, verbosity);
+  }
+
+  /**
+   * Creates a Fileprocessor that overwrites all output files, and does not
+   * fail fast.
+   * @param extension the file extension to filter for. if this is null, all
+   * files and subdirectories in a directory will be processed recursively.
+   * @see #getExtensionFilter(String extension)
+   */
+  public FileProcessor(String extension, boolean verbosity)
+  {
+    this(getExtensionFilter(extension), verbosity);
+  }
+
+  /**
+   * @param in the input file or directory
+   * @param out if the input is a directory, then this must be the output
+   *  directory. Otherwise, this is the output file.
+   * @return true if there were no errors. false otherwise.  */
+  public boolean process(File in, File out)
+  {
+    if (isVerbose) System.out.println("Processing file:"+in+" to file:"+out);
+
+    if (in.isDirectory())
+    {
+      boolean success = true;
+      String[] names = in.list(_filter);
+      for(int i=0, sz=names.length; i<sz; i++)
+      {
+        File subIn = new File(in, names[i]);
+        File subOut = new File(out, names[i]);
+        success &= process(subIn, subOut);
+        if (_failFast && (!success)) return false;
+      }
+      return success;
+    }
+    else
+    {
+      try
+      {
+        if (_dontOverwrite && out.exists())
+        {
+          if (isVerbose) System.out.println("Skipping file:"+in+
+                                          " as destination file:"+out+
+                                          " already exists.");
+        }
+        else
+        {
+          out.getParentFile().mkdirs();
+          processFile(in, out);
+        }
+        return true;
+      }
+      catch (Exception e)
+      {
+        System.out.println("Error processing file:"+in+" to file:"+out);
+        e.printStackTrace();
+        return false;
+      }
+    }
+  }
+
+  /**
+   * Called to process a single file.
+   * @param in the input file. This is never a directory.
+   * @param out the output file. If this file exists and overwriting is not
+   * permitted, then this method is never called.
+   * @exception Exception if this class is set to <i>fail fast</i> then any
+   * exception thrown will cause all execution to halt. If this class does not
+   * fail fast, then the exception will be reported and execution will
+   * continue with the next file.  */
+  protected abstract void processFile(File in, File out) throws Exception;
+
+  /**
+   * If this is true, verbose output will be generated.
+   */
+  protected final boolean isVerbose;
+
+  private   final boolean _failFast, _dontOverwrite;
+  private   final FilenameFilter _filter;
+}
\ No newline at end of file

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/FileProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter1.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter1.java?rev=425117&view=auto
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter1.java (added)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter1.java Mon Jul 24 09:58:43 2006
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2000-2001,2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidadbuild.plugin.javascript.uixtools;
+
+import java.io.IOException;
+
+/**
+ * Removes all comments and redundant whitespace
+ * @version $Name:  $ ($Revision$) $Date$
+ * @author Arjuna Wijeyekoon - arjuna.wijeyekoon@oracle.com
+ */
+public class Filter1 implements TokenReader
+{
+
+  /**
+   * blocks until is has read atleast one token from the input reader
+   */
+  public Filter1(TokenReader in) throws IOException, InterruptedException
+  {
+    _in = in;
+    _next = _in.read();
+  }
+
+  /**
+   * @see TokenReader
+   */
+  public Token read() throws IOException, InterruptedException
+  {
+    Token cur = _next;
+    Token res = cur;
+    for(;cur!=null;)
+      {
+        _next = _in.read();
+        res = _filter(_prev, cur, _next) ;
+        if (res!=null)
+          {
+            _prev = res;
+            break;
+          }
+        else cur = _next;
+      }
+    return res;
+  }
+
+  /**
+   * Removes extra spaces/newlines and all comments
+   */
+  private Token _filter(Token prev, Token cur, Token next)
+  {
+    //ystem.out.println("filtering token:"+cur);
+    int ccode = cur.code;
+    if ((ccode==Token.COMMENT) ||   //skip comments
+        ((ccode==Token.WHITESPACE) &&
+         !(_isSpaceSensitive(prev) && _isSpaceSensitive(next))) ||
+        ((ccode==Token.NEWLINE) &&
+         ((prev==null) || (prev.code==Token.NEWLINE))))
+      return null;
+    else return cur;
+  }
+
+  /**
+   * @return true if the given token is affected by whitespace preceding or
+   *  following it.
+   */
+  private boolean _isSpaceSensitive(Token tok)
+  {
+    if (tok==null) return false;
+    int i = tok.code;
+    if ((i == Token.NAME) || (i == Token.NUMBER) || (i == Token.RESERVED) ||
+        (i == Token.PERIOD))
+      return true;
+    else return false;
+  }
+
+  private final TokenReader _in;
+  private Token _prev = null;
+  private Token _next;
+}
\ No newline at end of file

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter1.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter2.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter2.java?rev=425117&view=auto
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter2.java (added)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter2.java Mon Jul 24 09:58:43 2006
@@ -0,0 +1,320 @@
+/*
+ * Copyright 2000-2001,2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidadbuild.plugin.javascript.uixtools;
+
+import java.io.IOException;
+
+import java.util.Vector;
+import java.util.HashMap;
+
+/**
+ * Renames local variable names to short ones
+ * @version $Name:  $ ($Revision$) $Date$
+ * @author Arjuna Wijeyekoon - arjuna.wijeyekoon@oracle.com
+ */
+public class Filter2 implements TokenReader
+{
+
+  public Filter2(TokenReader in)
+  {
+    _in = in;
+    Runnable runner = new Runnable()
+      {
+        public void run()
+        {
+          try
+          {
+            //ystem.out.println("Compressor: start:"+Thread.currentThread());
+            _run();
+            //ystem.out.println("Comressor: end:"+Thread.currentThread());
+          }
+          catch (InterruptedException e)
+          {
+            e.printStackTrace();
+          }
+        }
+      };
+    new Thread(runner).start();
+  }
+
+  /**
+   * @see TokenReader#read()
+   */
+  public Token read() throws IOException, InterruptedException
+  {
+    return _buffer.read();
+  }
+
+  private void _run() throws InterruptedException
+  {
+    try
+    {
+      Token cur = _in.read();
+      for(;cur!=null;)
+      {
+        _process(cur);
+        cur = _in.read();
+      }
+    }
+    catch (IOException e)
+    {
+      _buffer.write(e);
+    }
+    catch (TokenException e)
+    {
+      e.printStackTrace();
+      _buffer.write(new IOException("Error parsing line:"+
+                                    e.getToken().lineNumber));
+    }
+    catch (RuntimeException e)
+    {
+      e.printStackTrace();
+      _buffer.write(new IOException());
+    }
+    _buffer.close();
+  }
+
+  /**
+   * renames local variable names to short names.
+   * First pass. sets a flag if this function uses the JS eval method.
+   */
+  private void _process(Token cur) throws InterruptedException
+  {
+    if ((cur.code == Token.LEFT_BRACE) && (cur.ch == '{'))
+      _openCurly++;
+    else if ((cur.code == Token.RIGHT_BRACE) && (cur.ch == '}'))
+      _openCurly--;
+
+
+    switch(_state)
+    {
+    case ROOT_MODE :
+      if ((cur.code==Token.RESERVED) && (cur.string.equals("function")))
+      {
+        _state = FUNCTION_PARAM_MODE;
+        _function.clear();
+        _isFunctionUsingEval = false;
+        _function.add(cur);
+      }
+      else _buffer.write(cur);
+      break;
+    case FUNCTION_PARAM_MODE :
+      _function.add(cur);
+      if ((cur.code==Token.LEFT_BRACE) && (cur.ch=='{'))
+      {
+        _state = FUNCTION_BODY_MODE;
+        _beginFunction = _openCurly;
+      }
+      break;
+    case FUNCTION_BODY_MODE :
+      _function.add(cur);
+      if (_openCurly<_beginFunction)
+      {
+        _state = ROOT_MODE;
+        if (_isFunctionUsingEval) _writeTokens(_function);
+        else
+        {
+          for(int i=0,sz=_function.size(); i<sz; i++)
+          {
+            _process2((Token) _function.get(i));
+          }
+        }
+      }
+      else if ((cur.code==Token.NAME) && cur.string.equals("eval"))
+      {
+        _isFunctionUsingEval = true;
+      }
+      break;
+    }
+  }
+
+  /**
+   * 2nd pass
+   * Does the actual renaming
+   */
+  private void _process2(Token cur) throws InterruptedException
+  {
+    if ((cur.code == Token.LEFT_BRACE) && (cur.ch == '{'))
+      _openCurly++;
+    else if ((cur.code == Token.RIGHT_BRACE) && (cur.ch == '}'))
+      _openCurly--;
+
+    switch(_state)
+    {
+    case ROOT_MODE :
+      if ((cur.code==Token.RESERVED) && (cur.string.equals("function")))
+        _state = FUNCTION_MODE;
+      break;
+    case FUNCTION_MODE :
+      if ((cur.code==Token.LEFT_BRACE) && (cur.ch=='('))
+      {
+        _state = FUNCTION_PARAM_MODE;
+        _localVarMap.clear();
+      }
+      else if (cur.code==Token.NAME)
+      {
+        //ystem.out.println("function name;"+cur.string);
+        _nameGen.reset();
+      }
+      break;
+    case FUNCTION_PARAM_MODE :
+      if ((cur.code==Token.LEFT_BRACE) && (cur.ch=='{'))
+      {
+        _state = FUNCTION_BODY_MODE;
+        _beginFunction = _openCurly;
+      }
+      else if (cur.code == Token.NAME)
+      {
+        //ystem.out.println(" param:"+cur.string);
+        Token tok = _getNewToken(cur);
+        cur = tok;
+      }
+      break;
+    case FUNCTION_BODY_MODE :
+      if (_openCurly<_beginFunction)
+      {
+        _state = ROOT_MODE;
+      }
+      else if (cur.code==Token.PERIOD)
+        _state = PERIOD_MODE;
+      else if ((cur.code==Token.RESERVED) && (cur.string.equals("var")))
+        _state = VAR_DEF_MODE;
+      else if (cur.code==Token.NAME)
+      {
+        cur = _substForToken(cur);
+      }
+      break;
+    case VAR_DEF_MODE :
+      if (cur.code==Token.NAME)
+      {
+        _state = FUNCTION_BODY_MODE;
+        //ystem.out.println(" local var:"+cur.string);
+        Token tok = _getNewToken(cur);
+        cur = tok;
+      }
+      break;
+    case PERIOD_MODE :
+      // this is just to skip the next token after a period.
+      _state = FUNCTION_BODY_MODE;
+      break;
+    }
+    _buffer.write(cur);
+  }
+
+  private void _writeTokens(Vector tokens) throws InterruptedException
+  {
+    for(int i=0,sz=tokens.size(); i<sz; i++)
+    {
+      _buffer.write((Token) tokens.get(i));
+    }
+  }
+
+  /**
+   * @return a new token to replace the old one with. the new one will have
+   *  a short name
+   */
+  private Token _getNewToken(Token oldToken)
+  {
+    String oldName = oldToken.string;
+    String newName = (String) _localVarMap.get(oldName);
+    if (newName==null)
+    {
+      newName = _nameGen.getNext();
+      _localVarMap.put(oldName, newName);
+    }
+    return new Token(oldToken.code, oldToken.lineNumber, newName);
+  }
+
+  /**
+   * @return the substitute token. if no token has been substituted for the
+   *  <code>oldToken</code> then the <code>oldToken</code> is returned.
+   * @param oldToken the token to substitute for.
+   */
+  private Token _substForToken(Token oldToken)
+  {
+    String oldName = oldToken.string;
+    String newName = (String) _localVarMap.get(oldName);
+    if (newName==null)
+    {
+      if (_nameGen.isInUse(oldName))
+        throw new TokenException(oldToken,
+                                 "Conflict with global var:"+oldName);
+      return oldToken;
+    }
+    Token tok = new Token(oldToken.code, oldToken.lineNumber, newName);
+    return tok;
+  }
+
+  private class NameGen
+  {
+    private int _i = 0;
+    private char _ch = 'a';
+    private final StringBuffer _sb = new StringBuffer();
+
+    /**
+     * @return a new unique short name
+     */
+    public String getNext()
+    {
+      _sb.setLength(0);
+      return _sb.append(_ch).append(_i++).toString();
+    }
+
+    public void reset()
+    {
+      _i = 0;
+    }
+
+    /**
+     * @return true if <code>varName</code> has already been returned by
+     *   the method <code>getNext()</code>
+     * @see #getNext()
+     */
+    public boolean isInUse(String varName)
+    {
+      int sz=varName.length();
+      if ((varName.charAt(0)!=_ch) || (sz<=1)) return false;
+
+      for(int i=1; i<sz; i++)
+      {
+        if (!Character.isDigit(varName.charAt(i))) return false;
+      }
+      String ipart = varName.substring(1);
+      int j = Integer.parseInt(ipart);
+      if (j >= _i) return false;
+      else return true;
+    }
+  }
+
+  private int _state = ROOT_MODE;
+  private int _openCurly = 0;
+  private int _beginFunction = 0;
+  private boolean _isFunctionUsingEval = false;
+
+  private final TokenReader _in;
+  private final NameGen _nameGen = new NameGen();
+  private final HashMap _localVarMap = new HashMap();
+  private final TokenBuffer _buffer = new TokenBuffer();
+  private final Vector _function = new Vector();
+
+  private static final int ROOT_MODE =           0;
+  private static final int FUNCTION_MODE =       1;
+  private static final int FUNCTION_PARAM_MODE = 2;
+  private static final int FUNCTION_BODY_MODE =  3;
+  private static final int VAR_DEF_MODE =        4;
+  private static final int PERIOD_MODE =         5;
+
+}
\ No newline at end of file

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter2.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL