update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / refactoring / move / moveClassesOrPackages / AutocreatingMoveDestination.java
blobcb832aebc03db3443d088aa32d50e51347a43892
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.refactoring.move.moveClassesOrPackages;
18 import com.intellij.openapi.roots.ProjectFileIndex;
19 import com.intellij.openapi.roots.ProjectRootManager;
20 import com.intellij.openapi.vfs.VirtualFile;
21 import com.intellij.psi.PsiDirectory;
22 import com.intellij.psi.PsiFile;
23 import com.intellij.psi.PsiManager;
24 import com.intellij.refactoring.MoveDestination;
25 import com.intellij.refactoring.PackageWrapper;
26 import com.intellij.refactoring.RefactoringBundle;
27 import com.intellij.refactoring.util.RefactoringUtil;
28 import com.intellij.util.IncorrectOperationException;
29 import org.jetbrains.annotations.Nullable;
31 /**
32 * @author dsl
34 public abstract class AutocreatingMoveDestination implements MoveDestination {
35 protected final PackageWrapper myPackage;
36 protected final PsiManager myManager;
37 protected final ProjectFileIndex myFileIndex;
39 public AutocreatingMoveDestination(PackageWrapper targetPackage) {
40 myPackage = targetPackage;
41 myManager = myPackage.getManager();
42 myFileIndex = ProjectRootManager.getInstance(myManager.getProject()).getFileIndex();
45 public abstract PackageWrapper getTargetPackage();
47 public abstract PsiDirectory getTargetDirectory(PsiDirectory source) throws IncorrectOperationException;
49 public abstract PsiDirectory getTargetDirectory(PsiFile source) throws IncorrectOperationException;
51 @Nullable
52 protected String checkCanCreateInSourceRoot(final VirtualFile targetSourceRoot) {
53 final String targetQName = myPackage.getQualifiedName();
54 final String sourceRootPackage = myFileIndex.getPackageNameByDirectory(targetSourceRoot);
55 if (!RefactoringUtil.canCreateInSourceRoot(sourceRootPackage, targetQName)) {
56 return RefactoringBundle.message("source.folder.0.has.package.prefix.1", targetSourceRoot.getPresentableUrl(),
57 sourceRootPackage, targetQName);
59 return null;