Package org.ec4j.core
Class ResourcePropertiesService
java.lang.Object
org.ec4j.core.ResourcePropertiesService
A service able to query
Propertys applicable to a given Resource.
This is a typical entry point for the users of ec4j.core.
To create a new default ResourcePropertiesService use
ResourcePropertiesService propService = ResourcePropertiesService.default_();Use
builder() if you need something special:
Cache myCache = ...;
EditorConfigLoader myLoader = ...;
ResourcePropertiesService propService = ResourcePropertiesService.builder()
.cache(myCache)
.loader(myLoader)
.rootDirectory(ResourcePaths.ofPath(Paths.get("/my/dir")))
.build();
ResourceProperties props = propService.queryProperties(Resources.ofPath(Paths.get("/my/dir1/Class1.java")));
IndentStyleValue indentStyleValue = props.getValue(PropertyType.indent_style, IndentStyleValue.space);
char indentChar = indentStyleValue.getIndentChar();
// Now you can e.g. check that /my/dir1/Class1.java is indented using indentChar
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprivate static classA pair ofEditorConfigLoaderandResourcePathof the directory under which the underlyinf.editorconfigfile is located. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Cacheprivate final Stringprivate final List<EditorConfig> private final booleanprivate final EditorConfigLoaderprivate final Set<ResourcePath> -
Constructor Summary
ConstructorsConstructorDescriptionResourcePropertiesService(String configFileName, Set<ResourcePath> rootDirectories, List<EditorConfig> defaultEditorConfigs, Cache cache, EditorConfigLoader loader, boolean keepUnset) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()static ResourcePropertiesServicedefault_()A shorthand forResourcePropertiesService.builder().build().getCache()queryProperties(Resource resource)
-
Field Details
-
cache
-
configFileName
-
defaultEditorConfigs
-
keepUnset
private final boolean keepUnset -
loader
-
rootDirectories
-
-
Constructor Details
-
ResourcePropertiesService
ResourcePropertiesService(String configFileName, Set<ResourcePath> rootDirectories, List<EditorConfig> defaultEditorConfigs, Cache cache, EditorConfigLoader loader, boolean keepUnset)
-
-
Method Details
-
builder
- Returns:
- a new
ResourcePropertiesServiceResourcePropertiesService.Builder.
-
default_
A shorthand forResourcePropertiesService.builder().build(). Returns a newResourcePropertiesServicewithCache.Caches.none()Cache,EditorConfigConstants.EDITORCONFIGconfigFileName,EditorConfigLoader.default_()loader, emptyrootDirectoriesandkeepUnset = false.- Returns:
- a new default
ResourcePropertiesService
-
getCache
-
getConfigFileName
- Returns:
- the name of the EditorConfig file this
ResourcePropertiesServicelooks for (the default value is.editorconfig)
-
getDefaultEditorConfigs
- Returns:
- a
ListofEditorConfigmodels that contain default settings beyond the ones set in the filesystem. These can be used to implement user or system defaults. The order of the files matters: the last file will least significant. In other words, user defaults would appear before system defaults in the returned list.
-
getLoader
- Returns:
- the
EditorConfigLoaderassociated with thisResourcePropertiesService
-
getRootDirectories
- Returns:
- the
Setof root directories associated with thisResourcePropertiesService; nevernull
-
queryProperties
Walks up the resource tree from the givenResource, visits all.editorconfigfiles and filtersPropertys applicable to the givenResource.Note that the performance of this method is strongly influenced by the
Cacheimplementation thisResourcePropertiesServiceuses. If you do not specify anyCacheviaResourcePropertiesService.Builder.cache(Cache)explicitly,Cache.Caches.none()is used that causes this method to parse each.editorconfigfile every time it is necessary.- Parameters:
resource- the resource to find thePropertys for- Returns:
- a
ResourcePropertiesthat containsPropertys applicable to the givenResource - Throws:
IOException- on I/O problems during the reading from the.editorconfigfiles.
-