From 286653c06be5a15528d93f840ee42a1abaa65299 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 22 Aug 2013 12:44:52 +0200 Subject: [PATCH] Reduced cyclomatic complexity by using Preconditions Change-Id: Id267a876829d28f3359c1f2c3209d43ccbaa81bc Signed-off-by: Tony Tkacik --- code-generator/binding-generator-impl/pom.xml | 4 + .../generator/impl/BindingGeneratorImpl.java | 206 +++++------------- .../binding/yang/types/TypeProviderImpl.java | 122 +++-------- pom.xml | 5 + 4 files changed, 97 insertions(+), 240 deletions(-) diff --git a/code-generator/binding-generator-impl/pom.xml b/code-generator/binding-generator-impl/pom.xml index 5a722efd98..9a1fc491ee 100644 --- a/code-generator/binding-generator-impl/pom.xml +++ b/code-generator/binding-generator-impl/pom.xml @@ -37,6 +37,10 @@ commons-lang 2.1 + + com.google.guava + guava + diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java index 1760a7e13d..d8c9b93e6d 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java @@ -71,6 +71,9 @@ import org.opendaylight.yangtools.yang.model.util.ExtendedType; import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; import org.opendaylight.yangtools.yang.model.util.UnionType; +import com.google.common.base.Preconditions; +import com.google.common.base.Predicates; + public final class BindingGeneratorImpl implements BindingGenerator { /** @@ -139,13 +142,8 @@ public final class BindingGeneratorImpl implements BindingGenerator { */ @Override public List generateTypes(final SchemaContext context) { - if (context == null) { - throw new IllegalArgumentException("Schema Context reference cannot be NULL!"); - } - if (context.getModules() == null) { - throw new IllegalStateException("Schema Context does not contain defined modules!"); - } - + Preconditions.checkArgument(context != null,"Schema Context reference cannot be NULL."); + Preconditions.checkState(context.getModules() != null,"Schema Context does not contain defined modules."); final List generatedTypes = new ArrayList<>(); schemaContext = context; typeProvider = new TypeProviderImpl(context); @@ -201,15 +199,9 @@ public final class BindingGeneratorImpl implements BindingGenerator { */ @Override public List generateTypes(final SchemaContext context, final Set modules) { - if (context == null) { - throw new IllegalArgumentException("Schema Context reference cannot be NULL!"); - } - if (context.getModules() == null) { - throw new IllegalStateException("Schema Context does not contain defined modules!"); - } - if (modules == null) { - throw new IllegalArgumentException("Sef of Modules cannot be NULL!"); - } + Preconditions.checkArgument(context != null,"Schema Context reference cannot be NULL."); + Preconditions.checkState(context.getModules() != null,"Schema Context does not contain defined modules."); + Preconditions.checkArgument(modules != null,"Sef of Modules cannot be NULL."); final List filteredGenTypes = new ArrayList<>(); schemaContext = context; @@ -256,15 +248,9 @@ public final class BindingGeneratorImpl implements BindingGenerator { * */ private List allTypeDefinitionsToGenTypes(final Module module) { - if (module == null) { - throw new IllegalArgumentException("Module reference cannot be NULL!"); - } - if (module.getName() == null) { - throw new IllegalArgumentException("Module name cannot be NULL!"); - } - if (module.getTypeDefinitions() == null) { - throw new IllegalArgumentException("Type Definitions for module " + module.getName() + " cannot be NULL!"); - } + Preconditions.checkArgument(module != null,"Module reference cannot be NULL."); + Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL."); + Preconditions.checkArgument(module.getTypeDefinitions() != null,"Type Definitions for module " + module.getName() + " cannot be NULL."); final Set> typeDefinitions = module.getTypeDefinitions(); final List generatedTypes = new ArrayList<>(); @@ -297,17 +283,13 @@ public final class BindingGeneratorImpl implements BindingGenerator { * */ private List allContainersToGenTypes(final Module module) { - if (module == null) { - throw new IllegalArgumentException("Module reference cannot be NULL!"); - } + Preconditions.checkArgument(module != null,"Module reference cannot be NULL."); - if (module.getName() == null) { - throw new IllegalArgumentException("Module name cannot be NULL!"); - } + Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL."); if (module.getChildNodes() == null) { throw new IllegalArgumentException("Reference to Set of Child Nodes in module " + module.getName() - + " cannot be NULL!"); + + " cannot be NULL."); } final List generatedTypes = new ArrayList<>(); @@ -340,17 +322,13 @@ public final class BindingGeneratorImpl implements BindingGenerator { * */ private List allListsToGenTypes(final Module module) { - if (module == null) { - throw new IllegalArgumentException("Module reference cannot be NULL!"); - } + Preconditions.checkArgument(module != null,"Module reference cannot be NULL."); - if (module.getName() == null) { - throw new IllegalArgumentException("Module name cannot be NULL!"); - } + Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL."); if (module.getChildNodes() == null) { throw new IllegalArgumentException("Reference to Set of Child Nodes in module " + module.getName() - + " cannot be NULL!"); + + " cannot be NULL."); } final List generatedTypes = new ArrayList<>(); @@ -384,12 +362,8 @@ public final class BindingGeneratorImpl implements BindingGenerator { * */ private List allChoicesToGenTypes(final Module module) { - if (module == null) { - throw new IllegalArgumentException("Module reference cannot be NULL!"); - } - if (module.getName() == null) { - throw new IllegalArgumentException("Module name cannot be NULL!"); - } + Preconditions.checkArgument(module != null,"Module reference cannot be NULL."); + Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL."); final DataNodeIterator it = new DataNodeIterator(module); final List choiceNodes = it.allChoices(); @@ -422,15 +396,11 @@ public final class BindingGeneratorImpl implements BindingGenerator { * */ private List allAugmentsToGenTypes(final Module module) { - if (module == null) { - throw new IllegalArgumentException("Module reference cannot be NULL!"); - } - if (module.getName() == null) { - throw new IllegalArgumentException("Module name cannot be NULL!"); - } + Preconditions.checkArgument(module != null,"Module reference cannot be NULL."); + Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL."); if (module.getChildNodes() == null) { throw new IllegalArgumentException("Reference to Set of Augmentation Definitions in module " - + module.getName() + " cannot be NULL!"); + + module.getName() + " cannot be NULL."); } final List generatedTypes = new ArrayList<>(); @@ -459,12 +429,8 @@ public final class BindingGeneratorImpl implements BindingGenerator { * */ private List resolveAugmentations(final Module module) { - if (module == null) { - throw new IllegalArgumentException("Module reference cannot be NULL!"); - } - if (module.getAugmentations() == null) { - throw new IllegalStateException("Augmentations Set cannot be NULL!"); - } + Preconditions.checkArgument(module != null,"Module reference cannot be NULL."); + Preconditions.checkState(module.getAugmentations() != null,"Augmentations Set cannot be NULL."); final Set augmentations = module.getAugmentations(); final List sortedAugmentations = new ArrayList<>(augmentations); @@ -501,9 +467,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { * */ private GeneratedType moduleToDataType(final Module module) { - if (module == null) { - throw new IllegalArgumentException("Module reference cannot be NULL!"); - } + Preconditions.checkArgument(module != null,"Module reference cannot be NULL."); final GeneratedTypeBuilder moduleDataTypeBuilder = moduleTypeBuilder(module, "Data"); addImplementedInterfaceFromUses(module, moduleDataTypeBuilder); @@ -536,17 +500,13 @@ public final class BindingGeneratorImpl implements BindingGenerator { * */ private List allRPCMethodsToGenType(final Module module) { - if (module == null) { - throw new IllegalArgumentException("Module reference cannot be NULL!"); - } + Preconditions.checkArgument(module != null,"Module reference cannot be NULL."); - if (module.getName() == null) { - throw new IllegalArgumentException("Module name cannot be NULL!"); - } + Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL."); if (module.getChildNodes() == null) { throw new IllegalArgumentException("Reference to Set of RPC Method Definitions in module " - + module.getName() + " cannot be NULL!"); + + module.getName() + " cannot be NULL."); } final String basePackageName = moduleNamespaceToPackageName(module); @@ -640,17 +600,13 @@ public final class BindingGeneratorImpl implements BindingGenerator { * */ private List allNotificationsToGenType(final Module module) { - if (module == null) { - throw new IllegalArgumentException("Module reference cannot be NULL!"); - } + Preconditions.checkArgument(module != null,"Module reference cannot be NULL."); - if (module.getName() == null) { - throw new IllegalArgumentException("Module name cannot be NULL!"); - } + Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL."); if (module.getChildNodes() == null) { throw new IllegalArgumentException("Reference to Set of Notification Definitions in module " - + module.getName() + " cannot be NULL!"); + + module.getName() + " cannot be NULL."); } final String basePackageName = moduleNamespaceToPackageName(module); @@ -775,9 +731,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { * */ private List allGroupingsToGenTypes(final Module module) { - if (module == null) { - throw new IllegalArgumentException("Module parameter can not be null"); - } + Preconditions.checkArgument(module != null,"Module parameter can not be null"); final List genTypes = new ArrayList<>(); final String basePackageName = moduleNamespaceToPackageName(module); final Set groupings = module.getGroupings(); @@ -887,9 +841,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { * if module equals null */ private GeneratedTypeBuilder moduleTypeBuilder(final Module module, final String postfix) { - if (module == null) { - throw new IllegalArgumentException("Module reference cannot be NULL!"); - } + Preconditions.checkArgument(module != null,"Module reference cannot be NULL."); String packageName = moduleNamespaceToPackageName(module); final String moduleName = parseToClassName(module.getName()) + postfix; @@ -920,15 +872,9 @@ public final class BindingGeneratorImpl implements BindingGenerator { * */ private List augmentationToGenTypes(final String augmentPackageName, final AugmentationSchema augSchema) { - if (augmentPackageName == null) { - throw new IllegalArgumentException("Package Name cannot be NULL!"); - } - if (augSchema == null) { - throw new IllegalArgumentException("Augmentation Schema cannot be NULL!"); - } - if (augSchema.getTargetPath() == null) { - throw new IllegalStateException("Augmentation Schema does not contain Target Path (Target Path is NULL)."); - } + Preconditions.checkArgument(augmentPackageName != null,"Package Name cannot be NULL."); + Preconditions.checkArgument(augSchema != null,"Augmentation Schema cannot be NULL."); + Preconditions.checkState(augSchema.getTargetPath() != null,"Augmentation Schema does not contain Target Path (Target Path is NULL)."); final List genTypes = new ArrayList<>(); @@ -1253,15 +1199,9 @@ public final class BindingGeneratorImpl implements BindingGenerator { */ private void resolveChoiceSchemaNode(final String basePackageName, final GeneratedTypeBuilder typeBuilder, final ChoiceNode choiceNode) { - if (basePackageName == null) { - throw new IllegalArgumentException("Base Package Name cannot be NULL!"); - } - if (typeBuilder == null) { - throw new IllegalArgumentException("Generated Type Builder cannot be NULL!"); - } - if (choiceNode == null) { - throw new IllegalArgumentException("Choice Schema Node cannot be NULL!"); - } + Preconditions.checkArgument(basePackageName != null,"Base Package Name cannot be NULL."); + Preconditions.checkArgument(typeBuilder != null,"Generated Type Builder cannot be NULL."); + Preconditions.checkArgument(choiceNode != null,"Choice Schema Node cannot be NULL."); final String choiceName = choiceNode.getQName().getLocalName(); if (choiceName != null && !choiceNode.isAddedByUses()) { @@ -1295,12 +1235,8 @@ public final class BindingGeneratorImpl implements BindingGenerator { * */ private List choiceToGeneratedType(final String basePackageName, final ChoiceNode choiceNode) { - if (basePackageName == null) { - throw new IllegalArgumentException("Base Package Name cannot be NULL!"); - } - if (choiceNode == null) { - throw new IllegalArgumentException("Choice Schema Node cannot be NULL!"); - } + Preconditions.checkArgument(basePackageName != null,"Base Package Name cannot be NULL."); + Preconditions.checkArgument(choiceNode != null,"Choice Schema Node cannot be NULL."); final List generatedTypes = new ArrayList<>(); final String packageName = packageNameForGeneratedType(basePackageName, choiceNode.getPath()); @@ -1344,15 +1280,9 @@ public final class BindingGeneratorImpl implements BindingGenerator { */ private List generateTypesFromChoiceCases(final String basePackageName, final Type refChoiceType, final Set caseNodes) { - if (basePackageName == null) { - throw new IllegalArgumentException("Base Package Name cannot be NULL!"); - } - if (refChoiceType == null) { - throw new IllegalArgumentException("Referenced Choice Type cannot be NULL!"); - } - if (caseNodes == null) { - throw new IllegalArgumentException("Set of Choice Case Nodes cannot be NULL!"); - } + Preconditions.checkArgument(basePackageName != null,"Base Package Name cannot be NULL."); + Preconditions.checkArgument(refChoiceType != null,"Referenced Choice Type cannot be NULL."); + Preconditions.checkArgument(caseNodes != null,"Set of Choice Case Nodes cannot be NULL."); final List generatedTypes = new ArrayList<>(); for (final ChoiceCaseNode caseNode : caseNodes) { @@ -1399,15 +1329,9 @@ public final class BindingGeneratorImpl implements BindingGenerator { */ private List generateTypesFromAugmentedChoiceCases(final String basePackageName, final Type refChoiceType, final Set caseNodes) { - if (basePackageName == null) { - throw new IllegalArgumentException("Base Package Name cannot be NULL!"); - } - if (refChoiceType == null) { - throw new IllegalArgumentException("Referenced Choice Type cannot be NULL!"); - } - if (caseNodes == null) { - throw new IllegalArgumentException("Set of Choice Case Nodes cannot be NULL!"); - } + Preconditions.checkArgument(basePackageName != null,"Base Package Name cannot be NULL."); + Preconditions.checkArgument(refChoiceType != null,"Referenced Choice Type cannot be NULL."); + Preconditions.checkArgument(caseNodes != null,"Set of Choice Case Nodes cannot be NULL."); final List generatedTypes = new ArrayList<>(); for (final ChoiceCaseNode caseNode : caseNodes) { @@ -1734,19 +1658,11 @@ public final class BindingGeneratorImpl implements BindingGenerator { */ private GeneratedTypeBuilder addRawInterfaceDefinition(final String packageName, final SchemaNode schemaNode, final String prefix) { - if (schemaNode == null) { - throw new IllegalArgumentException("Data Schema Node cannot be NULL!"); - } - if (packageName == null) { - throw new IllegalArgumentException("Package Name for Generated Type cannot be NULL!"); - } - if (schemaNode.getQName() == null) { - throw new IllegalArgumentException("QName for Data Schema Node cannot be NULL!"); - } + Preconditions.checkArgument(schemaNode != null,"Data Schema Node cannot be NULL."); + Preconditions.checkArgument(packageName != null,"Package Name for Generated Type cannot be NULL."); + Preconditions.checkArgument(schemaNode.getQName() != null,"QName for Data Schema Node cannot be NULL."); final String schemaNodeName = schemaNode.getQName().getLocalName(); - if (schemaNodeName == null) { - throw new IllegalArgumentException("Local Name of QName for Data Schema Node cannot be NULL!"); - } + Preconditions.checkArgument(schemaNodeName != null,"Local Name of QName for Data Schema Node cannot be NULL."); final String genTypeName; if (prefix == null) { @@ -1865,12 +1781,8 @@ public final class BindingGeneratorImpl implements BindingGenerator { } private List listToGenType(final String basePackageName, final ListSchemaNode list) { - if (basePackageName == null) { - throw new IllegalArgumentException("Package Name for Generated Type cannot be NULL!"); - } - if (list == null) { - throw new IllegalArgumentException("List Schema Node cannot be NULL!"); - } + Preconditions.checkArgument(basePackageName != null,"Package Name for Generated Type cannot be NULL."); + Preconditions.checkArgument(list != null,"List Schema Node cannot be NULL."); final String packageName = packageNameForGeneratedType(basePackageName, list.getPath()); // final GeneratedTypeBuilder typeBuilder = @@ -1923,13 +1835,9 @@ public final class BindingGeneratorImpl implements BindingGenerator { */ private void addSchemaNodeToListBuilders(final String basePackageName, final DataSchemaNode schemaNode, final GeneratedTypeBuilder typeBuilder, final GeneratedTOBuilder genTOBuilder, final List listKeys) { - if (schemaNode == null) { - throw new IllegalArgumentException("Data Schema Node cannot be NULL!"); - } + Preconditions.checkArgument(schemaNode != null,"Data Schema Node cannot be NULL."); - if (typeBuilder == null) { - throw new IllegalArgumentException("Generated Type Builder cannot be NULL!"); - } + Preconditions.checkArgument(typeBuilder != null,"Generated Type Builder cannot be NULL."); if (schemaNode instanceof LeafSchemaNode) { final LeafSchemaNode leaf = (LeafSchemaNode) schemaNode; @@ -1950,9 +1858,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { private List typeBuildersToGenTypes(final GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder) { final List genTypes = new ArrayList<>(); - if (typeBuilder == null) { - throw new IllegalArgumentException("Generated Type Builder cannot be NULL!"); - } + Preconditions.checkArgument(typeBuilder != null,"Generated Type Builder cannot be NULL."); if (genTOBuilder != null) { final GeneratedTransferObject genTO = genTOBuilder.toInstance(); diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java index 01862296fa..7edc86a0e6 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java @@ -55,6 +55,8 @@ import org.opendaylight.yangtools.yang.model.util.StringType; import org.opendaylight.yangtools.yang.model.util.UnionType; import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort; +import com.google.common.base.Preconditions; + public final class TypeProviderImpl implements TypeProvider { /** * Contains the schema data red from YANG files. @@ -82,9 +84,7 @@ public final class TypeProviderImpl implements TypeProvider { * if schemaContext equal null. */ public TypeProviderImpl(final SchemaContext schemaContext) { - if (schemaContext == null) { - throw new IllegalArgumentException("Schema Context cannot be null!"); - } + Preconditions.checkArgument(schemaContext != null,"Schema Context cannot be null!"); this.schemaContext = schemaContext; this.genTypeDefsContextMap = new HashMap<>(); @@ -107,13 +107,9 @@ public final class TypeProviderImpl implements TypeProvider { * */ public void putReferencedType(final SchemaPath refTypePath, final Type refType) { - if (refTypePath == null) { - throw new IllegalArgumentException("Path reference of " + "Enumeration Type Definition cannot be NULL!"); - } + Preconditions.checkArgument(refTypePath != null,"Path reference of Enumeration Type Definition cannot be NULL!"); - if (refType == null) { - throw new IllegalArgumentException("Reference to Enumeration " + "Type cannot be NULL!"); - } + Preconditions.checkArgument(refType != null,"Reference to Enumeration Type cannot be NULL!"); referencedTypes.put(refTypePath, refType); } @@ -148,16 +144,12 @@ public final class TypeProviderImpl implements TypeProvider { @Override public Type javaTypeForSchemaDefinitionType(final TypeDefinition typeDefinition) { Type returnType = null; - if (typeDefinition == null) { - throw new IllegalArgumentException("Type Definition cannot be NULL!"); - } + Preconditions.checkArgument(typeDefinition != null,"Type Definition cannot be NULL!"); if (typeDefinition.getQName() == null) { throw new IllegalArgumentException( "Type Definition cannot have non specified QName (QName cannot be NULL!)"); } - if (typeDefinition.getQName().getLocalName() == null) { - throw new IllegalArgumentException("Type Definitions Local Name cannot be NULL!"); - } + Preconditions.checkArgument(typeDefinition.getQName().getLocalName() != null,"Type Definitions Local Name cannot be NULL!"); if (typeDefinition instanceof ExtendedType) { returnType = javaTypeForExtendedType(typeDefinition); @@ -255,9 +247,7 @@ public final class TypeProviderImpl implements TypeProvider { identity = id; } } - if (identity == null) { - throw new IllegalArgumentException("Target identity '" + baseIdQName + "' do not exists"); - } + Preconditions.checkArgument(identity != null,"Target identity '" + baseIdQName + "' do not exists"); final String basePackageName = moduleNamespaceToPackageName(module); final String packageName = packageNameForGeneratedType(basePackageName, identity.getPath()); @@ -285,16 +275,12 @@ public final class TypeProviderImpl implements TypeProvider { */ public Type generatedTypeForExtendedDefinitionType(final TypeDefinition typeDefinition) { Type returnType = null; - if (typeDefinition == null) { - throw new IllegalArgumentException("Type Definition cannot be NULL!"); - } + Preconditions.checkArgument(typeDefinition != null,"Type Definition cannot be NULL!"); if (typeDefinition.getQName() == null) { throw new IllegalArgumentException( "Type Definition cannot have non specified QName (QName cannot be NULL!)"); } - if (typeDefinition.getQName().getLocalName() == null) { - throw new IllegalArgumentException("Type Definitions Local Name cannot be NULL!"); - } + Preconditions.checkArgument(typeDefinition.getQName().getLocalName() != null,"Type Definitions Local Name cannot be NULL!"); final String typedefName = typeDefinition.getQName().getLocalName(); if (typeDefinition instanceof ExtendedType) { @@ -325,9 +311,7 @@ public final class TypeProviderImpl implements TypeProvider { * if extendTypeDef equal null */ private TypeDefinition baseTypeDefForExtendedType(final TypeDefinition extendTypeDef) { - if (extendTypeDef == null) { - throw new IllegalArgumentException("Type Definiition reference cannot be NULL!"); - } + Preconditions.checkArgument(extendTypeDef != null,"Type Definiition reference cannot be NULL!"); final TypeDefinition baseTypeDef = extendTypeDef.getBaseType(); if (baseTypeDef instanceof ExtendedType) { return baseTypeDefForExtendedType(baseTypeDef); @@ -356,13 +340,9 @@ public final class TypeProviderImpl implements TypeProvider { */ public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType) { Type returnType = null; - if (leafrefType == null) { - throw new IllegalArgumentException("Leafref Type Definition reference cannot be NULL!"); - } + Preconditions.checkArgument(leafrefType != null,"Leafref Type Definition reference cannot be NULL!"); - if (leafrefType.getPathStatement() == null) { - throw new IllegalArgumentException("The Path Statement for Leafref Type Definition cannot be NULL!"); - } + Preconditions.checkArgument(leafrefType.getPathStatement() != null,"The Path Statement for Leafref Type Definition cannot be NULL!"); final RevisionAwareXPath xpath = leafrefType.getPathStatement(); final String strXPath = xpath.toString(); @@ -460,18 +440,10 @@ public final class TypeProviderImpl implements TypeProvider { * */ private Enumeration provideTypeForEnum(final EnumTypeDefinition enumTypeDef, final String enumName) { - if (enumTypeDef == null) { - throw new IllegalArgumentException("EnumTypeDefinition reference cannot be NULL!"); - } - if (enumTypeDef.getValues() == null) { - throw new IllegalArgumentException("EnumTypeDefinition MUST contain at least ONE value definition!"); - } - if (enumTypeDef.getQName() == null) { - throw new IllegalArgumentException("EnumTypeDefinition MUST contain NON-NULL QName!"); - } - if (enumTypeDef.getQName().getLocalName() == null) { - throw new IllegalArgumentException("Local Name in EnumTypeDefinition QName cannot be NULL!"); - } + Preconditions.checkArgument(enumTypeDef != null,"EnumTypeDefinition reference cannot be NULL!"); + Preconditions.checkArgument(enumTypeDef.getValues() != null,"EnumTypeDefinition MUST contain at least ONE value definition!"); + Preconditions.checkArgument(enumTypeDef.getQName() != null,"EnumTypeDefinition MUST contain NON-NULL QName!"); + Preconditions.checkArgument(enumTypeDef.getQName().getLocalName() != null,"Local Name in EnumTypeDefinition QName cannot be NULL!"); final String enumerationName = parseToClassName(enumName); @@ -508,21 +480,11 @@ public final class TypeProviderImpl implements TypeProvider { */ private Enumeration addInnerEnumerationToTypeBuilder(final EnumTypeDefinition enumTypeDef, final String enumName, final GeneratedTypeBuilder typeBuilder) { - if (enumTypeDef == null) { - throw new IllegalArgumentException("EnumTypeDefinition reference cannot be NULL!"); - } - if (enumTypeDef.getValues() == null) { - throw new IllegalArgumentException("EnumTypeDefinition MUST contain at least ONE value definition!"); - } - if (enumTypeDef.getQName() == null) { - throw new IllegalArgumentException("EnumTypeDefinition MUST contain NON-NULL QName!"); - } - if (enumTypeDef.getQName().getLocalName() == null) { - throw new IllegalArgumentException("Local Name in EnumTypeDefinition QName cannot be NULL!"); - } - if (typeBuilder == null) { - throw new IllegalArgumentException("Generated Type Builder reference cannot be NULL!"); - } + Preconditions.checkArgument(enumTypeDef != null,"EnumTypeDefinition reference cannot be NULL!"); + Preconditions.checkArgument(enumTypeDef.getValues() != null,"EnumTypeDefinition MUST contain at least ONE value definition!"); + Preconditions.checkArgument(enumTypeDef.getQName() != null,"EnumTypeDefinition MUST contain NON-NULL QName!"); + Preconditions.checkArgument(enumTypeDef.getQName().getLocalName() != null,"Local Name in EnumTypeDefinition QName cannot be NULL!"); + Preconditions.checkArgument(typeBuilder != null,"Generated Type Builder reference cannot be NULL!"); final String enumerationName = parseToClassName(enumName); @@ -568,9 +530,7 @@ public final class TypeProviderImpl implements TypeProvider { */ private void resolveTypeDefsFromContext() { final Set modules = schemaContext.getModules(); - if (modules == null) { - throw new IllegalArgumentException("Sef of Modules cannot be NULL!"); - } + Preconditions.checkArgument(modules != null,"Sef of Modules cannot be NULL!"); final Module[] modulesArray = new Module[modules.size()]; int i = 0; for (Module modul : modules) { @@ -743,12 +703,8 @@ public final class TypeProviderImpl implements TypeProvider { */ public List provideGeneratedTOBuildersForUnionTypeDef(final String basePackageName, final TypeDefinition typedef, final String typeDefName) { - if (basePackageName == null) { - throw new IllegalArgumentException("Base Package Name cannot be NULL!"); - } - if (typedef == null) { - throw new IllegalArgumentException("Type Definition cannot be NULL!"); - } + Preconditions.checkArgument(basePackageName != null,"Base Package Name cannot be NULL!"); + Preconditions.checkArgument(typedef != null,"Type Definition cannot be NULL!"); if (typedef.getQName() == null) { throw new IllegalArgumentException( "Type Definition cannot have non specified QName (QName cannot be NULL!)"); @@ -993,12 +949,8 @@ public final class TypeProviderImpl implements TypeProvider { public GeneratedTOBuilder provideGeneratedTOBuilderForBitsTypeDefinition(final String basePackageName, final TypeDefinition typeDef, String typeDefName) { - if (typeDef == null) { - throw new IllegalArgumentException("typeDef cannot be NULL!"); - } - if (basePackageName == null) { - throw new IllegalArgumentException("Base Package Name cannot be NULL!"); - } + Preconditions.checkArgument(typeDef != null,"typeDef cannot be NULL!"); + Preconditions.checkArgument(basePackageName != null,"Base Package Name cannot be NULL!"); if (typeDef instanceof BitsTypeDefinition) { BitsTypeDefinition bitsTypeDefinition = (BitsTypeDefinition) typeDef; @@ -1037,9 +989,7 @@ public final class TypeProviderImpl implements TypeProvider { */ private List resolveRegExpressionsFromTypedef(ExtendedType typedef) { final List regExps = new ArrayList(); - if (typedef == null) { - throw new IllegalArgumentException("typedef can't be null"); - } + Preconditions.checkArgument(typedef != null,"typedef can't be null"); final TypeDefinition strTypeDef = baseTypeDefForExtendedType(typedef); if (strTypeDef instanceof StringType) { final List patternConstraints = typedef.getPatterns(); @@ -1112,15 +1062,9 @@ public final class TypeProviderImpl implements TypeProvider { private GeneratedTransferObject provideGeneratedTOFromExtendedType(final ExtendedType innerExtendedType, final String basePackageName, final String typedefName) { - if (innerExtendedType == null) { - throw new IllegalArgumentException("Extended type cannot be NULL!"); - } - if (basePackageName == null) { - throw new IllegalArgumentException("String with base package name cannot be NULL!"); - } - if (typedefName == null) { - throw new IllegalArgumentException("String with type definition name cannot be NULL!"); - } + Preconditions.checkArgument(innerExtendedType != null,"Extended type cannot be NULL!"); + Preconditions.checkArgument(basePackageName != null,"String with base package name cannot be NULL!"); + Preconditions.checkArgument(typedefName != null,"String with type definition name cannot be NULL!"); final String classTypedefName = parseToClassName(typedefName); final String innerTypeDef = innerExtendedType.getQName().getLocalName(); @@ -1190,9 +1134,7 @@ public final class TypeProviderImpl implements TypeProvider { * definition to the base type */ private int getTypeDefinitionDepth(final TypeDefinition typeDefinition) { - if (typeDefinition == null) { - throw new IllegalArgumentException("Type definition can't be null"); - } + Preconditions.checkArgument(typeDefinition != null,"Type definition can't be null"); int depth = 1; TypeDefinition baseType = typeDefinition.getBaseType(); diff --git a/pom.xml b/pom.xml index bc25c94539..2d4d5fd37b 100644 --- a/pom.xml +++ b/pom.xml @@ -118,6 +118,11 @@ slf4j-api 1.7.2 + + com.google.guava + guava + 14.0.1 + -- 2.36.6