copy package-info with package annotations (IDEA-79980)

This commit is contained in:
anna
2012-01-17 17:54:01 +01:00
parent c08a35f9a0
commit face21abec
4 changed files with 34 additions and 1 deletions
@@ -111,7 +111,8 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
if (packageStatement != null) {
if (packageName.length() > 0) {
packageStatement.replace(factory.createPackageStatement(packageName));
final PsiJavaCodeReferenceElement reference = packageStatement.getPackageReference();
reference.replace(factory.createReferenceFromText(packageName, packageStatement));
}
else {
packageStatement.delete();
@@ -0,0 +1,3 @@
@javax.xml.bind.annotation.XmlSchema(elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
namespace = "http://www.mynamespaceurl.com/myHits")
package from;
@@ -0,0 +1,3 @@
@javax.xml.bind.annotation.XmlSchema(elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
namespace = "http://www.mynamespaceurl.com/myHits")
package to;
@@ -93,4 +93,30 @@ public class CopyTest extends CodeInsightTestCase {
assertNotNull(root.findFileByRelativePath("to/1.txt"));
assertNotNull(root.findFileByRelativePath("to/2.txt"));
}
public void testPackageInfo() throws Exception {
String rootBefore = getRoot();
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final VirtualFile first = root.findFileByRelativePath("from/package-info.java");
assertNotNull(first);
final PsiFile firstPsi = myPsiManager.findFile(first);
assertTrue(CopyHandler.canCopy(new PsiElement[]{firstPsi}));
final VirtualFile toDir = root.findChild("to");
assertNotNull(toDir);
final PsiDirectory targetDirectory = myPsiManager.findDirectory(toDir);
CopyHandler.doCopy(new PsiElement[]{firstPsi}, targetDirectory);
final VirtualFile dest = root.findFileByRelativePath("to/package-info.java");
assertNotNull(dest);
VirtualFile fileExpected = root.findFileByRelativePath("to/package-info.expected.java");
PlatformTestUtil.assertFilesEqual(fileExpected, dest);
}
}