当前位置: 首页>>代码示例>>Java>>正文


Java PackageWrapper类代码示例

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


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

示例1: doAction

import com.intellij.refactoring.PackageWrapper; //导入依赖的package包/类
protected void doAction() {
  final boolean useExistingClass = useExistingClassButton.isSelected();
  final boolean createInnerClass = myCreateInnerClassButton.isSelected();
  final String existingClassName = existingClassField.getText().trim();
  final String className;
  final String packageName;
  if (useExistingClass) {
    className = StringUtil.getShortName(existingClassName);
    packageName = StringUtil.getPackageName(existingClassName);
  }
  else if (createInnerClass) {
    className = getInnerClassName();
    packageName = "";
  }
  else {
    className = getClassName();
    packageName = getPackageName();
  }
  invokeRefactoring(
    new WrapReturnValueProcessor(className, packageName, ((DestinationFolderComboBox)myDestinationCb).selectDirectory(new PackageWrapper(sourceMethod.getManager(), packageName), false),
                                 sourceMethod, useExistingClass, createInnerClass, (PsiField)myFieldsCombo.getSelectedItem()));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:WrapReturnValueDialog.java

示例2: doAction

import com.intellij.refactoring.PackageWrapper; //导入依赖的package包/类
protected void doAction() {
  TableUtil.stopEditing(myTable);

  final String className;
  final String packageName;
  if (myCreateBuilderClassRadioButton.isSelected()) {
    className = myNewClassName.getText().trim();
    packageName = myPackageTextField.getText().trim();
  } else {
    final String fqName = myExistentClassTF.getText().trim();
    className = StringUtil.getShortName(fqName);
    packageName = StringUtil.getPackageName(fqName);
    final PsiClass builderClass = JavaPsiFacade.getInstance(myProject).findClass(StringUtil.getQualifiedName(packageName, className), GlobalSearchScope.projectScope(myProject));
    if (builderClass != null && !CommonRefactoringUtil.checkReadOnlyStatus(myProject, builderClass)) return;
  }
  invokeRefactoring(new ReplaceConstructorWithBuilderProcessor(getProject(), myConstructors, myParametersMap, className, packageName,
                                                               ((DestinationFolderComboBox)myDestinationCb).selectDirectory(new PackageWrapper(myConstructors[0].getManager(), packageName), false),
                                                               myCreateBuilderClassRadioButton.isSelected()));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:ReplaceConstructorWithBuilderDialog.java

示例3: selectDirectory

import com.intellij.refactoring.PackageWrapper; //导入依赖的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

示例4: chooseSourceRoot

import com.intellij.refactoring.PackageWrapper; //导入依赖的package包/类
public static VirtualFile chooseSourceRoot(final PackageWrapper targetPackage,
                                           final List<VirtualFile> contentSourceRoots,
                                           final PsiDirectory initialDirectory) {
  Project project = targetPackage.getManager().getProject();
  //ensure that there would be no duplicates: e.g. when one content root is subfolder of another root (configured via excluded roots)
  LinkedHashSet<PsiDirectory> targetDirectories = new LinkedHashSet<PsiDirectory>();
  Map<PsiDirectory, String> relativePathsToCreate = new HashMap<PsiDirectory,String>();
  buildDirectoryList(targetPackage, contentSourceRoots, targetDirectories, relativePathsToCreate);

  final PsiDirectory selectedDirectory = DirectoryChooserUtil.chooseDirectory(
    targetDirectories.toArray(new PsiDirectory[targetDirectories.size()]),
    initialDirectory,
    project,
    relativePathsToCreate
  );

  if (selectedDirectory == null) return null;
  final VirtualFile virt = selectedDirectory.getVirtualFile();
  final VirtualFile sourceRootForFile = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(virt);
  LOG.assertTrue(sourceRootForFile != null);
  return sourceRootForFile;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:MoveClassesOrPackagesUtil.java

示例5: createPackageDirectoryInSourceRoot

import com.intellij.refactoring.PackageWrapper; //导入依赖的package包/类
public static PsiDirectory createPackageDirectoryInSourceRoot(PackageWrapper aPackage, final VirtualFile sourceRoot)
  throws IncorrectOperationException {
  final PsiDirectory[] directories = aPackage.getDirectories();
  for (PsiDirectory directory : directories) {
    if (VfsUtil.isAncestor(sourceRoot, directory.getVirtualFile(), false)) {
      return directory;
    }
  }
  String qNameToCreate = qNameToCreateInSourceRoot(aPackage, sourceRoot);
  final String[] shortNames = qNameToCreate.split("\\.");
  PsiDirectory current = aPackage.getManager().findDirectory(sourceRoot);
  LOG.assertTrue(current != null);
  for (String shortName : shortNames) {
    PsiDirectory subdirectory = current.findSubdirectory(shortName);
    if (subdirectory == null) {
      subdirectory = current.createSubdirectory(shortName);
    }
    current = subdirectory;
  }
  return current;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:RefactoringUtil.java

示例6: chooseDirectoryAndMove

import com.intellij.refactoring.PackageWrapper; //导入依赖的package包/类
private void chooseDirectoryAndMove(Project project, PsiFile myFile) {
  try {
    PsiDirectory directory = MoveClassesOrPackagesUtil.chooseDestinationPackage(project, myTargetPackage, myFile.getContainingDirectory());

    if (directory == null) {
      return;
    }
    String error = RefactoringMessageUtil.checkCanCreateFile(directory, myFile.getName());
    if (error != null) {
      Messages.showMessageDialog(project, error, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
      return;
    }
    new MoveClassesOrPackagesProcessor(
            project,
            ((PsiJavaFile) myFile).getClasses(),
            new SingleSourceRootMoveDestination(PackageWrapper.create(JavaDirectoryService.getInstance().getPackage(directory)), directory), false,
            false,
            null).run();
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:24,代码来源:MoveToPackageFix.java

示例7: selectDirectory

import com.intellij.refactoring.PackageWrapper; //导入依赖的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

示例8: chooseSourceRoot

import com.intellij.refactoring.PackageWrapper; //导入依赖的package包/类
public static VirtualFile chooseSourceRoot(final PackageWrapper targetPackage,
                                           final VirtualFile[] contentSourceRoots,
                                           final PsiDirectory initialDirectory) {
  Project project = targetPackage.getManager().getProject();
  //ensure that there would be no duplicates: e.g. when one content root is subfolder of another root (configured via excluded roots)
  LinkedHashSet<PsiDirectory> targetDirectories = new LinkedHashSet<PsiDirectory>();
  Map<PsiDirectory, String> relativePathsToCreate = new HashMap<PsiDirectory,String>();
  buildDirectoryList(targetPackage, contentSourceRoots, targetDirectories, relativePathsToCreate);

  final PsiDirectory selectedDirectory = DirectoryChooserUtil.chooseDirectory(
    targetDirectories.toArray(new PsiDirectory[targetDirectories.size()]),
    initialDirectory,
    project,
    relativePathsToCreate
  );

  if (selectedDirectory == null) return null;
  final VirtualFile virt = selectedDirectory.getVirtualFile();
  final VirtualFile sourceRootForFile = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(virt);
  LOG.assertTrue(sourceRootForFile != null);
  return sourceRootForFile;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:23,代码来源:MoveClassesOrPackagesUtil.java

示例9: selectDestination

import com.intellij.refactoring.PackageWrapper; //导入依赖的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

示例10: doOKAction

import com.intellij.refactoring.PackageWrapper; //导入依赖的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

示例11: preparePackage

import com.intellij.refactoring.PackageWrapper; //导入依赖的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

示例12: doMovePackage

import com.intellij.refactoring.PackageWrapper; //导入依赖的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

示例13: getPackageName

import com.intellij.refactoring.PackageWrapper; //导入依赖的package包/类
public static String getPackageName(PackageWrapper aPackage) {
  if (aPackage == null) {
    return null;
  }
  String name = aPackage.getQualifiedName();
  if (name.length() > 0) {
    return name;
  }
  else {
    return JavaFindUsagesProvider.DEFAULT_PACKAGE_NAME;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:MoveClassesOrPackagesUtil.java

示例14: chooseDestinationPackage

import com.intellij.refactoring.PackageWrapper; //导入依赖的package包/类
@Nullable
public static PsiDirectory chooseDestinationPackage(Project project, String packageName, @Nullable PsiDirectory baseDir) {
  final PsiManager psiManager = PsiManager.getInstance(project);
  final PackageWrapper packageWrapper = new PackageWrapper(psiManager, packageName);
  final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(packageName);
  PsiDirectory directory;

  PsiDirectory[] directories = aPackage != null ? aPackage.getDirectories() : null;
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  final VirtualFile baseDirVirtualFile = baseDir != null ? baseDir.getVirtualFile() : null;
  final boolean isBaseDirInTestSources = baseDirVirtualFile != null && fileIndex.isInTestSourceContent(baseDirVirtualFile);
  if (directories != null && directories.length == 1 && (baseDirVirtualFile == null ||
                                                         fileIndex.isInTestSourceContent(directories[0].getVirtualFile()) == isBaseDirInTestSources)) {
    directory = directories[0];
  }
  else {
    final List<VirtualFile> contentSourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(project);
    if (contentSourceRoots.size() == 1 && (baseDirVirtualFile == null || fileIndex.isInTestSourceContent(contentSourceRoots.get(0)) == isBaseDirInTestSources)) {
      directory = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
        @Override
        public PsiDirectory compute() {
          return RefactoringUtil.createPackageDirectoryInSourceRoot(packageWrapper, contentSourceRoots.get(0));
        }
      });
    }
    else {
      final VirtualFile sourceRootForFile = chooseSourceRoot(packageWrapper, contentSourceRoots, baseDir);
      if (sourceRootForFile == null) return null;
      directory = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
        @Override
        public PsiDirectory compute() {
          return new AutocreatingSingleSourceRootMoveDestination(packageWrapper, sourceRootForFile).getTargetDirectory((PsiDirectory)null);
        }
      });
    }
  }
  return directory;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:MoveClassesOrPackagesUtil.java

示例15: doAction

import com.intellij.refactoring.PackageWrapper; //导入依赖的package包/类
protected void doAction() {

    final List<PsiField> fields = getFieldsToExtract();
    final List<PsiMethod> methods = getMethodsToExtract();
    final List<PsiClass> classes = getClassesToExtract();
    final String newClassName = getClassName();
    final String packageName = getPackageName();

    Collections.sort(enumConstants, new Comparator<MemberInfo>() {
      public int compare(MemberInfo o1, MemberInfo o2) {
        return o1.getMember().getTextOffset() - o2.getMember().getTextOffset();
      }
    });
    final ExtractClassProcessor processor = new ExtractClassProcessor(sourceClass, fields, methods, classes, packageName,
                                                                      myDestinationFolderComboBox.selectDirectory(
                                                                        new PackageWrapper(PsiManager.getInstance(myProject), packageName),
                                                                        false),
                                                                      newClassName, myVisibilityPanel.getVisibility(),
                                                                      isGenerateAccessors(),
                                                                      isExtractAsEnum() ? enumConstants : Collections.<MemberInfo>emptyList());
    processor.setExtractInnerClass(createInner.isSelected());
    if (processor.getCreatedClass() == null) {
      Messages.showErrorDialog(myVisibilityPanel, "Unable to create class with the given name");
      classNameField.requestFocusInWindow();
      return;
    }
    invokeRefactoring(processor);
  }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:ExtractClassDialog.java


注:本文中的com.intellij.refactoring.PackageWrapper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。