• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java MoveDestination类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中com.intellij.refactoring.MoveDestination的典型用法代码示例。如果您正苦于以下问题:Java MoveDestination类的具体用法?Java MoveDestination怎么用?Java MoveDestination使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

MoveDestination类属于com.intellij.refactoring包,在下文中一共展示了MoveDestination类的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: ReplaceConstructorWithBuilderProcessor

点赞 3

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
public ReplaceConstructorWithBuilderProcessor(Project project,
                                              PsiMethod[] constructors,
                                              Map<String, ParameterData> parametersMap,
                                              String className,
                                              String packageName,
                                              MoveDestination moveDestination, boolean createNewBuilderClass) {
  super(project);
  myMoveDestination = moveDestination;
  myElementFactory = JavaPsiFacade.getInstance(myProject).getElementFactory();
  myConstructors = constructors;
  myParametersMap = parametersMap;

  myClassName = className;
  myPackageName = packageName;
  myCreateNewBuilderClass = createNewBuilderClass;
}
 

开发者ID:jskierbi,
项目名称:intellij-ce-playground,
代码行数:17,
代码来源:ReplaceConstructorWithBuilderProcessor.java

示例2: selectDirectory

点赞 3

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
@Nullable
public MoveDestination selectDirectory(final PackageWrapper targetPackage, final boolean showChooserWhenDefault) {
  final DirectoryChooser.ItemWrapper selectedItem = (DirectoryChooser.ItemWrapper)getComboBox().getSelectedItem();
  if (selectedItem == null || selectedItem == NULL_WRAPPER) {
    return new MultipleRootsMoveDestination(targetPackage);
  }
  final PsiDirectory selectedPsiDirectory = selectedItem.getDirectory();
  VirtualFile selectedDestination = selectedPsiDirectory.getVirtualFile();
  if (showChooserWhenDefault &&
      myInitialTargetDirectory != null && Comparing.equal(selectedDestination, myInitialTargetDirectory.getVirtualFile()) &&
      mySourceRoots.size() > 1) {
    selectedDestination = MoveClassesOrPackagesUtil.chooseSourceRoot(targetPackage, mySourceRoots, myInitialTargetDirectory);
  }
  if (selectedDestination == null) return null;
  return new AutocreatingSingleSourceRootMoveDestination(targetPackage, selectedDestination);
}
 

开发者ID:jskierbi,
项目名称:intellij-ce-playground,
代码行数:17,
代码来源:DestinationFolderComboBox.java

示例3: selectDirectory

点赞 3

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
@Nullable
public MoveDestination selectDirectory(final PackageWrapper targetPackage, final boolean showChooserWhenDefault) {
  final DirectoryChooser.ItemWrapper selectedItem = (DirectoryChooser.ItemWrapper)getComboBox().getSelectedItem();
  if (selectedItem == null || selectedItem == NULL_WRAPPER) {
    return new MultipleRootsMoveDestination(targetPackage);
  }
  final PsiDirectory selectedPsiDirectory = selectedItem.getDirectory();
  VirtualFile selectedDestination = selectedPsiDirectory.getVirtualFile();
  if (showChooserWhenDefault &&
      myInitialTargetDirectory != null && Comparing.equal(selectedDestination, myInitialTargetDirectory.getVirtualFile()) &&
      mySourceRoots.length > 1) {
    selectedDestination = MoveClassesOrPackagesUtil.chooseSourceRoot(targetPackage, mySourceRoots, myInitialTargetDirectory);
  }
  if (selectedDestination == null) return null;
  return new AutocreatingSingleSourceRootMoveDestination(targetPackage, selectedDestination);
}
 

开发者ID:lshain-android-source,
项目名称:tools-idea,
代码行数:17,
代码来源:DestinationFolderComboBox.java

示例4: selectDestination

点赞 3

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
@Nullable
private MoveDestination selectDestination() {
  final String packageName = getTargetPackage().trim();
  if (packageName.length() > 0 && !PsiNameHelper.getInstance(myManager.getProject()).isQualifiedName(packageName)) {
    Messages.showErrorDialog(myProject, RefactoringBundle.message("please.enter.a.valid.target.package.name"),
                             RefactoringBundle.message("move.title"));
    return null;
  }
  RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName);
  PackageWrapper targetPackage = new PackageWrapper(myManager, packageName);
  if (!targetPackage.exists()) {
    final int ret = Messages.showYesNoDialog(myProject, RefactoringBundle.message("package.does.not.exist", packageName),
                                             RefactoringBundle.message("move.title"), Messages.getQuestionIcon());
    if (ret != 0) return null;
  }

  return ((DestinationFolderComboBox)myDestinationFolderCB).selectDirectory(targetPackage, mySuggestToMoveToAnotherRoot);
}
 

开发者ID:consulo,
项目名称:consulo-java
代码行数:19,
代码来源:MoveClassesOrPackagesDialog.java

示例5: doOKAction

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
@Override
protected void doOKAction() {
  RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, myPackageComponent.getText());
  final String packageName = getPackageName();

  final String[] errorString = new String[1];
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      try {
        final PackageWrapper targetPackage = new PackageWrapper(PsiManager.getInstance(myProject), packageName);
        final MoveDestination destination = myDestinationCB.selectDirectory(targetPackage, false);
        if (destination == null) return;
        myTargetDirectory = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
          @Override
          public PsiDirectory compute() {
            return destination.getTargetDirectory(getBaseDir(packageName));
          }
        });
        if (myTargetDirectory == null) {
          errorString[0] = ""; // message already reported by PackageUtil
          return;
        }
        errorString[0] = RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getClassName());
      }
      catch (IncorrectOperationException e) {
        errorString[0] = e.getMessage();
      }
    }
  }, CodeInsightBundle.message("create.directory.command"), null);

  if (errorString[0] != null) {
    if (errorString[0].length() > 0) {
      Messages.showMessageDialog(myProject, errorString[0], CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    }
    return;
  }
  super.doOKAction();
}
 

开发者ID:jskierbi,
项目名称:intellij-ce-playground,
代码行数:40,
代码来源:CreateClassDialog.java

示例6: WrapReturnValueProcessor

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
public WrapReturnValueProcessor(String className,
                                String packageName,
                                MoveDestination moveDestination,
                                PsiMethod method,
                                boolean useExistingClass,
                                final boolean createInnerClass,
                                PsiField delegateField) {
  super(method.getProject());
  myMoveDestination = moveDestination;
  myMethod = method;
  myClassName = className;
  myPackageName = packageName;
  myCreateInnerClass = createInnerClass;
  myDelegateField = delegateField;
  myQualifiedName = StringUtil.getQualifiedName(packageName, className);
  myUseExistingClass = useExistingClass;

  final Set<PsiTypeParameter> typeParamSet = new HashSet<PsiTypeParameter>();
  final TypeParametersVisitor visitor = new TypeParametersVisitor(typeParamSet);
  final PsiTypeElement returnTypeElement = method.getReturnTypeElement();
  assert returnTypeElement != null;
  returnTypeElement.accept(visitor);
  myTypeParameters = new ArrayList<PsiTypeParameter>(typeParamSet);
  if (useExistingClass) {
    myUnwrapMethodName = calculateUnwrapMethodName();
  }
  else {
    myUnwrapMethodName = "getValue";
  }
}
 

开发者ID:jskierbi,
项目名称:intellij-ce-playground,
代码行数:31,
代码来源:WrapReturnValueProcessor.java

示例7: preparePackage

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
@Override
protected void preparePackage() throws OperationFailedException {
  final String targetPackageName = getTargetPackageName();
  final PsiFile containingFile = mySourceClass.getContainingFile();
  final boolean fromDefaultPackage = containingFile instanceof PsiClassOwner && ((PsiClassOwner)containingFile).getPackageName().isEmpty(); 
  if (!(fromDefaultPackage && StringUtil.isEmpty(targetPackageName)) && !PsiNameHelper.getInstance(myProject).isQualifiedName(targetPackageName)) {
    throw new OperationFailedException("Invalid package name: " + targetPackageName);
  }
  final PsiPackage aPackage = JavaPsiFacade.getInstance(myProject).findPackage(targetPackageName);
  if (aPackage != null) {
    final PsiDirectory[] directories = aPackage.getDirectories(mySourceClass.getResolveScope());
    if (directories.length >= 1) {
      myTargetDirectory = getDirUnderSameSourceRoot(directories);
    }
  }
  
  final MoveDestination moveDestination =
    myDestinationFolderComboBox.selectDirectory(new PackageWrapper(PsiManager.getInstance(myProject), targetPackageName), false);
  if (moveDestination == null) return;

  myTargetDirectory = myTargetDirectory != null ? ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
    @Override
    public PsiDirectory compute() {
      return moveDestination.getTargetDirectory(myTargetDirectory);
    }
  }) : null;

  if (myTargetDirectory == null) {
    throw new OperationFailedException(""); // message already reported by PackageUtil
  }
  String error = RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getExtractedSuperName());
  if (error != null) {
    throw new OperationFailedException(error);
  }
}
 

开发者ID:jskierbi,
项目名称:intellij-ce-playground,
代码行数:36,
代码来源:JavaExtractSuperBaseDialog.java

示例8: MoveClassesOrPackagesProcessor

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
public MoveClassesOrPackagesProcessor(Project project,
                                      PsiElement[] elements,
                                      @NotNull final MoveDestination moveDestination,
                                      boolean searchInComments,
                                      boolean searchInNonJavaFiles,
                                      MoveCallback moveCallback) {
  super(project);
  final Set<PsiElement> toMove = new LinkedHashSet<PsiElement>();
  for (PsiElement element : elements) {
    if (element instanceof PsiClassOwner) {
      Collections.addAll(toMove, ((PsiClassOwner)element).getClasses());
    } else {
      toMove.add(element);
    }
  }
  myElementsToMove = PsiUtilCore.toPsiElementArray(toMove);
  Arrays.sort(myElementsToMove, new Comparator<PsiElement>() {
    @Override
    public int compare(PsiElement o1, PsiElement o2) {
      if (o1 instanceof PsiClass && o2 instanceof PsiClass) {
        final PsiFile containingFile = o1.getContainingFile();
        if (Comparing.equal(containingFile, o2.getContainingFile())) {
          final VirtualFile virtualFile = containingFile.getVirtualFile();
          if (virtualFile != null) {
            final String fileName = virtualFile.getNameWithoutExtension();
            if (Comparing.strEqual(fileName, ((PsiClass)o1).getName())) return -1;
            if (Comparing.strEqual(fileName, ((PsiClass)o2).getName())) return 1;
          }
        }
      }
      return 0;
    }
  });
  myMoveDestination = moveDestination;
  myTargetPackage = myMoveDestination.getTargetPackage();
  mySearchInComments = searchInComments;
  mySearchInNonJavaFiles = searchInNonJavaFiles;
  myMoveCallback = moveCallback;
}
 

开发者ID:jskierbi,
项目名称:intellij-ce-playground,
代码行数:40,
代码来源:MoveClassesOrPackagesProcessor.java

示例9: doMovePackage

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
public static PsiPackage doMovePackage(PsiPackage aPackage, MoveDestination moveDestination)
  throws IncorrectOperationException {
  final PackageWrapper targetPackage = moveDestination.getTargetPackage();

  final String newPrefix;
  if ("".equals(targetPackage.getQualifiedName())) {
    newPrefix = "";
  }
  else {
    newPrefix = targetPackage.getQualifiedName() + ".";
  }

  final String newPackageQualifiedName = newPrefix + aPackage.getName();

  // do actual move
  final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(aPackage.getProject());
  PsiDirectory[] dirs = aPackage.getDirectories(projectScope);
  for (PsiDirectory dir : dirs) {
    final PsiDirectory targetDirectory = moveDestination.getTargetDirectory(dir);
    if (targetDirectory != null) {
      moveDirectoryRecursively(dir, targetDirectory);
    }
  }

  aPackage.handleQualifiedNameChange(newPackageQualifiedName);

  return JavaPsiFacade.getInstance(targetPackage.getManager().getProject()).findPackage(newPackageQualifiedName);
}
 

开发者ID:jskierbi,
项目名称:intellij-ce-playground,
代码行数:29,
代码来源:MoveClassesOrPackagesUtil.java

示例10: WrapReturnValueProcessor

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
public WrapReturnValueProcessor(String className,
                                String packageName,
                                MoveDestination moveDestination, PsiMethod method,
                                boolean useExistingClass,
                                final boolean createInnerClass, PsiField delegateField) {
  super(method.getProject());
  myMoveDestination = moveDestination;
  this.method = method;
  this.className = className;
  this.packageName = packageName;
  myCreateInnerClass = createInnerClass;
  myDelegateField = delegateField;
  myQualifiedName = StringUtil.getQualifiedName(packageName, className);
  this.myUseExistingClass = useExistingClass;

  final Set<PsiTypeParameter> typeParamSet = new HashSet<PsiTypeParameter>();
  final TypeParametersVisitor visitor = new TypeParametersVisitor(typeParamSet);
  final PsiTypeElement returnTypeElement = method.getReturnTypeElement();
  assert returnTypeElement != null;
  returnTypeElement.accept(visitor);
  typeParams = new ArrayList<PsiTypeParameter>(typeParamSet);
  if (useExistingClass) {
    unwrapMethodName = calculateUnwrapMethodName();
  }
  else {
    unwrapMethodName = "getValue";
  }
}
 

开发者ID:lshain-android-source,
项目名称:tools-idea,
代码行数:29,
代码来源:WrapReturnValueProcessor.java

示例11: preparePackage

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
@Override
protected void preparePackage() throws OperationFailedException {
  final String targetPackageName = getTargetPackageName();
  final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(myProject);
  final PsiFile containingFile = mySourceClass.getContainingFile();
  final boolean fromDefaultPackage = containingFile instanceof PsiClassOwner && ((PsiClassOwner)containingFile).getPackageName().isEmpty(); 
  if (!(fromDefaultPackage && StringUtil.isEmpty(targetPackageName)) && !psiFacade.getNameHelper().isQualifiedName(targetPackageName)) {
    throw new OperationFailedException("Invalid package name: " + targetPackageName);
  }
  final PsiPackage aPackage = psiFacade.findPackage(targetPackageName);
  if (aPackage != null) {
    final PsiDirectory[] directories = aPackage.getDirectories(mySourceClass.getResolveScope());
    if (directories.length >= 1) {
      myTargetDirectory = getDirUnderSameSourceRoot(directories);
    }
  }
  
  final MoveDestination moveDestination =
    myDestinationFolderComboBox.selectDirectory(new PackageWrapper(PsiManager.getInstance(myProject), targetPackageName), false);
  if (moveDestination == null) return;

  myTargetDirectory = myTargetDirectory != null ? ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
    @Override
    public PsiDirectory compute() {
      return moveDestination.getTargetDirectory(myTargetDirectory);
    }
  }) : null;

  if (myTargetDirectory == null) {
    throw new OperationFailedException(""); // message already reported by PackageUtil
  }
  String error = RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getExtractedSuperName());
  if (error != null) {
    throw new OperationFailedException(error);
  }
}
 

开发者ID:lshain-android-source,
项目名称:tools-idea,
代码行数:37,
代码来源:JavaExtractSuperBaseDialog.java

示例12: performRefactoring

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
protected void performRefactoring(Project project, PsiDirectory directory, PsiPackage aPackage,
                                  boolean searchInComments,
                                  boolean searchForTextOccurences) {
  final VirtualFile sourceRoot = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(directory.getVirtualFile());
  if (sourceRoot == null) {
    Messages.showErrorDialog(project, RefactoringBundle.message("destination.directory.does.not.correspond.to.any.package"),
                             RefactoringBundle.message("cannot.move"));
    return;
  }
  final JavaRefactoringFactory factory = JavaRefactoringFactory.getInstance(project);
  final MoveDestination destination = myPreserveSourceRoot.isSelected() && myPreserveSourceRoot.isVisible()
                                      ? factory.createSourceFolderPreservingMoveDestination(aPackage.getQualifiedName())
                                      : factory.createSourceRootMoveDestination(aPackage.getQualifiedName(), sourceRoot);

  MoveClassesOrPackagesProcessor processor = new MoveClassesOrPackagesProcessor(myDirectory.getProject(), myElementsToMove, destination,
                                                                                searchInComments, searchForTextOccurences,
                                                                                myMoveCallback);
  if (processor.verifyValidPackageName()) {
    processor.setPrepareSuccessfulSwingThreadCallback(new Runnable() {
      @Override
      public void run() {
      }
    });

    processor.run();
  }
}
 

开发者ID:lshain-android-source,
项目名称:tools-idea,
代码行数:28,
代码来源:MoveClassesOrPackagesToNewDirectoryDialog.java

示例13: preparePackage

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
@Override
protected void preparePackage() throws OperationFailedException {
  final String targetPackageName = getTargetPackageName();
  final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(myProject);
  final PsiFile containingFile = mySourceClass.getContainingFile();
  final boolean fromDefaultPackage = containingFile instanceof PsiClassOwner && ((PsiClassOwner)containingFile).getPackageName().isEmpty(); 
  if (!(fromDefaultPackage && StringUtil.isEmpty(targetPackageName)) && !PsiNameHelper.getInstance(myProject).isQualifiedName(targetPackageName)) {
    throw new OperationFailedException("Invalid package name: " + targetPackageName);
  }
  final PsiJavaPackage aPackage = psiFacade.findPackage(targetPackageName);
  if (aPackage != null) {
    final PsiDirectory[] directories = aPackage.getDirectories(mySourceClass.getResolveScope());
    if (directories.length >= 1) {
      myTargetDirectory = getDirUnderSameSourceRoot(directories);
    }
  }
  
  final MoveDestination moveDestination =
    myDestinationFolderComboBox.selectDirectory(new PackageWrapper(PsiManager.getInstance(myProject), targetPackageName), false);
  if (moveDestination == null) return;

  myTargetDirectory = myTargetDirectory != null ? ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
    @Override
    public PsiDirectory compute() {
      return moveDestination.getTargetDirectory(getTargetDirectory());
    }
  }) : null;

  if (myTargetDirectory == null) {
    throw new OperationFailedException(""); // message already reported by PackageUtil
  }
  String error = RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getExtractedSuperName());
  if (error != null) {
    throw new OperationFailedException(error);
  }
}
 

开发者ID:consulo,
项目名称:consulo-java
代码行数:37,
代码来源:JavaExtractSuperBaseDialog.java

示例14: doAction

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
protected void doAction() {
  final boolean useExistingClass = useExistingClass();
  final boolean keepMethod = keepMethodAsDelegate();
  final String className;
  final String packageName;
  final boolean createInnerClass = myCreateInnerClassRadioButton.isSelected();
  if (createInnerClass) {
    className = getInnerClassName();
    packageName = "";
  } else if (useExistingClass) {
    final String existingClassName = getExistingClassName();
    className = StringUtil.getShortName(existingClassName);
    packageName = StringUtil.getPackageName(existingClassName);
  }
  else {
    packageName = getPackageName();
    className = getClassName();
  }
  List<VariableData> parameters = new ArrayList<VariableData>();
  for (VariableData data : parameterInfo) {
    if (data.passAsParameter) {
      parameters.add(data);
    }
  }
  final String newVisibility =
    myEscalateVisibilityCheckBox.isEnabled() && myEscalateVisibilityCheckBox.isSelected() ? VisibilityUtil.ESCALATE_VISIBILITY : null;
  final MoveDestination moveDestination = ((DestinationFolderComboBox)myDestinationCb)
    .selectDirectory(new PackageWrapper(PsiManager.getInstance(myProject), packageName), false);
  invokeRefactoring(new IntroduceParameterObjectProcessor(className, packageName, moveDestination, sourceMethod,
                                                          parameters.toArray(new VariableData[parameters.size()]),
                                                          keepMethod, useExistingClass,
                                                          createInnerClass, newVisibility, myGenerateAccessorsCheckBox.isSelected()));
}
 

开发者ID:consulo,
项目名称:consulo-java
代码行数:34,
代码来源:IntroduceParameterObjectDialog.java

示例15: performRefactoring

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
protected void performRefactoring(Project project, PsiDirectory directory, PsiJavaPackage aPackage,
                                  boolean searchInComments,
                                  boolean searchForTextOccurences) {
  final VirtualFile sourceRoot = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(directory.getVirtualFile());
  if (sourceRoot == null) {
    Messages.showErrorDialog(project, RefactoringBundle.message("destination.directory.does.not.correspond.to.any.package"),
                             RefactoringBundle.message("cannot.move"));
    return;
  }
  final JavaRefactoringFactory factory = JavaRefactoringFactory.getInstance(project);
  final MoveDestination destination = myPreserveSourceRoot.isSelected() && myPreserveSourceRoot.isVisible()
                                      ? factory.createSourceFolderPreservingMoveDestination(aPackage.getQualifiedName())
                                      : factory.createSourceRootMoveDestination(aPackage.getQualifiedName(), sourceRoot);

  MoveClassesOrPackagesProcessor processor = new MoveClassesOrPackagesProcessor(myDirectory.getProject(), myElementsToMove, destination,
                                                                                searchInComments, searchForTextOccurences,
                                                                                myMoveCallback);
  if (processor.verifyValidPackageName()) {
    processor.setPrepareSuccessfulSwingThreadCallback(new Runnable() {
      @Override
      public void run() {
      }
    });

    processor.run();
  }
}
 

开发者ID:consulo,
项目名称:consulo-java
代码行数:28,
代码来源:MoveClassesOrPackagesToNewDirectoryDialog.java

示例16: doMovePackage

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
public static PsiJavaPackage doMovePackage(PsiJavaPackage aPackage, MoveDestination moveDestination)
  throws IncorrectOperationException {
  final PackageWrapper targetPackage = moveDestination.getTargetPackage();

  final String newPrefix;
  if ("".equals(targetPackage.getQualifiedName())) {
    newPrefix = "";
  }
  else {
    newPrefix = targetPackage.getQualifiedName() + ".";
  }

  final String newPackageQualifiedName = newPrefix + aPackage.getName();

  // do actual move
  final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(aPackage.getProject());
  PsiDirectory[] dirs = aPackage.getDirectories(projectScope);
  for (PsiDirectory dir : dirs) {
    final PsiDirectory targetDirectory = moveDestination.getTargetDirectory(dir);
    if (targetDirectory != null) {
      moveDirectoryRecursively(dir, targetDirectory);
    }
  }

  aPackage.handleQualifiedNameChange(newPackageQualifiedName);

  return JavaPsiFacade.getInstance(targetPackage.getManager().getProject()).findPackage(newPackageQualifiedName);
}
 

开发者ID:consulo,
项目名称:consulo-java
代码行数:29,
代码来源:MoveClassesOrPackagesUtil.java

示例17: verifyDestinationForElement

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
@Nullable
private static String verifyDestinationForElement(final PsiElement element, final MoveDestination moveDestination) {
  final String message;
  if (element instanceof PsiDirectory) {
    message = moveDestination.verify((PsiDirectory)element);
  }
  else if (element instanceof PsiJavaPackage) {
    message = moveDestination.verify((PsiJavaPackage)element);
  }
  else {
    message = moveDestination.verify(element.getContainingFile());
  }
  return message;
}
 

开发者ID:consulo,
项目名称:consulo-java
代码行数:15,
代码来源:MoveClassesOrPackagesDialog.java

示例18: run

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
public void run() {
  Project project = myTargetModule.getProject();
  VirtualFile[] sourceRoots = ModuleRootManager.getInstance(myTargetModule).getSourceRoots();

  MultiMap<String, PsiClass> map = groupClassesByPackage(project);

  JavaRefactoringFactory factory = JavaRefactoringFactory.getInstance(project);
  for (String packageName : map.keySet()) {
    MoveDestination destination = factory.createSourceRootMoveDestination(packageName, sourceRoots[0]);
    Collection<PsiClass> elements = map.get(packageName);
    PsiElement[] elementArray = elements.toArray(new PsiElement[elements.size()]);
    MoveClassesOrPackagesRefactoring refactoring = factory.createMoveClassesOrPackages(elementArray, destination);
    refactoring.run();
  }
}
 

开发者ID:JetBrains,
项目名称:hackathon-unchain,
代码行数:16,
代码来源:UnchainMover.java

示例19: ExtractClassProcessor

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
public ExtractClassProcessor(PsiClass sourceClass,
                             List<PsiField> fields,
                             List<PsiMethod> methods,
                             List<PsiClass> classes,
                             String packageName,
                             MoveDestination moveDestination,
                             String newClassName,
                             String newVisibility,
                             boolean generateAccessors, List<MemberInfo> enumConstants) {
  super(sourceClass.getProject());
  this.sourceClass = sourceClass;
  this.newPackageName = packageName;
  myMoveDestination = moveDestination;
  myNewVisibility = newVisibility;
  myGenerateAccessors = generateAccessors;
  this.enumConstants = new ArrayList<PsiField>();
  for (MemberInfo constant : enumConstants) {
    if (constant.isChecked()) {
      this.enumConstants.add((PsiField)constant.getMember());
    }
  }
  this.fields = new ArrayList<PsiField>(fields);
  this.methods = new ArrayList<PsiMethod>(methods);
  this.innerClasses = new ArrayList<PsiClass>(classes);
  this.newClassName = newClassName;
  delegateFieldName = calculateDelegateFieldName();
  requiresBackpointer = new BackpointerUsageVisitor(fields, innerClasses, methods, sourceClass).backpointerRequired();
  if (requiresBackpointer) {
    ContainerUtil.addAll(typeParams, sourceClass.getTypeParameters());
  }
  else {
    final Set<PsiTypeParameter> typeParamSet = new HashSet<PsiTypeParameter>();
    final TypeParametersVisitor visitor = new TypeParametersVisitor(typeParamSet);
    for (PsiField field : fields) {
      field.accept(visitor);
    }
    for (PsiMethod method : methods) {
      method.accept(visitor);
      //do not include method's type parameters in class signature
      typeParamSet.removeAll(Arrays.asList(method.getTypeParameters()));
    }
    typeParams.addAll(typeParamSet);
  }
  myClass = new WriteCommandAction<PsiClass>(myProject, getCommandName()){
    @Override
    protected void run(@NotNull Result<PsiClass> result) throws Throwable {
      result.setResult(buildClass());
    }
  }.execute().getResultObject();
  myExtractEnumProcessor = new ExtractEnumProcessor(myProject, this.enumConstants, myClass);
}
 

开发者ID:jskierbi,
项目名称:intellij-ce-playground,
代码行数:52,
代码来源:ExtractClassProcessor.java

示例20: copyClassesImpl

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
private static void copyClassesImpl(final String copyClassName,
                                    final Project project,
                                    final Map<PsiFile, PsiClass[]> classes,
                                    final HashMap<PsiFile, String> map,
                                    final Object targetDirectory,
                                    final PsiDirectory defaultTargetDirectory,
                                    final String commandName,
                                    final boolean selectInActivePanel, 
                                    final boolean openInEditor) {
  final boolean[] result = new boolean[] {false};
  Runnable command = new Runnable() {
    public void run() {
      final Runnable action = new Runnable() {
        public void run() {
          try {
            PsiDirectory target;
            if (targetDirectory instanceof PsiDirectory) {
              target = (PsiDirectory)targetDirectory;
            } else {
              target = ((MoveDestination)targetDirectory).getTargetDirectory(defaultTargetDirectory);
            }
            Collection<PsiFile> files = doCopyClasses(classes, map, copyClassName, target, project);
            if (files != null) {
              if (openInEditor) {
                for (PsiFile file : files) {
                  CopyHandler.updateSelectionInActiveProjectView(file, project, selectInActivePanel);
                }
                EditorHelper.openFilesInEditor(files.toArray(new PsiFile[files.size()]));
              }

              result[0] = true;
            }
          }
          catch (final IncorrectOperationException ex) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
              public void run() {
                Messages.showMessageDialog(project, ex.getMessage(), RefactoringBundle.message("error.title"), Messages.getErrorIcon());
              }
            });
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  };
  CommandProcessor processor = CommandProcessor.getInstance();
  processor.executeCommand(project, command, commandName, null);

  if (result[0]) {
    ToolWindowManager.getInstance(project).invokeLater(new Runnable() {
      public void run() {
        ToolWindowManager.getInstance(project).activateEditorComponent();
      }
    });
  }
}
 

开发者ID:jskierbi,
项目名称:intellij-ce-playground,
代码行数:57,
代码来源:CopyClassesHandler.java

示例21: getTargetDirectory

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
public MoveDestination getTargetDirectory() {
  return myDestination;
}
 

开发者ID:jskierbi,
项目名称:intellij-ce-playground,
代码行数:4,
代码来源:CopyClassDialog.java

示例22: ExtractClassProcessor

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
public ExtractClassProcessor(PsiClass sourceClass,
                             List<PsiField> fields,
                             List<PsiMethod> methods,
                             List<PsiClass> classes,
                             String packageName,
                             MoveDestination moveDestination,
                             String newClassName,
                             String newVisibility,
                             boolean generateAccessors, List<MemberInfo> enumConstants) {
  super(sourceClass.getProject());
  this.sourceClass = sourceClass;
  this.newPackageName = packageName;
  myMoveDestination = moveDestination;
  myNewVisibility = newVisibility;
  myGenerateAccessors = generateAccessors;
  this.enumConstants = new ArrayList<PsiField>();
  for (MemberInfo constant : enumConstants) {
    if (constant.isChecked()) {
      this.enumConstants.add((PsiField)constant.getMember());
    }
  }
  this.fields = new ArrayList<PsiField>(fields);
  this.methods = new ArrayList<PsiMethod>(methods);
  this.innerClasses = new ArrayList<PsiClass>(classes);
  this.newClassName = newClassName;
  delegateFieldName = calculateDelegateFieldName();
  requiresBackpointer = new BackpointerUsageVisitor(fields, innerClasses, methods, sourceClass).backpointerRequired();
  if (requiresBackpointer) {
    ContainerUtil.addAll(typeParams, sourceClass.getTypeParameters());
  }
  else {
    final Set<PsiTypeParameter> typeParamSet = new HashSet<PsiTypeParameter>();
    final TypeParametersVisitor visitor = new TypeParametersVisitor(typeParamSet);
    for (PsiField field : fields) {
      field.accept(visitor);
    }
    for (PsiMethod method : methods) {
      method.accept(visitor);
      //do not include method's type parameters in class signature
      typeParamSet.removeAll(Arrays.asList(method.getTypeParameters()));
    }
    typeParams.addAll(typeParamSet);
  }
  myClass = new WriteCommandAction<PsiClass>(myProject, getCommandName()){
    @Override
    protected void run(Result<PsiClass> result) throws Throwable {
      result.setResult(buildClass());
    }
  }.execute().getResultObject();
  myExtractEnumProcessor = new ExtractEnumProcessor(myProject, this.enumConstants, myClass);
}
 

开发者ID:lshain-android-source,
项目名称:tools-idea,
代码行数:52,
代码来源:ExtractClassProcessor.java

示例23: copyClassesImpl

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
private static void copyClassesImpl(final String copyClassName,
                                    final Project project,
                                    final Map<PsiFile, PsiClass[]> classes,
                                    final HashMap<PsiFile, String> map,
                                    final Object targetDirectory,
                                    final PsiDirectory defaultTargetDirectory,
                                    final String commandName,
                                    final boolean selectInActivePanel, 
                                    final boolean openInEditor) {
  final boolean[] result = new boolean[] {false};
  Runnable command = new Runnable() {
    public void run() {
      final Runnable action = new Runnable() {
        public void run() {
          try {
            PsiDirectory target;
            if (targetDirectory instanceof PsiDirectory) {
              target = (PsiDirectory)targetDirectory;
            } else {
              target = ((MoveDestination)targetDirectory).getTargetDirectory(defaultTargetDirectory);
            }
            PsiElement newElement = doCopyClasses(classes, map, copyClassName, target, project);
            if (newElement != null) {
              CopyHandler.updateSelectionInActiveProjectView(newElement, project, selectInActivePanel);
              if (openInEditor) EditorHelper.openInEditor(newElement);

              result[0] = true;
            }
          }
          catch (final IncorrectOperationException ex) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
              public void run() {
                Messages.showMessageDialog(project, ex.getMessage(), RefactoringBundle.message("error.title"), Messages.getErrorIcon());
              }
            });
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  };
  CommandProcessor processor = CommandProcessor.getInstance();
  processor.executeCommand(project, command, commandName, null);

  if (result[0]) {
    ToolWindowManager.getInstance(project).invokeLater(new Runnable() {
      public void run() {
        ToolWindowManager.getInstance(project).activateEditorComponent();
      }
    });
  }
}
 

开发者ID:lshain-android-source,
项目名称:tools-idea,
代码行数:53,
代码来源:CopyClassesHandler.java

示例24: createMoveToPackageProcessor

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
protected MoveClassesOrPackagesProcessor createMoveToPackageProcessor(MoveDestination destination, final PsiElement[] elementsToMove,
                                                                      final MoveCallback callback) {
  return new MoveClassesOrPackagesProcessor(getProject(), elementsToMove, destination, isSearchInComments(), isSearchInNonJavaFiles(), callback);
}
 

开发者ID:consulo,
项目名称:consulo-java,
代码行数:5,
代码来源:MoveClassesOrPackagesDialog.java

示例25: ExtractClassProcessor

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
public ExtractClassProcessor(PsiClass sourceClass,
		List<PsiField> fields,
		List<PsiMethod> methods,
		List<PsiClass> classes,
		String packageName,
		MoveDestination moveDestination,
		String newClassName,
		String newVisibility,
		boolean generateAccessors,
		List<MemberInfo> enumConstants)
{
	super(sourceClass.getProject());
	this.sourceClass = sourceClass;
	this.newPackageName = packageName;
	myMoveDestination = moveDestination;
	myNewVisibility = newVisibility;
	myGenerateAccessors = generateAccessors;
	this.enumConstants = new ArrayList<PsiField>();
	for(MemberInfo constant : enumConstants)
	{
		if(constant.isChecked())
		{
			this.enumConstants.add((PsiField) constant.getMember());
		}
	}
	this.fields = new ArrayList<PsiField>(fields);
	this.methods = new ArrayList<PsiMethod>(methods);
	this.innerClasses = new ArrayList<PsiClass>(classes);
	this.newClassName = newClassName;
	delegateFieldName = calculateDelegateFieldName();
	requiresBackpointer = new BackpointerUsageVisitor(fields, innerClasses, methods, sourceClass).backpointerRequired();
	if(requiresBackpointer)
	{
		ContainerUtil.addAll(typeParams, sourceClass.getTypeParameters());
	}
	else
	{
		final Set<PsiTypeParameter> typeParamSet = new HashSet<PsiTypeParameter>();
		final TypeParametersVisitor visitor = new TypeParametersVisitor(typeParamSet);
		for(PsiField field : fields)
		{
			field.accept(visitor);
		}
		for(PsiMethod method : methods)
		{
			method.accept(visitor);
			//do not include method's type parameters in class signature
			typeParamSet.removeAll(Arrays.asList(method.getTypeParameters()));
		}
		typeParams.addAll(typeParamSet);
	}
	myClass = new WriteCommandAction<PsiClass>(myProject, getCommandName())
	{
		@Override
		protected void run(Result<PsiClass> result) throws Throwable
		{
			result.setResult(buildClass());
		}
	}.execute().getResultObject();
	myExtractEnumProcessor = new ExtractEnumProcessor(myProject, this.enumConstants, myClass);
}
 

开发者ID:consulo,
项目名称:consulo-java,
代码行数:62,
代码来源:ExtractClassProcessor.java

示例26: copyClassesImpl

点赞 2

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
private static void copyClassesImpl(final String copyClassName,
                                    final Project project,
                                    final Map<PsiFile, PsiClass[]> classes,
                                    final HashMap<PsiFile, String> map,
                                    final Object targetDirectory,
                                    final PsiDirectory defaultTargetDirectory,
                                    final String commandName,
                                    final boolean selectInActivePanel) {
  final boolean[] result = new boolean[] {false};
  Runnable command = new Runnable() {
    public void run() {
      final Runnable action = new Runnable() {
        public void run() {
          try {
            PsiDirectory target;
            if (targetDirectory instanceof PsiDirectory) {
              target = (PsiDirectory)targetDirectory;
            } else {
              target = ((MoveDestination)targetDirectory).getTargetDirectory(defaultTargetDirectory);
            }
            PsiElement newElement = doCopyClasses(classes, map, copyClassName, target, project);
            if (newElement != null) {
              CopyHandler.updateSelectionInActiveProjectView(newElement, project, selectInActivePanel);
              EditorHelper.openInEditor(newElement);

              result[0] = true;
            }
          }
          catch (final IncorrectOperationException ex) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
              public void run() {
                Messages.showMessageDialog(project, ex.getMessage(), RefactoringBundle.message("error.title"), Messages.getErrorIcon());
              }
            });
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  };
  CommandProcessor processor = CommandProcessor.getInstance();
  processor.executeCommand(project, command, commandName, null);

  if (result[0]) {
    ToolWindowManager.getInstance(project).invokeLater(new Runnable() {
      public void run() {
        ToolWindowManager.getInstance(project).activateEditorComponent();
      }
    });
  }
}
 

开发者ID:consulo,
项目名称:consulo-java,
代码行数:52,
代码来源:CopyClassesHandler.java

示例27: classesOrPackagesMoved

点赞 1

import com.intellij.refactoring.MoveDestination; //导入依赖的package包/类
void classesOrPackagesMoved(MoveDestination destination); 

开发者ID:jskierbi,
项目名称:intellij-ce-playground,
代码行数:2,
代码来源:MoveClassesOrPackagesCallback.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)