|
JavaScriptFindUsagesProvider.java
|
1 /*
2 * Copyright 2000-2005 JetBrains s.r.o.
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package com.intellij.lang.javascript.findUsages;
17
18 import com.intellij.lang.cacheBuilder.WordsScanner;
19 import com.intellij.lang.findUsages.FindUsagesProvider;
20 import com.intellij.lang.javascript.JSElementTypes;
21 import com.intellij.lang.javascript.JSTokenTypes;
22 import com.intellij.lang.javascript.JSWordsScanner;
23 import com.intellij.lang.javascript.psi.JSFunction;
24 import com.intellij.lang.javascript.psi.JSParameter;
25 import com.intellij.lang.javascript.psi.JSProperty;
26 import com.intellij.lang.javascript.psi.JSVariable;
27 import com.intellij.psi.PsiElement;
28 import com.intellij.psi.PsiNamedElement;
29 import com.intellij.psi.search.UsageSearchContext;
30 import com.intellij.psi.tree.IElementType;
31
32 /**
33 * Created by IntelliJ IDEA.
34 * User: max
35 * Date: Feb 14, 2005
36 * Time: 6:44:02 PM
37 * To change this template use File | Settings | File Templates.
38 */
39 public class JavaScriptFindUsagesProvider implements FindUsagesProvider {
40 public boolean canFindUsagesFor(PsiElement psiElement) {
41 return psiElement instanceof PsiNamedElement;
42 }
43
44 public String getHelpId(PsiElement psiElement) {
45 return null;
46 }
47
48 public String getType(PsiElement element) {
49 if (element instanceof JSFunction) return "function";
50 if (element instanceof JSParameter) return "parameter";
51 if (element instanceof JSProperty) return "property";
52 if (element instanceof JSVariable) return "variable";
53 return "";
54 }
55
56 public String getDescriptiveName(PsiElement element) {
57 return ((PsiNamedElement)element).getName();
58 }
59
60 public String getNodeText(PsiElement element, boolean useFullName) {
61 return getDescriptiveName(element);
62 }
63
64 public boolean mayHaveReferences(IElementType token, final short searchContext) {
65 if ((searchContext & UsageSearchContext.IN_CODE) != 0 && token == JSElementTypes.REFERENCE_EXPRESSION) return true;
66 if ((searchContext & UsageSearchContext.IN_COMMENTS) != 0 && JSTokenTypes.COMMENTS.isInSet(token)) return true;
67 if ((searchContext & UsageSearchContext.IN_STRINGS) != 0 && token == JSTokenTypes.STRING_LITERAL) return true;
68 return false;
69 }
70
71 public WordsScanner getWordsScanner() {
72 return new JSWordsScanner();
73 }
74 }
75