Skip to content

Commit

Permalink
Configuration keys #53
Browse files Browse the repository at this point in the history
added first implementation for stop.bubbling
  • Loading branch information
Michail Plushnikov committed Dec 29, 2014
1 parent d2c2245 commit 0511f52
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 29 deletions.
Expand Up @@ -25,13 +25,19 @@ public String getStringLombokConfigProperty(@NotNull ConfigKeys configKey, @NotN
final PsiFile psiFile = psiClass.getContainingFile();
if (psiFile instanceof PsiJavaFile) {
final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(psiClass.getProject());

String packageName = ((PsiJavaFile) psiFile).getPackageName();
while (null != packageName) {
final ConfigIndexKey configIndexKey = new ConfigIndexKey(packageName, configKey.getConfigKey());
final List<String> values = fileBasedIndex.getValues(LombokConfigIndex.NAME, configIndexKey, GlobalSearchScope.projectScope(psiClass.getProject()));
if (!values.isEmpty()) {
return values.iterator().next();

final String property = readProperty(fileBasedIndex, searchScope, packageName, configKey);
if (null == property) {
final String stopBublingProperty = readProperty(fileBasedIndex, searchScope, packageName, ConfigKeys.CONFIG_STOP_BUBBLING);
if (Boolean.parseBoolean(stopBublingProperty)) {
break;
}
} else {
return property;
}

if (!packageName.isEmpty()) {
Expand All @@ -44,6 +50,15 @@ public String getStringLombokConfigProperty(@NotNull ConfigKeys configKey, @NotN
return configKey.getConfigDefaultValue();
}

private String readProperty(FileBasedIndex fileBasedIndex, GlobalSearchScope searchScope, String packageName, ConfigKeys configKey) {
final ConfigIndexKey configIndexKey = new ConfigIndexKey(packageName, configKey.getConfigKey());
final List<String> values = fileBasedIndex.getValues(LombokConfigIndex.NAME, configIndexKey, searchScope);
if (!values.isEmpty()) {
return values.iterator().next();
}
return null;
}

public boolean getBooleanLombokConfigProperty(@NotNull ConfigKeys configKey, @NotNull PsiClass psiClass) {
final String configProperty = getStringLombokConfigProperty(configKey, psiClass);
return Boolean.parseBoolean(configProperty);
Expand Down
Expand Up @@ -5,6 +5,9 @@
import java.util.HashSet;

public enum ConfigKeys {

CONFIG_STOP_BUBBLING("config.stopBubbling", "false"),

LOG_FIELDNAME("lombok.log.fieldName", "log"),
LOG_FIELD_IS_STATIC("lombok.log.fieldIsStatic", "true"),

Expand Down
Expand Up @@ -52,20 +52,13 @@ public Map<ConfigIndexKey, String> map(@NotNull FileContent inputData) {
if (null != directoryPackage) {
final LombokConfigProperty[] configProperties = LombokConfigUtil.getLombokConfigProperties((LombokConfigFile) inputData.getPsiFile());
for (LombokConfigProperty configProperty : configProperties) {
addSubPackageMapping(result, directoryPackage, configProperty);
result.put(new ConfigIndexKey(directoryPackage.getQualifiedName(), configProperty.getKey()), configProperty.getValue());
}
}
}

return result;
}

private void addSubPackageMapping(Map<ConfigIndexKey, String> result, PsiPackage directoryPackage, LombokConfigProperty configProperty) {
result.put(new ConfigIndexKey(directoryPackage.getQualifiedName(), configProperty.getKey()), configProperty.getValue());
for (PsiPackage subPackage : directoryPackage.getSubPackages()) {
addSubPackageMapping(result, subPackage, configProperty);
}
}
};
}

Expand Down Expand Up @@ -115,6 +108,6 @@ public boolean dependsOnFileContent() {

@Override
public int getVersion() {
return 3;
return 1;
}
}
Expand Up @@ -3,14 +3,14 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class LogTest {
public class LogTest1 {

public void logSomething(){
LOG2.info("Hello World!");
}

public static void main(String[] args) {
LOG2.info("Test");
new LogTest().logSomething();
new LogTest1().logSomething();
}
}
Expand Up @@ -3,14 +3,14 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class LogTest {
public class LogTest2 {

public void logSomething(){
LOGGER1.info("Hello World!");
}

public static void main(String[] args) {
LOGGER1.info("Test");
new LogTest().logSomething();
new LogTest2().logSomething();
}
}
Expand Up @@ -3,14 +3,14 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class LogTest {
public class LogTest3 {

public void logSomething(){
LOGGER1.info("Hello World!");
}

public static void main(String[] args) {
LOGGER1.info("Test");
new LogTest().logSomething();
new LogTest3().logSomething();
}
}
@@ -1,14 +1,4 @@
lombok.log.fieldName = LOGGER1
lombok.log.fieldIsStatic = true

#sdassasd
lombok.anyConstructor.suppressConstructorProperties = true

lombok.accessors.fluent = true
lombok.anyConstructor.flagUsage = WARNING

clear lombok.anyConstructor.flagUsage

lombok.accessors.prefix = m
lombok.accessors.chain = true
config.stopBubbling = true

0 comments on commit 0511f52

Please sign in to comment.