update copyright
[fedora-idea.git] / plugins / properties / src / com / intellij / psi / impl / search / PropertyReferenceViaLastWordSearcher.java
blob4fa4ed8ac9a63d93719ad3e99a78bfc2b5c97f54
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.lang.properties.psi.Property;
19 import com.intellij.openapi.application.ApplicationManager;
20 import com.intellij.openapi.fileTypes.StdFileTypes;
21 import com.intellij.openapi.util.Computable;
22 import com.intellij.openapi.util.text.StringUtil;
23 import com.intellij.openapi.progress.ProgressManager;
24 import com.intellij.psi.PsiElement;
25 import com.intellij.psi.PsiManager;
26 import com.intellij.psi.PsiReference;
27 import com.intellij.psi.search.*;
28 import com.intellij.psi.search.searches.ReferencesSearch;
29 import com.intellij.util.Processor;
30 import com.intellij.util.QueryExecutor;
32 import java.util.List;
34 /**
35 * @author ven
37 public class PropertyReferenceViaLastWordSearcher implements QueryExecutor<PsiReference, ReferencesSearch.SearchParameters> {
38 // add to the search results occurences in JSPs of the last word in the property name, since this stuff is possible:
39 // <bla:bla ref.key="lastWord> (can reference to xxx.lastWord property)
40 public boolean execute(final ReferencesSearch.SearchParameters queryParameters, final Processor<PsiReference> consumer) {
41 final PsiElement refElement = queryParameters.getElementToSearch();
42 if (refElement instanceof Property) {
43 final String name = ((Property)refElement).getName();
44 if (name == null) return true;
45 final List<String> words = StringUtil.getWordsIn(name);
46 if (words.isEmpty()) return true;
47 final String lastWord = words.get(words.size() - 1);
49 SearchScope searchScope = ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
50 public SearchScope compute() {
51 return queryParameters.getEffectiveSearchScope();
53 });
54 if (searchScope instanceof GlobalSearchScope) {
55 searchScope = GlobalSearchScope.getScopeRestrictedByFileTypes((GlobalSearchScope)searchScope, StdFileTypes.JSP, StdFileTypes.JSPX);
57 final PsiSearchHelper helper = PsiManager.getInstance(refElement.getProject()).getSearchHelper();
58 final TextOccurenceProcessor processor = new TextOccurenceProcessor() {
59 public boolean execute(PsiElement element, int offsetInElement) {
60 ProgressManager.getInstance().checkCanceled();
61 final PsiReference[] refs = element.getReferences();
62 for (PsiReference ref : refs) {
63 if (ref.getRangeInElement().contains(offsetInElement) && ref.isReferenceTo(refElement)) {
64 return consumer.process(ref);
66 ProgressManager.getInstance().checkCanceled();
68 return true;
72 if (!helper.processElementsWithWord(processor, searchScope, lastWord, UsageSearchContext.IN_FOREIGN_LANGUAGES, false)) {
73 return false;
77 return true;