Skip to content

Commit

Permalink
Cache processing done in generatorconfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
KlemenDEV committed Jan 18, 2024
1 parent 0bce16a commit 555bfca
Showing 1 changed file with 48 additions and 42 deletions.
90 changes: 48 additions & 42 deletions src/main/java/net/mcreator/generator/GeneratorConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public static GeneratorConfiguration getRecommendedGeneratorForBaseLanguage(

private final Map<String, TemplateGeneratorConfiguration> templateGeneratorConfigs = new ConcurrentHashMap<>();

// Cached values
private final List<String> compatibleJavaModelKeys = new ArrayList<>();
private final List<String> compatibleJavaModelRequirementKeyWords = new ArrayList<>();
private final List<String> importFormatterDuplicatesWhitelist = new ArrayList<>();
private final Map<String, String> importFormatterPriorityImports = new HashMap<>();

public GeneratorConfiguration(String generatorName) {
this.generatorName = generatorName;

Expand All @@ -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);
}

Expand Down Expand Up @@ -169,57 +212,19 @@ public String getJavaModelsKey() {
}

public List<String> getCompatibleJavaModelKeys() {
List<String> 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<String> getJavaModelRequirementKeyWords() {
List<String> 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<String> getImportFormatterDuplicatesWhitelist() {
List<String> 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<String, String> getImportFormatterPriorityImports() {
Map<String, String> 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() {
Expand Down Expand Up @@ -307,4 +312,5 @@ public GeneratorVariableTypes getVariableTypes() {
return o.getGeneratorStats().getStatus().ordinal() - generatorStats.getStatus().ordinal();
}
}

}

0 comments on commit 555bfca

Please sign in to comment.