History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEADEV-2343
Type: New Feature New Feature
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Maxim Shafirov
Reporter: Sven Steiniger
Votes: 22
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
IDEA: Development

Lang-API: fully support references with different names

Created: 30 Aug 05 10:47   Updated: 09 May 06 03:56
Component/s: Plugin Support. API
Fix Version/s: Demetra 5281

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 3,436
Fixed in build: 5,266
Severity: High


 Description  « Hide
Having an custom language where references may have an different name than the referenced item.
For example java-bean access. The java methods look like:
String getPropValue()
setPropValue(String)
and in the custom language file it is just used as
"propValue"

With the current API Goto-Action works, but Find Usages/Rename not.

Note: this is not tied to bean-like access. Arbitrary references should be supported.



 All   Comments   Work Log   Change History      Sort Order:
Sven Steiniger - 27 Sep 05 10:23
Ummhh, no work-around, no schedule, nothing.
Please JB, any news?

Maxim Mossienko - 28 Sep 05 14:44
Property references are looked in XML/JSP/JSPX files only.

Sven Steiniger - 09 Nov 05 11:41
What about this simple solution:
FindUsageProvider:
public FindUsageHint[] getFindUsageHints(PsiElement elem)

public class FindUsageHint
{
public String getWord();
public boolean isIgnoreCase();
}

So IDEA first calls this method to get all words to be search for.
And plugins providers can check the passed element to only
return the necessary search patterns.


Maxim Shafirov - 09 May 06 01:29
It actually possible for quite a while in Demetra. You're to register your own custom reference searcher to a ref searchers registry as follows:
ReferenceSearch.INSTANCE.registerExecutor(new CustomReferenceSearcher());

somwhere at plugin loading time.
CustomReferenceSearcher code goes below (it searches references for methods named xxxSomething in XML, where reference text is somewhat like yyySomething).

/**
 * @author max
 */
public class CustomReferencesSearcher implements QueryExecutor<PsiReference, ReferencesSearch.SearchParameters> {
  public boolean execute(final ReferencesSearch.SearchParameters params, final Processor<PsiReference> consumer) {
    final PsiElement target = params.getElementToSearch();
    final SearchScope searchScope = limitToFileType(params.getScope(), StdFileTypes.XML); // Your custom language file type here

    if (target instanceof PsiMethod) {
      String name = ((PsiMethod)target).getName();
      if (name.startsWith("xxx")) {
        String searchText = "yyy" + name.substring(3);
        final TextOccurenceProcessor processor = new TextOccurenceProcessor() {
          public boolean execute(PsiElement element, int offsetInElement) {
            final PsiReference[] refs = element.getReferences();
            for (PsiReference ref : refs) {
              if (ref.getRangeInElement().contains(offsetInElement)) {
                if (ref.isReferenceTo(target)) {
                  return consumer.process(ref);
                }
              }
            }
            return true;
          }
        };
        
        return PsiManager.getInstance(target.getProject()).getSearchHelper().processElementsWithWord(processor, searchScope, searchText, UsageSearchContext.IN_CODE, true);
      }
    }

    return true;
  }

  private static SearchScope limitToFileType(SearchScope scope, final FileType type) {
    return scope.intersectWith(new GlobalSearchScope() {
      public boolean contains(VirtualFile file) {
        return file.getFileType() == type;
      }

      public int compare(VirtualFile file1, VirtualFile file2) {
        return 0; // irrelevant
      }

      public boolean isSearchInModuleContent(Module aModule) {
        return true;
      }

      public boolean isSearchInLibraries() {
        return false;
      }
    });
  }
}

Keith Lea - 09 May 06 03:56
This is exciting!