Author: dazarov
Date: 2010-12-30 10:36:42 -0500 (Thu, 30 Dec 2010)
New Revision: 27829
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeInjectedPointUnambiguousMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/SelectBeanMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizard.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/SelectBeanWizard.java
Log:
https://issues.jboss.org/browse/JBIDE-7635
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-12-30
15:34:40 UTC (rev 27828)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-12-30
15:36:42 UTC (rev 27829)
@@ -87,6 +87,7 @@
public static String MAKE_INJECTED_POINT_UNAMBIGUOUS_TITLE;
public static String SELECT_BEAN_TITLE;
+ public static String SELECT_BEAN_WIZARD_TITLE;
public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_TITLE;
public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_AVAILABLE;
public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_IN_BEAN;
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-12-30
15:34:40 UTC (rev 27828)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-12-30
15:36:42 UTC (rev 27829)
@@ -68,9 +68,10 @@
ADD_LOCAL_BEAN_MARKER_RESOLUTION_TITLE=Add @LocalBean annotation to
''{0}'' class
DELETE_ALL_DISPOSER_DUPLICANT_MARKER_RESOLUTION_TITLE=Delete @Disposes annotations from
all methods except ''{0}'' method
DELETE_ALL_INJECTED_CONSTRUCTORS_MARKER_RESOLUTION_TITLE=Delete @Inject annotations from
all constructors except ''{0}'' constructor
-MAKE_INJECTED_POINT_UNAMBIGUOUS_TITLE=Make injected point unambiguous by specifying
''{0}'' bean
+MAKE_INJECTED_POINT_UNAMBIGUOUS_TITLE=Specify ''{0}'' CDI Bean for the
Injection Point
SELECT_BEAN_TITLE=Select CDI Bean to configure the Injection Point
+SELECT_BEAN_WIZARD_TITLE=Specify CDI Bean for the Injection Point
ADD_QUALIFIERS_TO_BEAN_WIZARD_TITLE=Add Qualifiers to the Bean
ADD_QUALIFIERS_TO_BEAN_WIZARD_AVAILABLE=Available:
ADD_QUALIFIERS_TO_BEAN_WIZARD_IN_BEAN=In the Bean:
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeInjectedPointUnambiguousMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeInjectedPointUnambiguousMarkerResolution.java 2010-12-30
15:34:40 UTC (rev 27828)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeInjectedPointUnambiguousMarkerResolution.java 2010-12-30
15:36:42 UTC (rev 27829)
@@ -14,36 +14,21 @@
import java.util.List;
import java.util.Set;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.ITypeParameter;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IMarkerResolution2;
import org.eclipse.ui.internal.Workbench;
-import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IInjectionPoint;
-import org.jboss.tools.cdi.core.IInjectionPointField;
-import org.jboss.tools.cdi.core.IInjectionPointMethod;
-import org.jboss.tools.cdi.core.IInjectionPointParameter;
import org.jboss.tools.cdi.core.IQualifier;
import org.jboss.tools.cdi.ui.CDIUIMessages;
-import org.jboss.tools.cdi.ui.CDIUIPlugin;
import org.jboss.tools.cdi.ui.wizard.AddQualifiersToBeanComposite;
import org.jboss.tools.cdi.ui.wizard.AddQualifiersToBeanWizard;
-import org.jboss.tools.common.EclipseUtil;
/**
* @author Daniel Azarov
@@ -75,7 +60,7 @@
return;
List<IQualifier> deployed = wizard.getDeployedQualifiers();
- addQualifiersToBean(deployed);
+ MarkerResolutionUtils.addQualifiersToBean(deployed, selectedBean);
try {
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
} catch (InterruptedException e) {
@@ -92,82 +77,9 @@
}
}
- addQualifiersToInjectedPoint();
+ MarkerResolutionUtils.addQualifiersToInjectedPoint(injectionPoint, selectedBean);
}
- private void addQualifiersToBean(List<IQualifier> deployed){
- IFile file = (IFile)selectedBean.getBeanClass().getResource();
- try{
- ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- IType type = compilationUnit.findPrimaryType();
- if(type != null){
- for(IQualifier qualifier : deployed){
- String qualifierName = qualifier.getSourceType().getFullyQualifiedName();
- if(!qualifierName.equals(CDIConstants.ANY_QUALIFIER_TYPE_NAME) &&
!qualifierName.equals(CDIConstants.DEFAULT_QUALIFIER_TYPE_NAME)){
- MarkerResolutionUtils.addAnnotation(qualifier.getSourceType().getFullyQualifiedName(),
compilationUnit, type);
- }
-
- }
- }
-
- compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
- compilationUnit.discardWorkingCopy();
- }catch(CoreException ex){
- CDIUIPlugin.getDefault().logError(ex);
- }
- }
-
- private void addQualifiersToInjectedPoint(){
- try{
- ICompilationUnit original =
injectionPoint.getClassBean().getBeanClass().getCompilationUnit();
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- Set<IQualifier> qualifiers = selectedBean.getQualifiers();
- for(IQualifier qualifier : qualifiers){
- String qualifierName = qualifier.getSourceType().getFullyQualifiedName();
- if(!qualifierName.equals(CDIConstants.ANY_QUALIFIER_TYPE_NAME) &&
!qualifierName.equals(CDIConstants.DEFAULT_QUALIFIER_TYPE_NAME)){
- IJavaElement element = getInjectedJavaElement(compilationUnit);
- MarkerResolutionUtils.addQualifier(qualifierName, compilationUnit, element);
- }
- }
-
- compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
- compilationUnit.discardWorkingCopy();
- }catch(CoreException ex){
- CDIUIPlugin.getDefault().logError(ex);
- }
- }
-
- private IJavaElement getInjectedJavaElement(ICompilationUnit compolationUnit){
- if(injectionPoint instanceof IInjectionPointField){
- IField field = ((IInjectionPointField)injectionPoint).getField();
- IType type = field.getDeclaringType();
- IType t = compolationUnit.getType(type.getElementName());
- IField f = t.getField(field.getElementName());
-
- return f;
- }else if(injectionPoint instanceof IInjectionPointMethod){
- IMethod method = ((IInjectionPointMethod)injectionPoint).getMethod();
- IType type = method.getDeclaringType();
- IType t = compolationUnit.getType(type.getElementName());
- IMethod m = t.getMethod(method.getElementName(), method.getParameterTypes());
-
- return m;
- }else if(injectionPoint instanceof IInjectionPointParameter){
- String paramName = ((IInjectionPointParameter)injectionPoint).getName();
- IMethod method =
((IInjectionPointParameter)injectionPoint).getBeanMethod().getMethod();
- IType type = method.getDeclaringType();
- IType t = compolationUnit.getType(type.getElementName());
- IMethod m = t.getMethod(method.getElementName(), method.getParameterTypes());
- ITypeParameter p = m.getTypeParameter(paramName);
-
- return p;
- }
- return null;
- }
-
private boolean checkBeans(){
Set<IQualifier> qualifiers = selectedBean.getQualifiers();
if(qualifiers.size() == 0)
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java 2010-12-30
15:34:40 UTC (rev 27828)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java 2010-12-30
15:36:42 UTC (rev 27829)
@@ -10,21 +10,37 @@
******************************************************************************/
package org.jboss.tools.cdi.ui.marker;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IAnnotatable;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IBuffer;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IImportDeclaration;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageDeclaration;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeParameter;
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.core.CDIConstants;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.IInjectionPoint;
+import org.jboss.tools.cdi.core.IInjectionPointField;
+import org.jboss.tools.cdi.core.IInjectionPointMethod;
+import org.jboss.tools.cdi.core.IInjectionPointParameter;
+import org.jboss.tools.cdi.core.IQualifier;
+import org.jboss.tools.cdi.core.IQualifierDeclaration;
+import org.jboss.tools.cdi.ui.CDIUIPlugin;
+import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
/**
@@ -103,7 +119,7 @@
IAnnotation annotation = getAnnotation(element, qualifiedName);
if(annotation != null && annotation.exists())
return;
-
+
addImport(qualifiedName, compilationUnit);
String lineDelim = SPACE;
@@ -149,5 +165,125 @@
}
return null;
}
+
+ private static boolean contains(IQualifierDeclaration declaration, Set<IQualifier>
qualifiers){
+ for(IQualifier qualifier : qualifiers){
+ if(declaration.getQualifier().getSourceType().getFullyQualifiedName().equals(qualifier.getSourceType().getFullyQualifiedName()))
+ return true;
+ }
+ return false;
+ }
+
+ public static void deleteQualifierAnnotation(ICompilationUnit compilationUnit,
IJavaElement element, IQualifier qualifier) throws JavaModelException{
+ if(element instanceof IAnnotatable){
+ String fullName = qualifier.getSourceType().getFullyQualifiedName();
+ String shortName = getShortName(fullName);
+ IAnnotation annotation = ((IAnnotatable)element).getAnnotation(fullName);
+ if(annotation == null || !annotation.exists()){
+ annotation = ((IAnnotatable)element).getAnnotation(shortName);
+ }
+ if(annotation != null && annotation.exists()){
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ buffer.replace(annotation.getSourceRange().getOffset(),
annotation.getSourceRange().getLength(), "");
+
+ synchronized(compilationUnit) {
+ compilationUnit.reconcile(ICompilationUnit.NO_AST, true, null, null);
+ }
+ }
+ }
+ }
+ private static List<IQualifier> findQualifiersToDelete(IInjectionPoint
injectionPoint, Set<IQualifier> qualifiers){
+ ArrayList<IQualifier> list = new ArrayList<IQualifier>();
+ Set<IQualifierDeclaration> declarations =
injectionPoint.getQualifierDeclarations();
+ for(IQualifierDeclaration declaration : declarations){
+ if(!contains(declaration, qualifiers))
+ list.add(declaration.getQualifier());
+ }
+ return list;
+ }
+
+ public static void addQualifiersToInjectedPoint(IInjectionPoint injectionPoint, IBean
bean){
+ try{
+ ICompilationUnit original =
injectionPoint.getClassBean().getBeanClass().getCompilationUnit();
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+ IJavaElement element = getInjectedJavaElement(compilationUnit, injectionPoint);
+ Set<IQualifier> qualifiers = bean.getQualifiers();
+
+ // delete unneeded qualifiers
+
+ List<IQualifier> toDelete = findQualifiersToDelete(injectionPoint, qualifiers);
+
+ for(IQualifier qualifier : toDelete){
+ deleteQualifierAnnotation(compilationUnit, element, qualifier);
+ }
+
+ for(IQualifier qualifier : qualifiers){
+ String qualifierName = qualifier.getSourceType().getFullyQualifiedName();
+ if(!qualifierName.equals(CDIConstants.ANY_QUALIFIER_TYPE_NAME) &&
!qualifierName.equals(CDIConstants.DEFAULT_QUALIFIER_TYPE_NAME)){
+ MarkerResolutionUtils.addQualifier(qualifierName, compilationUnit, element);
+ }
+ }
+
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ }
+
+ public static void addQualifiersToBean(List<IQualifier> deployed, IBean bean){
+ IFile file = (IFile)bean.getBeanClass().getResource();
+ try{
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ IType type = compilationUnit.findPrimaryType();
+ if(type != null){
+ for(IQualifier qualifier : deployed){
+ String qualifierName = qualifier.getSourceType().getFullyQualifiedName();
+ if(!qualifierName.equals(CDIConstants.ANY_QUALIFIER_TYPE_NAME) &&
!qualifierName.equals(CDIConstants.DEFAULT_QUALIFIER_TYPE_NAME)){
+ MarkerResolutionUtils.addAnnotation(qualifier.getSourceType().getFullyQualifiedName(),
compilationUnit, type);
+ }
+
+ }
+ }
+
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ }
+
+ public static IJavaElement getInjectedJavaElement(ICompilationUnit compolationUnit,
IInjectionPoint injectionPoint){
+ if(injectionPoint instanceof IInjectionPointField){
+ IField field = ((IInjectionPointField)injectionPoint).getField();
+ IType type = field.getDeclaringType();
+ IType t = compolationUnit.getType(type.getElementName());
+ IField f = t.getField(field.getElementName());
+
+ return f;
+ }else if(injectionPoint instanceof IInjectionPointMethod){
+ IMethod method = ((IInjectionPointMethod)injectionPoint).getMethod();
+ IType type = method.getDeclaringType();
+ IType t = compolationUnit.getType(type.getElementName());
+ IMethod m = t.getMethod(method.getElementName(), method.getParameterTypes());
+
+ return m;
+ }else if(injectionPoint instanceof IInjectionPointParameter){
+ String paramName = ((IInjectionPointParameter)injectionPoint).getName();
+ IMethod method =
((IInjectionPointParameter)injectionPoint).getBeanMethod().getMethod();
+ IType type = method.getDeclaringType();
+ IType t = compolationUnit.getType(type.getElementName());
+ IMethod m = t.getMethod(method.getElementName(), method.getParameterTypes());
+ ITypeParameter p = m.getTypeParameter(paramName);
+
+ return p;
+ }
+ return null;
+ }
+
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/SelectBeanMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/SelectBeanMarkerResolution.java 2010-12-30
15:34:40 UTC (rev 27828)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/SelectBeanMarkerResolution.java 2010-12-30
15:36:42 UTC (rev 27829)
@@ -13,13 +13,17 @@
import java.util.List;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IMarkerResolution2;
import org.eclipse.ui.internal.Workbench;
import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IInjectionPoint;
+import org.jboss.tools.cdi.core.IQualifier;
import org.jboss.tools.cdi.ui.CDIUIMessages;
import org.jboss.tools.cdi.ui.wizard.SelectBeanWizard;
@@ -48,7 +52,26 @@
int status = dialog.open();
if(status != WizardDialog.OK)
return;
-
+
+ IBean selectedBean = wizard.getBean();
+
+ List<IQualifier> deployed = wizard.getDeployedQualifiers();
+ MarkerResolutionUtils.addQualifiersToBean(deployed, selectedBean);
+ try {
+ Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+ // reload selectedBean
+ ICDIProject cdiProject = selectedBean.getCDIProject();
+ IBean[] beans = cdiProject.getBeans();
+ for(IBean bean : beans){
+ if(bean.getBeanClass().getFullyQualifiedName().equals(selectedBean.getBeanClass().getFullyQualifiedName())){
+ selectedBean = bean;
+ break;
+ }
+ }
+ MarkerResolutionUtils.addQualifiersToInjectedPoint(injectionPoint, selectedBean);
}
public String getDescription() {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizard.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizard.java 2010-12-30
15:34:40 UTC (rev 27828)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizard.java 2010-12-30
15:36:42 UTC (rev 27829)
@@ -23,7 +23,7 @@
public AddQualifiersToBeanWizard(IInjectionPoint injectionPoint, List<IBean>
beans, IBean bean){
super(injectionPoint, beans, bean);
- setWindowTitle(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_TITLE);
+ setWindowTitle(CDIUIMessages.SELECT_BEAN_WIZARD_TITLE);
setDefaultPageImageDescriptor(ModelUIImages.getImageDescriptor(ModelUIImages.WIZARD_DEFAULT));
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/SelectBeanWizard.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/SelectBeanWizard.java 2010-12-30
15:34:40 UTC (rev 27828)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/SelectBeanWizard.java 2010-12-30
15:36:42 UTC (rev 27829)
@@ -46,7 +46,7 @@
public SelectBeanWizard(IInjectionPoint injectionPoint, java.util.List<IBean>
beans){
super(injectionPoint, beans);
- setWindowTitle(CDIUIMessages.SELECT_BEAN_TITLE);
+ setWindowTitle(CDIUIMessages.SELECT_BEAN_WIZARD_TITLE);
setDefaultPageImageDescriptor(ModelUIImages.getImageDescriptor(ModelUIImages.WIZARD_DEFAULT));
}