update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / search / SimpleAccessorReferenceSearcher.java
blob0b5924d057c5e80456e626bcace5055692f35940
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.psi.impl.search;
18 import com.intellij.openapi.application.ApplicationManager;
19 import com.intellij.openapi.fileTypes.StdFileTypes;
20 import com.intellij.openapi.util.Computable;
21 import com.intellij.openapi.util.text.StringUtil;
22 import com.intellij.psi.PsiElement;
23 import com.intellij.psi.PsiManager;
24 import com.intellij.psi.PsiMethod;
25 import com.intellij.psi.PsiReference;
26 import com.intellij.psi.search.*;
27 import com.intellij.psi.search.searches.ReferencesSearch;
28 import com.intellij.psi.util.PropertyUtil;
29 import com.intellij.util.Processor;
30 import com.intellij.util.QueryExecutor;
32 /**
33 * @author ven
35 public class SimpleAccessorReferenceSearcher implements QueryExecutor<PsiReference, ReferencesSearch.SearchParameters> {
36 public boolean execute(final ReferencesSearch.SearchParameters queryParameters, final Processor<PsiReference> consumer) {
37 final PsiElement refElement = queryParameters.getElementToSearch();
38 if (!(refElement instanceof PsiMethod)) return true;
39 final PsiMethod method = (PsiMethod)refElement;
40 final String propertyName = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
41 public String compute() {
42 if (!method.isValid()) return null;
43 return PropertyUtil.getPropertyName(method);
45 });
46 if (StringUtil.isEmptyOrSpaces(propertyName)) {
47 return true;
49 SearchScope searchScope = ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
50 public SearchScope compute() {
51 SearchScope searchScope = queryParameters.getEffectiveSearchScope();
52 if (searchScope instanceof GlobalSearchScope) {
53 searchScope = GlobalSearchScope.getScopeRestrictedByFileTypes((GlobalSearchScope)searchScope,
54 StdFileTypes.JSP,
55 StdFileTypes.JSPX,
56 StdFileTypes.XML,
57 StdFileTypes.XHTML);
59 return searchScope;
61 });
63 final PsiSearchHelper helper = PsiManager.getInstance(refElement.getProject()).getSearchHelper();
64 final TextOccurenceProcessor processor = new TextOccurenceProcessor() {
65 public boolean execute(PsiElement element, int offsetInElement) {
66 final PsiReference[] refs = element.getReferences();
67 for (PsiReference ref : refs) {
68 if (ref.getRangeInElement().contains(offsetInElement)) {
69 if (ref.isReferenceTo(refElement)) {
70 return consumer.process(ref);
74 return true;
78 return helper.processElementsWithWord(processor, searchScope, propertyName, UsageSearchContext.IN_FOREIGN_LANGUAGES, false);