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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ matrix:
env: JACOCO=true
- jdk: openjdk8
env: JACOCO=true SONAR=publish
script: ./mvnw -V clean verify sonar:sonar --fail-at-end -U
notifications:
email:
on_failure: change
Empty file modified pom.xml
100755 → 100644
Empty file.
Empty file modified src/main/java/pl/wavesoftware/utils/stringify/Stringify.java
100755 → 100644
Empty file.
Empty file.
Empty file modified src/main/java/pl/wavesoftware/utils/stringify/api/Inspect.java
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

import pl.wavesoftware.utils.stringify.api.Configuration;
import pl.wavesoftware.utils.stringify.api.Mode;
import pl.wavesoftware.utils.stringify.impl.beans.BeansModule;
import pl.wavesoftware.utils.stringify.spi.BeanFactory;

/**
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
* @since 2.0.0
*/
final class DefaultConfiguration implements Configuration {
static final DefaultBeanFactory DEFAULT_BEAN_FACTORY =
new DefaultBeanFactory();
private static final BeanFactory DEFAULT_BEAN_FACTORY =
BeansModule.INSTANCE.defaultBeanFactory();

private Mode mode = Mode.DEFAULT_MODE;
private BeanFactory beanFactory = DEFAULT_BEAN_FACTORY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package pl.wavesoftware.utils.stringify.impl;

import pl.wavesoftware.utils.stringify.impl.inspector.InspectionContext;

import java.util.IdentityHashMap;
import java.util.Map;

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
package pl.wavesoftware.utils.stringify.impl;

import pl.wavesoftware.utils.stringify.api.InspectionPoint;
import pl.wavesoftware.utils.stringify.impl.beans.BeanFactoryCache;
import pl.wavesoftware.utils.stringify.impl.inspector.InspectionContext;
import pl.wavesoftware.utils.stringify.impl.inspector.InspectorModule;
import pl.wavesoftware.utils.stringify.impl.inspector.ObjectInspector;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
Expand All @@ -30,16 +33,9 @@
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
* @since 2.0.0
*/
final class Inspector implements ToStringResolver {
private static final Iterable<ObjectInspector> OBJECT_INSPECTORS = Arrays.asList(
new CharSequenceInspector(),
new PrimitiveInspector(),
new CharacterInspector(),
new JpaLazyInspector(),
new MapInspector(),
new IterableInspector(),
new RecursionInspector()
);
final class InspectorBasedToStringResolver implements ToStringResolver {
private static final Iterable<ObjectInspector> OBJECT_INSPECTORS =
InspectorModule.INSTANCE.inspectors();

private final DefaultConfiguration configuration;
private final Object target;
Expand All @@ -48,7 +44,7 @@ final class Inspector implements ToStringResolver {
private final BeanFactoryCache beanFactoryCache;
private final InspectingFieldFactory inspectingFieldFactory;

Inspector(
InspectorBasedToStringResolver(
DefaultConfiguration configuration,
Object target,
InspectionContext inspectionContext,
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/pl/wavesoftware/utils/stringify/impl/ToStringResolverImpl.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import pl.wavesoftware.utils.stringify.api.Configuration;
import pl.wavesoftware.utils.stringify.api.Mode;
import pl.wavesoftware.utils.stringify.impl.beans.BeanFactoryCache;
import pl.wavesoftware.utils.stringify.impl.beans.BeansModule;
import pl.wavesoftware.utils.stringify.impl.inspector.InspectionContext;
import pl.wavesoftware.utils.stringify.spi.BeanFactory;

import java.util.function.Function;
Expand All @@ -29,7 +32,7 @@
final class ToStringResolverImpl implements ToStringResolver, Configuration {

private final DefaultConfiguration configuration;
private final Inspector inspector;
private final InspectorBasedToStringResolver delegateResolver;

/**
* A default constructor
Expand All @@ -42,10 +45,8 @@ final class ToStringResolverImpl implements ToStringResolver, Configuration {
target,
configuration,
new DefaultInspectionContext(),
new BeanFactoryCache(() ->
new FallbackBootFactory(
new BootAwareBootFactory(configuration.getBeanFactory(), target)
)
BeansModule.INSTANCE.cachedBeanFactory(
configuration::getBeanFactory, target
),
new InspectingFieldFactory(configuration::getMode)
);
Expand All @@ -59,34 +60,34 @@ final class ToStringResolverImpl implements ToStringResolver, Configuration {
InspectingFieldFactory inspectingFieldFactory
) {
this.configuration = configuration;
this.inspector = new Inspector(
this.delegateResolver = new InspectorBasedToStringResolver(
configuration, target, inspectionContext, new ObjectInspectorImpl(),
beanFactoryCache, inspectingFieldFactory
);
}

@Override
public CharSequence resolve() {
return inspector.resolve();
return delegateResolver.resolve();
}

@Override
public Configuration mode(Mode mode) {
inspector.clear();
delegateResolver.clear();
return configuration.mode(mode);
}

@Override
public Configuration beanFactory(BeanFactory beanFactory) {
inspector.clear();
delegateResolver.clear();
return configuration.beanFactory(beanFactory);
}

private final class ObjectInspectorImpl implements Function<Object, CharSequence> {

@Override
public CharSequence apply(Object object) {
return inspector.inspectObject(object);
return delegateResolver.inspectObject(object);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2018-2019 Wave Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pl.wavesoftware.utils.stringify.impl.beans;

import pl.wavesoftware.utils.stringify.spi.BeanFactory;

/**
* A cache for bean factory.
*
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
* @since 0.1.0
*/
public interface BeanFactoryCache extends BeanFactory {
/**
* Clears a bean factory.
*/
void clear();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2018-2019 Wave Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pl.wavesoftware.utils.stringify.impl.beans;

import pl.wavesoftware.utils.stringify.spi.BeanFactory;

import java.util.function.Supplier;

/**
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
* @since 2.0.0
*/
public enum BeansModule {
INSTANCE;

public BeanFactory defaultBeanFactory() {
return new DefaultBeanFactory();
}

public BeanFactoryCache cachedBeanFactory(Supplier<BeanFactory> beanFactory, Object target) {
return new DefaultBeanFactoryCache(() ->
new FallbackBootFactory(
new BootAwareBootFactory(beanFactory, target)
)
);
}
}
21 changes: 14 additions & 7 deletions .../stringify/impl/BootAwareBootFactory.java → ...gify/impl/beans/BootAwareBootFactory.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
* limitations under the License.
*/

package pl.wavesoftware.utils.stringify.impl;
package pl.wavesoftware.utils.stringify.impl.beans;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.wavesoftware.utils.stringify.impl.lang.Inspectable;
import pl.wavesoftware.utils.stringify.impl.lang.LangModule;
import pl.wavesoftware.utils.stringify.spi.BeanFactory;
import pl.wavesoftware.utils.stringify.spi.BootingAware;

import static pl.wavesoftware.utils.stringify.impl.InspectionUtils.safeInspect;
import java.util.function.Supplier;

/**
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
Expand All @@ -30,11 +32,11 @@
final class BootAwareBootFactory implements BeanFactory, Inspectable {
private static final Logger LOGGER =
LoggerFactory.getLogger(BootAwareBootFactory.class);
private final BeanFactory delegate;
private final Supplier<BeanFactory> delegateSupplier;
private final Object target;

BootAwareBootFactory(BeanFactory delegate, Object target) {
this.delegate = delegate;
BootAwareBootFactory(Supplier<BeanFactory> delegateSupplier, Object target) {
this.delegateSupplier = delegateSupplier;
this.target = target;
}

Expand All @@ -44,6 +46,7 @@ public <T> T create(Class<T> contractClass) {
}

private BeanFactory getBeanFactory(Class<?> contractClass) {
BeanFactory delegate = delegateSupplier.get();
if (delegate instanceof BootingAware) {
BootingAware bootingAware = (BootingAware) delegate;
if (!bootingAware.isReady() && LOGGER.isWarnEnabled()) {
Expand All @@ -54,14 +57,18 @@ private BeanFactory getBeanFactory(Class<?> contractClass) {
"fallback for this call.",
safeInspect(delegate), safeInspect(target), contractClass
);
return DefaultConfiguration.DEFAULT_BEAN_FACTORY;
return BeansModule.INSTANCE.defaultBeanFactory();
}
}
return delegate;
}

@Override
public String inspect() {
return safeInspect(delegate);
return safeInspect(delegateSupplier);
}

private static String safeInspect(Object object) {
return LangModule.INSTANCE.safeInspector().inspect(object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package pl.wavesoftware.utils.stringify.impl;
package pl.wavesoftware.utils.stringify.impl.beans;

import pl.wavesoftware.utils.stringify.spi.BeanFactory;

Expand Down
Loading