Author: dazarov
Date: 2010-12-28 13:05:32 -0500 (Tue, 28 Dec 2010)
New Revision: 27776
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/CDIProblemMarkerResolutionGenerator.java
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/wizard/AddQualifiersToBeanComposite.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-28
17:55:19 UTC (rev 27775)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-12-28
18:05:32 UTC (rev 27776)
@@ -85,6 +85,7 @@
public static String DELETE_ALL_DISPOSER_DUPLICANT_MARKER_RESOLUTION_TITLE;
public static String DELETE_ALL_INJECTED_CONSTRUCTORS_MARKER_RESOLUTION_TITLE;
public static String MAKE_INJECTED_POINT_UNAMBIGUOUS_TITLE;
+ public static String COLLECTING_MARKER_RESOLUTIONS;
public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_TITLE;
public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_AVAILABLE;
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-28
17:55:19 UTC (rev 27775)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-12-28
18:05:32 UTC (rev 27776)
@@ -69,6 +69,7 @@
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
+COLLECTING_MARKER_RESOLUTIONS=Collecting CDI Marker Resolutions...
ADD_QUALIFIERS_TO_BEAN_WIZARD_TITLE=Add Qualifiers to the Bean
ADD_QUALIFIERS_TO_BEAN_WIZARD_AVAILABLE=Available:
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2010-12-28
17:55:19 UTC (rev 27775)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2010-12-28
18:05:32 UTC (rev 27776)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.cdi.ui.marker;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -17,6 +18,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
@@ -25,8 +27,11 @@
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator2;
+import org.eclipse.ui.PlatformUI;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.CDIUtil;
@@ -34,6 +39,7 @@
import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IInjectionPoint;
import org.jboss.tools.cdi.internal.core.validation.CDIValidationErrorManager;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
import org.jboss.tools.cdi.ui.CDIUIPlugin;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
@@ -45,6 +51,7 @@
public class CDIProblemMarkerResolutionGenerator implements
IMarkerResolutionGenerator2 {
private static final String JAVA_EXTENSION = "java"; //$NON-NLS-1$
+ IMarkerResolution[] resolutions;
public IMarkerResolution[] getResolutions(IMarker marker) {
try {
@@ -64,12 +71,12 @@
int messageId = attribute.intValue();
- IFile file = (IFile) marker.getResource();
+ final IFile file = (IFile) marker.getResource();
attribute = ((Integer) marker.getAttribute(IMarker.CHAR_START));
if (attribute == null)
return new IMarkerResolution[] {};
- int start = attribute.intValue();
+ final int start = attribute.intValue();
if (JAVA_EXTENSION.equals(file.getFileExtension())) {
if (messageId == CDIValidationErrorManager.ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN_ID)
{
@@ -112,22 +119,76 @@
new DeleteAllInjectedConstructorsMarkerResolution(method, file)
};
}
- }else if(messageId == CDIValidationErrorManager.UNSATISFIED_INJECTION_POINTS_ID ||
- messageId == CDIValidationErrorManager.AMBIGUOUS_INJECTION_POINTS_ID){
+ }else if(messageId == CDIValidationErrorManager.AMBIGUOUS_INJECTION_POINTS_ID){
IInjectionPoint injectionPoint = findInjectionPoint(file, start);
if(injectionPoint != null){
List<IBean> beans = findBeans(injectionPoint);
IMarkerResolution[] resolutions = new IMarkerResolution[beans.size()];
for(int i = 0; i < beans.size(); i++){
- resolutions[i] = new MakeInjectedPointUnambiguousMarkerResolution(injectionPoint,
beans, file, i);
+ resolutions[i] = new MakeInjectedPointUnambiguousMarkerResolution(injectionPoint,
beans, i);
}
return resolutions;
}
+ }else if(messageId == CDIValidationErrorManager.UNSATISFIED_INJECTION_POINTS_ID){
+
+ if (Display.getCurrent() != null) {
+ try{
+ PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new
IRunnableWithProgress(){
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ monitor.beginTask(CDIUIMessages.COLLECTING_MARKER_RESOLUTIONS, 10);
+ monitor.worked(3);
+ resolutions = collectMarkerResolutions(file, start);
+ monitor.worked(7);
+ }
+ });
+ }catch(InterruptedException ie){
+ CDIUIPlugin.getDefault().logError(ie);
+ }catch(InvocationTargetException ite){
+ CDIUIPlugin.getDefault().logError(ite);
+ }
+ } else {
+ resolutions = collectMarkerResolutions(file, start);
+ }
+ return resolutions;
}
}
return new IMarkerResolution[] {};
}
+ private IMarkerResolution[] collectMarkerResolutions(IFile file, int start){
+ IJavaElement element = findJavaElement(file, start);
+ if(element != null){
+ CDICoreNature cdiNature = CDIUtil.getCDINatureWithProgress(file.getProject());
+ if(cdiNature != null){
+ ICDIProject cdiProject = cdiNature.getDelegate();
+ if(cdiProject != null){
+ Set<IBean> allBeans = cdiProject.getBeans(file.getFullPath());
+
+ IInjectionPoint injectionPoint = CDIUtil.findInjectionPoint(allBeans, element,
start);
+
+ IBean[] bs = cdiProject.getBeans();
+ ArrayList<IBean> beans = new ArrayList<IBean>();
+ try{
+ for(IBean b : bs){
+ if(Flags.isPublic(b.getBeanClass().getFlags()))
+ beans.add(b);
+ }
+
+ IMarkerResolution[] resolutions = new IMarkerResolution[beans.size()];
+ for(int i = 0; i < beans.size(); i++){
+ resolutions[i] = new MakeInjectedPointUnambiguousMarkerResolution(injectionPoint,
beans, i);
+ }
+ return resolutions;
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ }
+ }
+ }
+ return new IMarkerResolution[]{};
+ }
+
private IInjectionPoint findInjectionPoint(IFile file, int start){
IJavaElement element = findJavaElement(file, start);
if(element == null)
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-28
17:55:19 UTC (rev 27775)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeInjectedPointUnambiguousMarkerResolution.java 2010-12-28
18:05:32 UTC (rev 27776)
@@ -33,6 +33,7 @@
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;
@@ -49,13 +50,11 @@
*/
public class MakeInjectedPointUnambiguousMarkerResolution implements IMarkerResolution2
{
private String label;
- private IFile file;
private IInjectionPoint injectionPoint;
private List<IBean> beans;
private IBean selectedBean;
- public MakeInjectedPointUnambiguousMarkerResolution(IInjectionPoint injectionPoint,
List<IBean> beans, IFile file, int index){
- this.file = file;
+ public MakeInjectedPointUnambiguousMarkerResolution(IInjectionPoint injectionPoint,
List<IBean> beans, int index){
this.injectionPoint = injectionPoint;
this.beans = beans;
this.selectedBean = beans.get(index);
@@ -78,11 +77,20 @@
List<IQualifier> deployed = wizard.getDeployedQualifiers();
addQualifiersToBean(deployed);
try {
- Thread.sleep(3000);
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;
+ }
+ }
+
}
addQualifiersToInjectedPoint();
}
@@ -96,7 +104,11 @@
IType type = compilationUnit.findPrimaryType();
if(type != null){
for(IQualifier qualifier : deployed){
- MarkerResolutionUtils.addAnnotation(qualifier.getSourceType().getFullyQualifiedName(),
compilationUnit, type);
+ 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);
+ }
+
}
}
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-28
17:55:19 UTC (rev 27775)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java 2010-12-28
18:05:32 UTC (rev 27776)
@@ -20,9 +20,7 @@
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.ISourceReference;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeParameter;
import org.eclipse.jdt.core.JavaModelException;
@@ -82,7 +80,11 @@
}
- public static void addAnnotation(String qualifiedName, ICompilationUnit compilationUnit,
ISourceReference element) throws JavaModelException{
+ public static void addAnnotation(String qualifiedName, ICompilationUnit compilationUnit,
IType element) throws JavaModelException{
+ IAnnotation annotation = getAnnotation(element, qualifiedName);
+ if(annotation != null && annotation.exists())
+ return;
+
addImport(qualifiedName, compilationUnit);
String lineDelim = compilationUnit.findRecommendedLineSeparator();
@@ -98,6 +100,10 @@
}
public static void addQualifier(String qualifiedName, ICompilationUnit compilationUnit,
IJavaElement element) throws JavaModelException{
+ IAnnotation annotation = getAnnotation(element, qualifiedName);
+ if(annotation != null && annotation.exists())
+ return;
+
addImport(qualifiedName, compilationUnit);
String lineDelim = SPACE;
@@ -105,7 +111,7 @@
IBuffer buffer = compilationUnit.getBuffer();
String shortName = getShortName(qualifiedName);
- IAnnotation annotation = getAnnotation(element,
CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
+ annotation = getAnnotation(element, CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
buffer.replace(annotation.getSourceRange().getOffset()+annotation.getSourceRange().getLength(),
0, lineDelim+AT+shortName);
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanComposite.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanComposite.java 2010-12-28
17:55:19 UTC (rev 27775)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanComposite.java 2010-12-28
18:05:32 UTC (rev 27776)
@@ -518,7 +518,11 @@
}
public ArrayList<IQualifier> getDeployedQualifiers(){
- return deployed;
+ total.clear();
+ total.addAll(originalQualifiers);
+ total.addAll(deployed);
+
+ return total;
}
class QualifiersListLabelProvider implements ILabelProvider{