Merge "BUG-868: stop using getChildren()"
authorTony Tkacik <ttkacik@cisco.com>
Mon, 26 May 2014 19:32:20 +0000 (19:32 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 26 May 2014 19:32:20 +0000 (19:32 +0000)
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/BindingMapping.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/repo/SchemaSourceProviders.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySort.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ParserUtils.java

index cee410c66e050025e749abdff46e6344cb1792dd..b420ed80d1289148fe2f3fb2df1acbc26a109d42 100644 (file)
@@ -14,12 +14,9 @@ import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -43,6 +40,8 @@ import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 
+import com.google.common.base.Splitter;
+
 /**
  * Contains the methods for converting strings to valid JAVA language strings
  * (package names, class names, attribute names).
@@ -64,17 +63,6 @@ public final class BindingGeneratorUtil {
         }
     };
 
-    /**
-     * Array of strings values which represents JAVA reserved words.
-     */
-    @Deprecated
-    private static final String[] SET_VALUES = new String[] { "abstract", "assert", "boolean", "break", "byte", "case",
-            "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends",
-            "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int",
-            "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return",
-            "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient",
-            "true", "try", "void", "volatile", "while" };
-
     /**
      * Impossible to instantiate this class. All of the methods or attributes
      * are static.
@@ -82,17 +70,12 @@ public final class BindingGeneratorUtil {
     private BindingGeneratorUtil() {
     }
 
-    /**
-     * Hash set of words which are reserved in JAVA language.
-     */
-    @Deprecated
-    private static final Set<String> JAVA_RESERVED_WORDS = new HashSet<String>(Arrays.asList(SET_VALUES));
-
     /**
      * Pre-compiled replacement pattern.
      */
     private static final Pattern COLON_SLASH_SLASH = Pattern.compile("://", Pattern.LITERAL);
     private static final String QUOTED_DOT = Matcher.quoteReplacement(".");
+    private static final Splitter DOT = Splitter.on('.');
 
     /**
      * Converts string <code>packageName</code> to valid JAVA package name.
@@ -105,26 +88,27 @@ public final class BindingGeneratorUtil {
      * @return package name which contains words separated by point.
      */
     private static String validateJavaPackage(final String packageName) {
-        if (packageName != null) {
-            final String[] packNameParts = packageName.toLowerCase().split("\\.");
-            if (packNameParts != null) {
-                final StringBuilder builder = new StringBuilder();
-                for (int i = 0; i < packNameParts.length; ++i) {
-                    final String packNamePart = packNameParts[i];
-                    if (Character.isDigit(packNamePart.charAt(0))) {
-                        packNameParts[i] = "_" + packNamePart;
-                    } else if (JAVA_RESERVED_WORDS.contains(packNamePart)) {
-                        packNameParts[i] = "_" + packNamePart;
-                    }
-                    if (i > 0) {
-                        builder.append(".");
-                    }
-                    builder.append(packNameParts[i]);
-                }
-                return builder.toString();
+        if (packageName == null) {
+            return null;
+        }
+
+        final StringBuilder builder = new StringBuilder();
+        boolean first = true;
+
+        for (String p : DOT.split(packageName.toLowerCase())) {
+            if (first) {
+                first = false;
+            } else {
+                builder.append('.');
+            }
+
+            if (Character.isDigit(p.charAt(0)) || BindingMapping.JAVA_RESERVED_WORDS.contains(p)) {
+                builder.append('_');
             }
+            builder.append(p);
         }
-        return packageName;
+
+        return builder.toString();
     }
 
     /**
@@ -138,7 +122,7 @@ public final class BindingGeneratorUtil {
      * @return string with the admissible parameter name
      */
     public static String resolveJavaReservedWordEquivalency(final String parameterName) {
-        if (parameterName != null && JAVA_RESERVED_WORDS.contains(parameterName)) {
+        if (parameterName != null && BindingMapping.JAVA_RESERVED_WORDS.contains(parameterName)) {
             return "_" + parameterName;
         }
         return parameterName;
@@ -169,28 +153,32 @@ public final class BindingGeneratorUtil {
         if (module.getRevision() == null) {
             throw new IllegalArgumentException("Module " + module.getName() + " does not specify revision date!");
         }
-        packageNameBuilder.append("org.opendaylight.yang.gen.v");
-        packageNameBuilder.append(module.getYangVersion());
+        packageNameBuilder.append(BindingMapping.PACKAGE_PREFIX);
         packageNameBuilder.append('.');
 
         String namespace = module.getNamespace().toString();
         namespace = COLON_SLASH_SLASH.matcher(namespace).replaceAll(QUOTED_DOT);
 
-        // FIXME: improve these
-        namespace = namespace.replace("/", ".");
-        namespace = namespace.replace(":", ".");
-        namespace = namespace.replace("-", ".");
-        namespace = namespace.replace("@", ".");
-        namespace = namespace.replace("$", ".");
-        namespace = namespace.replace("#", ".");
-        namespace = namespace.replace("'", ".");
-        namespace = namespace.replace("*", ".");
-        namespace = namespace.replace("+", ".");
-        namespace = namespace.replace(",", ".");
-        namespace = namespace.replace(";", ".");
-        namespace = namespace.replace("=", ".");
-
-        packageNameBuilder.append(namespace);
+        final char[] chars = namespace.toCharArray();
+        for (int i = 0; i < chars.length; ++i) {
+            switch (chars[i]) {
+            case '/':
+            case ':':
+            case '-':
+            case '@':
+            case '$':
+            case '#':
+            case '\'':
+            case '*':
+            case '+':
+            case ',':
+            case ';':
+            case '=':
+                chars[i] = '.';
+            }
+        }
+
+        packageNameBuilder.append(chars);
         packageNameBuilder.append(".rev");
         packageNameBuilder.append(DATE_FORMAT.get().format(module.getRevision()));
 
@@ -235,11 +223,11 @@ public final class BindingGeneratorUtil {
             traversalSteps = (pathToNode.size() - 1);
         }
         for (int i = 0; i < traversalSteps; ++i) {
-            builder.append(".");
+            builder.append('.');
             String nodeLocalName = pathToNode.get(i).getLocalName();
 
-            nodeLocalName = nodeLocalName.replace(":", ".");
-            nodeLocalName = nodeLocalName.replace("-", ".");
+            nodeLocalName = nodeLocalName.replace(':', '.');
+            nodeLocalName = nodeLocalName.replace('-', '.');
             builder.append(nodeLocalName);
         }
         return validateJavaPackage(builder.toString());
index 7abb03b7841935f9f272c5f4cbe8791a50559048..30048130443b483f323698c020b9a1d85f360a4c 100644 (file)
@@ -33,7 +33,7 @@ public final class BindingMapping {
     public static final String QNAME_STATIC_FIELD_NAME = "QNAME";
     public static final String PACKAGE_PREFIX = "org.opendaylight.yang.gen.v1";
 
-    private static final Splitter SPACE_SPLITTER = Splitter.on(" ").omitEmptyStrings().trimResults();
+    private static final Splitter SPACE_SPLITTER = Splitter.on(' ').omitEmptyStrings().trimResults();
 
     public static final String MODULE_INFO_CLASS_NAME = "$YangModuleInfoImpl";
     public static final String MODEL_BINDING_PROVIDER_CLASS_NAME = "$YangModelBindingProvider";
index 10fa4d52a2cab66a3603e66740bb3e5b26a445f9..a0a2f512444f8610bb27924f4e16cdd7b9f337be 100644 (file)
@@ -7,11 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.model.util.repo;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
-import java.io.StringBufferInputStream;
 
 import org.opendaylight.yangtools.concepts.Delegator;
 
+import com.google.common.base.Charsets;
 import com.google.common.base.Optional;
 
 public class SchemaSourceProviders {
@@ -20,12 +21,12 @@ public class SchemaSourceProviders {
     private static final SchemaSourceProvider NOOP_PROVIDER = new AdvancedSchemaSourceProvider() {
 
         @Override
-        public Optional getSchemaSource(String moduleName, Optional revision) {
+        public Optional getSchemaSource(final String moduleName, final Optional revision) {
             return Optional.absent();
         }
 
         @Override
-        public Optional getSchemaSource(SourceIdentifier sourceIdentifier) {
+        public Optional getSchemaSource(final SourceIdentifier sourceIdentifier) {
             return Optional.absent();
         }
 
@@ -33,15 +34,15 @@ public class SchemaSourceProviders {
 
     @SuppressWarnings("unchecked")
     public static <T> SchemaSourceProvider<T> noopProvider() {
-        return (SchemaSourceProvider<T>) NOOP_PROVIDER;
+        return NOOP_PROVIDER;
     }
 
     public static SchemaSourceProvider<InputStream> inputStreamProviderfromStringProvider(
-            AdvancedSchemaSourceProvider<String> delegate) {
+            final AdvancedSchemaSourceProvider<String> delegate) {
         return new StringToInputStreamSchemaSourceProvider(delegate);
     }
 
-    public static <O> AdvancedSchemaSourceProvider<O> toAdvancedSchemaSourceProvider(SchemaSourceProvider<O> schemaSourceProvider) {
+    public static <O> AdvancedSchemaSourceProvider<O> toAdvancedSchemaSourceProvider(final SchemaSourceProvider<O> schemaSourceProvider) {
         if (schemaSourceProvider instanceof AdvancedSchemaSourceProvider<?>) {
             return (AdvancedSchemaSourceProvider<O>) schemaSourceProvider;
         }
@@ -51,9 +52,9 @@ public class SchemaSourceProviders {
     private final static class StringToInputStreamSchemaSourceProvider implements //
             AdvancedSchemaSourceProvider<InputStream>, Delegator<AdvancedSchemaSourceProvider<String>> {
 
-        private AdvancedSchemaSourceProvider<String> delegate;
+        private final AdvancedSchemaSourceProvider<String> delegate;
 
-        public StringToInputStreamSchemaSourceProvider(AdvancedSchemaSourceProvider<String> delegate) {
+        public StringToInputStreamSchemaSourceProvider(final AdvancedSchemaSourceProvider<String> delegate) {
             this.delegate = delegate;
         }
 
@@ -63,19 +64,18 @@ public class SchemaSourceProviders {
         }
 
         @Override
-        public Optional<InputStream> getSchemaSource(SourceIdentifier sourceIdentifier) {
+        public Optional<InputStream> getSchemaSource(final SourceIdentifier sourceIdentifier) {
             Optional<String> potentialSource = getDelegate().getSchemaSource(sourceIdentifier);
             if (potentialSource.isPresent()) {
-                String stringSource = potentialSource.get();
-                @SuppressWarnings("deprecation")
-                StringBufferInputStream stringInputStream = new StringBufferInputStream(stringSource);
-                return Optional.<InputStream> of(stringInputStream);
+                final String stringSource = potentialSource.get();
+                return Optional.<InputStream> of(
+                        new ByteArrayInputStream(stringSource.getBytes(Charsets.UTF_8)));
             }
             return Optional.absent();
         }
 
         @Override
-        public Optional<InputStream> getSchemaSource(String moduleName, Optional<String> revision) {
+        public Optional<InputStream> getSchemaSource(final String moduleName, final Optional<String> revision) {
             return getSchemaSource(SourceIdentifier.create(moduleName, revision));
         }
     }
@@ -86,7 +86,7 @@ public class SchemaSourceProviders {
 
         private final SchemaSourceProvider<O> delegate;
 
-        public SchemaSourceCompatibilityWrapper(SchemaSourceProvider<O> delegate) {
+        public SchemaSourceCompatibilityWrapper(final SchemaSourceProvider<O> delegate) {
             this.delegate = delegate;
         }
 
@@ -94,17 +94,17 @@ public class SchemaSourceProviders {
         public SchemaSourceProvider<O> getDelegate() {
             return delegate;
         }
-        
+
         @Override
-        public Optional<O> getSchemaSource(SourceIdentifier sourceIdentifier) {
-            
+        public Optional<O> getSchemaSource(final SourceIdentifier sourceIdentifier) {
+
             final String moduleName = sourceIdentifier.getName();
             Optional<String> revision = Optional.fromNullable(sourceIdentifier.getRevision());
             return delegate.getSchemaSource(moduleName, revision);
         }
-        
+
         @Override
-        public Optional<O> getSchemaSource(String moduleName, Optional<String> revision) {
+        public Optional<O> getSchemaSource(final String moduleName, final Optional<String> revision) {
             return delegate.getSchemaSource(moduleName, revision);
         }
     }
index ea304d4f10696b48dd3c41dde8ca7a76aca0ec6e..7e5941c0534fec35eb1e6bc814b7616625c5dfc5 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.parser.util;
 
 import java.net.URI;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -19,6 +18,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -295,7 +295,7 @@ public final class ModuleDependencySort {
     }
 
     private static String formatRevDate(final Date rev) {
-        return rev.equals(DEFAULT_REVISION) ? "default" : new SimpleDateFormat("yyyy-MM-dd").format(rev);
+        return rev.equals(DEFAULT_REVISION) ? "default" : SimpleDateFormatUtil.getRevisionFormat().format(rev);
     }
 
     @VisibleForTesting
index bd227125df7d57a4acf241f9699475a889c8ddb9..a8914d5e6ff775521f50c2e759b1962e6a5ca1f7 100644 (file)
@@ -7,10 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.util;
 
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Collections2;
-import com.google.common.io.ByteSource;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -21,10 +17,12 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
+
 import org.apache.commons.io.IOUtils;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
@@ -71,14 +69,22 @@ import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuil
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Collections2;
+import com.google.common.io.ByteSource;
+
 public final class ParserUtils {
 
     private static final Logger LOG = LoggerFactory.getLogger(ParserUtils.class);
+    private static final Splitter SLASH_SPLITTER = Splitter.on('/');
+    private static final Splitter COLON_SPLITTER = Splitter.on(':');
 
     private ParserUtils() {
     }
 
-    public static Collection<ByteSource> streamsToByteSources(Collection<InputStream> streams) {
+    public static Collection<ByteSource> streamsToByteSources(final Collection<InputStream> streams) {
         return Collections2.transform(streams, new Function<InputStream, ByteSource>() {
             @Override
             public ByteSource apply(final InputStream input) {
@@ -101,7 +107,7 @@ public final class ParserUtils {
         };
     }
 
-    public static Collection<ByteSource> filesToByteSources(Collection<File> streams) throws FileNotFoundException {
+    public static Collection<ByteSource> filesToByteSources(final Collection<File> streams) throws FileNotFoundException {
         return Collections2.transform(streams, new Function<File, ByteSource>() {
             @Override
             public ByteSource apply(final File input) {
@@ -121,7 +127,7 @@ public final class ParserUtils {
      * @param sourceToBuilder
      *            source to module mapping
      */
-    public static void setSourceToBuilder(Map<ByteSource, ModuleBuilder> sourceToBuilder) throws IOException {
+    public static void setSourceToBuilder(final Map<ByteSource, ModuleBuilder> sourceToBuilder) throws IOException {
         for (Map.Entry<ByteSource, ModuleBuilder> entry : sourceToBuilder.entrySet()) {
             ModuleBuilder builder = entry.getValue();
             ByteSource source = entry.getKey();
@@ -153,7 +159,7 @@ public final class ParserUtils {
      *            one or more qnames added to base path
      * @return new SchemaPath from given path and qname
      */
-    public static SchemaPath createSchemaPath(SchemaPath schemaPath, QName... qname) {
+    public static SchemaPath createSchemaPath(final SchemaPath schemaPath, final QName... qname) {
         List<QName> path = new ArrayList<>(schemaPath.getPath());
         path.addAll(Arrays.asList(qname));
         return new SchemaPath(path, schemaPath.isAbsolute());
@@ -168,7 +174,7 @@ public final class ParserUtils {
      *            prefix associated with import
      * @return ModuleImport based on given prefix
      */
-    public static ModuleImport getModuleImport(ModuleBuilder builder, String prefix) {
+    public static ModuleImport getModuleImport(final ModuleBuilder builder, final String prefix) {
         for (ModuleImport mi : builder.getModuleImports()) {
             if (mi.getPrefix().equals(prefix)) {
                 return mi;
@@ -191,8 +197,8 @@ public final class ParserUtils {
      *            current line in yang model
      * @return module builder if found, null otherwise
      */
-    public static ModuleBuilder findModuleFromBuilders(Map<String, TreeMap<Date, ModuleBuilder>> modules,
-            ModuleBuilder module, String prefix, int line) {
+    public static ModuleBuilder findModuleFromBuilders(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            final ModuleBuilder module, final String prefix, final int line) {
         ModuleBuilder dependentModule = null;
         Date dependentModuleRevision = null;
 
@@ -234,8 +240,8 @@ public final class ParserUtils {
      *            current line in yang model
      * @return module based on given prefix if found in context, null otherwise
      */
-    public static Module findModuleFromContext(SchemaContext context, ModuleBuilder currentModule, String prefix,
-            int line) {
+    public static Module findModuleFromContext(final SchemaContext context, final ModuleBuilder currentModule, final String prefix,
+            final int line) {
         if (context == null) {
             throw new YangParseException(currentModule.getName(), line, "Cannot find module with prefix '" + prefix
                     + "'.");
@@ -275,18 +281,20 @@ public final class ParserUtils {
      *            XPath as String
      * @return SchemaPath from given String
      */
-    public static SchemaPath parseXPathString(String xpathString) {
-        boolean absolute = xpathString.startsWith("/");
-        String[] splittedPath = xpathString.split("/");
-        List<QName> path = new ArrayList<QName>();
-        QName name;
-        for (String pathElement : splittedPath) {
+    public static SchemaPath parseXPathString(final String xpathString) {
+        final boolean absolute = xpathString.indexOf('/') == 0;
+
+        final List<QName> path = new ArrayList<QName>();
+        for (String pathElement : SLASH_SPLITTER.split(xpathString)) {
             if (pathElement.length() > 0) {
-                String[] splittedElement = pathElement.split(":");
-                if (splittedElement.length == 1) {
-                    name = new QName(null, null, null, splittedElement[0]);
+                final Iterator<String> it = COLON_SPLITTER.split(pathElement).iterator();
+                final String s = it.next();
+
+                final QName name;
+                if (it.hasNext()) {
+                    name = new QName(null, null, s, it.next());
                 } else {
-                    name = new QName(null, null, splittedElement[0], splittedElement[1]);
+                    name = new QName(null, null, null, s);
                 }
                 path.add(name);
             }
@@ -302,7 +310,7 @@ public final class ParserUtils {
      * @param target
      *            augmentation target node
      */
-    public static void fillAugmentTarget(AugmentationSchemaBuilder augment, Builder target) {
+    public static void fillAugmentTarget(final AugmentationSchemaBuilder augment, final Builder target) {
         if (target instanceof DataNodeContainerBuilder) {
             fillAugmentTarget(augment, (DataNodeContainerBuilder) target);
         } else if (target instanceof ChoiceBuilder) {
@@ -323,7 +331,7 @@ public final class ParserUtils {
      * @param target
      *            augmentation target node
      */
-    private static void fillAugmentTarget(AugmentationSchemaBuilder augment, DataNodeContainerBuilder target) {
+    private static void fillAugmentTarget(final AugmentationSchemaBuilder augment, final DataNodeContainerBuilder target) {
         for (DataSchemaNodeBuilder child : augment.getChildNodeBuilders()) {
             DataSchemaNodeBuilder childCopy = CopyUtils.copy(child, target, false);
             if (augment.getParent() instanceof UsesNodeBuilder) {
@@ -349,7 +357,7 @@ public final class ParserUtils {
      * @param target
      *            augmentation target choice node
      */
-    private static void fillAugmentTarget(AugmentationSchemaBuilder augment, ChoiceBuilder target) {
+    private static void fillAugmentTarget(final AugmentationSchemaBuilder augment, final ChoiceBuilder target) {
         for (DataSchemaNodeBuilder builder : augment.getChildNodeBuilders()) {
             DataSchemaNodeBuilder childCopy = CopyUtils.copy(builder, target, false);
             if (augment.getParent() instanceof UsesNodeBuilder) {
@@ -371,7 +379,7 @@ public final class ParserUtils {
      *
      * @param node
      */
-    private static void setNodeAugmenting(DataSchemaNodeBuilder node) {
+    private static void setNodeAugmenting(final DataSchemaNodeBuilder node) {
         node.setAugmenting(true);
         if (node instanceof DataNodeContainerBuilder) {
             DataNodeContainerBuilder dataNodeChild = (DataNodeContainerBuilder) node;
@@ -391,7 +399,7 @@ public final class ParserUtils {
      *
      * @param node
      */
-    public static void setNodeAddedByUses(GroupingMember node) {
+    public static void setNodeAddedByUses(final GroupingMember node) {
         node.setAddedByUses(true);
         if (node instanceof DataNodeContainerBuilder) {
             DataNodeContainerBuilder dataNodeChild = (DataNodeContainerBuilder) node;
@@ -414,7 +422,7 @@ public final class ParserUtils {
      * @param config
      *            new config value
      */
-    public static void setNodeConfig(DataSchemaNodeBuilder node, Boolean config) {
+    public static void setNodeConfig(final DataSchemaNodeBuilder node, final Boolean config) {
         if (node instanceof ContainerSchemaNodeBuilder || node instanceof LeafSchemaNodeBuilder
                 || node instanceof LeafListSchemaNodeBuilder || node instanceof ListSchemaNodeBuilder
                 || node instanceof ChoiceBuilder || node instanceof AnyXmlBuilder) {
@@ -433,7 +441,7 @@ public final class ParserUtils {
         }
     }
 
-    public static DataSchemaNodeBuilder findSchemaNode(List<QName> path, SchemaNodeBuilder parentNode) {
+    public static DataSchemaNodeBuilder findSchemaNode(final List<QName> path, final SchemaNodeBuilder parentNode) {
         DataSchemaNodeBuilder node = null;
         SchemaNodeBuilder parent = parentNode;
         int i = 0;
@@ -464,7 +472,7 @@ public final class ParserUtils {
         return node;
     }
 
-    public static SchemaNodeBuilder findSchemaNodeInModule(List<QName> pathToNode, ModuleBuilder module) {
+    public static SchemaNodeBuilder findSchemaNodeInModule(final List<QName> pathToNode, final ModuleBuilder module) {
         List<QName> path = new ArrayList<>(pathToNode);
         QName first = path.remove(0);
 
@@ -506,7 +514,7 @@ public final class ParserUtils {
      *            path to augment target
      * @return true if augmentation process succeed, false otherwise
      */
-    public static boolean processAugmentation(AugmentationSchemaBuilder augment, ModuleBuilder firstNodeParent) {
+    public static boolean processAugmentation(final AugmentationSchemaBuilder augment, final ModuleBuilder firstNodeParent) {
         List<QName> path = augment.getTargetPath().getPath();
         Builder targetNode = findSchemaNodeInModule(path, firstNodeParent);
         if (targetNode == null) {
@@ -519,27 +527,31 @@ public final class ParserUtils {
         return true;
     }
 
-    public static IdentitySchemaNodeBuilder findBaseIdentity(Map<String, TreeMap<Date, ModuleBuilder>> modules,
-            ModuleBuilder module, String baseString, int line) {
-        IdentitySchemaNodeBuilder result = null;
-        if (baseString.contains(":")) {
-            String[] splittedBase = baseString.split(":");
-            if (splittedBase.length > 2) {
+    public static IdentitySchemaNodeBuilder findBaseIdentity(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            final ModuleBuilder module, final String baseString, final int line) {
+
+        // FIXME: optimize indexOf() away?
+        if (baseString.indexOf(':') != -1) {
+            final Iterator<String> it = COLON_SPLITTER.split(baseString).iterator();
+            final String prefix = it.next();
+            final String name = it.next();
+
+            if (it.hasNext()) {
                 throw new YangParseException(module.getName(), line, "Failed to parse identityref base: " + baseString);
             }
-            String prefix = splittedBase[0];
-            String name = splittedBase[1];
+
             ModuleBuilder dependentModule = findModuleFromBuilders(modules, module, prefix, line);
-            if (dependentModule != null) {
-                result = findIdentity(dependentModule.getAddedIdentities(), name);
+            if (dependentModule == null) {
+                return null;
             }
+
+            return findIdentity(dependentModule.getAddedIdentities(), name);
         } else {
-            result = findIdentity(module.getAddedIdentities(), baseString);
+            return findIdentity(module.getAddedIdentities(), baseString);
         }
-        return result;
     }
 
-    public static IdentitySchemaNodeBuilder findIdentity(Set<IdentitySchemaNodeBuilder> identities, String name) {
+    public static IdentitySchemaNodeBuilder findIdentity(final Set<IdentitySchemaNodeBuilder> identities, final String name) {
         for (IdentitySchemaNodeBuilder identity : identities) {
             if (identity.getQName().getLocalName().equals(name)) {
                 return identity;
@@ -554,7 +566,7 @@ public final class ParserUtils {
      * @param node
      * @return builder of module where this node is defined
      */
-    public static ModuleBuilder getParentModule(Builder node) {
+    public static ModuleBuilder getParentModule(final Builder node) {
         if (node instanceof ModuleBuilder) {
             return (ModuleBuilder) node;
         }
@@ -570,8 +582,8 @@ public final class ParserUtils {
         return parentModule;
     }
 
-    public static Set<DataSchemaNodeBuilder> wrapChildNodes(String moduleName, int line, Set<DataSchemaNode> nodes,
-            SchemaPath parentPath, URI ns, Date rev, String pref) {
+    public static Set<DataSchemaNodeBuilder> wrapChildNodes(final String moduleName, final int line, final Set<DataSchemaNode> nodes,
+            final SchemaPath parentPath, final URI ns, final Date rev, final String pref) {
         Set<DataSchemaNodeBuilder> result = new HashSet<>();
 
         for (DataSchemaNode node : nodes) {
@@ -582,8 +594,8 @@ public final class ParserUtils {
         return result;
     }
 
-    public static DataSchemaNodeBuilder wrapChildNode(String moduleName, int line, DataSchemaNode node,
-            SchemaPath parentPath, QName qname) {
+    public static DataSchemaNodeBuilder wrapChildNode(final String moduleName, final int line, final DataSchemaNode node,
+            final SchemaPath parentPath, final QName qname) {
         List<QName> path = new ArrayList<>(parentPath.getPath());
         path.add(qname);
         SchemaPath schemaPath = new SchemaPath(path, parentPath.isAbsolute());
@@ -608,8 +620,8 @@ public final class ParserUtils {
         }
     }
 
-    public static Set<GroupingBuilder> wrapGroupings(String moduleName, int line, Set<GroupingDefinition> nodes,
-            SchemaPath parentPath, URI ns, Date rev, String pref) {
+    public static Set<GroupingBuilder> wrapGroupings(final String moduleName, final int line, final Set<GroupingDefinition> nodes,
+            final SchemaPath parentPath, final URI ns, final Date rev, final String pref) {
         Set<GroupingBuilder> result = new HashSet<>();
         for (GroupingDefinition node : nodes) {
             QName qname = new QName(ns, rev, pref, node.getQName().getLocalName());
@@ -621,8 +633,8 @@ public final class ParserUtils {
         return result;
     }
 
-    public static Set<TypeDefinitionBuilder> wrapTypedefs(String moduleName, int line, DataNodeContainer dataNode,
-            SchemaPath parentPath, URI ns, Date rev, String pref) {
+    public static Set<TypeDefinitionBuilder> wrapTypedefs(final String moduleName, final int line, final DataNodeContainer dataNode,
+            final SchemaPath parentPath, final URI ns, final Date rev, final String pref) {
         Set<TypeDefinition<?>> nodes = dataNode.getTypeDefinitions();
         Set<TypeDefinitionBuilder> result = new HashSet<>();
         for (TypeDefinition<?> node : nodes) {
@@ -635,8 +647,8 @@ public final class ParserUtils {
         return result;
     }
 
-    public static List<UnknownSchemaNodeBuilder> wrapUnknownNodes(String moduleName, int line,
-            List<UnknownSchemaNode> nodes, SchemaPath parentPath, URI ns, Date rev, String pref) {
+    public static List<UnknownSchemaNodeBuilder> wrapUnknownNodes(final String moduleName, final int line,
+            final List<UnknownSchemaNode> nodes, final SchemaPath parentPath, final URI ns, final Date rev, final String pref) {
         List<UnknownSchemaNodeBuilder> result = new ArrayList<>();
         for (UnknownSchemaNode node : nodes) {
             QName qname = new QName(ns, rev, pref, node.getQName().getLocalName());