package com.intellij.psi.impl.source;

import com.intellij.lexer.JavaLexer;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.psi.*;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;

public class PsiJavaFileImpl extends PsiJavaFileBaseImpl {
  public PsiJavaFileImpl(FileViewProvider file) {
    super(JAVA_FILE, JAVA_FILE, file);
  }

  public String toString(){
    return "PsiJavaFile:" + getName();
  }

  public Lexer createLexer() {
    return new JavaLexer(getLanguageLevel());
  }

  @NotNull
  public FileType getFileType() {
    return StdFileTypes.JAVA;
  }

  public void setPackageName(final String packageName) throws IncorrectOperationException {
    PsiManager manager = getManager();
    PsiPackageStatement packageStatement = getPackageStatement();
    if (packageStatement != null) {
      if (packageName.length() > 0) {
        PsiJavaCodeReferenceElement packageRef = packageStatement.getPackageReference();
        PsiJavaCodeReferenceElement newRef =
          JavaPsiFacade.getInstance(getProject()).getElementFactory().createReferenceElementByFQClassName(packageName, getResolveScope());
        packageRef.replace(newRef);
      }
      else {
        packageStatement.delete();
      }
    }
    else {
      if (packageName.length() > 0) {
        add(JavaPsiFacade.getInstance(getProject()).getElementFactory().createPackageStatement(packageName));
      }
    }
  }
}

@@ -230,9 +230,151 @@
 psi.
-*
+FileViewProvider;%0Aimport com.intellij.psi.JavaPsiFacade;%0Aimport com.intellij.psi.PsiElementFactory;%0Aimport com.intellij.psi.PsiPackageStatement
 ;%0Aim
@@ -951,47 +951,8 @@
 n %7B%0A
-    PsiManager manager = getManager();%0A
     
@@ -1021,384 +1021,253 @@
     
-if (packageStatement != null) %7B%0A      if (packageName.length() %3E 0) %7B%0A        PsiJavaCodeReferenceElement packageRef = packageStatement.getPackageReference();%0A        PsiJavaCodeReferenceElement newRef =%0A          JavaPsiFacade.getInstance(getProject()).getElementFactory().createReferenceElementByFQClassName(packageName, getResolveScope());%0A        packageRef.replace(newRef
+final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();%0A    if (packageStatement != null) %7B%0A      if (packageName.length() %3E 0) %7B%0A        packageStatement.replace(factory.createPackageStatement(packageName)
 );%0A 
@@ -1400,67 +1400,15 @@
 add(
-JavaPsiFacade.getInstance(getProject()).getElementF
+f
 actory
-()
 .cre

fix move refactoring.