Remove use of xtend 03/13203/3
authorRobert Varga <rovarga@cisco.com>
Thu, 27 Nov 2014 23:49:18 +0000 (00:49 +0100)
committerRobert Varga <rovarga@cisco.com>
Mon, 1 Dec 2014 16:53:48 +0000 (17:53 +0100)
This patch converts RuntimeCodeGenerator into pure Java, optimizing it
in the process a bit. Since this is the last piece of Xtend code in
controller, also remove any trace of xtend.

Change-Id: I462968202d0e26c852aa683905b97bab8c5f99cf
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/commons/opendaylight/pom.xml
opendaylight/md-sal/pom.xml
opendaylight/md-sal/sal-binding-broker/pom.xml
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/DefaultRuntimeCodeGenerator.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend [deleted file]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/SingletonHolder.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/codegen/impl/DefaultRuntimeCodeGeneratorTest.java [moved from opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/RuntimeCodeGeneratorTest.java with 97% similarity]
opendaylight/md-sal/topology-lldp-discovery/pom.xml

index b2585adb04908ab7a3ba69419bb45374ff13ef1c..6bb302de6fa432bc6cb801af89576569deb99cff 100644 (file)
     <usermanager.version>0.5.0-SNAPSHOT</usermanager.version>
     <nsf.version>0.5.0-SNAPSHOT</nsf.version>
     <web.version>0.5.0-SNAPSHOT</web.version>
-    <xtend.dstdir>src/main/xtend-gen</xtend.dstdir>
     <yang-ext.version>2013.09.07.7-SNAPSHOT</yang-ext.version>
     <yang-jmx-generator.version>1.1.0-SNAPSHOT</yang-jmx-generator.version>
     <yangtools.version>0.7.0-SNAPSHOT</yangtools.version>
       </dependency>
 
       <!-- md-sal -->
-      <dependency>
-        <groupId>org.eclipse.xtend</groupId>
-        <artifactId>org.eclipse.xtend.lib</artifactId>
-        <version>${xtend.version}</version>
-      </dependency>
       <dependency>
         <groupId>org.glassfish.jersey.test-framework.providers</groupId>
         <artifactId>jersey-test-framework-provider-grizzly2</artifactId>
           <artifactId>maven-clean-plugin</artifactId>
           <configuration>
             <filesets>
-              <fileset>
-                <directory>${xtend.dstdir}</directory>
-                <includes>
-                  <include>**</include>
-                </includes>
-              </fileset>
               <fileset>
                 <directory>${jmxGeneratorPath}</directory>
                 <includes>
                   <source>src/main/yang</source>
                   <source>${jmxGeneratorPath}</source>
                   <source>${salGeneratorPath}</source>
-                  <source>${xtend.dstdir}</source>
                 </sources>
               </configuration>
             </execution>
             </lifecycleMappingMetadata>
           </configuration>
         </plugin>
-        <plugin>
-          <groupId>org.eclipse.xtend</groupId>
-          <artifactId>xtend-maven-plugin</artifactId>
-          <version>${xtend.version}</version>
-          <executions>
-            <execution>
-              <goals>
-                <goal>compile</goal>
-              </goals>
-              <configuration>
-                <outputDirectory>${xtend.dstdir}</outputDirectory>
-              </configuration>
-            </execution>
-          </executions>
-        </plugin>
         <plugin>
           <groupId>org.jacoco</groupId>
           <artifactId>jacoco-maven-plugin</artifactId>
           <includeTestSourceDirectory>true</includeTestSourceDirectory>
           <sourceDirectory>${project.basedir}</sourceDirectory>
           <includes>**\/*.java,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat</includes>
-          <excludes>**\/target\/,**\/bin\/,**\/target-ide\/,**\/${jmxGeneratorPath}\/,**\/${salGeneratorPath}\/,**\/xtend-gen\/,**\/protobuff\/</excludes>
+          <excludes>**\/target\/,**\/bin\/,**\/target-ide\/,**\/${jmxGeneratorPath}\/,**\/${salGeneratorPath}\/,**\/protobuff\/</excludes>
         </configuration>
         <dependencies>
           <dependency>
index 38756f29060f486fb31198e796045a0eb8a629ee..7abbe6bfd65d8d30181ce225e427b48a13c7c433 100644 (file)
             </lifecycleMappingMetadata>
           </configuration>
         </plugin>
-        <plugin>
-          <groupId>org.eclipse.xtend</groupId>
-          <artifactId>xtend-maven-plugin</artifactId>
-          <version>${xtend.version}</version>
-        </plugin>
         <plugin>
           <groupId>org.jacoco</groupId>
           <artifactId>jacoco-maven-plugin</artifactId>
index ade3e1b8f6ba73376f5391a8db1da0f1d8c0dcb1..9346e223df1b0fcb5a0f298386a2912578503c30 100644 (file)
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.eclipse.xtend</groupId>
-      <artifactId>org.eclipse.xtend.lib</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.javassist</groupId>
       <artifactId>javassist</artifactId>
           </execution>
         </executions>
       </plugin>
-      <plugin>
-        <groupId>org.eclipse.xtend</groupId>
-        <artifactId>xtend-maven-plugin</artifactId>
-      </plugin>
       <plugin>
         <groupId>org.jacoco</groupId>
         <artifactId>jacoco-maven-plugin</artifactId>
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/DefaultRuntimeCodeGenerator.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/DefaultRuntimeCodeGenerator.java
new file mode 100644 (file)
index 0000000..dfa164b
--- /dev/null
@@ -0,0 +1,286 @@
+/*
+ * 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.impl;
+
+import com.google.common.base.Supplier;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
+import java.lang.reflect.Method;
+import java.util.Map;
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtMethod;
+import javassist.NotFoundException;
+import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeSpecification;
+import org.opendaylight.yangtools.sal.binding.generator.util.ClassGenerator;
+import org.opendaylight.yangtools.sal.binding.generator.util.MethodGenerator;
+import org.opendaylight.yangtools.util.ClassLoaderUtils;
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+import org.opendaylight.yangtools.yang.binding.Notification;
+import org.opendaylight.yangtools.yang.binding.NotificationListener;
+import org.opendaylight.yangtools.yang.binding.RpcImplementation;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
+
+final class DefaultRuntimeCodeGenerator extends AbstractRuntimeCodeGenerator {
+
+    DefaultRuntimeCodeGenerator(final ClassPool pool) {
+        super(pool);
+    }
+
+    @Override
+    protected <T extends RpcService> Supplier<T> directProxySupplier(final Class<T> serviceType) {
+        return new Supplier<T>() {
+            @SuppressWarnings("unchecked")
+            @Override
+            public T get() {
+                final String proxyName = RuntimeCodeSpecification.getDirectProxyName(serviceType);
+
+                final Class<?> potentialClass = ClassLoaderUtils.tryToLoadClassWithTCCL(proxyName);
+                if (potentialClass != null) {
+                    try {
+                        return (T)potentialClass.newInstance();
+                    } catch (InstantiationException | IllegalAccessException e) {
+                        throw new IllegalStateException("Failed to instantiate class " + potentialClass.getName(), e);
+                    }
+                }
+
+                final CtClass supertype = utils.asCtClass(serviceType);
+                final String directProxyName = RuntimeCodeSpecification.getDirectProxyName(serviceType);
+
+                final CtClass createdCls;
+                try {
+                    createdCls = utils.createClass(directProxyName, supertype, new ClassGenerator() {
+                        @Override
+                        public void process(final CtClass cls) throws CannotCompileException {
+                            utils.field(cls, RuntimeCodeSpecification.DELEGATE_FIELD, serviceType);
+                            utils.implementsType(cls, utils.asCtClass(RpcImplementation.class));
+                            utils.implementMethodsFrom(cls, supertype, new MethodGenerator() {
+                                @Override
+                                public void process(final CtMethod method) throws CannotCompileException {
+                                    final StringBuilder sb = new StringBuilder("\n");
+                                    sb.append("{\n");
+                                    sb.append("    if (").append(RuntimeCodeSpecification.DELEGATE_FIELD).append(" == null) {\n");
+                                    sb.append("        throw new java.lang.IllegalStateException(\"No default provider is available\");\n");
+                                    sb.append("    }\n");
+                                    sb.append("    return ($r) ").append(RuntimeCodeSpecification.DELEGATE_FIELD).append('.').append(method.getName()).append("($$);\n");
+                                    sb.append("}\n");
+                                    method.setBody(sb.toString());
+                                }
+                            });
+
+                            // FIXME: copy this one...
+                            utils.implementMethodsFrom(cls, utils.asCtClass(RpcImplementation.class), new MethodGenerator() {
+                                @Override
+                                public void process(final CtMethod method) throws CannotCompileException {
+                                    final StringBuilder sb = new StringBuilder("\n");
+                                    sb.append("{\n");
+                                    sb.append("    throw new java.lang.IllegalStateException(\"No provider is processing supplied message\");\n");
+                                    sb.append("    return ($r) null;\n");
+                                    sb.append("}\n");
+                                    method.setBody(sb.toString());
+                                }
+                            });
+                        }
+                    });
+                } catch (CannotCompileException e) {
+                    throw new IllegalStateException("Failed to create class " + directProxyName, e);
+                }
+
+                final Class<?> c;
+                try {
+                    c = createdCls.toClass(serviceType.getClassLoader(), serviceType.getProtectionDomain());
+                } catch (CannotCompileException e) {
+                    throw new IllegalStateException(String.format("Failed to create class %s", createdCls), e);
+                }
+
+                try {
+                    return (T) c.newInstance();
+                } catch (InstantiationException | IllegalAccessException e) {
+                    throw new IllegalStateException(String.format("Failed to instantiated class %s", c), e);
+                }
+            }
+        };
+    }
+
+    @Override
+    protected <T extends RpcService> Supplier<T> routerSupplier(final Class<T> serviceType, final RpcServiceMetadata metadata) {
+        return new Supplier<T>() {
+            @SuppressWarnings("unchecked")
+            @Override
+            public T get() {
+                final CtClass supertype = utils.asCtClass(serviceType);
+                final String routerName = RuntimeCodeSpecification.getRouterName(serviceType);
+                final Class<?> potentialClass = ClassLoaderUtils.tryToLoadClassWithTCCL(routerName);
+                if (potentialClass != null) {
+                    try {
+                        return (T)potentialClass.newInstance();
+                    } catch (InstantiationException | IllegalAccessException e) {
+                        throw new IllegalStateException("Failed to instantiate class", e);
+                    }
+                }
+
+                final CtClass targetCls;
+                try {
+                    targetCls = utils.createClass(routerName, supertype, new ClassGenerator() {
+                        @Override
+                        public void process(final CtClass cls) throws CannotCompileException {
+                            utils.field(cls, RuntimeCodeSpecification.DELEGATE_FIELD, serviceType);
+                            //utils.field(cls, REMOTE_INVOKER_FIELD,iface);
+                            utils.implementsType(cls, utils.asCtClass(RpcImplementation.class));
+
+                            for (final Class<? extends BaseIdentity> ctx : metadata.getContexts()) {
+                                utils.field(cls, RuntimeCodeSpecification.getRoutingTableField(ctx), Map.class);
+                            }
+
+                            utils.implementMethodsFrom(cls, supertype, new MethodGenerator() {
+                                @Override
+                                public void process(final CtMethod method) throws CannotCompileException {
+                                    final int ptl;
+                                    try {
+                                        ptl = method.getParameterTypes().length;
+                                    } catch (NotFoundException e) {
+                                        throw new CannotCompileException(e);
+                                    }
+                                    final StringBuilder sb = new StringBuilder();
+
+                                    switch (ptl) {
+                                    case 0:
+                                        sb.append("return ($r) ").append(RuntimeCodeSpecification.DELEGATE_FIELD).append('.').append(method.getName()).append("($$);");
+                                        break;
+                                    case 1:
+                                        final RpcMetadata rpcMeta = metadata.getRpcMethod(method.getName());
+                                        final String rtGetter = rpcMeta.getInputRouteGetter().getName();
+                                        final String stName = supertype.getName();
+
+                                        sb.append('\n');
+                                        sb.append("{\n");
+                                        sb.append("    if ($1 == null) {\n");
+                                        sb.append("        throw new IllegalArgumentException(\"RPC input must not be null and must contain a value for field ").append(rtGetter).append("\");\n");
+                                        sb.append("    }\n");
+                                        sb.append("    if ($1.").append(rtGetter).append("() == null) {\n");
+                                        sb.append("        throw new IllegalArgumentException(\"Field ").append(rtGetter).append(" must not be null\");\n");
+                                        sb.append("    }\n");
+
+                                        sb.append("    final org.opendaylight.yangtools.yang.binding.InstanceIdentifier identifier = $1.").append(rtGetter).append("()");
+                                        if (rpcMeta.isRouteEncapsulated()) {
+                                            sb.append(".getValue()");
+                                        }
+                                        sb.append(";\n");
+
+                                        sb.append("    ").append(supertype.getName()).append(" instance = (").append(stName).append(") ").append(RuntimeCodeSpecification.getRoutingTableField(rpcMeta.getContext())).append(".get(identifier);\n");
+                                        sb.append("    if (instance == null) {\n");
+                                        sb.append("        instance = ").append(RuntimeCodeSpecification.DELEGATE_FIELD).append(";\n");
+                                        sb.append("    }\n");
+
+                                        sb.append("    if (instance == null) {\n");
+                                        sb.append("        throw new java.lang.IllegalStateException(\"No routable provider is processing routed message for \" + String.valueOf(identifier));\n");
+                                        sb.append("    }\n");
+                                        sb.append("    return ($r) instance.").append(method.getName()).append("($$);\n");
+                                        sb.append('}');
+                                        break;
+                                    default:
+                                        throw new CannotCompileException(String.format("Unsupported parameters length %s", ptl));
+                                    }
+
+                                    method.setBody(sb.toString());
+                                }
+                            });
+
+                            // FIXME: move this into a template class
+                            utils.implementMethodsFrom(cls, utils.asCtClass(RpcImplementation.class), new MethodGenerator() {
+                                @Override
+                                public void process(final CtMethod method) throws CannotCompileException {
+                                    final StringBuilder sb = new StringBuilder("\n");
+                                    sb.append("{\n");
+                                    sb.append("    throw new java.lang.IllegalStateException(\"No provider is processing supplied message\");\n");
+                                    sb.append("    return ($r) null;\n");
+                                    sb.append("}\n");
+
+                                    method.setBody(sb.toString());
+                                }
+                            });
+                        }
+                    });
+                } catch (CannotCompileException e) {
+                    throw new IllegalStateException("Failed to create class " + routerName, e);
+                }
+
+                final Class<?> c;
+                try {
+                    c = targetCls.toClass(serviceType.getClassLoader(), serviceType.getProtectionDomain());
+                } catch (CannotCompileException e) {
+                    throw new IllegalStateException(String.format("Failed to compile class %s", targetCls), e);
+                }
+
+                try {
+                    return (T)c.newInstance();
+                } catch (InstantiationException | IllegalAccessException e) {
+                    throw new IllegalStateException(String.format("Failed to instantiate class %s", c), e);
+                }
+            }
+        };
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    protected RuntimeGeneratedInvokerPrototype generateListenerInvoker(final Class<? extends NotificationListener> listenerType) {
+        final String invokerName = RuntimeCodeSpecification.getInvokerName(listenerType);
+        final CtClass targetCls;
+
+        // Builder for a set of supported types. Filled while the target class is being generated
+        final Builder<Class<? extends Notification>> b = ImmutableSet.builder();
+
+        try {
+            targetCls = utils.createClass(invokerName, getBrokerNotificationListener(), new ClassGenerator() {
+                @Override
+                public void process(final CtClass cls) throws CannotCompileException {
+                    utils.field(cls, RuntimeCodeSpecification.DELEGATE_FIELD, listenerType);
+                    utils.implementMethodsFrom(cls, getBrokerNotificationListener(), new MethodGenerator() {
+                        @Override
+                        public void process(final CtMethod method) throws CannotCompileException {
+                            final StringBuilder sb = new StringBuilder("\n");
+
+                            sb.append("{\n");
+
+                            for (Method m : listenerType.getMethods()) {
+                                if (BindingReflections.isNotificationCallback(m)) {
+                                    final Class<?> argType = m.getParameterTypes()[0];
+
+                                    // populates builder above
+                                    b.add((Class<? extends Notification>) argType);
+
+                                    sb.append("    if ($1 instanceof ").append(argType.getName()).append(") {\n");
+                                    sb.append("        ").append(RuntimeCodeSpecification.DELEGATE_FIELD).append('.').append(m.getName()).append("((").append(argType.getName()).append(") $1);\n");
+                                    sb.append("        return null;\n");
+                                    sb.append("    } else ");
+                                }
+                            }
+
+                            sb.append("    return null;\n");
+                            sb.append("}\n");
+                            method.setBody(sb.toString());
+                        }
+                    });
+                }
+            });
+        } catch (CannotCompileException e) {
+            throw new IllegalStateException("Failed to create class " + invokerName, e);
+        }
+
+        final Class<?> finalClass;
+        try {
+            finalClass = targetCls.toClass(listenerType.getClassLoader(), listenerType.getProtectionDomain());
+        } catch (CannotCompileException e) {
+            throw new IllegalStateException(String.format("Failed to compile class %s", targetCls), e);
+        }
+
+        return new RuntimeGeneratedInvokerPrototype(b.build(), (Class<? extends org.opendaylight.controller.sal.binding.api.NotificationListener<?>>) finalClass);
+    }
+}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend
deleted file mode 100644 (file)
index 834eb4f..0000000
+++ /dev/null
@@ -1,146 +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.impl
-
-import java.util.Map
-import javassist.ClassPool
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.opendaylight.yangtools.yang.binding.Notification
-import org.opendaylight.yangtools.yang.binding.RpcImplementation
-import org.opendaylight.yangtools.yang.binding.util.BindingReflections
-import org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils
-
-import static extension org.opendaylight.controller.sal.binding.codegen.RuntimeCodeSpecification.*
-import org.opendaylight.yangtools.yang.binding.RpcService
-
-class RuntimeCodeGenerator extends AbstractRuntimeCodeGenerator {
-
-    new(ClassPool pool) {
-        super(pool)
-    }
-
-    override directProxySupplier(Class iface) {
-        return [|
-            val proxyName = iface.directProxyName;
-            val potentialClass = ClassLoaderUtils.tryToLoadClassWithTCCL(proxyName)
-            if(potentialClass != null) {
-                return potentialClass.newInstance as RpcService;
-            }
-            val supertype = iface.asCtClass
-            val createdCls = createClass(iface.directProxyName, supertype) [
-                field(DELEGATE_FIELD, iface);
-                implementsType(RpcImplementation.asCtClass)
-                implementMethodsFrom(supertype) [
-                    body = '''
-                    {
-                        if(«DELEGATE_FIELD» == null) {
-                            throw new java.lang.IllegalStateException("No default provider is available");
-                        }
-                        return ($r) «DELEGATE_FIELD».«it.name»($$);
-                    }
-                    '''
-                ]
-                implementMethodsFrom(RpcImplementation.asCtClass) [
-                    body = '''
-                    {
-                        throw new java.lang.IllegalStateException("No provider is processing supplied message");
-                        return ($r) null;
-                    }
-                    '''
-                ]
-            ]
-            return createdCls.toClass(iface.classLoader).newInstance as RpcService
-        ]
-    }
-
-    override routerSupplier(Class iface, RpcServiceMetadata metadata) {
-        return [ |
-            val supertype = iface.asCtClass
-            val routerName = iface.routerName;
-            val potentialClass = ClassLoaderUtils.tryToLoadClassWithTCCL(routerName)
-            if(potentialClass != null) {
-                return potentialClass.newInstance as RpcService;
-            }
-
-            val targetCls = createClass(iface.routerName, supertype) [
-
-
-                field(DELEGATE_FIELD, iface)
-                //field(REMOTE_INVOKER_FIELD,iface);
-                implementsType(RpcImplementation.asCtClass)
-
-                for (ctx : metadata.contexts) {
-                    field(ctx.routingTableField, Map)
-                }
-                implementMethodsFrom(supertype) [
-                    if (parameterTypes.size === 1) {
-                        val rpcMeta = metadata.getRpcMethod(name);
-                        val bodyTmp = '''
-                        {
-                            if($1 == null) {
-                                throw new IllegalArgumentException("RPC input must not be null and must contain a value for field «rpcMeta.inputRouteGetter.name»");
-                            }
-                            if($1.«rpcMeta.inputRouteGetter.name»() == null) {
-                                throw new IllegalArgumentException("Field «rpcMeta.inputRouteGetter.name» must not be null");
-                            }
-                            final «InstanceIdentifier.name» identifier = $1.«rpcMeta.inputRouteGetter.name»()«IF rpcMeta.
-                            routeEncapsulated».getValue()«ENDIF»;
-                            «supertype.name» instance = («supertype.name») «rpcMeta.context.routingTableField».get(identifier);
-                            if(instance == null) {
-                               instance = «DELEGATE_FIELD»;
-                            }
-                            if(instance == null) {
-                                throw new java.lang.IllegalStateException("No routable provider is processing routed message for " + String.valueOf(identifier));
-                            }
-                            return ($r) instance.«it.name»($$);
-                        }'''
-                        body = bodyTmp
-                    } else if (parameterTypes.size === 0) {
-                        body = '''return ($r) «DELEGATE_FIELD».«it.name»($$);'''
-                    }
-                ]
-                implementMethodsFrom(RpcImplementation.asCtClass) [
-                    body = '''
-                    {
-                        throw new java.lang.IllegalStateException("No provider is processing supplied message");
-                        return ($r) null;
-                    }
-                    '''
-                ]
-            ]
-            return  targetCls.toClass(iface.classLoader,iface.protectionDomain).newInstance as RpcService
-        ];
-    }
-
-    override generateListenerInvoker(Class iface) {
-        val callbacks = iface.methods.filter[BindingReflections.isNotificationCallback(it)]
-
-        val supportedNotification = callbacks.map[parameterTypes.get(0) as Class<? extends Notification>].toSet;
-
-        val targetCls = createClass(iface.invokerName, brokerNotificationListener) [
-            field(DELEGATE_FIELD, iface)
-            implementMethodsFrom(brokerNotificationListener) [
-                body = '''
-                    {
-                        «FOR callback : callbacks SEPARATOR " else "»
-                            «val cls = callback.parameterTypes.get(0).name»
-                                if($1 instanceof «cls») {
-                                    «DELEGATE_FIELD».«callback.name»((«cls») $1);
-                                    return null;
-                                }
-                        «ENDFOR»
-                        return null;
-                    }
-                '''
-            ]
-        ]
-        val finalClass = targetCls.toClass(iface.classLoader, iface.protectionDomain)
-        return new RuntimeGeneratedInvokerPrototype(supportedNotification,
-            finalClass as Class<? extends org.opendaylight.controller.sal.binding.api.NotificationListener<?>>);
-    }
-}
index f037e679be72fbb037318708c98217325782dd66..4664b58d2a7d442e0ab20c59b32cedc7c1943696 100644 (file)
@@ -33,7 +33,7 @@ public class SingletonHolder {
 
     public static final ClassPool CLASS_POOL = ClassPool.getDefault();
     public static final JavassistUtils JAVASSIST = JavassistUtils.forClassPool(CLASS_POOL);
-    public static final org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator RPC_GENERATOR_IMPL = new org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator(
+    public static final org.opendaylight.controller.sal.binding.codegen.impl.DefaultRuntimeCodeGenerator RPC_GENERATOR_IMPL = new org.opendaylight.controller.sal.binding.codegen.impl.DefaultRuntimeCodeGenerator(
             CLASS_POOL);
     public static final RuntimeCodeGenerator RPC_GENERATOR = RPC_GENERATOR_IMPL;
     public static final NotificationInvokerFactory INVOKER_FACTORY = RPC_GENERATOR_IMPL.getInvokerFactory();
@@ -5,7 +5,7 @@
  * 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.test;
+package org.opendaylight.controller.sal.binding.codegen.impl;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -13,17 +13,14 @@ import static org.junit.Assert.assertSame;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
-
 import java.util.ArrayList;
 import java.util.List;
-
 import javassist.ClassPool;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.sal.binding.api.rpc.RpcRouter;
 import org.opendaylight.controller.sal.binding.api.rpc.RpcRoutingTable;
-import org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator;
+import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator;
 import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory;
 import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory.NotificationInvoker;
 import org.opendaylight.controller.sal.binding.test.mock.BarListener;
@@ -41,14 +38,14 @@ import org.opendaylight.yangtools.yang.binding.DataContainer;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class RuntimeCodeGeneratorTest {
+public class DefaultRuntimeCodeGeneratorTest {
 
     private RuntimeCodeGenerator codeGenerator;
     private NotificationInvokerFactory invokerFactory;
 
     @Before
     public void initialize() {
-        this.codeGenerator = new RuntimeCodeGenerator(ClassPool.getDefault());
+        this.codeGenerator = new DefaultRuntimeCodeGenerator(ClassPool.getDefault());
         this.invokerFactory = codeGenerator.getInvokerFactory();
     }
 
index e6a9a75337a50635cf4a132cfd5f2fa93bb2e734..cc684a58b2815dac30e68780902880e4f5ff66ab 100644 (file)
@@ -14,7 +14,6 @@
     <bundle.plugin.version>2.4.0</bundle.plugin.version>
     <guava.version>14.0.1</guava.version>
     <maven.clean.plugin.version>2.5</maven.clean.plugin.version>
-    <xtend.version>2.4.3</xtend.version>
   </properties>
   <dependencies>
     <dependency>