From: Robert Varga Date: Wed, 28 May 2014 07:14:33 +0000 (+0200) Subject: BUG-614: convert RuntimeCodeSpecification X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~17^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=209c4ca77e590458aa9717b275d0d7bbf177b09b;hp=26da3c2a206a753356b507b018052cbb9cccca7d BUG-614: convert RuntimeCodeSpecification This migrates RuntimeCodeSpecification from xtend to Java, increasing its efficiency. Change-Id: I00b3ab7f3a47e0d3fc71e55b4bec99364bfa8e5f Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeSpecification.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeSpecification.java new file mode 100644 index 0000000000..22b6f6f1c7 --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeSpecification.java @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.sal.binding.codegen; + +import org.opendaylight.yangtools.yang.binding.BaseIdentity; +import org.opendaylight.yangtools.yang.binding.NotificationListener; +import org.opendaylight.yangtools.yang.binding.RpcService; + +public final class RuntimeCodeSpecification { + public final static String DIRECT_PROXY_SUFFIX = "DirectProxy"; + public final static String INVOKER_SUFFIX = "ListenerInvoker"; + public final static String ROUTER_SUFFIX = "Router"; + + public final static String DELEGATE_FIELD = "_delegate"; + public final static String ROUTING_TABLE_FIELD_PREFIX = "_routes_"; + + private RuntimeCodeSpecification() { + throw new UnsupportedOperationException("Utility class"); + } + + /** + * Returns a name for generated interface + */ + private static String getGeneratedName(final Class cls, final String suffix) { + return cls.getName() + "$$Broker$" + suffix; + } + + public static String getInvokerName(final Class listener) { + return getGeneratedName(listener, RuntimeCodeSpecification.INVOKER_SUFFIX); + } + + /** + * Returns a name for DirectProxy implementation + */ + public static String getDirectProxyName(final Class base) { + return getGeneratedName(base, RuntimeCodeSpecification.DIRECT_PROXY_SUFFIX); + } + + /** + * Returns a name for Router implementation + */ + public static String getRouterName(final Class base) { + return getGeneratedName(base, RuntimeCodeSpecification.ROUTER_SUFFIX); + } + + /** + * Returns a field name for specified routing context + */ + public static String getRoutingTableField(final Class routingContext) { + return "_routes_" + routingContext.getSimpleName(); + } +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeSpecification.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeSpecification.xtend deleted file mode 100644 index c5648adaa5..0000000000 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeSpecification.xtend +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.binding.codegen - -import org.opendaylight.yangtools.yang.binding.RpcService -import org.opendaylight.yangtools.yang.binding.BaseIdentity -import org.opendaylight.yangtools.yang.binding.NotificationListener - -/** - * - * - */ -class RuntimeCodeSpecification { - - //public static val PACKAGE_PREFIX = "_gen."; - - public static val DIRECT_PROXY_SUFFIX = "DirectProxy"; - public static val ROUTER_SUFFIX = "Router"; - public static val INVOKER_SUFFIX = "ListenerInvoker"; - - public static val DELEGATE_FIELD = "_delegate" - public static val ROUTING_TABLE_FIELD_PREFIX = "_routes_" - - public static def getInvokerName(Class listener) { - getGeneratedName(listener, INVOKER_SUFFIX); - } - - /** - * Returns a name for DirectProxy implementation - * - * - */ - public static def getDirectProxyName(Class base) { - getGeneratedName(base, DIRECT_PROXY_SUFFIX); - } - - /** - * Returns a name for Router implementation - * - */ - public static def getRouterName(Class base) { - getGeneratedName(base, ROUTER_SUFFIX); - } - - /** - * Returns a name for generated interface - * - */ - public static def getGeneratedName(Class cls, String suffix) { - '''«cls.name»$$Broker$«suffix»'''.toString() - } - - /** - * Returns a field name for specified routing context - * - */ - public static def getRoutingTableField(Class routingContext) { - return '''_routes_«routingContext.simpleName»'''.toString; - } -} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/YangtoolsMappingHelper.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/YangtoolsMappingHelper.java index 0bc11d9b35..4ad0bb0558 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/YangtoolsMappingHelper.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/YangtoolsMappingHelper.java @@ -5,18 +5,19 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - - package org.opendaylight.controller.sal.binding.codegen; import java.lang.reflect.Method; + import org.opendaylight.yangtools.yang.binding.Notification; -@SuppressWarnings("all") -public class YangtoolsMappingHelper { - public static boolean isNotificationCallback(final Method it) { - return it.getName().startsWith("on") && (it.getParameterTypes().length == 1) && - Notification.class.isAssignableFrom(it.getParameterTypes()[0]); - } +public final class YangtoolsMappingHelper { + private YangtoolsMappingHelper() { + throw new UnsupportedOperationException("Utility class"); + } + public static boolean isNotificationCallback(final Method it) { + return it.getName().startsWith("on") && (it.getParameterTypes().length == 1) && + Notification.class.isAssignableFrom(it.getParameterTypes()[0]); + } } \ No newline at end of file