Navigating from reference using definitionsScopedSearch

Hi there,

I've implemented a <definitionsScopedSearch> that allows me to use ctrl-alt-b to navigate from a field in a Java class to another field in a related Java class. This is working quite nicely.

However, I'd also like to navigate to the field in the related class when invoking ctrl-alt-b on a reference to the original field.
Currently, this brings me to the definition of the original field, rather than to the related class. In my debugger, I do see my custom QueryExecutor being called, and it is finding the field in the related class (which I'd like it to navigate to) and supplying it to the process() call on the consumer. Still, it's not navigating to that field, but to the original field.


Any thoughts on how to make it navigate to the field in the related class?

 

Hope I'm making any sense.
To clarify this a bit more:

  • Invoking ctrl-alt-b on source (the 2nd line) in class A below brings me to Related.target.That's great.
  • Invoking ctrl-alt-b on source in the println() call brings me to line 2. But I would like it to bring me to Related.target.
class A {
String source;

A() {
System.out.println(source);
}
}

class Related {
String target;
}
5 comments

My QueryExecutor is as follows:

 

public class ValueObjectMetaFieldSearcher extends QueryExecutorBase<PsiField, DefinitionsScopedSearch.SearchParameters> {

public ValueObjectMetaFieldSearcher() {
super(true);
}

@Override
public void processQuery(@NotNull DefinitionsScopedSearch.SearchParameters params, @NotNull Processor<PsiField> consumer) {

final PsiElement element = params.getElement();

if (!(element instanceof PsiField)) return;

final PsiClass baseClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);

if (baseClass.getModifierList().findAnnotation("com.foo.MyAnnotation") == null) {
return;
}

PsiClass targetClass = MyClassUtil.findClassByName(element.getProject(),
MyClassUtil.determineTargetClassName(baseClass));

PsiField field = targetClass.findFieldByName(((PsiField) element).getName(), false);

if (field != null) {
consumer.process(field);
}
}
}
0

Hello Guno,

Are you implementing goto or view quick definition?

is source resolved to target?

0

Hi Imants,

 

I'm implementing goto. And it does work actually, source is resolved to target. when invoking ctrl-alt-b on source on line 2 in my example.
But not when I invoke ctrl-alt-b on the reference to source in the println() call. If I do that, it navigates to the definition of source, instead of to the definition of target.

0

a, ctrl-alt-b is goto implementation

take a look at GotoImplementationAction and GotoImplementationHandler

maybe add a custom action with a custom handler?

 

0

I'll try that, thanks!

[edit]
Working fine now, using a custom action and handler!

0

Please sign in to leave a comment.