Skip to content

Commit

Permalink
Fix tabulator performance (finos#830)
Browse files Browse the repository at this point in the history
* Fix tabulator performance

* Fix whitespace

* More whitespace fiddling

* Whitespace fiddling

* Update expectation

* Whitespace

* Got it
  • Loading branch information
hugohills-regnosys authored Sep 9, 2024
1 parent c20eb67 commit 2753bb1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
package com.regnosys.rosetta.generator.java.reports

import org.eclipse.xtext.generator.IFileSystemAccess2
import com.regnosys.rosetta.rosetta.simple.Data
import com.google.inject.ImplementedBy
import com.regnosys.rosetta.RosettaEcoreUtil
import com.regnosys.rosetta.config.RosettaConfiguration
import com.regnosys.rosetta.generator.GeneratedIdentifier
import com.regnosys.rosetta.generator.java.JavaScope
import javax.inject.Inject
import com.regnosys.rosetta.generator.java.types.JavaTypeTranslator
import org.eclipse.xtend2.lib.StringConcatenationClient
import com.regnosys.rosetta.generator.java.util.ImportManagerExtension
import com.rosetta.util.types.JavaClass
import com.rosetta.model.lib.reports.Tabulator
import com.regnosys.rosetta.rosetta.RosettaExternalRuleSource
import com.regnosys.rosetta.rosetta.RosettaReport
import com.regnosys.rosetta.rosetta.RosettaRule
import com.regnosys.rosetta.rosetta.simple.Data
import com.regnosys.rosetta.rosetta.simple.Function
import com.regnosys.rosetta.types.RAttribute
import com.regnosys.rosetta.types.RDataType
import com.rosetta.util.DottedPath
import com.regnosys.rosetta.types.RObjectFactory
import com.regnosys.rosetta.types.RosettaTypeProvider
import com.regnosys.rosetta.utils.ExternalAnnotationUtil
import com.regnosys.rosetta.utils.ModelIdProvider
import com.rosetta.model.lib.ModelSymbolId
import com.rosetta.model.lib.reports.Tabulator
import com.rosetta.model.lib.reports.Tabulator.Field
import com.rosetta.model.lib.reports.Tabulator.FieldImpl
import java.util.Optional
import com.regnosys.rosetta.generator.GeneratedIdentifier
import java.util.List
import java.util.Arrays
import com.rosetta.model.lib.reports.Tabulator.FieldValue
import java.util.stream.Collectors
import com.rosetta.model.lib.reports.Tabulator.FieldValueImpl
import com.regnosys.rosetta.rosetta.RosettaExternalRuleSource
import java.util.Map
import com.regnosys.rosetta.types.RosettaTypeProvider
import java.util.Set
import org.apache.commons.text.StringEscapeUtils
import com.rosetta.model.lib.reports.Tabulator.MultiNestedFieldValueImpl
import com.rosetta.model.lib.reports.Tabulator.NestedFieldValueImpl
import com.rosetta.model.lib.ModelSymbolId
import com.regnosys.rosetta.rosetta.RosettaReport
import com.regnosys.rosetta.rosetta.RosettaRule
import com.regnosys.rosetta.rosetta.simple.Function
import com.regnosys.rosetta.config.RosettaConfiguration
import com.regnosys.rosetta.utils.ModelIdProvider
import com.regnosys.rosetta.utils.ExternalAnnotationUtil
import com.google.inject.ImplementedBy
import com.regnosys.rosetta.types.RAttribute
import com.regnosys.rosetta.types.RObjectFactory
import com.rosetta.util.DottedPath
import com.rosetta.util.types.JavaClass
import java.util.Arrays
import java.util.List
import java.util.Map
import java.util.Objects
import com.regnosys.rosetta.RosettaEcoreUtil
import java.util.Optional
import java.util.Set
import java.util.stream.Collectors
import javax.inject.Inject
import javax.inject.Singleton
import org.apache.commons.text.StringEscapeUtils
import org.eclipse.xtend2.lib.StringConcatenationClient
import org.eclipse.xtext.generator.IFileSystemAccess2

class TabulatorGenerator {
private interface TabulatorContext {
Expand Down Expand Up @@ -296,7 +297,8 @@ class TabulatorGenerator {
'''
@«ImplementedBy»(«tabulatorClass».Impl.class)
public interface «tabulatorClass» extends «Tabulator»<«inputClass»> {
public class Impl implements «tabulatorClass» {
@«Singleton»
class Impl implements «tabulatorClass» {
private final «innerTabulatorClass» «innerTabulatorInstance»;
@«Inject»
Expand All @@ -317,6 +319,7 @@ class TabulatorGenerator {
'''
@«ImplementedBy»(«tabulatorClass».Impl.class)
public interface «tabulatorClass» extends «Tabulator»<«inputClass»> {
@«Singleton»
class Impl implements «tabulatorClass» {
@Override
Expand All @@ -341,7 +344,8 @@ class TabulatorGenerator {
'''
@«ImplementedBy»(«tabulatorClass».Impl.class)
public interface «tabulatorClass» extends «Tabulator»<«inputClass»> {
public class Impl implements «tabulatorClass» {
@«Singleton»
class Impl implements «tabulatorClass» {
«FOR attr : inputType.allNonOverridenAttributes»
«IF context.isTabulated(attr)»
«val fieldId = classScope.getIdentifierOrThrow(attr)»
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.rosetta.model.lib.reports;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -76,11 +77,11 @@ public interface FieldValueVisitor<C> {
void visitMultiNested(MultiNestedFieldValue fieldValue, C context);
}
public static class FieldImpl implements Field {
private String attributeName;
private boolean isMulti;
private Optional<ModelSymbolId> ruleId;
private Optional<String> identifier;
private List<Field> children;
private final String attributeName;
private final boolean isMulti;
private final Optional<ModelSymbolId> ruleId;
private final Optional<String> identifier;
private final List<Field> children;

public FieldImpl(String attributeName, boolean isMulti, Optional<ModelSymbolId> ruleId, Optional<String> identifier, List<Field> children) {
Objects.requireNonNull(ruleId);
Expand All @@ -91,7 +92,7 @@ public FieldImpl(String attributeName, boolean isMulti, Optional<ModelSymbolId>
this.attributeName = attributeName;
this.isMulti = isMulti;
this.identifier = identifier;
this.children = children;
this.children = Collections.unmodifiableList(children);
}
@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ class ConfigurableTypeTabulatorTest {
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import javax.inject.Singleton;
@ImplementedBy(FooTypeTabulator.Impl.class)
public interface FooTypeTabulator extends Tabulator<Foo> {
public class Impl implements FooTypeTabulator {
@Singleton
class Impl implements FooTypeTabulator {
private final Field barField;
public Impl() {
Expand Down Expand Up @@ -94,12 +96,14 @@ class ConfigurableTypeTabulatorTest {
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Singleton;
import model1.Foo;
@ImplementedBy(FooTypeTabulator.Impl.class)
public interface FooTypeTabulator extends Tabulator<Foo> {
public class Impl implements FooTypeTabulator {
@Singleton
class Impl implements FooTypeTabulator {
private final Field barField;
private final BarTypeTabulator barTypeTabulator;
Expand Down Expand Up @@ -163,12 +167,14 @@ class ConfigurableTypeTabulatorTest {
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.inject.Singleton;
import model2.EngineSpecification;
@ImplementedBy(EngineSpecificationTypeTabulator.Impl.class)
public interface EngineSpecificationTypeTabulator extends Tabulator<EngineSpecification> {
public class Impl implements EngineSpecificationTypeTabulator {
@Singleton
class Impl implements EngineSpecificationTypeTabulator {
private final Field fuelField;
public Impl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ class TabulatorTest {
import com.rosetta.test.model.Report;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
@ImplementedBy(TEST_REGCorpReportTabulator.Impl.class)
public interface TEST_REGCorpReportTabulator extends Tabulator<Report> {
public class Impl implements TEST_REGCorpReportTabulator {
@Singleton
class Impl implements TEST_REGCorpReportTabulator {
private final ReportTypeTabulator tabulator;
@Inject
Expand Down Expand Up @@ -139,11 +141,13 @@ class TabulatorTest {
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Singleton;
@ImplementedBy(ReportTypeTabulator.Impl.class)
public interface ReportTypeTabulator extends Tabulator<Report> {
public class Impl implements ReportTypeTabulator {
@Singleton
class Impl implements ReportTypeTabulator {
private final Field basicField;
private final Field subreportField;
private final Field subreportWithRuleField;
Expand Down Expand Up @@ -280,11 +284,13 @@ class TabulatorTest {
import java.util.Optional;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Singleton;
@ImplementedBy(ReportTypeTabulator.Impl.class)
public interface ReportTypeTabulator extends Tabulator<Report> {
public class Impl implements ReportTypeTabulator {
@Singleton
class Impl implements ReportTypeTabulator {
private final Field basicListField;
private final Field subreportListField;
Expand Down Expand Up @@ -475,11 +481,13 @@ class TabulatorTest {
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import javax.inject.Singleton;
@ImplementedBy(ReportTypeTabulator.Impl.class)
public interface ReportTypeTabulator extends Tabulator<Report> {
public class Impl implements ReportTypeTabulator {
@Singleton
class Impl implements ReportTypeTabulator {
private final Field basic1Field;
private final Field basic2Field;
private final Field basic3Field;
Expand Down

0 comments on commit 2753bb1

Please sign in to comment.