Ec4j
Java EditorConfig Parser
Install / Use
/learn @ec4j/Ec4jREADME
image::src/main/images/ec4j-logo-with-name.svg[ec4j,height=60]
{empty}
https://github.com/ec4j/ec4j/blob/master/LICENSE[image:https://img.shields.io/github/license/ec4j/ec4j.svg[License]] http://search.maven.org/#search%7Cga%7C1%7Corg.ec4j.core[image:https://img.shields.io/maven-central/v/org.ec4j.core/ec4j-core.svg[Maven Central]] image:https://github.com/ec4j/ec4j/workflows/Linux%20%26%20Windows%20CI/badge.svg[link="https://github.com/ec4j/ec4j/actions"]
ec4j is an http://editorconfig.org/[EditorConfig] implementation for Java. It provides:
- A parser for
.editorconfigfiles - An API for querying EditorConfig properties applicable to a given file
- A model of an
editorconfigfile rich enough to support validation, folding, code completion, etc. of.editorconfigfiles in editors and IDEs.
== Who is using ec4j?
Here are some projects that use ec4j:
- https://github.com/angelozerr/ec4e[EditorConfig for Eclipse] based on GenericEditor and https://github.com/eclipse/tm4e/[tm4e].
https://github.com/ec4j/editorconfig-maven-plugin[editorconfig-maven-plugin]https://github.com/ec4j/editorconfig-gradle-plugin[editorconfig-gradle-plugin]https://github.com/ec4j/editorconfig-ant-tasks[editorconfig-ant-tasks]https://github.com/pinterest/ktlint[ktlint]
== Basic usage
Add the following dependency to your project:
[source,xml]
<dependency> <groupId>org.ec4j.core</groupId> <artifactId>ec4j-core</artifactId> <version><!-- check the latest on http://central.maven.org/maven2/org/ec4j/core/ec4j-core/ --></version> </dependency> ----To parse a single .editorconfig file into an EditorConfig model:
[source,java]
java.nio.file.Path editorConfigFile = Paths.get("path/to/my/.editorconfig"); EditorConfigParser parser = EditorConfigParser.builder().build(); EditorConfigModelHandler handler = new EditorConfigModelHandler(PropertyTypeRegistry.default_(), Version.CURRENT); parser.parse(Resources.ofPath(editorConfigFile, StandardCharsets.UTF_8), handler, ErrorHandler.THROW_SYNTAX_ERRORS_IGNORE_OTHERS); EditorConfig editorConfig = handler.getEditorConfig();
To query the properties applicable to a file in a source tree:
[source,java]
Cache myCache = ...; // e.g. Caches.permanent() EditorConfigLoader myLoader = ...; // e.g. EditorConfigLoader.default_() ResourcePropertiesService propService = ResourcePropertiesService.builder() .cache(myCache) .loader(myLoader) .rootDirectory(ResourcePaths.ofPath(Paths.get("/my/dir"), StandardCharsets.UTF_8)) .build();
ResourceProperties props = propService.queryProperties(Resources.ofPath(Paths.get("/my/dir1/Class1.java"), StandardCharsets.UTF_8)); IndentStyleValue indentStyleValue = props.getValue(PropertyType.indent_style, IndentStyleValue.space, true); char indentChar = indentStyleValue.getIndentChar(); // Now you can e.g. check that /my/dir1/Class1.java is indented using indentChar
== How to build
Prerequisites:
- Java 8+
- Optionally Maven 3.6.1+, unless you want to use
./mvnwormvnw.batdelivered by the project - cmake 2.6+ to run the https://github.com/editorconfig/editorconfig-core-test[editorconfig-core-test] testsuite (optional).
The most common build with unit tests:
[source,shell]
./mvnw clean install
On Windows:
[source,shell]
mvnw.bat clean install
A build with https://github.com/editorconfig/editorconfig-core-test[editorconfig-core-test] testsuite:
[source,shell]
git submodule init git submodule update mvn -Pcore-test clean install && ( cd core && cmake . && ctest . )
== Relationship to editorconfig-core-java
The authors of ec4j decided to start ec4j because they were unsuccessful with their proposals in
editorconfig-core-java.
Although ec4j is not a fork of editorconfig-core-java it uses a few portions of code from
editorconfig-core-java. Such ones are clearly marked in ec4j 's JavaDoc.
ec4j aims at offering a superset of
https://github.com/editorconfig/editorconfig-core-java[editorconfig-core-java] 's functionality.
While editorconfig-core-java supports just the basic use case of querying the EditorConfig properties
applicable to a given file, ec4j offers much more in addition to that:
- A proper link:core/src/main/java/org/eclipse/ec4j/core/model/EditorConfig.java[model of an
.editorconfigfile] - link:src/main/java/org/eclipse/ec4j/core/model/Property.java[Type safe property values]
- link:core/src/main/java/org/eclipse/ec4j/core/parser/EditorConfigParser.java[EditorConfigParser] and
link:core/src/main/java/org/eclipse/ec4j/core/parser/EditorConfigHandler.java[EditorConfigHandler] interface
designed to support syntax highlighting, validation, folding, etc. of
.editorconfigfiles in IDEs. ec4jis available on Maven Centralec4jperforms better against the https://github.com/editorconfig/editorconfig-core-test[editorconfig-core test suite]:
|===
| Library | Lib. revision | Tests passed/total on Linux | Tests passed/total on Windows
| ec4j | fa51d88 | 189/189 | 185/187
| editorconfig-core-java | e3e0905 | 185/189 | ?
|===
+
editorconfig-core-test revision: https://github.com/editorconfig/editorconfig-core-test/commit/0001aa28f3816bb72cdbea09598252b50e4695c2[0001aa2]
== Misc.
- All code and contributions are under link:/LICENSE[Apache License]
- Issues and Discussions: https://github.com/ec4j/ec4j/issues
- The
https://github.com/ec4j/ec4j[ec4j/ec4j]repository is the reference repository for contributing toec4j.
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
