Skip to content

Commit

Permalink
Shorted the static imports and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dilipkrish committed Apr 11, 2015
1 parent 57d29d1 commit 13f663d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 33 deletions.
Expand Up @@ -27,7 +27,6 @@
import springfox.documentation.service.AllowableValues;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand All @@ -36,8 +35,6 @@

public class Enums {

public static final AllowableListValues EMPTY_LIST = new AllowableListValues(new ArrayList<String>(), "LIST");

private Enums() {
throw new UnsupportedOperationException();
}
Expand Down
Expand Up @@ -35,6 +35,9 @@
import java.util.Map;

import static com.google.common.collect.Maps.*;
import static springfox.documentation.schema.Collections.*;
import static springfox.documentation.schema.Maps.*;
import static springfox.documentation.schema.Types.*;


@Component
Expand All @@ -61,11 +64,11 @@ public DefaultModelProvider(TypeResolver resolver,
@Override
public com.google.common.base.Optional<Model> modelFor(ModelContext modelContext) {
ResolvedType propertiesHost = modelContext.alternateFor(modelContext.resolvedType(resolver));
if (Collections.isContainerType(propertiesHost)
|| Maps.isMapType(propertiesHost)
|| propertiesHost.getErasedType().isEnum()
|| Types.isBaseType(Types.typeNameFor(propertiesHost.getErasedType()))
|| modelContext.hasSeenBefore(propertiesHost)) {
if (isContainerType(propertiesHost)
|| isMapType(propertiesHost)
|| propertiesHost.getErasedType().isEnum()
|| isBaseType(Types.typeNameFor(propertiesHost.getErasedType()))
|| modelContext.hasSeenBefore(propertiesHost)) {
return Optional.absent();
}
Map<String, ModelProperty> properties = newTreeMap();
Expand All @@ -75,19 +78,19 @@ public com.google.common.base.Optional<Model> modelFor(ModelContext modelContext
}

private Model modelBuilder(ResolvedType propertiesHost,
Map<String, ModelProperty> properties,
ModelContext modelContext) {
Map<String, ModelProperty> properties,
ModelContext modelContext) {
String typeName = typeNameExtractor.typeName(ModelContext.fromParent(modelContext, propertiesHost));
modelContext.getBuilder()
.id(typeName)
.type(propertiesHost)
.name(typeName)
.qualifiedType(ResolvedTypes.simpleQualifiedTypeName(propertiesHost))
.properties(properties)
.description("")
.baseModel("")
.discriminator("")
.subTypes(new ArrayList<String>());
.id(typeName)
.type(propertiesHost)
.name(typeName)
.qualifiedType(ResolvedTypes.simpleQualifiedTypeName(propertiesHost))
.properties(properties)
.description("")
.baseModel("")
.discriminator("")
.subTypes(new ArrayList<String>());
return schemaPluginsManager.model(modelContext);
}

Expand Down
Expand Up @@ -28,7 +28,9 @@

import java.lang.reflect.Type;

import static springfox.documentation.spi.schema.contexts.ModelContext.fromParent;
import static springfox.documentation.schema.Collections.*;
import static springfox.documentation.schema.Maps.*;
import static springfox.documentation.spi.schema.contexts.ModelContext.*;

public class ResolvedTypes {

Expand Down Expand Up @@ -58,12 +60,12 @@ public static Function<? super ResolvedType, ModelRef> modelRefFactory(final Mod
return new Function<ResolvedType, ModelRef>() {
@Override
public ModelRef apply(ResolvedType type) {
if (Collections.isContainerType(type)) {
ResolvedType collectionElementType = Collections.collectionElementType(type);
if (isContainerType(type)) {
ResolvedType collectionElementType = collectionElementType(type);
String elementTypeName = typeNameExtractor.typeName(fromParent(parentContext, collectionElementType));
return new ModelRef(Collections.containerType(type), elementTypeName);
}
if (springfox.documentation.schema.Maps.isMapType(type)) {
if (isMapType(type)) {
String elementTypeName = typeNameExtractor.typeName(fromParent(parentContext, springfox
.documentation.schema.Maps.mapValueType(type)));
return new ModelRef("Map", elementTypeName, true);
Expand Down
Expand Up @@ -33,6 +33,7 @@
import java.lang.reflect.Type;

import static com.google.common.base.Optional.*;
import static springfox.documentation.schema.Collections.*;
import static springfox.documentation.schema.Types.*;

@Component
Expand All @@ -49,8 +50,8 @@ public TypeNameExtractor(TypeResolver typeResolver, SchemaPluginsManager plugins

public String typeName(ModelContext context) {
ResolvedType type = asResolved(context.getType());
if (Collections.isContainerType(type)) {
return Collections.containerType(type);
if (isContainerType(type)) {
return containerType(type);
}
return innerTypeName(type, context);
}
Expand Down
Expand Up @@ -25,6 +25,9 @@
import springfox.documentation.service.AllowableValues;
import springfox.documentation.spi.schema.AlternateTypeProvider;

import static com.google.common.base.Optional.fromNullable;
import static springfox.documentation.schema.ResolvedTypes.simpleQualifiedTypeName;

public abstract class BaseModelProperty implements ModelProperty {

private final String name;
Expand Down Expand Up @@ -52,12 +55,12 @@ public String qualifiedTypeName() {
if (getType().getTypeParameters().size() > 0) {
return getType().toString();
}
return ResolvedTypes.simpleQualifiedTypeName(getType());
return simpleQualifiedTypeName(getType());
}

@Override
public AllowableValues allowableValues() {
Optional<AllowableValues> allowableValues = Optional.fromNullable(ResolvedTypes.allowableValues(getType()));
Optional<AllowableValues> allowableValues = fromNullable(ResolvedTypes.allowableValues(getType()));
//Preference to inferred allowable values over list values via ApiModelProperty
if (allowableValues.isPresent()) {
return allowableValues.get();
Expand Down
Expand Up @@ -54,6 +54,7 @@
import static com.google.common.collect.Lists.*;
import static com.google.common.collect.Maps.*;
import static springfox.documentation.schema.ResolvedTypes.*;
import static springfox.documentation.schema.property.BeanPropertyDefinitions.*;
import static springfox.documentation.spi.schema.contexts.ModelContext.*;

@Component
Expand Down Expand Up @@ -127,7 +128,7 @@ public List<ModelProperty> propertiesFor(ResolvedType type, ModelContext givenCo

BeanPropertyDefinition propertyDefinition = each.getValue();
Optional<BeanPropertyDefinition> jacksonProperty
= BeanPropertyDefinitions.jacksonPropertyWithSameInternalName(beanDescription, propertyDefinition);
= jacksonPropertyWithSameInternalName(beanDescription, propertyDefinition);
AnnotatedMember member = propertyDefinition.getPrimaryMember();
Optional<ResolvedMethod> accessor = findAccessorMethod(type, each.getKey(), member);
if (accessor.isPresent()) {
Expand Down Expand Up @@ -176,5 +177,4 @@ private ModelProperty beanModelProperty(ResolvedMethod childProperty, Optional<B
}



}
Expand Up @@ -28,8 +28,7 @@ public class FieldModelProperty extends BaseModelProperty {

private final ResolvedField childField;

public FieldModelProperty(String fieldName,
ResolvedField childField, AlternateTypeProvider alternateTypeProvider) {
public FieldModelProperty(String fieldName, ResolvedField childField, AlternateTypeProvider alternateTypeProvider) {

super(fieldName, alternateTypeProvider);
this.childField = childField;
Expand Down
Expand Up @@ -35,7 +35,8 @@
import com.wordnik.swagger.models.properties.Property;
import org.mapstruct.Mapper;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.schema.Types;

import static springfox.documentation.schema.Types.*;


@Mapper
Expand Down Expand Up @@ -107,7 +108,7 @@ private Model fromModelRef(ModelRef modelRef) {
baseModel.additionalProperties(ModelMapper.property(modelRef.getItemType()));
return baseModel;
}
if (Types.isBaseType(modelRef.getType())) {
if (isBaseType(modelRef.getType())) {
ModelImpl baseModel = new ModelImpl();
baseModel.setType(modelRef.getType());
return baseModel;
Expand Down

0 comments on commit 13f663d

Please sign in to comment.