Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Widmer2006-01-26 10:45:19 +0000
committerTobias Widmer2006-01-26 10:45:19 +0000
commit1e30cf84771a70447012f95dbb3be314a6779797 (patch)
tree6de0abe6b06352c7c19c8c6d8350eff8d9a1feee /org.eclipse.ltk.core.refactoring
parent5eee62dc19aaf1e3d11bfdc42b0145fe2a835319 (diff)
downloadeclipse.jdt.ui-1e30cf84771a70447012f95dbb3be314a6779797.tar.gz
eclipse.jdt.ui-1e30cf84771a70447012f95dbb3be314a6779797.tar.xz
eclipse.jdt.ui-1e30cf84771a70447012f95dbb3be314a6779797.zip
Converted refactoring instance factory to use extension point
Diffstat (limited to 'org.eclipse.ltk.core.refactoring')
-rw-r--r--org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCoreMessages.java6
-rw-r--r--org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCoreMessages.properties4
-rw-r--r--org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCorePlugin.java3
-rw-r--r--org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/history/RefactoringInstanceFactory.java94
4 files changed, 84 insertions, 23 deletions
diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCoreMessages.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCoreMessages.java
index aebbb17cc1..1bf46fb312 100644
--- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCoreMessages.java
+++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCoreMessages.java
@@ -27,7 +27,11 @@ public final class RefactoringCoreMessages extends NLS {
public static String RefactoringCorePlugin_internal_error;
public static String RefactoringCorePlugin_listener_removed;
public static String RefactoringCorePlugin_participant_removed;
-
+ public static String RefactoringCorePlugin_duplicate_warning;
+ public static String RefactoringCorePlugin_creation_error;
+ public static String RefactoringCorePlugin_missing_class_attribute;
+ public static String RefactoringCorePlugin_missing_attribute;
+
public static String Resources_outOfSyncResources;
public static String Resources_outOfSync;
public static String Resources_modifiedResources;
diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCoreMessages.properties b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCoreMessages.properties
index 75a038cba5..ed1e81ccc1 100644
--- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCoreMessages.properties
+++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCoreMessages.properties
@@ -14,8 +14,12 @@ ValidateEditChecker_failed= Team provider refused file modification.
Changes_validateEdit= Team provider refused file modification.
RefactoringCorePlugin_internal_error=Internal Error
+RefactoringCorePlugin_creation_error=ERROR: Could not create refactoring creator from extension ''{1}'' of extension point ''{0}''.
RefactoringCorePlugin_listener_removed=Listener removed due to the following exception
+RefactoringCorePlugin_duplicate_warning=WARNING: Duplicate extension with id ''{0}'' for extension point ''{1}''
+RefactoringCorePlugin_missing_attribute=ERROR: Extension point ''{0}'' contains extension with missing attribute ''{1}''
RefactoringCorePlugin_participant_removed=Participant {0} removed due to the following exception
+RefactoringCorePlugin_missing_class_attribute=ERROR: Refactoring creator contribution from extension ''{1}'' of extension point ''{0}'' has no ''{2}'' attribute.
Resources_outOfSyncResources= Some resources are out of sync
Resources_outOfSync= Resource ''{0}'' is out of sync with file system.
diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCorePlugin.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCorePlugin.java
index bbdd9f0636..8971b2a04a 100644
--- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCorePlugin.java
+++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/RefactoringCorePlugin.java
@@ -28,6 +28,7 @@ import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryListener;
import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistorySerializer;
import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService;
+import org.eclipse.ltk.internal.core.refactoring.history.RefactoringInstanceFactory;
import org.osgi.framework.BundleContext;
@@ -110,6 +111,7 @@ public class RefactoringCorePlugin extends Plugin {
public void start(BundleContext context) throws Exception {
super.start(context);
+ RefactoringInstanceFactory.getInstance().connect();
final RefactoringHistoryService service= RefactoringHistoryService.getInstance();
service.connect();
fRefactoringHistoryListener= new RefactoringHistorySerializer();
@@ -129,6 +131,7 @@ public class RefactoringCorePlugin extends Plugin {
service.disconnect();
if (fRefactoringHistoryListener != null)
service.removeHistoryListener(fRefactoringHistoryListener);
+ RefactoringInstanceFactory.getInstance().disconnect();
super.stop(context);
}
diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/history/RefactoringInstanceFactory.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/history/RefactoringInstanceFactory.java
index e3f4e519c7..52b8a2bc08 100644
--- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/history/RefactoringInstanceFactory.java
+++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/history/RefactoringInstanceFactory.java
@@ -15,23 +15,41 @@ import java.util.Map;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.ltk.core.refactoring.IRefactoringInstanceCreator;
import org.eclipse.ltk.core.refactoring.Refactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringCore;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.participants.RefactoringArguments;
+import org.eclipse.ltk.internal.core.refactoring.Messages;
+import org.eclipse.ltk.internal.core.refactoring.RefactoringCoreMessages;
+import org.eclipse.ltk.internal.core.refactoring.RefactoringCorePlugin;
+
/**
* Factory class to create refactoring instances from refactoring descriptors.
*
* @since 3.2
*/
-public final class RefactoringInstanceFactory implements IRefactoringInstanceCreator {
+public final class RefactoringInstanceFactory implements IRegistryChangeListener, IRefactoringInstanceCreator {
+
+ /** The class attribute */
+ private static final String ATTRIBUTE_CLASS= "class"; //$NON-NLS-1$
+
+ /** The id attribute */
+ private static final String ATTRIBUTE_ID= "id"; //$NON-NLS-1$
/** The singleton instance */
private static RefactoringInstanceFactory fInstance= null;
+ /** The refactoring creators extension point */
+ private static final String REFACTORING_CREATORS_EXTENSION_POINT= "refactoringCreators"; //$NON-NLS-1$
+
/**
* Returns the singleton instance of the refactoring instance factory.
*
@@ -44,10 +62,10 @@ public final class RefactoringInstanceFactory implements IRefactoringInstanceCre
}
/**
- * The creator registry (element type: <String,
- * IRefactoringInstanceCreator>)
+ * The refactoring creator cache (element type: <String,
+ * <code>IRefactoringInstanceCreator&gt;</code>)
*/
- private Map fCreatorRegistry= new HashMap();
+ private Map fCreatorCache= null;
/**
* Creates a new refactoring instance factory.
@@ -57,13 +75,20 @@ public final class RefactoringInstanceFactory implements IRefactoringInstanceCre
}
/**
+ * Connects this factory to the platform's extension registry.
+ */
+ public void connect() {
+ Platform.getExtensionRegistry().addRegistryChangeListener(this, RefactoringCore.ID_PLUGIN);
+ }
+
+ /**
* {@inheritDoc}
*/
public RefactoringArguments createArguments(final RefactoringDescriptor descriptor) {
Assert.isNotNull(descriptor);
final String id= descriptor.getID();
if (id != null) {
- final IRefactoringInstanceCreator creator= (IRefactoringInstanceCreator) fCreatorRegistry.get(id);
+ final IRefactoringInstanceCreator creator= createRefactoringCreator(id);
if (creator != null)
return creator.createArguments(descriptor);
}
@@ -77,7 +102,7 @@ public final class RefactoringInstanceFactory implements IRefactoringInstanceCre
Assert.isNotNull(descriptor);
final String id= descriptor.getID();
if (id != null) {
- final IRefactoringInstanceCreator creator= (IRefactoringInstanceCreator) fCreatorRegistry.get(id);
+ final IRefactoringInstanceCreator creator= createRefactoringCreator(id);
if (creator != null)
return creator.createRefactoring(descriptor);
}
@@ -85,31 +110,56 @@ public final class RefactoringInstanceFactory implements IRefactoringInstanceCre
}
/**
- * Registers the specified refactoring instance creator with the specified
- * refactoring id.
+ * Creates a refactoring instance creator for the specified id.
*
* @param id
* the refactoring id
- * @param creator
- * the refactoring instance creator
+ * @return the refactoring instance creator, or <code>null</code>
*/
- public void registerCreator(final String id, final IRefactoringInstanceCreator creator) {
+ private IRefactoringInstanceCreator createRefactoringCreator(final String id) {
Assert.isNotNull(id);
Assert.isTrue(!"".equals(id)); //$NON-NLS-1$
- Assert.isNotNull(creator);
- fCreatorRegistry.put(id, creator);
+ if (fCreatorCache == null) {
+ fCreatorCache= new HashMap();
+ final IConfigurationElement[] elements= Platform.getExtensionRegistry().getConfigurationElementsFor(RefactoringCore.ID_PLUGIN, REFACTORING_CREATORS_EXTENSION_POINT);
+ for (int index= 0; index < elements.length; index++) {
+ final IConfigurationElement element= elements[index];
+ final String attributeId= element.getAttribute(ATTRIBUTE_ID);
+ final String point= RefactoringCore.ID_PLUGIN + "." + REFACTORING_CREATORS_EXTENSION_POINT; //$NON-NLS-1$
+ if (attributeId != null && !"".equals(attributeId)) { //$NON-NLS-1$
+ final String className= element.getAttribute(ATTRIBUTE_CLASS);
+ if (className != null && !"".equals(className)) { //$NON-NLS-1$
+ try {
+ final Object implementation= element.createExecutableExtension(ATTRIBUTE_CLASS);
+ if (implementation instanceof IRefactoringInstanceCreator) {
+ if (fCreatorCache.get(attributeId) != null)
+ RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages.RefactoringCorePlugin_duplicate_warning, new String[] { attributeId, point}));
+ fCreatorCache.put(attributeId, implementation);
+ } else
+ RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages.RefactoringCorePlugin_creation_error, new String[] { point, attributeId}));
+ } catch (CoreException exception) {
+ RefactoringCorePlugin.log(exception);
+ }
+ } else
+ RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages.RefactoringCorePlugin_missing_class_attribute, new String[] { point, attributeId, ATTRIBUTE_CLASS}));
+ } else
+ RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages.RefactoringCorePlugin_missing_attribute, new String[] { point, ATTRIBUTE_ID}));
+ }
+ }
+ return (IRefactoringInstanceCreator) fCreatorCache.get(id);
}
/**
- * Unregisters the refactoring instance creator registered with the
- * specified id.
- *
- * @param id
- * the refactoring id
+ * Disconnects this factory from the platform's extensionr registry.
*/
- public void unregisterCreator(final String id) {
- Assert.isNotNull(id);
- Assert.isTrue(!"".equals(id)); //$NON-NLS-1$
- fCreatorRegistry.remove(id);
+ public void disconnect() {
+ Platform.getExtensionRegistry().removeRegistryChangeListener(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void registryChanged(final IRegistryChangeEvent event) {
+ fCreatorCache= null;
}
} \ No newline at end of file

Back to the top