Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions .claude/tasks/optimization.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,22 @@ public AstRenderBlockWith( String scopePath, TemplateType type, AstRender scopeA

@Override
public void render( Render render ) {
String sv = render.newVariableWithCustomPrefix( "with_" );
render
.ntab().append( "// --- with ( %s )", scopePath )
.ntab().append( "%s %s = null;", scopeType.getTypeName(), sv );
scopeAst.render( render.withScopeVar( sv ) );
render.ntab().append( "// --- with ( %s )", scopePath );

render.ntab().append( "// --- with ( %s ) START BODY ", scopePath );
String sv;
if( isSingleLevelField( scopeAst ) ) {
AstRenderField sf = ( AstRenderField ) scopeAst;
new AstRenderField( sf.fieldName, sf.type, sf.forceCast, sf.castType ).render( render );
sv = render.newVariable( sf.fieldName ).name;
} else {
sv = render.newVariableWithCustomPrefix( "with_" );
render.ntab().append( "%s %s = null;", scopeType.getTypeName(), sv );
scopeAst.render( render.withScopeVar( sv ) );
}

render.ntab().append( "// --- with ( %s ) START BODY", scopePath );

Render bodyRender = render.newBlock().withField( sv ).withParentType( scopeType );
Render bodyRender = render.newBlock().withFieldDirect( sv ).withParentType( scopeType );
boolean hasNullable = bodyChildren.stream().anyMatch( c -> extractNullable( c ) != null );

if( hasNullable ) {
Expand Down Expand Up @@ -93,6 +100,14 @@ public void render( Render render ) {
render.ntab().append( "// --- with ( %s ) END body ", scopePath ).n();
}

private static boolean isSingleLevelField( AstRender scopeAst ) {
if( !( scopeAst instanceof AstRenderField sf ) ) return false;
if( sf.children.size() != 1 ) return false;
AstRender child = sf.children.getFirst();
if( !( child instanceof AstRenderNullable ) ) return false;
return child.children.size() == 1 && child.children.getFirst() instanceof AstRenderCaptureScope;
}

private static AstRenderNullable extractNullable( AstRender child ) {
if( child instanceof AstRenderNullable n ) return n;
if( child instanceof AstRenderComment c && c.children.size() == 1 && c.children.getFirst() instanceof AstRenderNullable n ) return n;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ public Render withScopeVar( String scopeVar ) {
this.templateAccumulatorName, this.tab, ids, tryVariable, booleanIfVar, scopeVar, rootField, prefix, rangeVarMap, variables );
}

public Render withFieldDirect( String field ) {
return new Render( this.sb, this.templateName, this.content, this.parentType, this.templateAccumulator, field,
this.templateAccumulatorName, this.tab, ids, tryVariable, booleanIfVar, scopeVar, rootField, field, rangeVarMap, variables );
}

public Render withRootField( String rootField ) {
return new Render( this.sb, this.templateName, this.content, this.parentType, this.templateAccumulator, this.field,
this.templateAccumulatorName, this.tab, ids, tryVariable, booleanIfVar, scopeVar, rootField, prefix, rangeVarMap, variables );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void testBlockWithMultipleFields() {
"{{% with child }}{{ field }}-{{ field2 }}{{% end }}", STRING, null ).render( c ).get() )
.isEqualTo( "f1-f2" );

assertThat( listener.javaCode ).containsOnlyOnce( "if ( with_1 != null ) {" );
assertThat( listener.javaCode )
.containsOnlyOnce( """
oap.template.TestTemplateClass s_child = s.child;
// --- with ( child ) START BODY
if ( s_child != null ) {
""" );
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</distributionManagement>

<properties>
<oap.project.version>25.6.1</oap.project.version>
<oap.project.version>25.6.2</oap.project.version>

<oap.deps.config.version>25.0.1</oap.deps.config.version>
<oap.deps.oap-teamcity.version>25.0.0</oap.deps.oap-teamcity.version>
Expand Down
Loading