package fi.vincit.jmobster.processor.languages.javascript.valueconverters;
/*
 * Copyright 2012 Juha Siponen
 *
 * 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.
*/

/**
 * Converter for Java Enums. Primitive enum types are
 * boxed to Enum objects and converted using this
 * converter. Enums are considered as Strings in JavaScript.
 */
public final class EnumConverter extends StringConverter {
    public static enum EnumMode {
        STRING,
        ORDINAL
    }

    private final EnumMode enumMode;

    public EnumConverter(EnumMode enumMode) {
        this.enumMode = enumMode;
    }

    @Override
    protected String getValueAsString( Object value ) {
        switch( enumMode ) {
            case STRING: return super.getValueAsString(value);
            case ORDINAL: return getEnumOrdinal(value);
            default:
                throw new RuntimeException("Invalid enum mode: " + enumMode);
        }
    }

    private String getEnumOrdinal( Object value ) {
        Enum enumValue = (Enum)value;
        return "" + enumValue.ordinal();
    }
}

@@ -789,55 +789,8 @@
 ter.
- Enums are considered as Strings in JavaScript.
 %0A */
@@ -857,114 +857,453 @@
     
-public static enum EnumMode %7B%0A        STRING,%0A        ORDINAL%0A    %7D%0A%0A    private final EnumMode enumMode;%0A
+/**%0A     * How enums are converted%0A     */%0A    public static enum EnumMode %7B%0A        /**%0A         * Enums are converted to strings. E.g. ENUM1 will be converted to %22ENUM1%22%0A         */%0A        STRING,%0A        /**%0A         * Enums are converted to ordinals (starting from zero)%0A         */%0A        ORDINAL%0A    %7D%0A%0A    private final EnumMode enumMode;%0A%0A    /**%0A     * Constructs an enum converter.%0A     * @param enumMode Enum conversion mode%0A     */
 %0A   
@@ -1712,32 +1712,211 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * Returns the enum ordinal (first being zero) as string%0A     * @param value Value to convert (must be instance of Enum)%0A     * @return Enum ordinal as string%0A     */%0A
     private Stri

Add and fix documentation for EnumConverter