private void delegateCall( AbstractSrcMethod method, boolean isInstanceExtensionMethod, SrcMethod srcMethod ) { StringBuilder call = new StringBuilder(); SrcType returnType = srcMethod.getReturnType(); if( returnType != null && !returnType.getName().equals( void.class.getName() ) ) { call.append( "return " ); } String extClassName = ((SrcClass)method.getOwner()).getName(); call.append( extClassName ).append( '.' ).append( srcMethod.getSimpleName() ).append( '(' ); if( isInstanceExtensionMethod ) { call.append( "this" ); } for( SrcParameter param : srcMethod.getParameters() ) { if( call.charAt( call.length()-1 ) != '(' ) { call.append( ", " ); } call.append( param.getSimpleName() ); } call.append( ");\n" ); srcMethod.body( new SrcStatementBlock() .addStatement( new SrcRawStatement() .rawText( call.toString() ) ) ); }
public StringBuilder render( StringBuilder sb, int indent, boolean sameLine ) { if( sameLine ) { sb.append( " {\n" ); } else { sb.append( indent( sb, indent ) ).append( "{\n" ); } for( SrcStatement stmt : _statements ) { stmt.render( sb, indent + INDENT ); } sb.append( indent( sb, indent ) ).append( "}\n" ); return sb; } }
@Override public StringBuilder render( StringBuilder sb, int indent ) { return render( sb, indent, true ); }
public SrcClass addStaticBlock( SrcStatementBlock block ) { _staticBlocks.add( block ); block.setOwner( this ); return this; }
private void delegateCall( AbstractSrcMethod method, boolean isInstanceExtensionMethod, SrcMethod srcMethod ) { StringBuilder call = new StringBuilder(); SrcType returnType = srcMethod.getReturnType(); if( returnType != null && !returnType.getName().equals( void.class.getName() ) ) { call.append( "return " ); } String extClassName = ((SrcClass)method.getOwner()).getName(); call.append( extClassName ).append( '.' ).append( srcMethod.getSimpleName() ).append( '(' ); if( isInstanceExtensionMethod ) { call.append( "this" ); } for( SrcParameter param : srcMethod.getParameters() ) { if( call.charAt( call.length()-1 ) != '(' ) { call.append( ", " ); } call.append( param.getSimpleName() ); } call.append( ");\n" ); srcMethod.body( new SrcStatementBlock() .addStatement( new SrcRawStatement() .rawText( call.toString() ) ) ); }
private void renderStaticBlocks( StringBuilder sb, int indent ) { sb.append( "\n" ).append( indent( sb, indent ) ).append( "// static blocks //\n" ); for( SrcStatementBlock block : _staticBlocks ) { sb.append( "\n" ).append( indent( sb, indent ) ).append( "static {" ); block.render( sb, indent ); sb.append( "\n" ).append( indent( sb, indent ) ).append( "}" ); } }
private void addGetValueMethod( SrcClass srcClass, FqnCacheNode<String> node ) { srcClass.addMethod( new SrcMethod( srcClass ) .name( "getValue" ) .modifiers( Modifier.PUBLIC | (isRootProperty( node ) ? Modifier.STATIC : 0) ) .returns( new SrcType( "String" ) ) .body( new SrcStatementBlock() .addStatement( new SrcReturnStatement( String.class, node.getUserData() ) ) ) ); }
@Override public StringBuilder render( StringBuilder sb, int indent ) { indent( sb, indent ); sb.append( "case " ).append( _expr ).append( ":\n" ); if( _stmt != null ) { if( _stmt instanceof SrcStatementBlock ) { ((SrcStatementBlock)_stmt).render( sb, indent, false ); } else { _stmt.render( sb, indent + INDENT ); } } return sb; } }
private void addGetValueByNameMethod( SrcClass srcClass, FqnCacheNode<String> node ) { srcClass.addMethod( new SrcMethod( srcClass ) .name( "getValueByName" ) .modifiers( Modifier.PUBLIC | (isRootProperty( node ) ? Modifier.STATIC : 0) ) .returns( new SrcType( "String" ) ) .addParam( new SrcParameter( "propertyName" ).type( "String" ) ) .body( new SrcStatementBlock() .addStatement( makeGetValueBynameSwitch( node ) ) .addStatement( new SrcReturnStatement( String.class, null ) ) ) ); }
public StringBuilder render( StringBuilder sb, int indent, boolean sameLine ) { indent( sb, indent ); sb.append( "switch(" ).append( _expr ).append( ") { \n" ); for( SrcSwitchCase caseStmt : _cases ) { caseStmt.render( sb, indent + INDENT ); } if( _default != null ) { indent( sb, indent + INDENT ); sb.append( "default:\n" ); if( _default instanceof SrcStatementBlock ) { ((SrcStatementBlock)_default).render( sb, indent, false ); } else { _default.render( sb, indent + INDENT ); } } sb.append( indent( sb, indent ) ).append( "}\n" ); return sb; } }
private void addGetValueMethod( SrcClass srcClass, FqnCacheNode<String> node ) { srcClass.addMethod( new SrcMethod( srcClass ) .name( "getValue" ) .modifiers( Modifier.PUBLIC | (isRootProperty( node ) ? Modifier.STATIC : 0) ) .returns( new SrcType( "String" ) ) .body( new SrcStatementBlock() .addStatement( new SrcReturnStatement( String.class, node.getUserData() ) ) ) ); }
_body.render( sb, indent );
private void addGetValueByNameMethod( SrcClass srcClass, FqnCacheNode<String> node ) { srcClass.addMethod( new SrcMethod( srcClass ) .name( "getValueByName" ) .modifiers( Modifier.PUBLIC | (isRootProperty( node ) ? Modifier.STATIC : 0) ) .returns( new SrcType( "String" ) ) .addParam( new SrcParameter( "propertyName" ).type( "String" ) ) .body( new SrcStatementBlock() .addStatement( makeGetValueBynameSwitch( node ) ) .addStatement( new SrcReturnStatement( String.class, null ) ) ) ); }
private void addToString( SrcClass srcClass ) { srcClass.addMethod( new SrcMethod( srcClass ) .name( "toString" ) .modifiers( Modifier.PUBLIC ) .returns( new SrcType( "String" ) ) .body( new SrcStatementBlock() .addStatement( new SrcReturnStatement( new SrcMethodCallExpression( "getValue" ) ) ) ) ); }
private void addToString( SrcClass srcClass ) { srcClass.addMethod( new SrcMethod( srcClass ) .name( "toString" ) .modifiers( Modifier.PUBLIC ) .returns( new SrcType( "String" ) ) .body( new SrcStatementBlock() .addStatement( new SrcReturnStatement( new SrcMethodCallExpression( "getValue" ) ) ) ) ); }
private static void addUtilityMethods( SrcClass clazz, ClassNode classNode, String fqn ) { long timestamp = incUid(); SrcMethod m = new SrcMethod() .name( "getEngine" ) .modifiers( Modifier.PRIVATE | Modifier.STATIC ) .returns( ScriptEngine.class ) .body( new SrcStatementBlock() .addStatement( new SrcRawStatement() .rawText( "if( " + timestamp + "L != TIMESTAMP ) {\n" + " synchronized( " + classNode.getName() + ".class ) {\n" + " if( " + timestamp + "L != TIMESTAMP ) {\n" + " TIMESTAMP = " + timestamp + "L;\n" + " ENGINE = JavascriptClass.init(\"" + fqn + "\");\n" + " }\n" + " }\n" + " }\n" + " return ENGINE;" ) ) ); clazz.addMethod( m ); }
private static void addUtilityMethods( SrcClass clazz, ClassNode classNode, String fqn ) { long timestamp = incUid(); SrcMethod m = new SrcMethod() .name( "getEngine" ) .modifiers( Modifier.PRIVATE | Modifier.STATIC ) .returns( ScriptEngine.class ) .body( new SrcStatementBlock() .addStatement( new SrcRawStatement() .rawText( "if( " + timestamp + "L != TIMESTAMP ) {\n" + " synchronized( " + classNode.getName() + ".class ) {\n" + " if( " + timestamp + "L != TIMESTAMP ) {\n" + " TIMESTAMP = " + timestamp + "L;\n" + " ENGINE = JavascriptClass.init(\"" + fqn + "\");\n" + " }\n" + " }\n" + " }\n" + " return ENGINE;" ) ) ); clazz.addMethod( m ); }
.type( URL.class ) ) .modifiers( Modifier.PRIVATE ) .body( new SrcStatementBlock() .addStatement( new SrcRawStatement() .rawText( "super(url);" ) ) .addStatement( new SrcRawStatement() .rawText( "INSTANCE = this;" ) ) ) ) .addMethod( new SrcMethod().modifiers( Modifier.PUBLIC | Modifier.STATIC ) .name( "get" ) .returns( simpleName ) .body( new SrcStatementBlock() .addStatement( new SrcRawStatement() .rawText( "try {" )
.addAnnotation( new SrcAnnotationExpression( This.class ) ) ) .returns( String.class ) .body( new SrcStatementBlock() .addStatement( new SrcReturnStatement( String.class, entry.getValue()._value.toString() ) ) ); method.addAnnotation( makeSourcePositionAnnotation( entry.getKey() ) );
.type( URL.class ) ) .modifiers( Modifier.PRIVATE ) .body( new SrcStatementBlock() .addStatement( new SrcRawStatement() .rawText( "super(url);" ) ) .addStatement( new SrcRawStatement() .rawText( "INSTANCE = this;" ) ) ) ) .addMethod( new SrcMethod().modifiers( Modifier.PUBLIC | Modifier.STATIC ) .name( "get" ) .returns( simpleName ) .body( new SrcStatementBlock() .addStatement( new SrcRawStatement() .rawText( "try {" )