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


Java PackageUtil类代码示例

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


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

示例1: moveClass

import com.intellij.ide.util.PackageUtil; //导入依赖的package包/类
private void moveClass(Project project, Editor editor, PsiFile file, PsiClass aClass) {
  RefactoringActionHandler moveHandler = RefactoringActionHandlerFactory.getInstance().createMoveHandler();
  DataManager dataManager = DataManager.getInstance();
  DataContext dataContext = dataManager.getDataContext();
  final String fqName = aClass.getQualifiedName();
  LOG.assertTrue(fqName != null);
  PsiDirectory directory = PackageUtil
    .findOrCreateDirectoryForPackage(myCurrentModule, StringUtil.getPackageName(fqName), mySourceRoot, true);
  DataContext context = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT.getName(), directory, dataContext);

  moveHandler.invoke(project, new PsiElement[]{aClass}, context);
  PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
  PsiClass newClass = JavaPsiFacade.getInstance(project).findClass(fqName, GlobalSearchScope.moduleScope(myCurrentModule));
  if (reference != null && newClass != null) {
    final QuestionAction action = new AddImportAction(project, reference, editor, newClass);
    action.execute();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:MoveClassToModuleFix.java

示例2: getTargetClass

import com.intellij.ide.util.PackageUtil; //导入依赖的package包/类
@Nullable
public PsiClass getTargetClass() {
  if (myTargetClass != null) return myTargetClass;
  final String packageName = StringUtil.getPackageName(myQualifiedName);
  final String shortName = StringUtil.getShortName(myQualifiedName);
  if (Comparing.strEqual(myParentClass.getQualifiedName(), packageName)) {
    myTargetClass = (PsiClass)myParentClass.add(JavaPsiFacade.getElementFactory(myProject).createClass(shortName));
    return myTargetClass;
  }
  PsiPackage psiPackage = JavaPsiFacade.getInstance(myProject).findPackage(packageName);
  final PsiDirectory psiDirectory;
  if (psiPackage != null) {
    final PsiDirectory[] directories = psiPackage.getDirectories(GlobalSearchScope.allScope(myProject));
    psiDirectory = directories.length > 1 ? DirectoryChooserUtil.chooseDirectory(directories, null, myProject, new HashMap<PsiDirectory, String>()) : directories[0];
  } else {
    psiDirectory = PackageUtil.findOrCreateDirectoryForPackage(myProject, packageName, myParentClass.getContainingFile().getContainingDirectory(), false);
  }
  myTargetClass = psiDirectory != null ? JavaDirectoryService.getInstance().createClass(psiDirectory, shortName) : null;
  return myTargetClass;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:BaseExpressionToFieldHandler.java

示例3: doFix

import com.intellij.ide.util.PackageUtil; //导入依赖的package包/类
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  PsiFile file = descriptor.getPsiElement().getContainingFile();

  if (!(file instanceof GroovyFile)) return;

  VirtualFile vfile = file.getVirtualFile();
  if (vfile == null) return;

  final Module module = ModuleUtilCore.findModuleForFile(vfile, project);
  if (module == null) return;

  final String packageName = ((GroovyFile)file).getPackageName();
  PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(module, packageName, null, true);
  if (directory == null) return;

  String error = RefactoringMessageUtil.checkCanCreateFile(directory, file.getName());
  if (error != null) {
    Messages.showMessageDialog(project, error, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    return;
  }
  new MoveFilesOrDirectoriesProcessor(project, new PsiElement[]{file}, directory, false, false, false, null, null).run();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:GrMoveToDirFix.java

示例4: moveClass

import com.intellij.ide.util.PackageUtil; //导入依赖的package包/类
private void moveClass(Project project, Editor editor, PsiFile file, PsiClass aClass) {
  RefactoringActionHandler moveHandler = RefactoringActionHandlerFactory.getInstance().createMoveHandler();
  DataManager dataManager = DataManager.getInstance();
  DataContext dataContext = dataManager.getDataContext();
  final String fqName = aClass.getQualifiedName();
  LOG.assertTrue(fqName != null);
  PsiDirectory directory = PackageUtil
    .findOrCreateDirectoryForPackage(myCurrentModule, StringUtil.getPackageName(fqName), mySourceRoot, true);
  DataContext context = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT, directory, dataContext);

  moveHandler.invoke(project, new PsiElement[]{aClass}, context);
  PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
  PsiClass newClass = JavaPsiFacade.getInstance(project).findClass(fqName, GlobalSearchScope.moduleScope(myCurrentModule));
  if (reference != null && newClass != null) {
    final QuestionAction action = new AddImportAction(project, reference, editor, newClass);
    action.execute();
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:MoveClassToModuleFix.java

示例5: getTargetClass

import com.intellij.ide.util.PackageUtil; //导入依赖的package包/类
@Nullable
public PsiClass getTargetClass() {
  if (myTargetClass != null) return myTargetClass;
  final String packageName = StringUtil.getPackageName(myQualifiedName);
  final String shortName = StringUtil.getShortName(myQualifiedName);
  if (Comparing.strEqual(myParentClass.getQualifiedName(), packageName)) {
    myTargetClass = (PsiClass)myParentClass.add(JavaPsiFacade.getElementFactory(myProject).createClass(shortName));
    return myTargetClass;
  }
  PsiJavaPackage psiPackage = JavaPsiFacade.getInstance(myProject).findPackage(packageName);
  final PsiDirectory psiDirectory;
  if (psiPackage != null) {
    final PsiDirectory[] directories = psiPackage.getDirectories(GlobalSearchScope.allScope(myProject));
    psiDirectory = directories.length > 1 ? DirectoryChooserUtil.chooseDirectory(directories, null, myProject, new HashMap<PsiDirectory, String>()) : directories[0];
  } else {
    psiDirectory = PackageUtil.findOrCreateDirectoryForPackage(myProject, packageName, myParentClass.getContainingFile().getContainingDirectory(), false);
  }
  myTargetClass = psiDirectory != null ? JavaDirectoryService.getInstance().createClass(psiDirectory, shortName) : null;
  return myTargetClass;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:21,代码来源:BaseExpressionToFieldHandler.java

示例6: findDefaultSketchPackage

import com.intellij.ide.util.PackageUtil; //导入依赖的package包/类
private PsiDirectory findDefaultSketchPackage(Collection<Module> modules, String packageFqn) {
    PsiDirectory defaultSketchPackage = null;

    for (Module module : modules) {
        PsiDirectory defaultSketchPackageResult = PackageUtil.findPossiblePackageDirectoryInModule(module, packageFqn);

        if (defaultSketchPackageResult != null) {
            defaultSketchPackage = defaultSketchPackageResult;
            break;
        }
    }

    return defaultSketchPackage;
}
 
开发者ID:mistodev,项目名称:processing-idea,代码行数:15,代码来源:ImportSketchClasses.java

示例7: generateEverything

import com.intellij.ide.util.PackageUtil; //导入依赖的package包/类
public static String generateEverything(final PsiPackage psiPackage, final PsiClass rootClass, final String visitorName) {
  final String visitorQName = PsiNameHelper.getShortClassName(visitorName).equals(visitorName)?
                              psiPackage.getQualifiedName()+"."+ visitorName : visitorName;
  final PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(rootClass.getProject(),
                                                                             StringUtil.getPackageName(visitorQName), null, false);
  generateVisitorClass(visitorQName, rootClass, directory, new PackageScope(psiPackage, false, false));
  return visitorQName;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:GenerateVisitorByHierarchyAction.java

示例8: doOKAction

import com.intellij.ide.util.PackageUtil; //导入依赖的package包/类
@Override
protected void doOKAction() {
  final String packageName = getPackageName();

  final Ref<String> errorStringRef = new Ref<String>();
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      try {
        final PsiDirectory baseDir = myModule == null ? null : PackageUtil.findPossiblePackageDirectoryInModule(myModule, packageName);
        myTargetDirectory = myModule == null ? null
            : PackageUtil.findOrCreateDirectoryForPackage(myModule, packageName, baseDir, true);
        if (myTargetDirectory == null) {
          errorStringRef.set("");
          return;
        }
        errorStringRef.set(RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getClassName()));
      }
      catch (IncorrectOperationException e) {
        errorStringRef.set(e.getMessage());
      }
    }
  }, GroovyInspectionBundle.message("create.directory.command"), null);

  if (errorStringRef.get() != null) {
    if (!errorStringRef.get().isEmpty()) {
      Messages.showMessageDialog(myProject, errorStringRef.get(), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    }
    return;
  }
  super.doOKAction();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:GroovyCreateClassDialog.java

示例9: doOKAction

import com.intellij.ide.util.PackageUtil; //导入依赖的package包/类
protected void doOKAction() {
  final String packageName = getPackageName();

  final Ref<String> errorStringRef = new Ref<String>();
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    public void run() {
      try {
        final PsiDirectory baseDir = myModule == null ? null : PackageUtil.findPossiblePackageDirectoryInModule(myModule, packageName);
        myTargetDirectory = myModule == null ? null
            : PackageUtil.findOrCreateDirectoryForPackage(myModule, packageName, baseDir, true);
        if (myTargetDirectory == null) {
          errorStringRef.set("");
          return;
        }
        errorStringRef.set(RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getClassName()));
      }
      catch (IncorrectOperationException e) {
        errorStringRef.set(e.getMessage());
      }
    }
  }, GroovyInspectionBundle.message("create.directory.command"), null);

  if (errorStringRef.get() != null) {
    if (errorStringRef.get().length() > 0) {
      Messages.showMessageDialog(myProject, errorStringRef.get(), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    }
    return;
  }
  super.doOKAction();
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:31,代码来源:GroovyCreateClassDialog.java

示例10: generateEverything

import com.intellij.ide.util.PackageUtil; //导入依赖的package包/类
public static String generateEverything(final PsiJavaPackage psiPackage, final PsiClass rootClass, final String visitorName) {
  final String visitorQName = PsiNameHelper.getShortClassName(visitorName).equals(visitorName)?
                              psiPackage.getQualifiedName()+"."+ visitorName : visitorName;
  final PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(rootClass.getProject(),
                                                                             StringUtil.getPackageName(visitorQName), null, false);
  generateVisitorClass(visitorQName, rootClass, directory, new PackageScope(psiPackage, false, false));
  return visitorQName;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:9,代码来源:GenerateVisitorByHierarchyAction.java

示例11: getBaseDir

import com.intellij.ide.util.PackageUtil; //导入依赖的package包/类
@Nullable
protected PsiDirectory getBaseDir(String packageName) {
  return myModule == null? null : PackageUtil.findPossiblePackageDirectoryInModule(myModule, packageName);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:CreateClassDialog.java

示例12: findOrCreateTargetClass

import com.intellij.ide.util.PackageUtil; //导入依赖的package包/类
@Nullable
private PsiClass findOrCreateTargetClass(final PsiManager manager, final String fqName) throws IncorrectOperationException {
  final String className;
  final String packageName;
  int dotIndex = fqName.lastIndexOf('.');
  if (dotIndex >= 0) {
    packageName = fqName.substring(0, dotIndex);
    className = (dotIndex + 1 < fqName.length())? fqName.substring(dotIndex + 1) : "";
  }
  else {
    packageName = "";
    className = fqName;
  }


  PsiClass aClass = JavaPsiFacade.getInstance(manager.getProject()).findClass(fqName, GlobalSearchScope.projectScope(myProject));
  if (aClass != null) return aClass;

  final PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(
              myProject,
              packageName,
              mySourceClass.getContainingFile().getContainingDirectory(),
              true);

  if (directory == null) {
    return null;
  }

  int answer = Messages.showYesNoDialog(
          myProject,
          RefactoringBundle.message("class.0.does.not.exist", fqName),
          MoveMembersImpl.REFACTORING_NAME,
          Messages.getQuestionIcon()
  );
  if (answer != 0) return null;
  final Ref<IncorrectOperationException> eRef = new Ref<IncorrectOperationException>();
  final PsiClass newClass = ApplicationManager.getApplication().runWriteAction(new Computable<PsiClass>() {
        public PsiClass compute() {
          try {
            return JavaDirectoryService.getInstance().createClass(directory, className);
          }
          catch (IncorrectOperationException e) {
            eRef.set(e);
            return null;
          }
        }
      });
  if (!eRef.isNull()) throw eRef.get();
  return newClass;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:51,代码来源:MoveMembersDialog.java


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