Author: dazarov
Date: 2011-10-07 20:16:00 -0400 (Fri, 07 Oct 2011)
New Revision: 35500
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java
Log:
Quick fixes for problem markers in beans.xml
https://issues.jboss.org/browse/JBIDE-9833
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 2011-10-07
23:52:00 UTC (rev 35499)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2011-10-08
00:16:00 UTC (rev 35500)
@@ -43,9 +43,11 @@
import org.jboss.tools.cdi.core.CDIUtil;
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.ICDIProject;
+import org.jboss.tools.cdi.core.IClassBean;
import org.jboss.tools.cdi.core.IDecorator;
import org.jboss.tools.cdi.core.IInjectionPoint;
import org.jboss.tools.cdi.core.IInterceptor;
+import org.jboss.tools.cdi.core.IStereotype;
import org.jboss.tools.cdi.core.IStereotyped;
import org.jboss.tools.cdi.internal.core.impl.CDIProject;
import org.jboss.tools.cdi.internal.core.validation.CDIValidationErrorManager;
@@ -515,14 +517,14 @@
};
}
}else if(messageId == CDIValidationErrorManager.ILLEGAL_ALTERNATIVE_BEAN_CLASS_ID){
- IJavaElement element = findJavaElementByQualifiedName(file.getProject(), text);
+ IJavaElement element = getTypeToAddAlternativeToBean(file.getProject(), text);
if(element != null){
return new IMarkerResolution[] {
new AddAnnotationMarkerResolution(element,
CDIConstants.ALTERNATIVE_ANNOTATION_TYPE_NAME)
};
}
}else if(messageId == CDIValidationErrorManager.ILLEGAL_ALTERNATIVE_ANNOTATION_ID){
- IJavaElement element = findJavaElementByQualifiedName(file.getProject(), text);
+ IJavaElement element = getTypeToAddAlternativeToStereotype(file.getProject(), text);
if(element != null){
return new IMarkerResolution[] {
new AddAnnotationMarkerResolution(element,
CDIConstants.ALTERNATIVE_ANNOTATION_TYPE_NAME)
@@ -547,6 +549,56 @@
return new IMarkerResolution[] {};
}
+ private IType getTypeToAddAlternativeToBean(IProject project, String qualifiedName){
+ IJavaProject javaProject = EclipseUtil.getJavaProject(project);
+ IType type = null;
+ try {
+ type = javaProject.findType(qualifiedName);
+ } catch (JavaModelException ex) {
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+
+ if(type != null){
+ CDICoreNature cdiNature = CDIUtil.getCDINatureWithProgress(project);
+ if(cdiNature != null){
+ ICDIProject cdiProject = cdiNature.getDelegate();
+
+ if(cdiProject != null){
+ IClassBean classBean = cdiProject.getBeanClass(type);
+ if(classBean != null && !classBean.isAlternative()){
+ return type;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private IType getTypeToAddAlternativeToStereotype(IProject project, String
qualifiedName){
+ IJavaProject javaProject = EclipseUtil.getJavaProject(project);
+ IType type = null;
+ try {
+ type = javaProject.findType(qualifiedName);
+ } catch (JavaModelException ex) {
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+
+ if(type != null){
+ CDICoreNature cdiNature = CDIUtil.getCDINatureWithProgress(project);
+ if(cdiNature != null){
+ ICDIProject cdiProject = cdiNature.getDelegate();
+
+ if(cdiProject != null){
+ IStereotype stereotype = cdiProject.getStereotype(qualifiedName);
+ if(stereotype != null && !stereotype.isAlternative()){
+ return type;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
private IJavaElement findJavaElementByQualifiedName(IProject project, String
qualifiedName){
IJavaProject javaProject = EclipseUtil.getJavaProject(project);
try {
@@ -651,7 +703,6 @@
CDICoreNature cdiNature = CDIUtil.getCDINatureWithProgress(file.getProject());
if(cdiNature == null)
return null;
-
ICDIProject cdiProject = cdiNature.getDelegate();