FELIX-3550 : Reimplement the SCR Generator

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1354836 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
index 339a3db..317c129 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
@@ -238,6 +238,7 @@
                     }
                 }
             }
+
             validator.validate();
 
             // ignore component if it has errors
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassModifier.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassModifier.java
index 28df6d9..bb9a7a9 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassModifier.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassModifier.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.felix.scrplugin.helper;
 
 import java.io.File;
@@ -13,8 +31,23 @@
 import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.tree.ClassNode;
 
-public class ClassModifier {
+/**
+ * Helper class for injecting/generating accessor methods for
+ * unary references.
+ */
+public abstract class ClassModifier {
 
+    /**
+     * Add bind/unbind methods
+     * @param className       The class name in which the methods are injected
+     * @param referenceName   Name of the reference
+     * @param fieldName       Name of the field
+     * @param typeName        Name of the type
+     * @param createBind      Name of the bind method or null
+     * @param createUnbind    Name of the unbind method or null
+     * @param outputDirectory Output directory where the class file is stored
+     * @throws SCRDescriptorException
+     */
     public static void addMethods(final String className,
                            final String referenceName,
                            final String fieldName,
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/StringUtils.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/StringUtils.java
index efee6d3..58bc0f6 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/StringUtils.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/StringUtils.java
@@ -18,35 +18,12 @@
  */
 package org.apache.felix.scrplugin.helper;
 
+/**
+ * Some string utilities.
+ */
+public abstract class StringUtils {
 
-public class StringUtils
-{
-
-    public static String[] split( String value, String sep )
-    {
-        return value.split( sep );
-    }
-
-
-    public static boolean isEmpty( final String string )
-    {
+    public static boolean isEmpty( final String string ) {
         return string == null || string.length() == 0;
     }
-
-
-    public static String leftPad( final String base, final int width, final String pad )
-    {
-        StringBuilder builder = new StringBuilder( width );
-
-        int missing = width - base.length();
-        while ( missing > 0 )
-        {
-            builder.append( pad );
-            missing -= pad.length();
-        }
-
-        builder.append( base );
-
-        return builder.toString();
-    }
 }
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/Validator.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/Validator.java
index 374453c..593bb4c 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/Validator.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/Validator.java
@@ -169,11 +169,12 @@
                         "Component must not be immediate if component factory: " + this.container.getClassDescription().getDescribedClass().getName());
                 }
             }
-        }
-        if (iLog.getNumberOfErrors() == currentIssueCount) {
-            // verify references
-            for (final ReferenceDescription ref : this.container.getReferences().values()) {
-                this.validateReference(ref, component.isAbstract());
+
+            if (iLog.getNumberOfErrors() == currentIssueCount) {
+                // verify references
+                for (final ReferenceDescription ref : this.container.getReferences().values()) {
+                    this.validateReference(ref, component.isAbstract());
+                }
             }
         }
     }
@@ -200,14 +201,7 @@
                 }
             }
         }
-        try {
-            return this.container.getClassDescription().getDescribedClass().getDeclaredMethod(name, classSig);
-        } catch (final SecurityException e) {
-            // ignore
-        } catch (final NoSuchMethodException e) {
-            // ignore
-        }
-        return null;
+        return this.getMethod(name, classSig);
     }
 
     /**
@@ -473,7 +467,7 @@
         final Method method = this.findMethod(ref, methodName);
         if (method == null) {
             if (!componentIsAbstract) {
-                this.logError(ref,
+                this.logError(this.container.getComponentDescription(),
                                 "Missing method " + methodName + " for reference "
                                                 + (ref.getName() == null ? "" : ref.getName()));
             }
@@ -495,12 +489,16 @@
     private static final String TYPE_SERVICE_REFERENCE = "org.osgi.framework.ServiceReference";
 
     private Method getMethod(final String name, final Class<?>[] sig) {
-        try {
-            return this.container.getClassDescription().getDescribedClass().getDeclaredMethod(name, sig);
-        } catch (final SecurityException e) {
-            // ignore
-        } catch (final NoSuchMethodException e) {
-            // ignore
+        Class<?> checkClass = this.container.getClassDescription().getDescribedClass();
+        while ( checkClass != null ) {
+            try {
+                return checkClass.getDeclaredMethod(name, sig);
+            } catch (final SecurityException e) {
+                // ignore
+            } catch (final NoSuchMethodException e) {
+                // ignore
+            }
+            checkClass = checkClass.getSuperclass();
         }
         return null;
     }