コード例 #1
0
  public void testGetXLintOptions() throws Exception {
    String lint = AspectJPreferences.getLintOptions(project);
    int ind = lint.indexOf("-Xlintfile"); // $NON-NLS-1$
    if (ind == -1) {
      fail(
          "Didn't find -Xlintfile in string returned from AspectJPreferences.getLintOptions(). Got: "
              + lint); //$NON-NLS-1$
    }
    int ind2 = lint.indexOf('\"', ind);
    if (ind2 == -1) {
      fail(
          "Didn't find start quote in string returned from AspectJPreferences.getLintOptions(). Got: "
              + lint); //$NON-NLS-1$
    }
    int ind3 = lint.indexOf('\"', ind2 + 1);
    if (ind3 == -1) {
      fail(
          "Didn't find end quote in string returned from AspectJPreferences.getLintOptions(). Got: "
              + lint); //$NON-NLS-1$
    }
    String fileName = lint.substring(ind2 + 1, ind3);

    // check the file exists
    File file = new File(fileName);
    assertTrue("Xlintfile does not exist: " + file, file.exists()); // $NON-NLS-1$

    // now try to read from it and check for typeNotExposedToWeaver=warning
    boolean gotWarning =
        checkXlintOption(file, "typeNotExposedToWeaver", "warning"); // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(
        "Did not find typeNotExpostedToWeaver entry set to warning", gotWarning); // $NON-NLS-1$

    boolean isProjectSettings = AspectJPreferences.isUsingProjectSettings(project);
    String original = prefStore.getString(AspectJPreferences.OPTION_ReportTypeNotExposedToWeaver);
    try {
      // change option to ignore
      AspectJPreferences.setUsingProjectSettings(project, false);
      prefStore.setValue(AspectJPreferences.OPTION_ReportTypeNotExposedToWeaver, JavaCore.IGNORE);

      // recheck
      checkXlintOption(file, "typeNotExposedToWeaver", "ignore"); // $NON-NLS-1$ //$NON-NLS-2$
      assertTrue(
          "Did not find typeNotExpostedToWeaver entry set to ignore", gotWarning); // $NON-NLS-1$
    } finally {
      // restore settings
      AspectJPreferences.setUsingProjectSettings(project, isProjectSettings);
      prefStore.setValue(AspectJPreferences.OPTION_ReportTypeNotExposedToWeaver, original);
    }
  }