org.editorconfig.core.EditorConfig Java Examples

The following examples show how to use org.editorconfig.core.EditorConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LineEndingsManager.java    From editorconfig-jetbrains with MIT License 6 votes vote down vote up
private void applySettings(VirtualFile file) {
    if (file == null || !file.isInLocalFileSystem()) return;

    final String filePath = file.getCanonicalPath();
    final List<EditorConfig.OutPair> outPairs = SettingsProviderComponent.getInstance().getOutPairs(filePath);
    final String lineEndings = Utils.configValueForKey(outPairs, lineEndingsKey);
    if (!lineEndings.isEmpty()) {
        try {
            LineSeparator separator = LineSeparator.valueOf(lineEndings.toUpperCase(Locale.US));
            String oldSeparator = file.getDetectedLineSeparator();
            String newSeparator = separator.getSeparatorString();
            if (!StringUtil.equals(oldSeparator, newSeparator)) {
                file.setDetectedLineSeparator(newSeparator);
                if (!statusBarUpdated) {
                    statusBarUpdated = true;
                    updateStatusBar();
                }
                LOG.debug(Utils.appliedConfigMessage(lineEndings, lineEndingsKey, filePath));
            }
        } catch (IllegalArgumentException e) {
            LOG.warn(Utils.invalidConfigMessage(lineEndings, lineEndingsKey, filePath));
        }
    }
}
 
Example #2
Source File: EditorSettingsManager.java    From editorconfig-jetbrains with MIT License 5 votes vote down vote up
private static void applySettings(VirtualFile file) {
    if (file == null || !file.isInLocalFileSystem()) return;
    // Get editorconfig settings
    final String filePath = file.getCanonicalPath();
    final SettingsProviderComponent settingsProvider = SettingsProviderComponent.getInstance();
    final List<EditorConfig.OutPair> outPairs = settingsProvider.getOutPairs(filePath);
    // Apply trailing spaces setting
    final String trimTrailingWhitespace = Utils.configValueForKey(outPairs, trimTrailingWhitespaceKey);
    applyConfigValueToUserData(file, TrailingSpacesStripper.OVERRIDE_STRIP_TRAILING_SPACES_KEY,
                               trimTrailingWhitespaceKey, trimTrailingWhitespace, trimMap);
    // Apply final newline setting
    final String insertFinalNewline = Utils.configValueForKey(outPairs, insertFinalNewlineKey);
    applyConfigValueToUserData(file, TrailingSpacesStripper.OVERRIDE_ENSURE_NEWLINE_KEY,
                               insertFinalNewlineKey, insertFinalNewline, newlineMap);
}
 
Example #3
Source File: EditorConfigCLI.java    From editorconfig-core-java with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
  List<String> filePaths = new ArrayList<String>();
  String configFilename = null;
  String version = EditorConfig.VERSION;
  for (int i = 0; i < args.length; i++) {
    String arg = args[i];
    if ("-v".equals(arg) || "--version".equals(arg)) {
      System.out.println("EditorConfig Java Version " + version);
      System.exit(0);
    }
    if ("-h".equals(arg) || "--help".equals(arg)) {
      printUsage(false);
    }
    if ("-b".equals(arg)) {
      if (i + 1 < args.length) {
        version = args[++i];
        continue;
      } else {
        printUsage(true);
      }
    }
    if ("-f".equals(arg)) {
      if (i + 1 < args.length) {
        configFilename = args[++i];
        continue;
      } else {
        printUsage(true);
      }
    }
    filePaths.add(arg);
  }
  if (filePaths.isEmpty()) {
    printUsage(true);
  }
  for (String filePath : filePaths) {
    List<EditorConfig.OutPair> properties = new EditorConfig(configFilename, version).getProperties(filePath);
    if (filePaths.size() > 1) {
      System.out.println("[" + filePath + "]");
    }
    for (EditorConfig.OutPair property : properties) {
      System.out.println(property.getKey() + "=" + property.getVal());
    }
  }
}
 
Example #4
Source File: SettingsProviderComponent.java    From editorconfig-jetbrains with MIT License 4 votes vote down vote up
public SettingsProviderComponent() {
    editorConfig = new EditorConfig();
}