Clover coverage report - clover
Coverage timestamp: Sat Oct 8 2005 22:54:17 EDT
file stats: LOC: 179   Methods: 7
NCLOC: 149   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PropertyCallEditor.java 88.1% 97.5% 85.7% 93.8%
coverage coverage
 1   
 package abbot.editor.editors;
 2   
 
 3   
 import java.awt.Component;
 4   
 import java.awt.event.ActionEvent;
 5   
 import java.lang.reflect.*;
 6   
 import java.util.*;
 7   
 
 8   
 import javax.swing.*;
 9   
 
 10   
 import abbot.Log;
 11   
 import abbot.i18n.Strings;
 12   
 import abbot.script.*;
 13   
 import abbot.tester.ComponentTester;
 14   
 
 15   
 /** Provide convenient editing of a PropertyCall step. */
 16   
 public abstract class PropertyCallEditor extends CallEditor {
 17   
 
 18   
     private JComboBox component;
 19   
     private PropertyCall call;
 20   
 
 21  8
     public PropertyCallEditor(PropertyCall call) {
 22  8
         super(call);
 23  8
         this.call = call;
 24  8
         component = addComponentSelector(Strings.get("ComponentID"),
 25   
                                          call.getComponentID(),
 26   
                                          call.getResolver(), true);
 27  8
         component.setName(TAG_COMPONENT);
 28   
     }
 29   
 
 30   
     /** Get the class of the current component target, if any. */
 31  14
     protected Class getComponentTargetClass(Class cls) {
 32  14
         String[] args = getCall().getArguments();
 33  14
         if (args.length == 1) {
 34  9
             String id = args[0];
 35  9
             ComponentReference ref =
 36   
                 getCall().getResolver().getComponentReference(id);
 37  9
             if (ref != null) {
 38  9
                 try {
 39  9
                     return getCall().resolveClass(ref.getRefClassName());
 40   
                 }
 41   
                 catch(ClassNotFoundException e) {
 42   
                 }
 43   
             }
 44   
         }
 45  5
         return null;
 46   
     }
 47   
 
 48   
     /** If the target is Component or ComponentTester, provide a merge of
 49   
         property-like methods from both.
 50   
     */
 51  26
     protected Map getMethods(Class cls, int mask) {
 52  26
         boolean isTester = ComponentTester.class.isAssignableFrom(cls);
 53  26
         boolean isComponent = Component.class.isAssignableFrom(cls);
 54  26
         Class componentClass = isTester
 55   
             ? getComponentTargetClass(cls)
 56  14
             : (isComponent ? cls : null);
 57  26
         Class testerClass = isTester
 58  14
             ? cls : (isComponent
 59   
                      ? ComponentTester.getTester(componentClass).getClass()
 60   
                      : null);
 61  26
         if (!isTester && !isComponent)
 62  2
             return super.getMethods(cls, mask);
 63   
 
 64  24
         Map map = new HashMap();
 65  24
         if (componentClass != null) {
 66  19
             Iterator iter =
 67   
                 super.getMethods(componentClass, mask).values().iterator();
 68  19
             while (iter.hasNext()) {
 69  5606
                 Method m = (Method)iter.next();
 70  5606
                 if (PropertyCall.isPropertyMethod(m)) {
 71  1898
                     map.put(m.getName(), m);
 72   
                 }
 73   
             }
 74   
         }
 75   
         // Scan the corresponding component tester for additional property
 76   
         // methods 
 77  24
         try {
 78  24
             ComponentTester tester = componentClass != null
 79   
                 ? ComponentTester.getTester(componentClass)
 80   
                 : (ComponentTester)testerClass.newInstance();
 81  24
             Iterator iter = getComponentTesterMethods(tester).iterator();
 82  24
             while (iter.hasNext()) {
 83  64
                 Method m = (Method)iter.next();
 84  64
                 map.put(m.getName(), m);
 85   
             }
 86   
         }
 87   
         catch(Exception e) {
 88   
         }
 89  24
         return map;
 90   
     }
 91   
 
 92  0
     protected boolean includeMethod(Class cls, Method m) {
 93  0
         return true;
 94   
     }
 95   
 
 96  10
     protected Collection getComponentTesterMethods(ComponentTester tester) {
 97  10
         return Arrays.asList(tester.getPropertyMethods());
 98   
     }
 99   
 
 100   
     /** Synchronize the component selector with the PropertyCall data. */
 101  3
     protected void componentChanged() {
 102  3
         component.setSelectedItem(call.getComponentID());
 103   
     }
 104   
 
 105  55
     public void actionPerformed(ActionEvent ev) {
 106  55
         Object src = ev.getSource();
 107  55
         if (src == component) {
 108  3
             String id = (String)component.getSelectedItem();
 109  3
             if (id != null)
 110  3
                 id = id.trim();
 111  3
             if ("".equals(id)) {
 112  0
                 id = null;
 113   
             }
 114  3
             ComponentReference ref =
 115   
                 call.getResolver().getComponentReference(id);
 116  3
             String tcn = ref != null
 117   
                 ? ref.getRefClassName()
 118   
                 : Component.class.getClass().getName();
 119  3
             call.setComponentID(id);
 120   
 
 121  3
             call.setTargetClassName(tcn);
 122  3
             call.setArguments(new String[0]);
 123  3
             targetClassChanged();
 124  3
             argumentsChanged();
 125   
 
 126  3
             fireStepChanged();
 127   
         }
 128  52
         else if (src == method) {
 129  12
             super.actionPerformed(ev);
 130   
             // When the method changes to or from a ComponentTester
 131   
             // pseudo-property method, we need to change the target class.
 132  12
             try {
 133  12
                 Class cls = call.getTargetClass();
 134  12
                 String methodName = (String)method.getSelectedItem();
 135  12
                 Map methods = getMethods(cls, Modifier.PUBLIC);
 136  12
                 Method m = (Method)methods.get(methodName);
 137  12
                 if (m != null) {
 138  8
                     Class newClass = m.getDeclaringClass();
 139  8
                     if (ComponentTester.class.isAssignableFrom(newClass)
 140   
                         && Component.class.isAssignableFrom(cls)) {
 141  1
                         String id = call.getComponentID();
 142  1
                         if (id != null) {
 143  1
                             call.setArguments(new String[] { id });
 144  1
                             argumentsChanged();
 145   
                         }
 146  1
                         call.setComponentID(null);
 147  1
                         call.setTargetClassName(newClass.getName());
 148  1
                         componentChanged();
 149  1
                         targetClassChanged();
 150   
 
 151  1
                         fireStepChanged();
 152   
                     }
 153  7
                     else if (Component.class.isAssignableFrom(newClass)
 154   
                              && ComponentTester.class.isAssignableFrom(cls)
 155   
                              && call.getArguments().length == 1) {
 156  2
                         newClass = getComponentTargetClass(cls);
 157  2
                         String id = call.getArguments()[0];
 158   
 
 159  2
                         call.setArguments(new String[0]);
 160  2
                         call.setComponentID(id);
 161  2
                         call.setTargetClassName(newClass.getName());
 162  2
                         argumentsChanged();
 163  2
                         componentChanged();
 164  2
                         targetClassChanged();
 165   
 
 166  2
                         fireStepChanged();
 167   
                     }
 168   
                 }
 169   
             }
 170   
             catch(ClassNotFoundException e) {
 171   
                 // don't care
 172   
             }
 173   
         }
 174   
         else {
 175  40
             super.actionPerformed(ev);
 176   
         }
 177   
     }
 178   
 }
 179