Esempio n. 1
0
 public static File getCompilerSystemDirectory() {
   //noinspection HardCodedStringLiteral
   final String systemPath =
       ourSystemPath != null
           ? ourSystemPath
           : (ourSystemPath = PathUtil.getCanonicalPath(PathManager.getSystemPath()));
   return new File(systemPath, "compiler");
 }
Esempio n. 2
0
  private void doTestFor(
      Map<String, PsiFile> pathToFile, final IntentionAction intentionAction, String fileText)
      throws Exception {
    String isApplicableString =
        InTextDirectivesUtils.findStringWithPrefixes(fileText, "// IS_APPLICABLE: ");
    boolean isApplicableExpected = isApplicableString == null || isApplicableString.equals("true");

    Assert.assertTrue(
        "isAvailable() for "
            + intentionAction.getClass()
            + " should return "
            + isApplicableExpected,
        isApplicableExpected == intentionAction.isAvailable(getProject(), getEditor(), getFile()));

    String intentionTextString =
        InTextDirectivesUtils.findStringWithPrefixes(fileText, "// INTENTION_TEXT: ");

    if (intentionTextString != null) {
      assertEquals("Intention text mismatch.", intentionTextString, intentionAction.getText());
    }

    String shouldFailString =
        InTextDirectivesUtils.findStringWithPrefixes(fileText, "// SHOULD_FAIL_WITH: ");

    try {
      if (isApplicableExpected) {
        ApplicationPackage.executeWriteCommand(
            getProject(),
            intentionAction.getText(),
            new Function0<Object>() {
              @Override
              public Object invoke() {
                intentionAction.invoke(getProject(), getEditor(), getFile());
                return null;
              }
            });
        // Don't bother checking if it should have failed.
        if (shouldFailString == null) {
          for (Map.Entry<String, PsiFile> entry : pathToFile.entrySet()) {
            //noinspection AssignmentToStaticFieldFromInstanceMethod
            myFile = entry.getValue();
            String canonicalPathToExpectedFile =
                PathUtil.getCanonicalPath(entry.getKey() + ".after");

            checkResultByFile(canonicalPathToExpectedFile);
          }
        }
      }
      assertNull("Expected test to fail.", shouldFailString);
    } catch (IntentionTestException e) {
      assertEquals("Failure message mismatch.", shouldFailString, e.getMessage());
    } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
      assertEquals(
          "Failure message mismatch.", shouldFailString, StringUtil.join(e.getMessages(), ", "));
    }
  }
Esempio n. 3
0
 private void initPathMacros() {
   for (Map.Entry<Object, Object> property :
       SetSequence.fromSet(System.getProperties().entrySet())) {
     if (!(property.getKey() instanceof String) || !(property.getValue() instanceof String)) {
       continue;
     }
     String propertyKey = (String) property.getKey();
     String propertyValue = (String) property.getValue();
     if ((propertyKey == null || propertyKey.length() == 0)
         || !(propertyKey.startsWith(PROPERTY_PREFIX_PATH_MACRO))) {
       continue;
     }
     String canonicalPath = PathUtil.getCanonicalPath(propertyValue);
     File file = new File(canonicalPath);
     if (file.exists() && file.isDirectory()) {
       PathMacros.getInstance()
           .setMacro(propertyKey.substring(PROPERTY_PREFIX_PATH_MACRO.length()), canonicalPath);
     }
   }
 }
 /**
  * @param path target path
  * @return absolute path that points to the same location as the given one and that uses only
  *     slashes
  */
 @NotNull
 public static String toCanonicalPath(@NotNull String path) {
   return PathUtil.getCanonicalPath(new File(path).getAbsolutePath());
 }
Esempio n. 5
0
 private static String getAbsolutePath(String path) {
   path = VfsUtil.urlToPath(path);
   path = PathUtil.getCanonicalPath(path);
   return FileUtil.toSystemIndependentName(path);
 }
 /**
  * @param path target path
  * @return absolute path that points to the same location as the given one and that uses only
  *     slashes
  */
 @NotNull
 public static String toCanonicalPath(@NotNull String path) {
   String p = normalizePath(new File(path).getAbsolutePath());
   assert p != null;
   return PathUtil.getCanonicalPath(p);
 }