Java 类com.intellij.lang.surroundWith.SurroundDescriptor 实例源码

项目:intellij-ce-playground    文件:SurroundWithHandler.java   
private static void invokeSurrounderInTests(Project project,
                                            Editor editor,
                                            PsiFile file,
                                            Surrounder surrounder,
                                            int startOffset,
                                            int endOffset, List<SurroundDescriptor> surroundDescriptors) {
  assert ApplicationManager.getApplication().isUnitTestMode();
  for (SurroundDescriptor descriptor : surroundDescriptors) {
    final PsiElement[] elements = descriptor.getElementsToSurround(file, startOffset, endOffset);
    if (elements.length > 0) {
      for (Surrounder descriptorSurrounder : descriptor.getSurrounders()) {
        if (surrounder.getClass().equals(descriptorSurrounder.getClass())) {
          doSurround(project, editor, surrounder, elements);
          return;
        }
      }
    }
  }
}
项目:tools-idea    文件:SurroundWithHandler.java   
private static void invokeSurrounderInTests(Project project,
                                            Editor editor,
                                            PsiFile file,
                                            Surrounder surrounder,
                                            int startOffset,
                                            int endOffset, List<SurroundDescriptor> surroundDescriptors) {
  assert ApplicationManager.getApplication().isUnitTestMode();
  for (SurroundDescriptor descriptor : surroundDescriptors) {
    final PsiElement[] elements = descriptor.getElementsToSurround(file, startOffset, endOffset);
    if (elements.length > 0) {
      for (Surrounder descriptorSurrounder : descriptor.getSurrounders()) {
        if (surrounder.getClass().equals(descriptorSurrounder.getClass())) {
          doSurround(project, editor, surrounder, elements);
          return;
        }
      }
    }
  }
}
项目:consulo    文件:SurroundWithHandler.java   
private static void invokeSurrounderInTests(Project project,
                                            Editor editor,
                                            PsiFile file,
                                            Surrounder surrounder,
                                            int startOffset,
                                            int endOffset, List<SurroundDescriptor> surroundDescriptors) {
  assert ApplicationManager.getApplication().isUnitTestMode();
  for (SurroundDescriptor descriptor : surroundDescriptors) {
    final PsiElement[] elements = descriptor.getElementsToSurround(file, startOffset, endOffset);
    if (elements.length > 0) {
      for (Surrounder descriptorSurrounder : descriptor.getSurrounders()) {
        if (surrounder.getClass().equals(descriptorSurrounder.getClass())) {
          doSurround(project, editor, surrounder, elements);
          return;
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:JavaSurroundWithTest.java   
public void testNoParenthesisSurrounderForLambdaParameter() {
  configureByFile(BASE_PATH + getTestName(false) + ".java");

  SurroundDescriptor item = ContainerUtil.getFirstItem(LanguageSurrounders.INSTANCE.allForLanguage(JavaLanguage.INSTANCE));
  assertNotNull(item);
  SelectionModel selectionModel = getEditor().getSelectionModel();
  PsiElement[] elements = item.getElementsToSurround(getFile(), selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
  assertEmpty(elements);
}
项目:intellij-ce-playground    文件:JavaSurroundWithTest.java   
private void doTest(@NotNull String fileName, Surrounder surrounder) {
  configureByFile(BASE_PATH + fileName + ".java");

  SurroundDescriptor item = ContainerUtil.getFirstItem(LanguageSurrounders.INSTANCE.allForLanguage(JavaLanguage.INSTANCE));
  assertNotNull(item);
  SelectionModel selectionModel = getEditor().getSelectionModel();
  PsiElement[] elements = item.getElementsToSurround(getFile(), selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
  assertTrue(surrounder.isApplicable(elements));

  SurroundWithHandler.invoke(getProject(), getEditor(), getFile(), surrounder);
  checkResultByFile(BASE_PATH + fileName + "_after.java");
}