JSFile.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.psi; 
17    
18   import com.intellij.extapi.psi.PsiFileBase; 
19   import com.intellij.lang.javascript.JavaScriptSupportLoader; 
20   import com.intellij.openapi.fileTypes.FileType; 
21   import com.intellij.openapi.project.Project; 
22   import com.intellij.openapi.vfs.VirtualFile; 
23   import com.intellij.psi.PsiElement; 
24   import com.intellij.psi.PsiElementVisitor; 
25   import com.intellij.psi.PsiSubstitutor; 
26   import com.intellij.psi.scope.PsiScopeProcessor; 
27    
28   /** 
29    * Created by IntelliJ IDEA. 
30    * User: max 
31    * Date: Jan 28, 2005 
32    * Time: 12:25:04 AM 
33    * To change this template use File | Settings | File Templates. 
34    */ 
35   public class JSFile extends PsiFileBase implements JSElement { 
36     public JSFile(Project project, VirtualFile file) { 
37       super(project, file, JavaScriptSupportLoader.JAVASCRIPT.getLanguage()); 
38     } 
39    
40     public JSFile(Project project, String name, CharSequence text) { 
41       super(project, name, text, JavaScriptSupportLoader.JAVASCRIPT.getLanguage()); 
42     } 
43    
44     public FileType getFileType() { 
45       return JavaScriptSupportLoader.JAVASCRIPT; 
46     } 
47    
48     public String toString() { 
49       return "JSFile:" + getName(); 
50     } 
51    
52     public boolean processDeclarations(PsiScopeProcessor processor, 
53                                        PsiSubstitutor substitutor, 
54                                        PsiElement lastParent, 
55                                        PsiElement place) { 
56       final PsiElement[] children = getChildren(); 
57       for (PsiElement child : children) { 
58         if (child == lastParent) break; 
59         if (!child.processDeclarations(processor, substitutor, lastParent, place)) return false; 
60       } 
61       return true; 
62     } 
63    
64     public void accept(PsiElementVisitor visitor) { 
65       if (visitor instanceof JSElementVisitor) { 
66         ((JSElementVisitor)visitor).visitJSElement(this); 
67       } 
68       else { 
69         super.accept(visitor); 
70       } 
71     } 
72   } 
73