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
.file
;
18 import com
.intellij
.ide
.impl
.ProjectViewSelectInTarget
;
19 import com
.intellij
.ide
.projectView
.impl
.ProjectViewPane
;
20 import com
.intellij
.openapi
.diagnostic
.Logger
;
21 import com
.intellij
.openapi
.fileTypes
.FileType
;
22 import com
.intellij
.openapi
.fileTypes
.FileTypeManager
;
23 import com
.intellij
.openapi
.fileTypes
.StdFileTypes
;
24 import com
.intellij
.openapi
.vfs
.VirtualFile
;
25 import com
.intellij
.psi
.JavaDirectoryService
;
26 import com
.intellij
.psi
.PsiClass
;
27 import com
.intellij
.psi
.PsiElement
;
28 import com
.intellij
.psi
.PsiFile
;
29 import com
.intellij
.psi
.impl
.PsiManagerImpl
;
30 import com
.intellij
.util
.IncorrectOperationException
;
31 import org
.jetbrains
.annotations
.NotNull
;
33 public class PsiJavaDirectoryImpl
extends PsiDirectoryImpl
{
34 private static final Logger LOG
= Logger
.getInstance("#com.intellij.psi.impl.file.PsiJavaDirectoryImpl");
36 public PsiJavaDirectoryImpl(PsiManagerImpl manager
, VirtualFile file
) {
40 public void checkCreateFile(@NotNull final String name
) throws IncorrectOperationException
{
41 FileTypeManager fileTypeManager
= FileTypeManager
.getInstance();
42 FileType type
= fileTypeManager
.getFileTypeByFileName(name
);
43 if (type
== StdFileTypes
.CLASS
) {
44 throw new IncorrectOperationException("Cannot create class-file");
47 super.checkCreateFile(name
);
50 public PsiElement
add(@NotNull final PsiElement element
) throws IncorrectOperationException
{
51 if (element
instanceof PsiClass
) {
52 final String name
= ((PsiClass
)element
).getName();
54 final PsiClass newClass
= JavaDirectoryService
.getInstance().createClass(this, name
);
55 return newClass
.replace(element
);
58 LOG
.error("not implemented");
63 return super.add(element
);
67 public void checkAdd(@NotNull final PsiElement element
) throws IncorrectOperationException
{
68 if (element
instanceof PsiClass
) {
69 if (element
.getParent() instanceof PsiFile
) {
70 JavaDirectoryServiceImpl
.checkCreateClassOrInterface(this, ((PsiClass
)element
).getName());
73 LOG
.error("not implemented");
77 super.checkAdd(element
);
81 public void navigate(final boolean requestFocus
) {
82 ProjectViewSelectInTarget
.select(getProject(), this, ProjectViewPane
.ID
, null, getVirtualFile(), requestFocus
);