Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[mylar-dev] refactoring MylarPlugin#readBridge(IConfigurationElement element)

In general, for if-else statement, the common case should be put in if block.
If there are much nested if statement, we should make the nested if statements as little as possible.
So I guest be refactoring

From

        private static void readBridge(IConfigurationElement element) {
            try {
                Object object = element
                        .createExecutableExtension(CoreExtensionPointReader.ELEMENT_STRUCTURE_BRIDGE_CLASS );
                if (object instanceof IMylarStructureBridge) {
                    IMylarStructureBridge bridge = (IMylarStructureBridge) object;
                ...
                } else {
                    MylarStatusHandler.log("Could not load bridge: " + object.getClass().getCanonicalName()
                            + " must implement " + IMylarStructureBridge.class.getCanonicalName(), null);
                }
            } catch (CoreException e) {
                MylarStatusHandler.log(e, "Could not load bridge extension");
            }
        }
               
to


        private static void readBridge(IConfigurationElement element) {
            try {
                Object object = element
                        .createExecutableExtension(CoreExtensionPointReader.ELEMENT_STRUCTURE_BRIDGE_CLASS );
                if (!(object instanceof IMylarStructureBridge)) {
                    MylarStatusHandler.log("Could not load bridge: " + object.getClass().getCanonicalName()
                            + " must implement " + IMylarStructureBridge.class.getCanonicalName(), null);
                    return;
                }
               
                IMylarStructureBridge bridge = (IMylarStructureBridge) object;
                ...
               
            } catch (CoreException e) {
                MylarStatusHandler.log(e, "Could not load bridge extension");
            }
        }


Back to the top