Skip to content

Commit

Permalink
Change empty string to Optional<String>
Browse files Browse the repository at this point in the history
  • Loading branch information
eebus committed Jan 31, 2017
1 parent c4a20c2 commit ef60e98
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
Expand Up @@ -26,6 +26,7 @@
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
Expand Down Expand Up @@ -90,7 +91,7 @@ private Callables loadProcedures( URL jar, ClassLoader loader, Callables target
while ( classes.hasNext() )
{
Class<?> next = classes.next();
target.addAllProcedures( compiler.compileProcedure( next ) );
target.addAllProcedures( compiler.compileProcedure( next, Optional.empty() ) );
target.addAllFunctions( compiler.compileFunction( next ) );
target.addAllAggregationFunctions( compiler.compileAggregationFunction( next ) );
}
Expand Down
Expand Up @@ -140,7 +140,7 @@ public void registerProcedure( Class<?> proc ) throws KernelException
*/
public void registerProcedure( Class<?> proc, boolean overrideCurrentImplementation ) throws KernelException
{
registerProcedure( proc, overrideCurrentImplementation, "" );
registerProcedure( proc, overrideCurrentImplementation, Optional.empty() );
}

/**
Expand All @@ -149,7 +149,9 @@ public void registerProcedure( Class<?> proc, boolean overrideCurrentImplementat
* @param overrideCurrentImplementation set to true if procedures within this class should override older procedures with the same name
* @param warning the warning the procedure should generate when called
*/
public void registerProcedure( Class<?> proc, boolean overrideCurrentImplementation, String warning ) throws KernelException
public void registerProcedure( Class<?> proc, boolean overrideCurrentImplementation, Optional<String> warning )
throws
KernelException
{
for ( CallableProcedure procedure : compiler.compileProcedure( proc, warning ) )
{
Expand Down
Expand Up @@ -152,12 +152,7 @@ List<CallableUserAggregationFunction> compileAggregationFunction( Class<?> fcnDe
}
}

List<CallableProcedure> compileProcedure( Class<?> procDefinition ) throws KernelException
{
return compileProcedure( procDefinition, "" );
}

List<CallableProcedure> compileProcedure( Class<?> procDefinition, String warning ) throws KernelException
List<CallableProcedure> compileProcedure( Class<?> procDefinition, Optional<String> warning ) throws KernelException
{
try
{
Expand Down Expand Up @@ -191,7 +186,8 @@ List<CallableProcedure> compileProcedure( Class<?> procDefinition, String warnin
}
}

private ReflectiveProcedure compileProcedure( Class<?> procDefinition, MethodHandle constructor, Method method, String warning )
private ReflectiveProcedure compileProcedure( Class<?> procDefinition, MethodHandle constructor, Method method,
Optional<String> warning )
throws ProcedureException, IllegalAccessException
{
String valueName = method.getAnnotation( Procedure.class ).value();
Expand Down Expand Up @@ -222,11 +218,9 @@ private ReflectiveProcedure compileProcedure( Class<?> procDefinition, MethodHan
Optional<String> deprecated = deprecated( method, procedure::deprecatedBy,
"Use of @Procedure(deprecatedBy) without @Deprecated in " + procName );

Optional<String> warn = (warning == null || warning.isEmpty()) ? Optional.empty() : Optional.of( warning );

ProcedureSignature signature =
new ProcedureSignature( procName, inputSignature, outputMapper.signature(),
mode, deprecated, config.rolesFor( procName.toString() ), description, warn );
mode, deprecated, config.rolesFor( procName.toString() ), description, warning );

return new ReflectiveProcedure( signature, constructor, procedureMethod, outputMapper, setters );
}
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.junit.rules.ExpectedException;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import org.neo4j.collection.RawIterator;
Expand Down Expand Up @@ -75,7 +76,8 @@ public void shouldInjectLogging() throws KernelException
// Given
Log log = spy( Log.class );
components.register( Log.class, (ctx) -> log );
CallableProcedure procedure = procedureCompiler.compileProcedure( LoggingProcedure.class ).get( 0 );
CallableProcedure procedure =
procedureCompiler.compileProcedure( LoggingProcedure.class, Optional.empty() ).get( 0 );

// When
procedure.apply( new BasicContext(), new Object[0] );
Expand Down Expand Up @@ -275,7 +277,8 @@ public void shouldSupportProcedureDeprecation() throws Throwable
ProcedureAllowedConfig.DEFAULT );

// When
List<CallableProcedure> procs = procedureCompiler.compileProcedure( ProcedureWithDeprecation.class );
List<CallableProcedure> procs =
procedureCompiler.compileProcedure( ProcedureWithDeprecation.class, Optional.empty() );

// Then
verify( log ).warn( "Use of @Procedure(deprecatedBy) without @Deprecated in badProc" );
Expand Down Expand Up @@ -521,6 +524,6 @@ public void badProc()

private List<CallableProcedure> compile( Class<?> clazz ) throws KernelException
{
return procedureCompiler.compileProcedure( clazz );
return procedureCompiler.compileProcedure( clazz, Optional.empty() );
}
}
Expand Up @@ -28,6 +28,7 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import org.neo4j.collection.RawIterator;
Expand Down Expand Up @@ -214,6 +215,7 @@ public Stream<MyOutputRecord> defaultValues( @Name( value = "a", defaultValue =

private List<CallableProcedure> compile( Class<?> clazz ) throws KernelException
{
return new ReflectiveProcedureCompiler( new TypeMappers(), new ComponentRegistry(), NullLog.getInstance(), ProcedureAllowedConfig.DEFAULT ).compileProcedure( clazz );
return new ReflectiveProcedureCompiler( new TypeMappers(), new ComponentRegistry(), NullLog.getInstance(),
ProcedureAllowedConfig.DEFAULT ).compileProcedure( clazz, Optional.empty() );
}
}
Expand Up @@ -24,6 +24,7 @@
import org.junit.rules.ExpectedException;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import org.neo4j.helpers.collection.Iterators;
Expand Down Expand Up @@ -128,6 +129,7 @@ private List<CallableProcedure> compile( Class<?> clazz ) throws KernelException
{
ComponentRegistry components = new ComponentRegistry();
components.register( MyAwesomeAPI.class, (ctx) -> new MyAwesomeAPI() );
return new ReflectiveProcedureCompiler( new TypeMappers(), components, NullLog.getInstance(), ProcedureAllowedConfig.DEFAULT ).compileProcedure( clazz );
return new ReflectiveProcedureCompiler( new TypeMappers(), components, NullLog.getInstance(),
ProcedureAllowedConfig.DEFAULT ).compileProcedure( clazz, Optional.empty() );
}
}
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -110,7 +111,8 @@ public void setup( Dependencies dependencies ) throws KernelException
ctx -> authManager.getUserManager( asEnterprise( ctx.get( SECURITY_CONTEXT ) ) ) );
if ( config.get( SecuritySettings.auth_providers ).size() > 1 )
{
procedures.registerProcedure( UserManagementProcedures.class, true, "%s only applies to native users." );
procedures.registerProcedure( UserManagementProcedures.class, true,
Optional.of( "%s only applies to native users." ) );
}
else
{
Expand Down

0 comments on commit ef60e98

Please sign in to comment.