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.
20 package com
.intellij
.psi
;
22 import com
.intellij
.openapi
.fileTypes
.FileType
;
23 import com
.intellij
.openapi
.project
.Project
;
24 import com
.intellij
.openapi
.roots
.ProjectRootManager
;
25 import com
.intellij
.openapi
.roots
.ProjectFileIndex
;
26 import com
.intellij
.openapi
.vfs
.VirtualFile
;
27 import com
.intellij
.psi
.impl
.PsiManagerImpl
;
28 import com
.intellij
.psi
.impl
.compiled
.ClsFileImpl
;
29 import com
.intellij
.testFramework
.LightVirtualFile
;
30 import org
.jetbrains
.annotations
.NotNull
;
32 public class ClassFileViewProvider
extends SingleRootFileViewProvider
{
33 public ClassFileViewProvider(@NotNull final PsiManager manager
, @NotNull final VirtualFile file
) {
37 public ClassFileViewProvider(@NotNull final PsiManager manager
, @NotNull final VirtualFile virtualFile
, final boolean physical
) {
38 super(manager
, virtualFile
, physical
);
42 protected PsiFile
createFile(final Project project
, final VirtualFile vFile
, final FileType fileType
) {
43 final ProjectFileIndex fileIndex
= ProjectRootManager
.getInstance(project
).getFileIndex();
44 if (fileIndex
.isInLibraryClasses(vFile
) || !fileIndex
.isInSource(vFile
)) {
45 String name
= vFile
.getName();
47 // skip inners & anonymous
48 int dotIndex
= name
.lastIndexOf('.');
49 if (dotIndex
< 0) dotIndex
= name
.length();
50 int index
= name
.lastIndexOf('$', dotIndex
);
51 if (index
>= 0) return null;
53 return new ClsFileImpl((PsiManagerImpl
)PsiManager
.getInstance(project
), this);
59 public SingleRootFileViewProvider
createCopy(final LightVirtualFile copy
) {
60 return new ClassFileViewProvider(getManager(), copy
, false);