<commit_before>

import {IUISchemaGenerator} from './generators';
import {PathUtil} from '../services/pathutil';
import {IUISchemaElement, IControlObject, ILayout} from '../../jsonforms';

export class UISchemaGenerator implements IUISchemaGenerator {

    /**
     * Creates a new ILayout.
     * @param layoutType The type of the laoyut
     * @returns the new ILayout
     */
    private static createLayout(layoutType: string): ILayout {
        return {
            type: layoutType,
            elements: []
        };
    }

    /**
     * Determines if the property should be ignored because it is a meta property
     */
    private static isIgnoredProperty(propertyKey: string, propertyValue: any): boolean {
        // could be a string (json-schema-id). Ignore in that case
        return propertyKey === 'id' && typeof propertyValue === 'string';
        // TODO ignore all meta keywords
    }

    /**
     * Derives the type of the jsonSchema element
     */
    private static deriveType(jsonSchema: any): string {
        if (jsonSchema.type) {
            return jsonSchema.type;
        }
        if (jsonSchema.properties || jsonSchema.additionalProperties) {
            return 'object';
        }
        // ignore all remaining cases
        return 'null';
    }

    /**
     * Creates a IControlObject with the given label referencing the given ref
     */
    private static getControlObject(label: string, ref: string): IControlObject {
        let control: IControlObject = {
            type: 'Control',
            scope: {
                $ref: ref
            }
        };
        if (label) {
            control.label = label;
        }
        return control;
    }

    /**
     * Wraps the given {@code uiSchema} in a VerticalLayout if there is none already.
     * @param uiSchema The ui schema to wrap in a vertical layout.
     * @returns the wrapped uiSchema.
     */
    private static wrapInLayoutIfNecessary
        (uiSchema: IUISchemaElement, layoutType: string): ILayout {
        if (uiSchema['elements'] === undefined) {
            let verticalLayout: ILayout = UISchemaGenerator.createLayout(layoutType);
            verticalLayout.elements.push(uiSchema);
            return verticalLayout;
        }
        return <ILayout>uiSchema;
    }

    generateDefaultUISchema(jsonSchema: any, layoutType?: string): IUISchemaElement {
        if (layoutType === undefined) {
            layoutType = 'VerticalLayout';
        }
        let uiSchema = this.generateUISchema(jsonSchema, [], '#', '', layoutType);
        return UISchemaGenerator.wrapInLayoutIfNecessary(uiSchema, layoutType);<commit_msg>incorporated edgars review<commit_after>

import {IUISchemaGenerator} from './generators';
import {PathUtil} from '../services/pathutil';
import {IUISchemaElement, IControlObject, ILayout} from '../../jsonforms';

export class UISchemaGenerator implements IUISchemaGenerator {

    /**
     * Creates a new ILayout.
     * @param layoutType The type of the laoyut
     * @returns the new ILayout
     */
    private static createLayout(layoutType: string): ILayout {
        return {
            type: layoutType,
            elements: []
        };
    }

    /**
     * Determines if the property should be ignored because it is a meta property
     */
    private static isIgnoredProperty(propertyKey: string, propertyValue: any): boolean {
        // could be a string (json-schema-id). Ignore in that case
        return propertyKey === 'id' && typeof propertyValue === 'string';
        // TODO ignore all meta keywords
    }

    /**
     * Derives the type of the jsonSchema element
     */
    private static deriveType(jsonSchema: any): string {
        if (jsonSchema.type) {
            return jsonSchema.type;
        }
        if (jsonSchema.properties || jsonSchema.additionalProperties) {
            return 'object';
        }
        // ignore all remaining cases
        return 'null';
    }

    /**
     * Creates a IControlObject with the given label referencing the given ref
     */
    private static getControlObject(label: string, ref: string): IControlObject {
        let control: IControlObject = {
            type: 'Control',
            scope: {
                $ref: ref
            }
        };
        if (label) {
            control.label = label;
        }
        return control;
    }

    /**
     * Wraps the given {@code uiSchema} in a Layout if there is none already.
     * @param uiSchema The ui schema to wrap in a layout.
     * @param layoutType The type of the layout to create.
     * @returns the wrapped uiSchema.
     */
    private static wrapInLayoutIfNecessary
        (uiSchema: IUISchemaElement, layoutType: string): ILayout {
        if (uiSchema['elements'] === undefined) {
            let verticalLayout: ILayout = UISchemaGenerator.createLayout(layoutType);
            verticalLayout.elements.push(uiSchema);
            return verticalLayout;
        }
        return <ILayout>uiSchema;
    }

    generateDefaultUISchema(jsonSchema: any, layoutType = 'VerticalLayout'): IUISchemaElement {
        let uiSchema = this.generateUISchema(jsonSchema, [], '#', '', layoutType);
        return UISchemaGenerator.wrapInLayoutIfNecessary(uiSchema, layoutType);
{'fraction_non_alphanumeric': 0.0955184200531713, 'fraction_numerical': 0.0, 'mean_word_length': 2.283665835411471, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7388493', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1367, 'n_words': 420}