1919import com .github .cameltooling .idea .service .CamelCatalogService ;
2020import com .github .cameltooling .idea .service .CamelPreferenceService ;
2121import com .github .cameltooling .idea .service .CamelService ;
22+ import com .github .cameltooling .idea .util .BeanUtils ;
2223import com .github .cameltooling .idea .util .CamelIdeaUtils ;
2324import com .github .cameltooling .idea .util .IdeaUtils ;
2425import com .intellij .lang .annotation .AnnotationHolder ;
2526import com .intellij .lang .annotation .HighlightSeverity ;
2627import com .intellij .openapi .diagnostic .Logger ;
28+ import com .intellij .openapi .module .Module ;
29+ import com .intellij .openapi .module .ModuleUtilCore ;
2730import com .intellij .openapi .util .TextRange ;
2831import com .intellij .psi .PsiElement ;
2932import com .intellij .psi .xml .XmlAttributeValue ;
@@ -76,6 +79,14 @@ void validateText(@NotNull PsiElement element, @NotNull AnnotationHolder holder,
7679 if ("[null]" .equals (error )) {
7780 return ;
7881 }
82+ String missingBeanName = extractMissingBeanName (result );
83+ if (missingBeanName != null ) {
84+ Module module = ModuleUtilCore .findModuleForPsiElement (element );
85+ boolean beanExists = module != null && BeanUtils .getService ().findReferenceableBeanId (module , missingBeanName ).isPresent ();
86+ if (beanExists ) {
87+ return ; // camel catalog's validator can't see the beans we can see, let's ignore the error if we known the bean exists
88+ }
89+ }
7990 TextRange range = element .getTextRange ();
8091 if (result .getIndex () > 0 ) {
8192 range = getAdjustedTextRange (element , range , text , result );
@@ -90,6 +101,23 @@ void validateText(@NotNull PsiElement element, @NotNull AnnotationHolder holder,
90101 }
91102 }
92103
104+ /**
105+ * This is hoping that the error message will stay the same forever.
106+ * Could be implemented in a different way, see GH issue #1115 - supply list of beans we know to Camel catalog's validator.
107+ */
108+ private String extractMissingBeanName (LanguageValidationResult result ) {
109+ String missingBeanErrorPrefix = "No bean could be found in the registry for: " ;
110+ String error = result .getError ();
111+ if (error .startsWith (missingBeanErrorPrefix )) {
112+ return error .substring (missingBeanErrorPrefix .length ())
113+ .trim ()
114+ .split (" " )[0 ]
115+ .trim ();
116+ } else {
117+ return null ;
118+ }
119+ }
120+
93121 /**
94122 * Adjust the text range according to the type of ${@link PsiElement}
95123 * @return a new text range
0 commit comments