X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-generator-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fgenerator%2Fimpl%2FModuleInfoBackedContext.java;h=9bf375f7162161a1f6667e26bf20e63488ac7f48;hb=c77348ddc6ccebb90ef32b5e55f38e0997047f36;hp=e6d07c038aab88735a62002a0a1977927054fe8b;hpb=2cd00f1a5d28cb5df491e07ac18848c50338a4c5;p=mdsal.git diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/ModuleInfoBackedContext.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/ModuleInfoBackedContext.java index e6d07c038a..9bf375f716 100644 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/ModuleInfoBackedContext.java +++ b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/ModuleInfoBackedContext.java @@ -7,10 +7,11 @@ */ package org.opendaylight.mdsal.binding.generator.impl; -import com.google.common.base.Optional; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.ref.WeakReference; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy; @@ -32,7 +33,7 @@ import org.opendaylight.yangtools.yang.parser.repo.YangTextSchemaContextResolver import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ModuleInfoBackedContext extends GeneratedClassLoadingStrategy +public final class ModuleInfoBackedContext extends GeneratedClassLoadingStrategy implements ModuleInfoRegistry, SchemaContextProvider, SchemaSourceProvider { private final YangTextSchemaContextResolver ctxResolver = YangTextSchemaContextResolver.create("binding-context"); @@ -86,9 +87,10 @@ public class ModuleInfoBackedContext extends GeneratedClassLoadingStrategy // Implement remove ModuleInfo to update SchemaContext public Optional tryToCreateSchemaContext() { - return Optional.fromJavaUtil(ctxResolver.getSchemaContext()); + return ctxResolver.getSchemaContext(); } + @SuppressWarnings("checkstyle:illegalCatch") private boolean resolveModuleInfo(final Class cls) { try { return resolveModuleInfo(BindingReflections.getModuleInfo(cls)); @@ -97,22 +99,22 @@ public class ModuleInfoBackedContext extends GeneratedClassLoadingStrategy } } + @SuppressWarnings("checkstyle:illegalCatch") + @SuppressFBWarnings("REC_CATCH_EXCEPTION") private boolean resolveModuleInfo(final YangModuleInfo moduleInfo) { + final SourceIdentifier identifier = sourceIdentifierFrom(moduleInfo); + final YangModuleInfo previous = sourceIdentifierToModuleInfo.putIfAbsent(identifier, moduleInfo); + if (previous != null) { + return false; + } - SourceIdentifier identifier = sourceIdentifierFrom(moduleInfo); - YangModuleInfo previous = sourceIdentifierToModuleInfo.putIfAbsent(identifier, moduleInfo); ClassLoader moduleClassLoader = moduleInfo.getClass().getClassLoader(); try { - if (previous == null) { - String modulePackageName = moduleInfo.getClass().getPackage().getName(); - packageNameToClassLoader.putIfAbsent(modulePackageName, - new WeakReference<>(moduleClassLoader)); - ctxResolver.registerSource(toYangTextSource(identifier, moduleInfo)); - for (YangModuleInfo importedInfo : moduleInfo.getImportedModules()) { - resolveModuleInfo(importedInfo); - } - } else { - return false; + String modulePackageName = moduleInfo.getClass().getPackage().getName(); + packageNameToClassLoader.putIfAbsent(modulePackageName, new WeakReference<>(moduleClassLoader)); + ctxResolver.registerSource(toYangTextSource(identifier, moduleInfo)); + for (YangModuleInfo importedInfo : moduleInfo.getImportedModules()) { + resolveModuleInfo(importedInfo); } } catch (Exception e) { LOG.error("Not including {} in YANG sources because of error.", moduleInfo, e); @@ -163,7 +165,7 @@ public class ModuleInfoBackedContext extends GeneratedClassLoadingStrategy private final ModuleInfoBackedContext context; - public YangModuleInfoRegistration(final YangModuleInfo instance, final ModuleInfoBackedContext context) { + YangModuleInfoRegistration(final YangModuleInfo instance, final ModuleInfoBackedContext context) { super(instance); this.context = context; }