Help me with my plugin
hi,
I'm developing MyBatis plugin. It seems that @Autowired and @Resource annotation of spring do not work well sometimes when my plugin is enabled.
I'v tried my best to find the reason, but got nothing. I think the problem is something like component priority, but i can not get a good point to find the exact reason
The source code of my plugin is here: https://github.com/seventh7/intellij-mybatis-plugin
Can anyone give me some help please, thanks
Please sign in to leave a comment.
please explain "do not work well sometimes" and give sample code, thanks
I take some screenshots to describe my problem here.
Please help me, thanks
Attachment(s):
2.jpeg
I assume there's a problem with your LineMarkerProvider "interfering" with Spring's gutter annotation provider. Please try Pass.UPDATE_OVERRIDEN_MARKERS instead of Pass.UPDATE_ALL.
Or try using com.intellij.codeInsight.navigation.NavigationGutterIconBuilder in combination with com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider, you can find example in Struts 2 plugin com.intellij.struts2.annotators.ActionAnnotatorBase.
Ok, I'll follow your advice. Thank you for your help Yann
I'm sorry, it seems that the RelatedItemLineMarkerProvider and Pass.UPDATE_OVERRIDEN_MARKERS do not make sense
can you inspect my code please
/**
* @author yanglin
*/
public class InjectionLineMarkerProvider extends RelatedItemLineMarkerProvider {
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, Collection<? super RelatedItemLineMarkerInfo> result) {
if (!(element instanceof PsiField)) return;
PsiField field = (PsiField) element;
if (!isTargetField(field)) return;
PsiType type = field.getType();
if (!(type instanceof PsiClassReferenceType)) return;
Optional<PsiClass> clzz = JavaUtils.findClzz(element.getProject(), type.getCanonicalText());
if (!clzz.isPresent()) return;
PsiClass psiClass = clzz.get();
Optional<Mapper> mapper = MapperUtils.findFirstMapper(element.getProject(), psiClass);
if (!mapper.isPresent()) return;
NavigationGutterIconBuilder<PsiElement> builder =
NavigationGutterIconBuilder.create(Icons.SPRING_INJECTION_ICON)
.setAlignment(GutterIconRenderer.Alignment.LEFT)
.setTarget(psiClass)
.setTooltipTitle("Data asscess object found - " + psiClass.getQualifiedName());
result.add(builder.createLineMarkerInfo(field.getNameIdentifier()));
}
private boolean isTargetField(PsiField field) {
Optional<PsiAnnotation> wutowiredAnno = JavaUtils.getPsiAnnotation(field, Annotation.AUTOWIRED);
if (wutowiredAnno.isPresent()) {
return true;
}
Optional<PsiAnnotation> resourceAnno = JavaUtils.getPsiAnnotation(field, Annotation.RESOURCE);
if (resourceAnno.isPresent()) {
PsiAnnotationMemberValue nameValue = resourceAnno.get().findAttributeValue("name");
String name = nameValue.getText().replaceAll("\"", "");
return StringUtils.isBlank(name) || name.equals(field.getName());
}
return false;
}
}
I meant: either you change your existing code to use Pass.UPDATE_OVERRIDEN_MARKERS or you use second approach using RILMP (which you did). Does this version work now?
I tried both, and it seems none of them works
Please be more specific, what exactly does not work with the new solution? Did you check the annotation-code is being called?
The both solutions are working for my purpose(line marker and navigation works ), but it cause that the line marker for spring bean does not work, i mean that line marker provided by spring plugin does not appear
I'm so sorry for my bad english
Please verify Spring linemarker works again after commenting yours in your plugin.xml
If that's the case, please re-enable your provider and try using using different Icon in NavigationGutterIconBuilder.create(Icons.SPRING_INJECTION_ICON) and/or different PsiElement (just for testing) in builder.createLineMarkerInfo(field.getNameIdentifier()).
Hi, Yann
I think this case will happen when it meets some conditions, as i did not register InjectionLineMarkerProvider in plugin.xml when i make any release version to idea plugin repositories(as i'm still working on it). And a user of this plugin feedback this problem to me, then i prove that this problem really exist. so i look into it, but can not find the right solution.
I comment my InjectionLineMarkerProvider in plugin.xml, and it does not make sense as well, i think my plugin may have some conflict with some other plugin.
well, that's easy to find out - disable all of them ;-) anything suspicious in idea.log?
Hi, Yann
After i comment the declaration of "dom.fileDescription" in plugin.xml which is for spring configuration xml file, everything goes well :)
Thank you so much for your patience to help
Best regards,
Lin
What exactly did you comment out? Please paste definition here.
I commentted this line in plugin.xml "<dom.fileDescription implementation="com.seventh7.mybatis.dom.description.BeansDescription"/>"
BeansDescription:
public class BeansDescription extends DomFileDescription<Beans>{
public BeansDescription() {
super(Beans.class, "beans");
}
@Override
public boolean isMyFile(@NotNull XmlFile file, @Nullable Module module) {
return true;
}
}
Beans:
public interface Beans extends DomElement {
@NotNull
@SubTagList("bean")
public List<Bean> getBeans();
}
Bean:
public interface Bean extends DomElement {
@NotNull
@SubTagList("property")
public List<BeanProperty> getBeanProperties();
}
BeanProperty:
public interface BeanProperty extends DomElement {
@NotNull
@Attribute("name")
public GenericAttributeValue<String> getName();
@NotNull
@Attribute("value")
public GenericAttributeValue<String> getValue();
}
I see, that ofcourse will interfere with existing Spring plugin DOM.
Yes, it does. I am naive enough to think that this will work. As they belong to different packages. hehe
Thank you for your help, Yann