Skip to content

Commit

Permalink
Simplify the code generation API
Browse files Browse the repository at this point in the history
Remove specialized methods for different types of comparisons, instead
make the implementation perform the specialization.
  • Loading branch information
thobe committed Feb 21, 2017
1 parent 0efcc18 commit 4e4b518
Show file tree
Hide file tree
Showing 19 changed files with 983 additions and 403 deletions.
33 changes: 5 additions & 28 deletions community/codegen/src/main/java/org/neo4j/codegen/CodeBlock.java
Expand Up @@ -20,11 +20,7 @@
package org.neo4j.codegen; package org.neo4j.codegen;


import java.util.Iterator; import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;


import static org.neo4j.codegen.LocalVariables.copy; import static org.neo4j.codegen.LocalVariables.copy;
import static org.neo4j.codegen.MethodReference.methodReference; import static org.neo4j.codegen.MethodReference.methodReference;
Expand Down Expand Up @@ -163,33 +159,15 @@ public CodeBlock forEach( Parameter local, Expression iterable )
return block; return block;
} }


public CodeBlock whileLoop( Expression...tests ) public CodeBlock whileLoop( Expression test )
{ {
emitter.beginWhile( tests ); emitter.beginWhile( test );
return new CodeBlock( this ); return new CodeBlock( this );
} }


public CodeBlock ifStatement( Expression...tests ) public CodeBlock ifStatement( Expression test )
{ {
emitter.beginIf( tests ); emitter.beginIf( test );
return new CodeBlock( this );
}

public CodeBlock ifNotStatement( Expression...tests )
{
emitter.beginIfNot( tests );
return new CodeBlock( this );
}

public CodeBlock ifNullStatement( Expression...tests )
{
emitter.beginIfNull( tests );
return new CodeBlock( this );
}

public CodeBlock ifNonNullStatement( Expression...tests )
{
emitter.beginIfNonNull( tests );
return new CodeBlock( this ); return new CodeBlock( this );
} }


Expand All @@ -201,8 +179,7 @@ public CodeBlock block()


public void tryCatch( Consumer<CodeBlock> body, Consumer<CodeBlock> onError, Parameter exception ) public void tryCatch( Consumer<CodeBlock> body, Consumer<CodeBlock> onError, Parameter exception )
{ {
emitter.tryCatchBlock( body, onError, localVariables.createNew( exception.type(), exception.name() ), emitter.tryCatchBlock( body, onError, localVariables.createNew( exception.type(), exception.name() ), this );
this );
} }


public void returns() public void returns()
Expand Down

0 comments on commit 4e4b518

Please sign in to comment.