diff --git a/src/main/java/net/mcreator/generator/GeneratorConfiguration.java b/src/main/java/net/mcreator/generator/GeneratorConfiguration.java index 70804891ee0..aa864af86a5 100644 --- a/src/main/java/net/mcreator/generator/GeneratorConfiguration.java +++ b/src/main/java/net/mcreator/generator/GeneratorConfiguration.java @@ -66,6 +66,12 @@ public static GeneratorConfiguration getRecommendedGeneratorForBaseLanguage( private final Map templateGeneratorConfigs = new ConcurrentHashMap<>(); + // Cached values + private final List compatibleJavaModelKeys = new ArrayList<>(); + private final List compatibleJavaModelRequirementKeyWords = new ArrayList<>(); + private final List importFormatterDuplicatesWhitelist = new ArrayList<>(); + private final Map importFormatterPriorityImports = new HashMap<>(); + public GeneratorConfiguration(String generatorName) { this.generatorName = generatorName; @@ -89,6 +95,43 @@ public GeneratorConfiguration(String generatorName) { // load global variable definitions this.generatorVariableTypes = new GeneratorVariableTypes(this); + // Preprocess compatible java model keys + compatibleJavaModelKeys.add(getJavaModelsKey()); + if (generatorConfig.get("java_models") != null) { + if (((Map) generatorConfig.get("java_models")).get("compatible") != null) { + compatibleJavaModelKeys.addAll( + ((List) ((Map) generatorConfig.get("java_models")).get("compatible")).stream() + .map(Object::toString).toList()); + } + } + + // Preprocess compatible java model requirement keywords + if (generatorConfig.get("java_models") != null) { + if (((Map) generatorConfig.get("java_models")).get("requested_key_words") != null) { + compatibleJavaModelRequirementKeyWords.addAll( + ((List) ((Map) generatorConfig.get("java_models")).get("requested_key_words")).stream() + .map(Object::toString).toList()); + } + } + + // Preprocess import formatter duplicates whitelist + if (generatorConfig.get("import_formatter") != null) { + if (((Map) generatorConfig.get("import_formatter")).get("duplicates_whitelist") != null) { + importFormatterDuplicatesWhitelist.addAll( + ((List) ((Map) generatorConfig.get("import_formatter")).get( + "duplicates_whitelist")).stream().map(Object::toString).toList()); + } + } + + // Preprocess import formatter priority imports + if (generatorConfig.get("import_formatter") != null) { + if (((Map) generatorConfig.get("import_formatter")).get("priority_imports") != null) { + ((Map) ((Map) generatorConfig.get("import_formatter")).get("priority_imports")).forEach( + (k, v) -> importFormatterPriorityImports.put("." + k, v + "." + k)); + } + } + + // compute generator stats this.generatorStats = new GeneratorStats(this); } @@ -169,57 +212,19 @@ public String getJavaModelsKey() { } public List getCompatibleJavaModelKeys() { - List retval = new ArrayList<>(); - retval.add(getJavaModelsKey()); - - if (generatorConfig.get("java_models") != null) { - if (((Map) generatorConfig.get("java_models")).get("compatible") != null) { - retval.addAll(((List) ((Map) generatorConfig.get("java_models")).get("compatible")).stream() - .map(Object::toString).toList()); - } - } - - return retval; + return compatibleJavaModelKeys; } public List getJavaModelRequirementKeyWords() { - List retval = new ArrayList<>(); - - if (generatorConfig.get("java_models") != null) { - if (((Map) generatorConfig.get("java_models")).get("requested_key_words") != null) { - retval.addAll( - ((List) ((Map) generatorConfig.get("java_models")).get("requested_key_words")).stream() - .map(Object::toString).toList()); - } - } - - return retval; + return compatibleJavaModelRequirementKeyWords; } public List getImportFormatterDuplicatesWhitelist() { - List retval = new ArrayList<>(); - - if (generatorConfig.get("import_formatter") != null) { - if (((Map) generatorConfig.get("import_formatter")).get("duplicates_whitelist") != null) { - retval.addAll(((List) ((Map) generatorConfig.get("import_formatter")).get( - "duplicates_whitelist")).stream().map(Object::toString).toList()); - } - } - - return retval; + return importFormatterDuplicatesWhitelist; } public Map getImportFormatterPriorityImports() { - Map retval = new HashMap<>(); - - if (generatorConfig.get("import_formatter") != null) { - if (((Map) generatorConfig.get("import_formatter")).get("priority_imports") != null) { - ((Map) ((Map) generatorConfig.get("import_formatter")).get("priority_imports")).forEach( - (k, v) -> retval.put("." + k, v + "." + k)); - } - } - - return retval; + return importFormatterPriorityImports; } public String getGeneratorName() { @@ -307,4 +312,5 @@ public GeneratorVariableTypes getVariableTypes() { return o.getGeneratorStats().getStatus().ordinal() - generatorStats.getStatus().ordinal(); } } + }