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


Java CopyHandler类代码示例

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


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

示例1: testMultipleClasses

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
public void testMultipleClasses() throws Exception {
  String rootBefore = getRoot();
  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
  final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
  final PsiClass aClass = myJavaFacade.findClass("pack1.Klass");
  assertNotNull(aClass);

  final PsiFile containingFile = aClass.getContainingFile();

  assertTrue(CopyHandler.canCopy(new PsiElement[]{containingFile}));
  assertFalse(CopyHandler.canClone(new PsiElement[]{containingFile}));

  PsiPackage pack2 = myJavaFacade.findPackage("pack2");
  final PsiDirectory targetDirectory = pack2.getDirectories()[0];
  CopyHandler.doCopy(new PsiElement[]{containingFile}, targetDirectory);

  VirtualFile fileAfter = root.findFileByRelativePath("pack2/Klass.java");
  VirtualFile fileExpected = root.findFileByRelativePath("pack2/Klass.expected.java");

  PlatformTestUtil.assertFilesEqual(fileExpected, fileAfter);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:CopyTest.java

示例2: testMultipleFiles

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
public void testMultipleFiles() throws Exception {
  String rootBefore = getRoot();
  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
  final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);

  final VirtualFile first = root.findFileByRelativePath("from/1.txt");
  assertNotNull(first);
  final VirtualFile second = root.findFileByRelativePath("from/2.txt");
  assertNotNull(second);

  final PsiFile firstPsi = myPsiManager.findFile(first);
  final PsiFile secondPsi = myPsiManager.findFile(second);

  assertTrue(CopyHandler.canCopy(new PsiElement[]{firstPsi, secondPsi}));

  final VirtualFile toDir = root.findChild("to");
  assertNotNull(toDir);
  final PsiDirectory targetDirectory = myPsiManager.findDirectory(toDir);

  CopyHandler.doCopy(new PsiElement[]{firstPsi, secondPsi}, targetDirectory);

  assertNotNull(root.findFileByRelativePath("to/1.txt"));
  assertNotNull(root.findFileByRelativePath("to/2.txt"));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:CopyTest.java

示例3: updateForEditor

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
protected void updateForEditor(DataContext dataContext, Presentation presentation) {
  Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  if (editor == null) {
    presentation.setVisible(false);
    return;
  }

  Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return;

  }
  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());

  PsiElement element = getTargetElement(editor, project);
  boolean result = element != null && CopyHandler.canCopy(new PsiElement[]{element});

  if (!result && file != null) {
    result = CopyHandler.canCopy(new PsiElement[]{file});
  }

  presentation.setEnabled(result);
  presentation.setVisible(true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:CopyElementAction.java

示例4: doDrop

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
private void doDrop(TreeNode targetNode, PsiElement[] sourceElements) {
  final PsiElement targetElement = getPsiElement(targetNode);
  if (targetElement == null) return;
  final PsiDirectory psiDirectory;
  if (targetElement instanceof PsiDirectoryContainer) {
    final PsiDirectoryContainer directoryContainer = (PsiDirectoryContainer)targetElement;
    final PsiDirectory[] psiDirectories = directoryContainer.getDirectories();
    psiDirectory = psiDirectories.length != 0 ? psiDirectories[0] : null;
  }
  else if (targetElement instanceof PsiDirectory) {
    psiDirectory = (PsiDirectory)targetElement;
  }
  else {
    final PsiFile containingFile = targetElement.getContainingFile();
    LOG.assertTrue(containingFile != null);
    psiDirectory = containingFile.getContainingDirectory();
  }
  CopyHandler.doCopy(sourceElements, psiDirectory);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:ProjectViewDropTarget.java

示例5: testCopyingJavaFileReferencedByGlob

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
@Test
public void testCopyingJavaFileReferencedByGlob() {
  workspace.createDirectory(new WorkspacePath("java"));
  PsiFile javaFile =
      workspace.createPsiFile(
          new WorkspacePath("java/Test.java"), "package java;", "public class Test {}");

  PsiFile javaFile2 =
      workspace.createPsiFile(
          new WorkspacePath("java/Test2.java"), "package java;", "public class Test2 {}");

  createBuildFile(
      new WorkspacePath("java/BUILD"),
      "java_library(",
      "    name = 'lib',",
      "    srcs = glob(['**/*.java']),",
      ")");

  PsiDirectory otherDir = workspace.createPsiDirectory(new WorkspacePath("java/other"));

  WriteCommandAction.runWriteCommandAction(
      null,
      () -> {
        CopyHandler.doCopy(new PsiElement[] {javaFile, javaFile2}, otherDir);
      });
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:27,代码来源:FileCopyTest.java

示例6: updateForEditor

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
protected void updateForEditor(DataContext dataContext, Presentation presentation) {
  Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
  if (editor == null) {
    presentation.setVisible(false);
    return;
  }

  Project project = PlatformDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return;

  }
  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());

  PsiElement element = getTargetElement(editor, project);
  boolean result = element != null && CopyHandler.canCopy(new PsiElement[]{element});

  if (!result && file != null) {
    result = CopyHandler.canCopy(new PsiElement[]{file});
  }

  presentation.setEnabled(result);
  presentation.setVisible(true);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:CopyElementAction.java

示例7: updateForEditor

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
protected void updateForEditor(DataContext dataContext, Presentation presentation) {
  Editor editor = dataContext.getData(PlatformDataKeys.EDITOR);
  if (editor == null) {
    presentation.setVisible(false);
    return;
  }

  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return;

  }
  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());

  PsiElement element = getTargetElement(editor, project);
  boolean result = element != null && CopyHandler.canCopy(new PsiElement[]{element});

  if (!result && file != null) {
    result = CopyHandler.canCopy(new PsiElement[]{file});
  }

  presentation.setEnabled(result);
  presentation.setVisible(true);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:25,代码来源:CopyElementAction.java

示例8: doDrop

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
private void doDrop(TreeNode targetNode, PsiElement[] sourceElements) {
  final PsiElement targetElement = getPsiElement(targetNode);
  if (targetElement == null) return;

  if (DumbService.isDumb(myProject)) {
    Messages.showMessageDialog(myProject, "Copy refactoring is not available while indexing is in progress", "Indexing", null);
    return;
  }

  final PsiDirectory psiDirectory;
  if (targetElement instanceof PsiDirectoryContainer) {
    final PsiDirectoryContainer directoryContainer = (PsiDirectoryContainer)targetElement;
    final PsiDirectory[] psiDirectories = directoryContainer.getDirectories();
    psiDirectory = psiDirectories.length != 0 ? psiDirectories[0] : null;
  }
  else if (targetElement instanceof PsiDirectory) {
    psiDirectory = (PsiDirectory)targetElement;
  }
  else {
    final PsiFile containingFile = targetElement.getContainingFile();
    LOG.assertTrue(containingFile != null);
    psiDirectory = containingFile.getContainingDirectory();
  }
  TransactionGuard.getInstance().submitTransactionAndWait(() -> CopyHandler.doCopy(sourceElements, psiDirectory));
}
 
开发者ID:consulo,项目名称:consulo,代码行数:26,代码来源:ProjectViewDropTarget.java

示例9: testMultipleClasses

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
public void testMultipleClasses() throws Exception {
  String rootBefore = getRoot();
  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
  final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
  final PsiClass aClass = myJavaFacade.findClass("pack1.Klass");
  assertNotNull(aClass);

  final PsiFile containingFile = aClass.getContainingFile();

  assertTrue(CopyHandler.canCopy(new PsiElement[]{containingFile}));
  assertFalse(CopyHandler.canClone(new PsiElement[]{containingFile}));

  PsiJavaPackage pack2 = myJavaFacade.findPackage("pack2");
  final PsiDirectory targetDirectory = pack2.getDirectories()[0];
  CopyHandler.doCopy(new PsiElement[]{containingFile}, targetDirectory);

  VirtualFile fileAfter = root.findFileByRelativePath("pack2/Klass.java");
  VirtualFile fileExpected = root.findFileByRelativePath("pack2/Klass.expected.java");

  PlatformTestUtil.assertFilesEqual(fileExpected, fileAfter);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:CopyTest.java

示例10: doTest

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
private void doTest() throws Exception {
  String rootBefore = getRoot();
  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
  PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
  PsiPackage pack1 = myJavaFacade.findPackage("pack1");
  PsiPackage pack2 = myJavaFacade.findPackage("pack2");
  assertTrue(CopyHandler.canCopy(new PsiElement[]{pack1.getDirectories()[0], pack2.getDirectories()[0]}));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:CopyTest.java

示例11: actionPerformed

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
  final DataContext dataContext = e.getDataContext();
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return;
  }

  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    @Override
    public void run() {
      PsiDocumentManager.getInstance(project).commitAllDocuments();
    }}, "", null
  );
  final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  PsiElement[] elements;

  PsiDirectory defaultTargetDirectory;
  if (editor != null) {
    PsiElement aElement = getTargetElement(editor, project);
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file == null) return;
    elements = new PsiElement[]{aElement};
    if (aElement == null || !CopyHandler.canCopy(elements)) {
      elements = new PsiElement[]{file};
    }
    defaultTargetDirectory = file.getContainingDirectory();
  } else {
    PsiElement element = LangDataKeys.TARGET_PSI_ELEMENT.getData(dataContext);
    defaultTargetDirectory = element instanceof PsiDirectory ? (PsiDirectory)element : null;
    elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
  }
  doCopy(elements, defaultTargetDirectory);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:CopyElementAction.java

示例12: actionPerformed

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
  final DataContext dataContext = e.getDataContext();
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
  @SuppressWarnings({"ConstantConditions"}) final PsiElement element = PsiManager.getInstance(project).findFile(virtualFile);
  if(element==null) return;
  CopyHandler.doCopy(new PsiElement[] {element.getContainingFile()}, PlatformPackageUtil.getDirectory(element));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:SaveAsAction.java

示例13: canDrop

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
@Override
protected boolean canDrop(@NotNull final TreeNode[] sourceNodes, @Nullable final TreeNode targetNode) {
  final PsiElement[] sourceElements = getPsiElements(sourceNodes);
  final PsiElement targetElement = getPsiElement(targetNode);
  if (targetElement == null) return false;
  final PsiFile containingFile = targetElement.getContainingFile();
  final boolean isTargetAcceptable = targetElement instanceof PsiDirectoryContainer ||
                                     targetElement instanceof PsiDirectory ||
                                     (containingFile != null && containingFile.getContainingDirectory() != null);
  return isTargetAcceptable && CopyHandler.canCopy(sourceElements);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:ProjectViewDropTarget.java

示例14: updateForToolWindow

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
@Override
protected void updateForToolWindow(String id, DataContext dataContext,Presentation presentation) {
  // work only with single selection
  PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
  presentation.setEnabled(elements != null && elements.length == 1 && CopyHandler.canClone(elements));
  presentation.setVisible(true);
  if (!ToolWindowId.COMMANDER.equals(id)) {
    presentation.setVisible(false);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:11,代码来源:CloneElementAction.java

示例15: actionPerformed

import com.intellij.refactoring.copy.CopyHandler; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
  final DataContext dataContext = e.getDataContext();
  final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return;
  }

  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    @Override
    public void run() {
      PsiDocumentManager.getInstance(project).commitAllDocuments();
    }}, "", null
  );
  final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
  PsiElement[] elements;

  PsiDirectory defaultTargetDirectory;
  if (editor != null) {
    PsiElement aElement = getTargetElement(editor, project);
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file == null) return;
    elements = new PsiElement[]{aElement};
    if (aElement == null || !CopyHandler.canCopy(elements)) {
      elements = new PsiElement[]{file};
    }
    defaultTargetDirectory = file.getContainingDirectory();
  } else {
    PsiElement element = LangDataKeys.TARGET_PSI_ELEMENT.getData(dataContext);
    defaultTargetDirectory = element instanceof PsiDirectory ? (PsiDirectory)element : null;
    elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
  }
  doCopy(elements, defaultTargetDirectory);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:35,代码来源:CopyElementAction.java


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