コード例 #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;
  }
コード例 #3
0
 public String folderPath() {
   return TestUtils.getTestDataPath() + "/";
 }
コード例 #4
0
 public String getTestDataPath() {
   return TestUtils.getTestDataPath() + "/resolve/";
 }
 protected final String baseRootPath() {
   return TestUtils.getTestDataPath() + "/";
 }
/** @author Alexander Podkhalyuzin */
public abstract class ScalaLightPlatformCodeInsightTestCaseAdapter
    extends LightPlatformCodeInsightTestCase {
  private String JDK_HOME = TestUtils.getMockJdk();
  private ScalaLibraryLoader myLibraryLoader = null;

  protected String rootPath() {
    return null;
  }

  protected final String baseRootPath() {
    return TestUtils.getTestDataPath() + "/";
  }

  protected VirtualFile getSourceRootAdapter() {
    return getSourceRoot();
  }

  @Override
  protected Sdk getProjectJDK() {
    return JavaSdk.getInstance().createJdk("java sdk", JDK_HOME, false);
  }

  protected TestUtils.ScalaSdkVersion getDefaultScalaSDKVersion() {
    return TestUtils.DEFAULT_SCALA_SDK_VERSION;
  }

  @Override
  protected void setUp() throws Exception {
    setUp(getDefaultScalaSDKVersion());
  }

  protected void setUp(TestUtils.ScalaSdkVersion libVersion) throws Exception {
    super.setUp();
    myLibraryLoader =
        new ScalaLibraryLoader(
            getProject(),
            getModule(),
            rootPath(),
            isIncludeScalazLibrary(),
            isIncludeReflectLibrary());
    myLibraryLoader.loadLibrary(libVersion);
    // libLoader.clean();
  }

  protected boolean isIncludeReflectLibrary() {
    return false;
  }

  protected boolean isIncludeScalazLibrary() {
    return false;
  }

  protected VirtualFile getVFileAdapter() {
    return getVFile();
  }

  protected Editor getEditorAdapter() {
    return getEditor();
  }

  protected Project getProjectAdapter() {
    return getProject();
  }

  protected Module getModuleAdapter() {
    return getModule();
  }

  protected PsiFile getFileAdapter() {
    return getFile();
  }

  protected PsiManager getPsiManagerAdapter() {
    return getPsiManager();
  }

  protected DataContext getCurrentEditorDataContextAdapter() {
    return getCurrentEditorDataContext();
  }

  protected void executeActionAdapter(String actionId) {
    executeAction(actionId);
  }

  protected void configureFromFileTextAdapter(
      @NonNls final String fileName, @NonNls final String fileText) throws IOException {
    configureFromFileText(fileName, fileText);
  }

  @Override
  protected void tearDown() throws Exception {

    myLibraryLoader.clean();
    myLibraryLoader = null;
    super.tearDown();
    if (rootPath() != null) {
      new WriteAction<Object>() {
        @Override
        protected void run(Result<Object> objectResult) throws Throwable {
          closeAndDeleteProject();
        }
      }.execute().throwException();
    }
  }
}