-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
84 changed files
with
1,946 additions
and
2,191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,97 @@ | ||
package com.cflint.config; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
|
||
import com.cflint.config.CFLintPluginInfo.PluginInfoRule; | ||
import com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage; | ||
import com.cflint.plugins.CFLintScanner; | ||
|
||
public class CFLintChainedConfig { | ||
public class CFLintChainedConfig implements CFLintConfiguration{ | ||
|
||
final CFLintConfig config; | ||
final CFLintChainedConfig parent; | ||
|
||
public CFLintChainedConfig(CFLintConfig config) { | ||
public CFLintChainedConfig(CFLintConfiguration config) { | ||
super(); | ||
this.config = config; | ||
this.config = (CFLintConfig)config; | ||
parent = null; | ||
} | ||
public CFLintChainedConfig(CFLintConfig config,CFLintChainedConfig parent) { | ||
public CFLintChainedConfig(CFLintConfiguration config,CFLintChainedConfig parent) { | ||
super(); | ||
this.config = config; | ||
this.config = (CFLintConfig)config; | ||
this.parent = parent; | ||
} | ||
|
||
public CFLintChainedConfig createNestedConfig(CFLintConfig config){ | ||
return new CFLintChainedConfig(config,this); | ||
/** | ||
* Create a nested configuration. | ||
* @param config | ||
* @return | ||
*/ | ||
public CFLintChainedConfig createNestedConfig(CFLintConfiguration config){ | ||
return config==null?this:new CFLintChainedConfig(config,this); | ||
} | ||
|
||
public boolean includes(PluginMessage pluginMessage) { | ||
return config.includes(pluginMessage) || | ||
(config.isInheritParent() && parent!=null && parent.includes(pluginMessage)); | ||
} | ||
|
||
public Object excludes(PluginMessage pluginMessage) { | ||
return config.includes(pluginMessage) || | ||
(config.isInheritParent() && parent!=null && parent.includes(pluginMessage)); | ||
public boolean excludes(PluginMessage pluginMessage) { | ||
return config.excludes(pluginMessage) || | ||
(config.isInheritParent() && parent!=null && parent.excludes(pluginMessage)); | ||
} | ||
|
||
public CFLintChainedConfig getParent() { | ||
return parent; | ||
} | ||
|
||
@Override | ||
public PluginInfoRule getRuleByClass(Class<?> clazz) { | ||
PluginInfoRule retval = config.getRuleByClass(clazz); | ||
if(retval !=null || parent == null){ | ||
return retval; | ||
} | ||
return parent.getRuleByClass(clazz); | ||
} | ||
@Override | ||
public PluginInfoRule getRuleForPlugin(CFLintScanner plugin) { | ||
PluginInfoRule retval = config.getRuleForPlugin(plugin); | ||
if(retval !=null || parent == null){ | ||
return retval; | ||
} | ||
return parent.getRuleForPlugin(plugin); | ||
} | ||
@Override | ||
public void addInclude(PluginMessage pluginMessage) { | ||
config.addInclude(pluginMessage); | ||
} | ||
|
||
@Override | ||
public void addExclude(PluginMessage pluginMessage) { | ||
config.addExclude(pluginMessage); | ||
} | ||
@Override | ||
public Collection<PluginInfoRule> getRules() { | ||
final HashSet<PluginInfoRule> activeRules = new HashSet<PluginInfoRule>(); | ||
for(PluginInfoRule rule:getAllRules()){ | ||
for(PluginMessage pluginMessage:rule.getMessages()){ | ||
if(includes(pluginMessage) && !excludes(pluginMessage)){ | ||
activeRules.add(rule); | ||
break; | ||
} | ||
} | ||
} | ||
return activeRules; | ||
} | ||
|
||
public Collection<PluginInfoRule> getAllRules() { | ||
if(parent==null || !config.isInheritPlugins()){ | ||
return config.getRules(); | ||
} | ||
final HashSet<PluginInfoRule> retval = new HashSet<PluginInfoRule>(parent.getAllRules()); | ||
//Override any rules from the parent configuration | ||
retval.addAll(config.getRules()); | ||
return retval; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.