DATACMNS-601 - Fixes for most of the SonarQube warnings.

This commit is contained in:
Oliver Gierke
2014-11-26 09:10:00 +01:00
parent 0f448d509c
commit 71f1592200
23 changed files with 93 additions and 62 deletions

View File

@@ -39,7 +39,7 @@ import org.springframework.util.Assert;
* @author Oliver Gierke
* @since 1.5
*/
class AnnotationAuditingMetadata {
final class AnnotationAuditingMetadata {
private static final AnnotationFieldFilter CREATED_BY_FILTER = new AnnotationFieldFilter(CreatedBy.class);
private static final AnnotationFieldFilter CREATED_DATE_FILTER = new AnnotationFieldFilter(CreatedDate.class);

View File

@@ -115,7 +115,7 @@ class AuditableBeanWrapperFactory {
* @author Oliver Gierke
* @since 1.8
*/
static abstract class DateConvertingAuditableBeanWrapper implements AuditableBeanWrapper {
abstract static class DateConvertingAuditableBeanWrapper implements AuditableBeanWrapper {
private static final boolean IS_JODA_TIME_PRESENT = ClassUtils.isPresent("org.joda.time.DateTime",
ReflectionAuditingBeanWrapper.class.getClassLoader());

View File

@@ -19,7 +19,6 @@ import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.aop.target.LazyInitTargetSource;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -110,8 +109,7 @@ public class AuditingHandlerBeanDefinitionParser extends AbstractSingleBeanDefin
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#resolveId(org.w3c.dom.Element, org.springframework.beans.factory.support.AbstractBeanDefinition, org.springframework.beans.factory.xml.ParserContext)
*/
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) {
this.resolvedBeanName = super.resolveId(element, definition, parserContext);
return resolvedBeanName;

View File

@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
*/
public class CollectionFactory {
public abstract class CollectionFactory {
private CollectionFactory() {}

View File

@@ -33,7 +33,7 @@ import org.springframework.util.StringUtils;
public class SimpleTypeInformationMapper implements TypeInformationMapper {
public static final SimpleTypeInformationMapper INSTANCE = new SimpleTypeInformationMapper();
private static final Map<String, ClassTypeInformation<?>> cache = new ConcurrentHashMap<String, ClassTypeInformation<?>>();
private static final Map<String, ClassTypeInformation<?>> CACHE = new ConcurrentHashMap<String, ClassTypeInformation<?>>();
/**
* Returns the {@link TypeInformation} that shall be used when the given {@link String} value is found as type hint.
@@ -56,7 +56,7 @@ public class SimpleTypeInformationMapper implements TypeInformationMapper {
return null;
}
ClassTypeInformation<?> information = cache.get(value);
ClassTypeInformation<?> information = CACHE.get(value);
if (information != null) {
return information;
@@ -69,7 +69,7 @@ public class SimpleTypeInformationMapper implements TypeInformationMapper {
}
if (information != null) {
cache.put(value, information);
CACHE.put(value, information);
}
return information;

View File

@@ -44,10 +44,12 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
*/
public class SpringDataJaxb {
public abstract class SpringDataJaxb {
public static final String NAMESPACE = "http://www.springframework.org/schema/data/jaxb";
private SpringDataJaxb() {}
/**
* The DTO for {@link Pageable}s/{@link PageRequest}s.
*

View File

@@ -18,6 +18,7 @@ package org.springframework.data.geo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
/**
* Custom {@link Page} to carry the average distance retrieved from the {@link GeoResults} the {@link GeoPage} is set up
@@ -66,4 +67,33 @@ public class GeoPage<T> extends PageImpl<GeoResult<T>> {
public Distance getAverageDistance() {
return averageDistance;
}
/*
* (non-Javadoc)
* @see org.springframework.data.domain.PageImpl#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof GeoPage)) {
return false;
}
GeoPage<?> that = (GeoPage<?>) obj;
return super.equals(obj) && ObjectUtils.nullSafeEquals(this.averageDistance, that.averageDistance);
}
/*
* (non-Javadoc)
* @see org.springframework.data.domain.PageImpl#hashCode()
*/
@Override
public int hashCode() {
return super.hashCode() + ObjectUtils.nullSafeHashCode(this.averageDistance);
}
}

View File

@@ -69,15 +69,15 @@ public class PropertyPath implements Iterable<PropertyPath> {
Assert.notNull(owningType);
String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name);
TypeInformation<?> type = owningType.getProperty(propertyName);
TypeInformation<?> propertyType = owningType.getProperty(propertyName);
if (type == null) {
if (propertyType == null) {
throw new PropertyReferenceException(propertyName, owningType, base);
}
this.owningType = owningType;
this.isCollection = type.isCollectionLike();
this.type = type.getActualType();
this.isCollection = propertyType.isCollectionLike();
this.type = propertyType.getActualType();
this.name = propertyName;
}

View File

@@ -158,7 +158,7 @@ class DefaultPersistentPropertyPath<T extends PersistentProperty<T>> implements
return this;
}
List<T> properties = new ArrayList<T>();
List<T> result = new ArrayList<T>();
Iterator<T> iterator = iterator();
for (int i = 0; i < base.getLength(); i++) {
@@ -166,10 +166,10 @@ class DefaultPersistentPropertyPath<T extends PersistentProperty<T>> implements
}
while (iterator.hasNext()) {
properties.add(iterator.next());
result.add(iterator.next());
}
return new DefaultPersistentPropertyPath<T>(properties);
return new DefaultPersistentPropertyPath<T>(result);
}
/*

View File

@@ -156,9 +156,10 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
@Override
public boolean isTransient() {
if (isTransient == null) {
boolean isTransient = super.isTransient() || isAnnotationPresent(Transient.class);
this.isTransient = isTransient || isAnnotationPresent(Value.class) || isAnnotationPresent(Autowired.class);
if (this.isTransient == null) {
boolean potentiallyTransient = super.isTransient() || isAnnotationPresent(Transient.class);
this.isTransient = potentiallyTransient || isAnnotationPresent(Value.class)
|| isAnnotationPresent(Autowired.class);
}
return this.isTransient;

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.querydsl;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -35,7 +34,8 @@ public interface QueryDslPredicateExecutor<T> {
*
* @param predicate
* @return a single entity matching the given {@link Predicate} or {@literal null} if none was found.
* @throws IncorrectResultSizeDataAccessException if the predicate yields more than one result.
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the predicate yields more than one
* result.
*/
T findOne(Predicate predicate);

View File

@@ -49,7 +49,7 @@ public class RepositoryConfigurationDelegate {
private final RepositoryConfigurationSource configurationSource;
private final ResourceLoader resourceLoader;
private final Environment environment;
private final BeanNameGenerator generator;
private final BeanNameGenerator beanNameGenerator;
private final boolean isXml;
/**
@@ -87,7 +87,7 @@ public class RepositoryConfigurationDelegate {
RepositoryBeanNameGenerator generator = new RepositoryBeanNameGenerator();
generator.setBeanClassLoader(resourceLoader.getClassLoader());
this.generator = generator;
this.beanNameGenerator = generator;
this.configurationSource = configurationSource;
this.resourceLoader = resourceLoader;
this.environment = defaultEnvironment(environment, resourceLoader);
@@ -143,7 +143,7 @@ public class RepositoryConfigurationDelegate {
}
AbstractBeanDefinition beanDefinition = definitionBuilder.getBeanDefinition();
String beanName = generator.generateBeanName(beanDefinition, registry);
String beanName = beanNameGenerator.generateBeanName(beanDefinition, registry);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Registering repository: " + beanName + " - Interface: " + configuration.getRepositoryInterface()

View File

@@ -23,7 +23,7 @@ import org.springframework.data.repository.core.EntityInformation;
/**
* {@link EntityInformation} implementation that uses a {@link PersistentEntity} to obtain id type information and uses
* a {@link BeanWrapper} to access the property value if requested.
* a {@link org.springframework.data.mapping.IdentifierAccessor} to access the property value if requested.
*
* @author Oliver Gierke
*/

View File

@@ -255,7 +255,7 @@ public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter
*
* @param method
*/
private void assertEitherAllParamAnnotatedOrNone() {
private final void assertEitherAllParamAnnotatedOrNone() {
boolean nameFound = false;
int index = 0;

View File

@@ -119,9 +119,7 @@ public class QueryMethod {
* @return
*/
public String getNamedQueryName() {
Class<?> domainClass = getDomainClass();
return String.format("%s.%s", domainClass.getSimpleName(), method.getName());
return String.format("%s.%s", getDomainClass().getSimpleName(), method.getName());
}
/**
@@ -181,7 +179,7 @@ public class QueryMethod {
*
* @return
*/
public boolean isPageQuery() {
public final boolean isPageQuery() {
Class<?> returnType = method.getReturnType();
return org.springframework.util.ClassUtils.isAssignable(Page.class, returnType);

View File

@@ -45,7 +45,9 @@ import org.springframework.util.ClassUtils;
public class Repositories implements Iterable<Class<?>> {
static final Repositories NONE = new Repositories();
private static final RepositoryFactoryInformation<Object, Serializable> EMPTY_REPOSITORY_FACTORY_INFO = EmptyRepositoryFactoryInformation.INSTANCE;
private static final String DOMAIN_TYPE_MUST_NOT_BE_NULL = "Domain type must not be null!";
private final BeanFactory beanFactory;
private final Map<Class<?>, String> repositoryBeanNames;
@@ -102,7 +104,7 @@ public class Repositories implements Iterable<Class<?>> {
*/
public boolean hasRepositoryFor(Class<?> domainClass) {
Assert.notNull(domainClass, "Domain class must not be null!");
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
return repositoryFactoryInfos.containsKey(domainClass);
}
@@ -115,7 +117,7 @@ public class Repositories implements Iterable<Class<?>> {
*/
public Object getRepositoryFor(Class<?> domainClass) {
Assert.notNull(domainClass, "Domain class must not be null!");
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
String repositoryBeanName = repositoryBeanNames.get(domainClass);
return repositoryBeanName == null || beanFactory == null ? null : beanFactory.getBean(repositoryBeanName);
@@ -131,7 +133,7 @@ public class Repositories implements Iterable<Class<?>> {
*/
private RepositoryFactoryInformation<Object, Serializable> getRepositoryFactoryInfoFor(Class<?> domainClass) {
Assert.notNull(domainClass, "Domain class must not be null!");
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos.get(ClassUtils
.getUserClass(domainClass));
@@ -147,7 +149,7 @@ public class Repositories implements Iterable<Class<?>> {
@SuppressWarnings("unchecked")
public <T, S extends Serializable> EntityInformation<T, S> getEntityInformationFor(Class<?> domainClass) {
Assert.notNull(domainClass, "Domain class must not be null!");
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
return (EntityInformation<T, S>) getRepositoryFactoryInfoFor(domainClass).getEntityInformation();
}
@@ -161,7 +163,7 @@ public class Repositories implements Iterable<Class<?>> {
*/
public RepositoryInformation getRepositoryInformationFor(Class<?> domainClass) {
Assert.notNull(domainClass, "Domain class must not be null!");
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
RepositoryFactoryInformation<Object, Serializable> information = getRepositoryFactoryInfoFor(domainClass);
return information == EMPTY_REPOSITORY_FACTORY_INFO ? null : information.getRepositoryInformation();
@@ -177,7 +179,7 @@ public class Repositories implements Iterable<Class<?>> {
*/
public PersistentEntity<?, ?> getPersistentEntity(Class<?> domainClass) {
Assert.notNull(domainClass, "Domain class must not be null!");
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
return getRepositoryFactoryInfoFor(domainClass).getPersistentEntity();
}
@@ -189,7 +191,7 @@ public class Repositories implements Iterable<Class<?>> {
*/
public List<QueryMethod> getQueryMethodsFor(Class<?> domainClass) {
Assert.notNull(domainClass, "Domain class must not be null!");
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
return getRepositoryFactoryInfoFor(domainClass).getQueryMethods();
}

View File

@@ -38,14 +38,14 @@ import com.google.common.base.Optional;
* @author Oliver Gierke
* @since 1.8
*/
public class QueryExecutionConverters {
public abstract class QueryExecutionConverters {
private static final boolean GUAVA_PRESENT = ClassUtils.isPresent("com.google.common.base.Optional",
QueryExecutionConverters.class.getClassLoader());
private static final boolean JDK_PRESENT = ClassUtils.isPresent("java.util.Optional",
QueryExecutionConverters.class.getClassLoader());
private static Set<Class<?>> WRAPPER_TYPES = new HashSet<Class<?>>();
private static final Set<Class<?>> WRAPPER_TYPES = new HashSet<Class<?>>();
static {

View File

@@ -94,16 +94,16 @@ public class AnnotationDetectionMethodCallback<A extends Annotation> implements
return;
}
A annotation = AnnotationUtils.findAnnotation(method, annotationType);
A foundAnnotation = AnnotationUtils.findAnnotation(method, annotationType);
if (annotation != null) {
if (foundAnnotation != null) {
if (foundMethod != null && enforceUniqueness) {
throw new IllegalStateException(String.format(MULTIPLE_FOUND, annotation.getClass().getName(), foundMethod,
throw new IllegalStateException(String.format(MULTIPLE_FOUND, foundAnnotation.getClass().getName(), foundMethod,
method));
}
this.annotation = annotation;
this.annotation = foundAnnotation;
this.foundMethod = method;
}
}

View File

@@ -77,7 +77,7 @@ public class DirectFieldAccessFallbackBeanWrapper extends BeanWrapperImpl {
if (field == null) {
throw new NotWritablePropertyException(getWrappedClass(), propertyName,
"Could not find field for property during fallback access!");
"Could not find field for property during fallback access!", e);
}
makeAccessible(field);

View File

@@ -200,15 +200,15 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T>
return resolved;
}
Type[] types = type.getActualTypeArguments();
Type[] typeArguments = type.getActualTypeArguments();
if (types.length == 0) {
if (typeArguments.length == 0) {
return cacheAndReturn(false);
}
for (Type type : types) {
for (Type typeArgument : typeArguments) {
TypeInformation<?> info = createInfo(type);
TypeInformation<?> info = createInfo(typeArgument);
if (info instanceof ParameterizedTypeInformation) {
if (!((ParameterizedTypeInformation<?>) info).isResolvedCompletely()) {

View File

@@ -30,7 +30,7 @@ import org.springframework.util.ReflectionUtils.FieldFilter;
* @author Oliver Gierke
* @since 1.5
*/
public class ReflectionUtils {
public abstract class ReflectionUtils {
private ReflectionUtils() {}

View File

@@ -159,8 +159,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
Assert.notNull(constructor);
List<TypeInformation<?>> result = new ArrayList<TypeInformation<?>>();
for (Type type : constructor.getGenericParameterTypes()) {
result.add(createInfo(type));
for (Type parameterType : constructor.getGenericParameterTypes()) {
result.add(createInfo(parameterType));
}
return result;
@@ -201,14 +201,14 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
*/
private TypeInformation<?> getPropertyInformation(String fieldname) {
Class<?> type = getType();
Field field = ReflectionUtils.findField(type, fieldname);
Class<?> rawType = getType();
Field field = ReflectionUtils.findField(rawType, fieldname);
if (field != null) {
return createInfo(field.getGenericType());
}
PropertyDescriptor descriptor = findPropertyDescriptor(type, fieldname);
PropertyDescriptor descriptor = findPropertyDescriptor(rawType, fieldname);
return descriptor == null ? null : createInfo(getGenericType(descriptor));
}
@@ -417,8 +417,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
Type[] parameterTypes = method.getGenericParameterTypes();
List<TypeInformation<?>> result = new ArrayList<TypeInformation<?>>(parameterTypes.length);
for (Type type : parameterTypes) {
result.add(createInfo(type));
for (Type parameterType : parameterTypes) {
result.add(createInfo(parameterType));
}
return result;
@@ -430,9 +430,9 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
*/
public TypeInformation<?> getSuperTypeInformation(Class<?> superType) {
Class<?> type = getType();
Class<?> rawType = getType();
if (!superType.isAssignableFrom(type)) {
if (!superType.isAssignableFrom(rawType)) {
return null;
}
@@ -442,11 +442,11 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
List<Type> candidates = new ArrayList<Type>();
Type genericSuperclass = type.getGenericSuperclass();
Type genericSuperclass = rawType.getGenericSuperclass();
if (genericSuperclass != null) {
candidates.add(genericSuperclass);
}
candidates.addAll(Arrays.asList(type.getGenericInterfaces()));
candidates.addAll(Arrays.asList(rawType.getGenericInterfaces()));
for (Type candidate : candidates) {

View File

@@ -32,7 +32,7 @@ import org.springframework.util.ObjectUtils;
*
* @author Oliver Gierke
*/
class SpringDataAnnotationUtils {
abstract class SpringDataAnnotationUtils {
private SpringDataAnnotationUtils() {}