Fix null comparison warnings 22/52222/2
authorRobert Varga <rovarga@cisco.com>
Thu, 23 Feb 2017 17:48:17 +0000 (18:48 +0100)
committerRobert Varga <nite@hq.sk>
Fri, 24 Feb 2017 09:53:42 +0000 (09:53 +0000)
Xtend comparisons to null should be done via !==/===, fix offenders.

Change-Id: I4dff8e444104cca427843aa88a5df989b3fed77c
Signed-off-by: Robert Varga <rovarga@cisco.com>
binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/yangtools/yang/unified/doc/generator/GeneratorImpl.xtend
binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/yangtools/yang/wadl/generator/WadlRestconfGenerator.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BaseTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BuilderTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/ClassTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/InterfaceTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/UnionTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/YangModuleInfoTemplate.xtend

index 654b53160207c1d70be17567962ab4e15371ff24..3858beadfd348a3f3fb06da8c6e5dd78b5f16c1d 100644 (file)
@@ -343,14 +343,14 @@ class GeneratorImpl {
             val module = ctx.findModuleByNamespaceAndRevision(pathElement.namespace, pathElement.revision);
             if (module !== null) {
                 var foundNode = module.getDataChildByName(pathElement)
-                if(foundNode == null) {
+                if (foundNode === null) {
                     val child = nodes.last
                     if (child instanceof DataNodeContainer) {
                         val dataContNode = child as DataNodeContainer
                         foundNode = findNodeInChildNodes(pathElement, dataContNode.childNodes)
                     }
                 }
-                if(foundNode != null) {
+                if (foundNode !== null) {
                     nodes.add(foundNode);
                 }
             }
@@ -372,14 +372,13 @@ class GeneratorImpl {
         }
         // find recursively
         for(child : childNodes) {
-            if(child instanceof ContainerSchemaNode) {
+            if (child instanceof ContainerSchemaNode) {
                 val foundChild = findNodeInChildNodes(findingNode, child.childNodes)
-                if (foundChild != null)
+                if (foundChild !== null)
                     return foundChild;
-            }
-            else if(child instanceof ListSchemaNode) {
+            } else if (child instanceof ListSchemaNode) {
                 val foundChild = findNodeInChildNodes(findingNode, child.childNodes)
-                if (foundChild != null)
+                if (foundChild !== null)
                     return foundChild;
             }
         }
@@ -1205,7 +1204,7 @@ class GeneratorImpl {
         for (name : path) {
             if (parent instanceof DataNodeContainer) {
                 var SchemaNode node = parent.getDataChildByName(name)
-                if (node == null && (parent instanceof Module)) {
+                if (node === null && (parent instanceof Module)) {
                     val notifications = (parent as Module).notifications;
                     for (notification : notifications) {
                         if (notification.QName.equals(name)) {
@@ -1213,7 +1212,7 @@ class GeneratorImpl {
                         }
                     }
                 }
-                if (node == null && (parent instanceof Module)) {
+                if (node === null && (parent instanceof Module)) {
                     val rpcs = (parent as Module).rpcs;
                     for (rpc : rpcs) {
                         if (rpc.QName.equals(name)) {
@@ -1252,7 +1251,7 @@ class GeneratorImpl {
 
     def CharSequence childInfo(DataSchemaNode node, Map<SchemaPath, DataSchemaNode> childNodes) '''
         «val String path = nodeSchemaPathToPath(node, childNodes)»
-        «IF path != null»
+        «IF path !== null»
             «code(path)»
                 «IF node !== null»
                 <ul>
@@ -1324,7 +1323,7 @@ class GeneratorImpl {
     '''
 
     def toLengthStmt(Collection<LengthConstraint> lengths) '''
-        «IF lengths != null && !lengths.empty»
+        «IF lengths !== null && !lengths.empty»
             «listItem("Length restrictions:")»
             <ul>
             «FOR length : lengths»
@@ -1341,7 +1340,7 @@ class GeneratorImpl {
     '''
 
     def toRangeStmt(Collection<RangeConstraint> ranges) '''
-        «IF ranges != null && !ranges.empty»
+        «IF ranges !== null && !ranges.empty»
             «listItem("Range restrictions:")»
             <ul>
             «FOR range : ranges»
@@ -1358,7 +1357,7 @@ class GeneratorImpl {
     '''
 
     def toBaseStmt(TypeDefinition<?> baseType) '''
-        «IF baseType != null»
+        «IF baseType !== null»
         «listItem("Base type", typeAnchorLink(baseType?.path, baseType.QName.localName))»
         «ENDIF»
     '''
index 2a25d919a7a0acf4aade4284c987039e1ad28066..2db6253959782821dab2ec7d1d38ce5455a14dee 100644 (file)
@@ -133,7 +133,7 @@ class WadlRestconfGenerator {
                        <resource path="operations">
                                «FOR rpc : module.rpcs»
                                        <resource path="«module.name»:«rpc.QName.localName»">
-                                               «methodPostRpc(rpc.input != null, rpc.output !== null)»
+                                               «methodPostRpc(rpc.input !== null, rpc.output !== null)»
                                        </resource>
                                «ENDFOR»
                        </resource>
@@ -188,7 +188,7 @@ class WadlRestconfGenerator {
        
        private def resourceParams() '''
                «FOR pathParam : pathListParams»
-                   «IF pathParam != null»
+                   «IF pathParam !== null»
                        «val type = pathParam.type.QName.localName»
                        <param required="true" style="template" name="«pathParam.QName.localName»" type="«type»"/>
                        «ENDIF»
index c729af79e0fa47bf1f3a1d0b476275e2f9af5b99..530d53a06390ae4cecec8fb7f90ec95b8d229efa 100644 (file)
@@ -39,7 +39,7 @@ abstract class BaseTemplate {
     private static final Splitter NL_SPLITTER = Splitter.on(NL_MATCHER)
 
     new(GeneratedType _type) {
-        if (_type == null) {
+        if (_type === null) {
             throw new IllegalArgumentException("Generated type reference cannot be NULL!")
         }
         this.type = _type;
@@ -176,7 +176,7 @@ abstract class BaseTemplate {
      * @return string with comment in JAVA format
      */
     def protected CharSequence asJavadoc(String comment) {
-        if(comment == null) return ''
+        if(comment === null) return ''
         var txt = comment
 
         txt = comment.trim
@@ -290,7 +290,7 @@ abstract class BaseTemplate {
     }
 
     protected def formatToParagraph(String text) {
-        if(text == null || text.isEmpty)
+        if(text === null || text.isEmpty)
             return text
 
         var formattedText = text
@@ -401,7 +401,7 @@ abstract class BaseTemplate {
             }
         }
         val GeneratedTransferObject parent = gto.superType
-        if (parent != null) {
+        if (parent !== null) {
             return findProperty(parent, name)
         }
         return null
index 1d1b39257587c52d993e2206f5d2c0ef8d0ce5c7..b51d77b1203f16fe0fa5bfb42e05f93fb6de33d5 100644 (file)
@@ -105,7 +105,7 @@ class BuilderTemplate extends BaseTemplate {
      * @param implementedIfcs list of implemented interfaces
      */
     def private void collectImplementedMethods(Set<MethodSignature> methods, List<Type> implementedIfcs) {
-        if (implementedIfcs == null || implementedIfcs.empty) {
+        if (implementedIfcs === null || implementedIfcs.empty) {
             return
         }
         for (implementedIfc : implementedIfcs) {
@@ -169,13 +169,13 @@ class BuilderTemplate extends BaseTemplate {
      * @return set of generated property instances which represents the getter <code>methods</code>
      */
     def private propertiesFromMethods(Collection<MethodSignature> methods) {
-        if (methods == null || methods.isEmpty()) {
+        if (methods === null || methods.isEmpty()) {
             return Collections.emptySet
         }
         val Set<GeneratedProperty> result = new LinkedHashSet
         for (m : methods) {
             val createdField = m.propertyFromGetter
-            if (createdField != null) {
+            if (createdField !== null) {
                 result.add(createdField)
             }
         }
@@ -195,11 +195,11 @@ class BuilderTemplate extends BaseTemplate {
      * </ul>
      */
     def private GeneratedProperty propertyFromGetter(MethodSignature method) {
-        if (method == null || method.name == null || method.name.empty || method.returnType == null) {
+        if (method === null || method.name === null || method.name.empty || method.returnType === null) {
             throw new IllegalArgumentException("Method, method name, method return type reference cannot be NULL or empty!")
         }
         var prefix = "get";
-        if(Types.BOOLEAN.equals(method.returnType)) {
+        if (Types.BOOLEAN.equals(method.returnType)) {
             prefix = "is";
         }
         if (method.name.startsWith(prefix)) {
@@ -419,7 +419,7 @@ class BuilderTemplate extends BaseTemplate {
     '''
 
     def private generateAugmentField(boolean isPrivate) '''
-        «IF augmentField != null»
+        «IF augmentField !== null»
             «IF isPrivate»private «ENDIF»«Map.importedName»<«Class.importedName»<? extends «augmentField.returnType.importedName»>, «augmentField.returnType.importedName»> «augmentField.name» = «Collections.importedName».emptyMap();
         «ENDIF»
     '''
@@ -433,7 +433,7 @@ class BuilderTemplate extends BaseTemplate {
         «FOR field : properties SEPARATOR '\n'»
              «/* FIXME: generate checkers as simple blocks and embed them directly in setters  */»
              «val restrictions = field.returnType.restrictions»
-             «IF !(field.returnType instanceof GeneratedType) && restrictions != null»
+             «IF !(field.returnType instanceof GeneratedType) && restrictions !== null»
                     «IF !restrictions.rangeConstraints.nullOrEmpty»
                         «val rangeGenerator = AbstractRangeGenerator.forType(field.returnType)»
                         «rangeGenerator.generateRangeChecker(field.name.toFirstUpper, restrictions.rangeConstraints)»
@@ -445,8 +445,8 @@ class BuilderTemplate extends BaseTemplate {
                     «ENDIF»
             «ENDIF»
             public «type.name»«BUILDER» set«field.name.toFirstUpper»(final «field.returnType.importedName» value) {
-            «IF !(field.returnType instanceof GeneratedType) && restrictions != null»
-                «IF restrictions != null && (!restrictions.rangeConstraints.nullOrEmpty || !restrictions.lengthConstraints.nullOrEmpty)»
+            «IF !(field.returnType instanceof GeneratedType) && restrictions !== null»
+                «IF restrictions !== null && (!restrictions.rangeConstraints.nullOrEmpty || !restrictions.lengthConstraints.nullOrEmpty)»
                 if (value != null) {
                     «IF !restrictions.rangeConstraints.nullOrEmpty»
                         «val rangeGenerator = AbstractRangeGenerator.forType(field.returnType)»
@@ -470,7 +470,7 @@ class BuilderTemplate extends BaseTemplate {
                 return this;
             }
         «ENDFOR»
-        «IF augmentField != null»
+        «IF augmentField !== null»
 
             public «type.name»«BUILDER» add«augmentField.name.toFirstUpper»(«Class.importedName»<? extends «augmentField.returnType.importedName»> augmentationType, «augmentField.returnType.importedName» augmentation) {
                 if (augmentation == null) {
@@ -499,7 +499,7 @@ class BuilderTemplate extends BaseTemplate {
             «val allProps = new ArrayList(properties)»
             «val isList = implementsIfc(type, Types.parameterizedTypeFor(Types.typeForClass(Identifiable), type))»
             «val keyType = type.getKey»
-            «IF isList && keyType != null»
+            «IF isList && keyType !== null»
                 «val keyProps = new ArrayList((keyType as GeneratedTransferObject).properties)»
                 «Collections.sort(keyProps,
                     [ p1, p2 |
@@ -529,7 +529,7 @@ class BuilderTemplate extends BaseTemplate {
             «FOR field : allProps»
                 this.«field.fieldName» = base.«field.getterMethodName»();
             «ENDFOR»
-            «IF augmentField != null»
+            «IF augmentField !== null»
                 «IF impl»
                     switch (base.«augmentField.name».size()) {
                     case 0:
@@ -585,7 +585,7 @@ class BuilderTemplate extends BaseTemplate {
                 toRemove = p;
             }
         }
-        if (toRemove != null) {
+        if (toRemove !== null) {
             props.remove(toRemove);
         }
     }
@@ -602,7 +602,7 @@ class BuilderTemplate extends BaseTemplate {
                 «field.getterMethod»
             «ENDFOR»
         «ENDIF»
-        «IF augmentField != null»
+        «IF augmentField !== null»
 
             @SuppressWarnings("unchecked")
             «IF addOverride»@Override«ENDIF»
@@ -621,7 +621,7 @@ class BuilderTemplate extends BaseTemplate {
      * @return string with the <code>hashCode()</code> method definition in JAVA format
      */
     def protected generateHashCode() '''
-        «IF !properties.empty || augmentField != null»
+        «IF !properties.empty || augmentField !== null»
             private int hash = 0;
             private volatile boolean hashValid = false;
 
@@ -640,7 +640,7 @@ class BuilderTemplate extends BaseTemplate {
                     result = prime * result + «Objects.importedName».hashCode(«property.fieldName»);
                     «ENDIF»
                 «ENDFOR»
-                «IF augmentField != null»
+                «IF augmentField !== null»
                     result = prime * result + «Objects.importedName».hashCode(«augmentField.name»);
                 «ENDIF»
 
@@ -657,7 +657,7 @@ class BuilderTemplate extends BaseTemplate {
      * @return string with the <code>equals()</code> method definition in JAVA format
      */
     def protected generateEquals() '''
-        «IF !properties.empty || augmentField != null»
+        «IF !properties.empty || augmentField !== null»
             @Override
             public boolean equals(«Object.importedName» obj) {
                 if (this == obj) {
@@ -680,7 +680,7 @@ class BuilderTemplate extends BaseTemplate {
                         return false;
                     }
                 «ENDFOR»
-                «IF augmentField != null»
+                «IF augmentField !== null»
                     if (getClass() == obj.getClass()) {
                         // Simple case: we are comparing against self
                         «type.name»«IMPL» otherImpl = («type.name»«IMPL») obj;
@@ -721,7 +721,7 @@ class BuilderTemplate extends BaseTemplate {
                             builder.append(«property.fieldName»);
                         «ENDIF»
                 «ENDFOR»
-                «IF augmentField != null»
+                «IF augmentField !== null»
                     «IF !properties.empty»
                 «««Append comma separator only if it's not there already from previous operation»»»
 final int builderLength = builder.length();
index 8c8f5ff0763a61fa591562141f764b38d59b1488..d0edc24741a216dde3c53fbe4b92c85eb367a114 100644 (file)
@@ -84,7 +84,7 @@ class ClassTemplate extends BaseTemplate {
         this.consts = genType.constantDefinitions
         this.enclosedGeneratedTypes = genType.enclosedTypes
 
-        if (restrictions != null && !restrictions.rangeConstraints.nullOrEmpty) {
+        if (restrictions !== null && !restrictions.rangeConstraints.nullOrEmpty) {
             rangeGenerator = AbstractRangeGenerator.forType(findProperty(genType, "value").returnType)
             Preconditions.checkNotNull(rangeGenerator)
         } else {
@@ -121,7 +121,7 @@ class ClassTemplate extends BaseTemplate {
             «constantsDeclarations»
             «generateFields»
 
-            «IF restrictions != null»
+            «IF restrictions !== null»
                 «IF !restrictions.lengthConstraints.nullOrEmpty»
                     «LengthGenerator.generateLengthChecker("_value", findProperty(genTO, "value").returnType, restrictions.lengthConstraints)»
                 «ENDIF»
@@ -387,7 +387,7 @@ class ClassTemplate extends BaseTemplate {
         ELSE»«
             " "»«
         ENDIF»class «type.name»«
-        IF (genTO.superType != null)»«
+        IF (genTO.superType !== null)»«
             " extends "»«genTO.superType.importedName»«
         ENDIF»
         «IF (!type.implements.empty)»«
@@ -413,13 +413,13 @@ class ClassTemplate extends BaseTemplate {
     '''
 
     def protected suidDeclaration() '''
-        «IF genTO.SUID != null»
+        «IF genTO.SUID !== null»
             private static final long serialVersionUID = «genTO.SUID.value»L;
         «ENDIF»
     '''
 
     def protected annotationDeclaration() '''
-        «IF genTO.getAnnotations != null»
+        «IF genTO.getAnnotations !== null»
             «FOR e : genTO.getAnnotations»
                 @«e.getName»
             «ENDFOR»
index 61c7b2a4cfc7bd2d8186a6f8dbeb15e34ace4b85..9b95ffa51e1c8817036ce34d94984a22a984ded9 100644 (file)
@@ -49,7 +49,7 @@ class InterfaceTemplate extends BaseTemplate {
      */
     new(GeneratedType genType) {
         super(genType)
-        if (genType == null) {
+        if (genType === null) {
             throw new IllegalArgumentException("Generated type reference cannot be NULL!")
         }
 
@@ -85,10 +85,10 @@ class InterfaceTemplate extends BaseTemplate {
 
 
     def private generateAnnotations(List<AnnotationType> annotations) '''
-        «IF annotations != null && !annotations.empty»
+        «IF annotations !== null && !annotations.empty»
             «FOR annotation : annotations»
                 @«annotation.importedName»
-                «IF annotation.parameters != null && !annotation.parameters.empty»
+                «IF annotation.parameters !== null && !annotation.parameters.empty»
                 (
                 «FOR param : annotation.parameters SEPARATOR ","»
                     «param.name»=«param.value»
index 85cdbde306c0e12e98fe56242f8c05955d38b4ea..7ff03a66f65f82af834f78248327780e3c4f0b9f 100644 (file)
@@ -36,7 +36,7 @@ class UnionTemplate extends ClassTemplate {
         for (property : finalProperties) {
             val propRet = property.returnType
             if (propRet instanceof GeneratedTransferObject && (propRet as GeneratedTransferObject).typedef &&
-                (propRet as GeneratedTransferObject).properties != null &&
+                (propRet as GeneratedTransferObject).properties !== null &&
                 !(propRet as GeneratedTransferObject).properties.empty &&
                 ((propRet as GeneratedTransferObject).properties.size == 1) &&
                 (propRet as GeneratedTransferObject).properties.get(0).name.equals("value") &&
@@ -144,7 +144,7 @@ class UnionTemplate extends ClassTemplate {
                                 «field.fieldName» = «property.fieldName».getValue();
                             «ELSEIF propRet instanceof GeneratedTransferObject // Is it a GeneratedTransferObject
                                     && (propRet as GeneratedTransferObject).typedef  // Is it a typedef
-                                    && (propRet as GeneratedTransferObject).properties != null
+                                    && (propRet as GeneratedTransferObject).properties !== null
                                     && !(propRet as GeneratedTransferObject).properties.empty
                                     && ((propRet as GeneratedTransferObject).properties.size == 1)
                                     && (propRet as GeneratedTransferObject).properties.get(0).name.equals("value")
@@ -153,7 +153,7 @@ class UnionTemplate extends ClassTemplate {
                                 «field.fieldName» = «property.fieldName».isValue().toString().toCharArray();
                             «ELSEIF propRet instanceof GeneratedTransferObject // Is it a GeneratedTransferObject
                                     && (propRet as GeneratedTransferObject).typedef  // Is it a typedef
-                                    && (propRet as GeneratedTransferObject).properties != null
+                                    && (propRet as GeneratedTransferObject).properties !== null
                                     && !(propRet as GeneratedTransferObject).properties.empty
                                     && ((propRet as GeneratedTransferObject).properties.size == 1)
                                     && (propRet as GeneratedTransferObject).properties.get(0).name.equals("value")
index 850e35e68f0a11a6cdf17c9a5f3b5c5a78fdaca7..cad96c65abdbdeac5a2387f674ca194b47a2350b 100644 (file)
@@ -104,7 +104,7 @@ class YangModuleInfoTemplate {
                 «FOR imp : m.imports»
                     «val name = imp.moduleName»
                     «val rev = imp.revision»
-                    «IF rev == null»
+                    «IF rev === null»
                         «val Set<Module> modules = ctx.modules»
                         «val TreeMap<Date, Module> sorted = new TreeMap()»
                         «FOR module : modules»
@@ -217,7 +217,7 @@ class YangModuleInfoTemplate {
         }
         if (type instanceof ParameterizedType) {
             val Type[] params = type.getActualTypeArguments()
-            if (params != null) {
+            if (params !== null) {
                 for (Type param : params) {
                     putTypeIntoImports(param);
                 }
@@ -262,7 +262,7 @@ class YangModuleInfoTemplate {
     }
 
     final def String getParameters(Type[] pTypes) {
-        if (pTypes == null || pTypes.length == 0) {
+        if (pTypes === null || pTypes.length == 0) {
             return "?";
         }
         val StringBuilder builder = new StringBuilder();