Author: akazakov
Date: 2011-03-03 15:37:19 -0500 (Thu, 03 Mar 2011)
New Revision: 29469
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolverFactoryManager.java
Log:
https://issues.jboss.org/browse/JBIDE-8281
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolverFactoryManager.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolverFactoryManager.java 2011-03-03
16:34:09 UTC (rev 29468)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolverFactoryManager.java 2011-03-03
20:37:19 UTC (rev 29469)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.common.el.core.resolver;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
@@ -32,6 +33,9 @@
private static final ELResolverFactoryManager INSTANCE = new
ELResolverFactoryManager();
+ private static HashMap<String, Set<ELResolver>> resolversByNature;
+ private static Set<ELResolverFactory> resolverFactories;
+
private ELResolverFactoryManager() {
}
@@ -43,6 +47,55 @@
return INSTANCE;
}
+ private void init() {
+ if(resolversByNature==null) {
+ resolversByNature = new HashMap<String, Set<ELResolver>>();
+ resolverFactories = new HashSet<ELResolverFactory>();
+
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint extensionPoint =
registry.getExtensionPoint("org.jboss.tools.common.el.core.elResolver");
//$NON-NLS-1$
+ IExtension[] extensions = extensionPoint.getExtensions();
+ for (int i=0; i<extensions.length; i++) {
+ IExtension extension = extensions[i];
+ IConfigurationElement[] elements = extension.getConfigurationElements();
+ for(int j=0; j<elements.length; j++) {
+ IConfigurationElement[] natures =
elements[j].getChildren("project-nature"); //$NON-NLS-1$
+ for (int k = 0; k < natures.length; k++) {
+ String natureId = natures[k].getAttribute("id"); //$NON-NLS-1$
+ try {
+ Object resolver =
natures[k].createExecutableExtension("resolver-class"); //$NON-NLS-1$
+ if(resolver instanceof ELResolver) {
+ Set<ELResolver> resolverSet = resolversByNature.get(natureId);
+ if(resolverSet==null) {
+ resolverSet = new HashSet<ELResolver>();
+ resolversByNature.put(natureId, resolverSet);
+ }
+ resolverSet.add((ELResolver)resolver);
+ } else {
+ ELCorePlugin.getPluginLog().logError(resolver.getClass().getName() + " must
be instance of org.jboss.tools.common.el.core.resolver.ELResolver"); //$NON-NLS-1$
+ }
+ } catch (CoreException e) {
+ ELCorePlugin.getPluginLog().logError(e);
+ }
+ }
+ IConfigurationElement[] factories = elements[j].getChildren("factory");
//$NON-NLS-1$
+ for (int k = 0; k < factories.length; k++) {
+ try {
+ Object factory = factories[k].createExecutableExtension("class");
//$NON-NLS-1$
+ if(factory instanceof ELResolverFactory) {
+ resolverFactories.add((ELResolverFactory)factory);
+ } else if(!(factory instanceof TestELResolverFactory)) {
+ ELCorePlugin.getPluginLog().logError(factory.getClass().getName() + " must
be instance of org.jboss.tools.common.el.core.resolver.ELResolverFactory");
//$NON-NLS-1$
+ }
+ } catch (CoreException e) {
+ ELCorePlugin.getPluginLog().logError(e);
+ }
+ }
+ }
+ }
+ }
+ }
+
/**
* Returns all EL resolvers for the resource
* @param resource
@@ -53,51 +106,29 @@
return new ELResolver[0];
}
IProject project = resource.getProject();
- if (project == null || !project.isAccessible())
+ if (project == null || !project.isAccessible()) {
return new ELResolver[0];
+ }
+ init();
+
Set<ELResolver> resolverSet = new HashSet<ELResolver>();
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IExtensionPoint extensionPoint =
registry.getExtensionPoint("org.jboss.tools.common.el.core.elResolver");
//$NON-NLS-1$
- IExtension[] extensions = extensionPoint.getExtensions();
- for (int i=0; i<extensions.length; i++) {
- IExtension extension = extensions[i];
- IConfigurationElement[] elements = extension.getConfigurationElements();
- for(int j=0; j<elements.length; j++) {
- IConfigurationElement[] natures =
elements[j].getChildren("project-nature"); //$NON-NLS-1$
- for (int k = 0; k < natures.length; k++) {
- String natureId = natures[k].getAttribute("id"); //$NON-NLS-1$
- try {
- if(project.hasNature(natureId)) {
- Object resolver =
natures[k].createExecutableExtension("resolver-class"); //$NON-NLS-1$
- if(resolver instanceof ELResolver) {
- resolverSet.add((ELResolver)resolver);
- } else {
- ELCorePlugin.getPluginLog().logError(resolver.getClass().getName() + " must
be instance of org.jboss.tools.common.el.core.resolver.ELResolver"); //$NON-NLS-1$
- }
- }
- } catch (CoreException e) {
- ELCorePlugin.getPluginLog().logError(e);
- }
+ Set<String> ids = resolversByNature.keySet();
+ for (String natureId : ids) {
+ try {
+ if(project.hasNature(natureId)) {
+ resolverSet.addAll(resolversByNature.get(natureId));
}
- IConfigurationElement[] factories = elements[j].getChildren("factory");
//$NON-NLS-1$
- for (int k = 0; k < factories.length; k++) {
- try {
- Object factory = factories[k].createExecutableExtension("class");
//$NON-NLS-1$
- if(factory instanceof ELResolverFactory) {
- ELResolver resolver = ((ELResolverFactory)factory).createResolver(resource);
- if(resolver!=null) {
- resolverSet.add(resolver);
- }
- } else if(!(factory instanceof TestELResolverFactory)) {
- ELCorePlugin.getPluginLog().logError(factory.getClass().getName() + " must be
instance of org.jboss.tools.common.el.core.resolver.ELResolverFactory");
//$NON-NLS-1$
- }
- } catch (CoreException e) {
- ELCorePlugin.getPluginLog().logError(e);
- }
- }
+ } catch (CoreException e) {
+ ELCorePlugin.getPluginLog().logError(e);
}
}
+ for (ELResolverFactory factory : resolverFactories) {
+ ELResolver resolver = factory.createResolver(resource);
+ if(resolver!=null) {
+ resolverSet.add(resolver);
+ }
+ }
return resolverSet.toArray(new ELResolver[resolverSet.size()]);
}
}
\ No newline at end of file