Author: scabanovich
Date: 2011-03-29 16:19:58 -0400 (Tue, 29 Mar 2011)
New Revision: 30118
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/feature/
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/feature/IBeanNameFeature.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionFactory.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionManager.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/ICDIExtension.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIElement.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java
Log:
JBIDE-3120
https://issues.jboss.org/browse/JBIDE-3120
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionFactory.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionFactory.java 2011-03-29
18:37:05 UTC (rev 30117)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionFactory.java 2011-03-29
20:19:58 UTC (rev 30118)
@@ -21,6 +21,7 @@
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.extension.feature.IBeanNameFeature;
/**
* Loads Eclipse extension point 'org.jboss.tools.cdi.core.cdiextensions'
@@ -29,12 +30,11 @@
* Attributes:
* 'runtime' - Qualified name of CDI runtime extension implementation class.
* 'class' - Qualified name of JBoss Tools CDI model extension implementation
class.
- * 'features' - It is not planned to add regular methods to this interface,
+ * Implements:
+ * IAdaptable - It is not planned to add regular methods to ICDIExtension,
* all features that are to be provided by implementations, will be available
* through IAdaptable. In that way, adding to core support of a new feature
* will not require to implement new methods in existing extensions.
- * In order to efficiently request only relevant implementations,
- * extensions must register supported features in this attribute.
*
* @author Viacheslav Kabanovich
*
@@ -42,6 +42,10 @@
public class CDIExtensionFactory {
static CDIExtensionFactory factory = null;
public static String POINT_ID = "org.jboss.tools.cdi.core.cdiextensions";
+
+ public static Class<?>[] FEATURES = {
+ IBeanNameFeature.class
+ };
public static CDIExtensionFactory getInstance() {
if(factory == null) {
@@ -59,7 +63,7 @@
/**
* Maps features to fully qualified names of implementations of ICDIExtention.
*/
- private Map<String, Set<String>> featureToDesign = new HashMap<String,
Set<String>>();
+ private Map<Class<?>, Set<String>> featureToDesign = new
HashMap<Class<?>, Set<String>>();
/**
* Maps fully qualified names of implementations of ICDIExtention to their Class
objects.
@@ -93,17 +97,17 @@
runtimeToDesign.put(runtime, classes);
}
classes.add(cls);
-
- String features = c.getAttribute("features");
- StringTokenizer st = new StringTokenizer(features, ",");
- while(st.hasMoreTokens()) {
- String feature = st.nextToken();
- classes = featureToDesign.get(feature);
- if(classes == null) {
- classes = new HashSet<String>();
- featureToDesign.put(feature, classes);
+
+ for (Class<?> f: FEATURES) {
+ Object adapter = adaptTo(extension, f);
+ if(adapter != null) {
+ classes = featureToDesign.get(f);
+ if(classes == null) {
+ classes = new HashSet<String>();
+ featureToDesign.put(f, classes);
+ }
+ classes.add(cls);
}
- classes.add(cls);
}
}
}
@@ -112,10 +116,10 @@
return runtimeToDesign.get(qualifiedName);
}
- public Set<String> getFeatures() {
+ public Set<Class<?>> getFeatures() {
return featureToDesign.keySet();
}
- public Set<String> getExtensionClassesByfeature(String featureName) {
+ public Set<String> getExtensionClassesByFeature(Class<?> featureName) {
return featureToDesign.get(featureName);
}
@@ -134,4 +138,13 @@
return null;
}
+ static <F> F adaptTo(ICDIExtension extension, Class<F> feature) {
+ if(extension == null || feature == null) return null;
+ Class<?> cls = extension.getClass();
+ if(feature.isAssignableFrom(cls)) {
+ return (F)extension;
+ }
+ return (F)extension.getAdapter(feature);
+ }
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionManager.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionManager.java 2011-03-29
18:37:05 UTC (rev 30117)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/CDIExtensionManager.java 2011-03-29
20:19:58 UTC (rev 30118)
@@ -10,13 +10,20 @@
******************************************************************************/
package org.jboss.tools.cdi.core.extension;
+
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.jboss.tools.cdi.core.CDICoreNature;
+import org.jboss.tools.cdi.core.extension.feature.IBeanNameFeature;
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
public class CDIExtensionManager {
CDICoreNature n;
/**
@@ -32,7 +39,9 @@
/**
* Mapping of feature ids to extension instances.
*/
- Map<String, Set<ICDIExtension>> featureToExtensions = new HashMap<String,
Set<ICDIExtension>>();
+ Map<Class<?>, Set<ICDIExtension>> featureToExtensions = new
HashMap<Class<?>, Set<ICDIExtension>>();
+
+ FeatureStorage featureStorage = new FeatureStorage();
public CDIExtensionManager(CDICoreNature n) {
this.n = n;
@@ -68,13 +77,12 @@
private void addRuntime(String runtime) {
CDIExtensionFactory factory = CDIExtensionFactory.getInstance();
Set<String> clss = factory.getExtensionClassesByRuntime(runtime);
- if(clss != null) for (String cls: clss) {
+ if(clss != null && !clss.isEmpty()) for (String cls: clss) {
ICDIExtension ext = factory.createExtensionInstance(cls);
if(ext == null) continue;
- //TODO initialize ext object.
instances.put(cls, ext);
- for (String feature: CDIExtensionFactory.getInstance().getFeatures()) {
- if(factory.getExtensionClassesByfeature(feature).contains(cls)) {
+ for (Class<?> feature: CDIExtensionFactory.getInstance().getFeatures()) {
+ if(factory.getExtensionClassesByFeature(feature).contains(cls)) {
Set<ICDIExtension> es = featureToExtensions.get(feature);
if(es == null) {
es = new HashSet<ICDIExtension>();
@@ -83,6 +91,7 @@
es.add(ext);
}
}
+ featureStorage.clean();
}
}
@@ -91,8 +100,8 @@
for (String cls: clss) {
ICDIExtension ext = instances.remove(cls);
if(ext != null) {
- String[] is = featureToExtensions.keySet().toArray(new String[0]);
- for (String feature: is) {
+ Class<?>[] is = featureToExtensions.keySet().toArray(new Class<?>[0]);
+ for (Class<?> feature: is) {
Set<ICDIExtension> es = featureToExtensions.get(feature);
if(es != null) {
es.remove(ext);
@@ -101,12 +110,47 @@
}
}
}
+ if(!clss.isEmpty()) {
+ featureStorage.clean();
+ }
}
static Set<ICDIExtension> EMPTY = new HashSet<ICDIExtension>();
- public Set<ICDIExtension> getExtensions(String feature) {
+ public Set<ICDIExtension> getExtensions(Class<?> feature) {
return featureToExtensions.containsKey(feature) ? featureToExtensions.get(feature) :
EMPTY;
}
+ public Set<IBeanNameFeature> getBeanNameFeature() {
+ Set<IBeanNameFeature> result = featureStorage.beanName;
+ if(result == null) {
+ featureStorage.beanName = result = getFeature(IBeanNameFeature.class);
+ }
+ return result;
+ }
+
+ private <F extends Object> Set<F> getFeature(Class<F> cls) {
+ Set<F> result = new HashSet<F>();
+ Set<ICDIExtension> extensions = getExtensions(cls);
+ if(!extensions.isEmpty()) {
+ for (ICDIExtension ext: extensions) {
+ F feature = CDIExtensionFactory.adaptTo(ext, cls);
+ if(feature != null) {
+ result.add(feature);
+ }
+ }
+ }
+ return result;
+ }
+
+ class FeatureStorage {
+ Set<IBeanNameFeature> beanName = null;
+
+ void clean() {
+ beanName = null;
+ }
+
+
+ }
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/ICDIExtension.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/ICDIExtension.java 2011-03-29
18:37:05 UTC (rev 30117)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/ICDIExtension.java 2011-03-29
20:19:58 UTC (rev 30118)
@@ -20,13 +20,11 @@
* where attribute 'runtime' is assigned to a CDI runtime extension
implementation class qualified name
* and attribute 'class' is assigned to a JBoss Tools CDI model extension
implementation class
* qualified name.
- * It is not planned to add regular methods to this interface, all features that are to
be provided
- * by implementations, will be available through IAdaptable. In that way, adding to core
support of
- * a new feature will not require to implement new methods in existing extensions. In
order to
- * let core efficiently request only relevant implementations, extensions must register
supported
- * features in attribute 'features' of extension point.
+ * It is not planned to add methods to this interface, all features that are to be
provided
+ * by implementations, will be available either through IAdaptable or by direct
implementing feature
+ * interfaces. In that way, adding to core support of a new feature will not require to
implement
+ * new methods in existing extensions.
*
- *
* @author Viacheslav Kabanovich
*
*/
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/feature/IBeanNameFeature.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/feature/IBeanNameFeature.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/feature/IBeanNameFeature.java 2011-03-29
20:19:58 UTC (rev 30118)
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.core.extension.feature;
+
+import org.jboss.tools.cdi.core.IBean;
+
+/**
+ * This feature is invoked by bean when it computes its name.
+ * The first non-null value is accepted.
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public interface IBeanNameFeature {
+ public static String ID =
"org.jboss.tools.cdi.core.extension.feature.IBeanNameFeature";
+
+ public String computeBeanName(IBean bean);
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/feature/IBeanNameFeature.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIElement.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIElement.java 2011-03-29
18:37:05 UTC (rev 30117)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIElement.java 2011-03-29
20:19:58 UTC (rev 30118)
@@ -17,6 +17,7 @@
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.ICDIElement;
+import org.jboss.tools.cdi.core.extension.CDIExtensionManager;
/**
*
@@ -31,6 +32,11 @@
return parent != null ? parent.getCDIProject() : null;
}
+ public CDIExtensionManager getExtensionManager() {
+ CDIProject project = getCDIProject();
+ return project == null ? null : project.getNature().getExtensionManager();
+ }
+
protected ParametedType getObjectType(IMember context) {
try {
return getCDIProject().getNature().getTypeFactory().getParametedType(context,
"QObject;");
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2011-03-29
18:37:05 UTC (rev 30117)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2011-03-29
20:19:58 UTC (rev 30118)
@@ -41,6 +41,7 @@
import org.jboss.tools.cdi.core.IStereotype;
import org.jboss.tools.cdi.core.IStereotypeDeclaration;
import org.jboss.tools.cdi.core.ITypeDeclaration;
+import org.jboss.tools.cdi.core.extension.feature.IBeanNameFeature;
import org.jboss.tools.cdi.internal.core.impl.definition.AbstractMemberDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.FieldDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.MethodDefinition;
@@ -313,6 +314,15 @@
if(specialized != null) {
return specialized.getName();
}
+
+ Set<IBeanNameFeature> fs = getExtensionManager().getBeanNameFeature();
+ if(fs != null) for (IBeanNameFeature f: fs) {
+ String result = f.computeBeanName(this);
+ if(result != null) {
+ return result;
+ }
+ }
+
AnnotationDeclaration named = findNamedAnnotation();
if(named == null) return null;
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java 2011-03-29
18:37:05 UTC (rev 30117)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java 2011-03-29
20:19:58 UTC (rev 30118)
@@ -22,6 +22,7 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.jboss.tools.cdi.core.CDIConstants;
+import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IAnnotated;
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
@@ -38,6 +39,7 @@
*
*/
public abstract class AbstractMemberDefinition implements IAnnotated {
+ CDICoreNature project;
protected List<IAnnotationDeclaration> annotations = new
ArrayList<IAnnotationDeclaration>();
protected IAnnotatable member;
protected Map<String, AnnotationDeclaration> annotationsByType = new
HashMap<String, AnnotationDeclaration>();
@@ -62,7 +64,18 @@
return null;
}
+ public PackageDefinition getPackageDefinition() {
+ AbstractTypeDefinition t = getTypeDefinition();
+ if(t == null) return null;
+ String qn = t.getQualifiedName();
+ if(qn == null) return null;
+ int d = qn.lastIndexOf('.');
+ String packageName = (d < 0) ? "" : qn.substring(0, d);
+ return project.getDefinitions().getPackageDefinition(packageName);
+ }
+
protected void init(IType contextType, DefinitionContext context) throws CoreException
{
+ project = context.getProject();
resource = ((IJavaElement)member).getResource();
IAnnotation[] ts = member.getAnnotations();
for (int i = 0; i < ts.length; i++) {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java 2011-03-29
18:37:05 UTC (rev 30117)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java 2011-03-29
20:19:58 UTC (rev 30118)
@@ -351,6 +351,10 @@
}
return result;
}
+
+ public PackageDefinition getPackageDefinition(String packageName) {
+ return packageDefinitions.get(packageName);
+ }
}