0.8.0 • Published 1 year ago

apex-lazy-static v0.8.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

The CLI tool to lazify apex static variables.

As the CLI works with a file system and there might be bugs use it on your own risk.

Config Guide

Here is a default config you get when calling als init-config

export default {
    projectRoot: './',
    isRecursiveSearch: true,
    regexesToExcludeNames: [],
    regexesToMatchClassFiles: [],
    pathToApexClassForTypeExclusion: null,
    skipLiteralNumberAssignments: true,
    skipLiteralStringAssignments: true,
    skipLiteralBooleanAssignments: true,
    getSetVisibilityTheSameAsVariable: true,
    propTextGenerator:  function  (rawModifiers, varVisibility, rawType, rawName, cleanName, rawAssignmentExpr) {

        rawAssignmentExpr =
            rawAssignmentExpr.split('\n').map( (part, index) => index == 0 ? part : ' '.repeat(20) + part).join('\n');

        return '' +
            `    ` + `${rawModifiers} ${rawType} ${rawName} {\n` +
            `    ` + `    ${varVisibility ? varVisibility + ' get' : 'get'} {\n` +
            `\n`   +
            `    ` + `        if (${cleanName} == null) {\n` +
            `\n`   +
            `    ` + `            ${cleanName} ${rawAssignmentExpr};\n` +
            `    ` + `        }\n` +
            `\n`   +
            `    ` + `        return ${cleanName};\n` +
            `    ` + `    }\n` +
            `    ` + `    ${varVisibility} set;\n` +
            `    ` + `}`;
    }
};

projectRoot - path to look for apex classes from.

isRecursiveSearch - whether to look for apex classes in projectRoot visiting all the subdirectories.

regexesToExcludeNames - an array of regexes for excluding static variables with names that match these regexes regexesToMatchClassFiles - if not empty, array of regexes to match classfile names to process. For example [/^(?!.*Test).*$/] - match classfiles that don't have 'Test' word in it.

pathToApexClassForTypeExclusion - path to an ApexClass whose static variable types will be used to filter out static variables from processing. For example you specify a path to the class that has

public static final Map<String, List<Integer>> myvar;

variables - in the processing scope all the static variables with Map<String, List<Integer>> type will not be converted to lazy version.

skipLiteralNumberAssignments - if true - static variables that have a number literal as its initializing expression will not be converted.

skipLiteralStringAssignments - if true - static variables that have a string literal as its initializing expression will not be converted.

skipLiteralBooleanAssignments - if true - static variables that have a boolean literal as its initializing expression will not be converted.

getSetVisibilityTheSameAsVariable - resulting get and set methods will have the same visibility modifier as its variable.

propTextGenerator - here you can specify your own function for generating text that replaces the non-lazy variable.

0.8.0

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago