コード例 #1
0
 public String transform(String testName, String[] data) throws Exception {
   setSettings();
   String fileText = data[0];
   final PsiFile psiFile = TestUtils.createPseudoPhysicalScalaFile(myProject, fileText);
   String result = processFile(psiFile);
   Console.println("------------------------ " + testName + " ------------------------");
   Console.println(result);
   Console.println("");
   return result;
 }
コード例 #2
0
  private String processFile(final PsiFile file)
      throws IncorrectOperationException, InvalidDataException, IOException {
    String result = "";
    String fileText = file.getText();
    int startOffset = fileText.indexOf(TestUtils.BEGIN_MARKER);
    if (startOffset < 0) {
      startOffset = fileText.indexOf(ALL_MARKER);
      replaceAllOccurences = true;
      fileText = removeAllMarker(fileText);
    } else {
      replaceAllOccurences = false;
      fileText = TestUtils.removeBeginMarker(fileText);
    }
    int endOffset = fileText.indexOf(TestUtils.END_MARKER);
    fileText = TestUtils.removeEndMarker(fileText);
    myFile = TestUtils.createPseudoPhysicalScalaFile(myProject, fileText);
    fileEditorManager = FileEditorManager.getInstance(myProject);
    myEditor =
        fileEditorManager.openTextEditor(
            new OpenFileDescriptor(myProject, myFile.getVirtualFile(), 0), false);

    try {

      String varName = "value";
      final ScType varType = null;

      ScalaVariableValidator validator =
          IntroduceVariableTestUtil.getValidator(
              myProject, myEditor, (ScalaFile) myFile, startOffset, endOffset);
      String[] res = validator.isOKImpl(varName, replaceAllOccurences);
      for (String s : res) result += s + "\n";
    } finally {
      fileEditorManager.closeFile(myFile.getVirtualFile());
      myEditor = null;
    }
    return result;
  }