update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / source / PsiJavaFileImpl.java
blobae7616a343c6aa2dd636e390eac884eb81ac54ff
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.source;
18 import com.intellij.lexer.JavaLexer;
19 import com.intellij.lexer.Lexer;
20 import com.intellij.openapi.fileTypes.FileType;
21 import com.intellij.openapi.fileTypes.StdFileTypes;
22 import com.intellij.openapi.roots.ProjectRootManager;
23 import com.intellij.openapi.roots.ProjectFileIndex;
24 import com.intellij.openapi.vfs.VirtualFile;
25 import com.intellij.psi.FileViewProvider;
26 import com.intellij.psi.JavaPsiFacade;
27 import com.intellij.psi.PsiElementFactory;
28 import com.intellij.psi.PsiPackageStatement;
29 import com.intellij.psi.search.GlobalSearchScope;
30 import com.intellij.util.IncorrectOperationException;
31 import com.intellij.testFramework.LightVirtualFile;
32 import org.jetbrains.annotations.NotNull;
34 public class PsiJavaFileImpl extends PsiJavaFileBaseImpl {
35 public PsiJavaFileImpl(FileViewProvider file) {
36 super(Constants.JAVA_FILE, Constants.JAVA_FILE, file);
39 public String toString(){
40 return "PsiJavaFile:" + getName();
43 public Lexer createLexer() {
44 return new JavaLexer(getLanguageLevel());
47 @NotNull
48 @Override
49 public GlobalSearchScope getResolveScope() {
50 final VirtualFile file = getVirtualFile();
51 if (file != null && !(file instanceof LightVirtualFile)) {
52 final ProjectFileIndex index = ProjectRootManager.getInstance(getProject()).getFileIndex();
53 if (!index.isInSource(file) && !index.isInLibraryClasses(file)) {
54 return GlobalSearchScope.fileScope(this);
57 return super.getResolveScope();
60 @NotNull
61 public FileType getFileType() {
62 return StdFileTypes.JAVA;
65 public void setPackageName(final String packageName) throws IncorrectOperationException {
66 PsiPackageStatement packageStatement = getPackageStatement();
67 final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
68 if (packageStatement != null) {
69 if (packageName.length() > 0) {
70 packageStatement.replace(factory.createPackageStatement(packageName));
72 else {
73 packageStatement.delete();
76 else {
77 if (packageName.length() > 0) {
78 add(factory.createPackageStatement(packageName));