All Downloads are FREE. Search and download functionalities are using the official Maven repository.

genesis.metaData.js Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2015 by Sebastian Hasait (sebastian at hasait dot de)
 *
 * 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.
 */

function process(scriptEnv) {
    var typeElement = scriptEnv.typeElement;
    var packageElement = typeElement.getEnclosingElement();
    var srcW = scriptEnv.createSrcFileWithSuffix("_MD");

    srcW.println("// Generated by " + scriptEnv.scriptFileName);
    srcW.println("package " + packageElement.getQualifiedName() + ";");
    srcW.println();
    srcW.println("/** MetaData for " + typeElement.getQualifiedName() + " */");
    srcW.println("public class " + typeElement.getSimpleName() + "_MD {");

    var processedPropertyNames = new java.util.HashSet();

    for each (var subElement in typeElement.getEnclosedElements()) {
        var propertyName = scriptEnv.determinePropertyNameFromAccessor(subElement);
        if (propertyName != null && !processedPropertyNames.contains(propertyName)) {
            processedPropertyNames.add(propertyName);

            srcW.println();
            srcW.println("\tpublic static final String " + scriptEnv.camelCaseToUpperCase(propertyName) + "__NAME = \"" + propertyName + "\";");

            var propertyType = scriptEnv.determinePropertyTypeFromAccessor(subElement);
            var propertyTypeJavaSrc = scriptEnv.typeMirrorToJavaSrc(propertyType);
            srcW.println("\tpublic static final Class " + scriptEnv.camelCaseToUpperCase(propertyName) + "__TYPE = " + propertyTypeJavaSrc + ";");
        }
    }

    srcW.println();
    srcW.println("}");

    srcW.close();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy