Added check for consistence of the white space strategies added in a single bulk

This commit is contained in:
Denis.Zhdanov
2011-12-19 15:42:13 +04:00
parent 3300cd7900
commit d5d02c0ca8
@@ -37,8 +37,12 @@ public class CompositeWhiteSpaceFormattingStrategy implements WhiteSpaceFormatti
private final List<WhiteSpaceFormattingStrategy> myStrategies = new ArrayList<WhiteSpaceFormattingStrategy>();
private boolean myReplaceDefaultStrategy;
public CompositeWhiteSpaceFormattingStrategy(@NotNull Collection<WhiteSpaceFormattingStrategy> strategies) {
myStrategies.addAll(strategies);
public CompositeWhiteSpaceFormattingStrategy(@NotNull Collection<WhiteSpaceFormattingStrategy> strategies)
throws IllegalArgumentException
{
for (WhiteSpaceFormattingStrategy strategy : strategies) {
addStrategy(strategy);
}
}
@Override
@@ -64,9 +68,9 @@ public class CompositeWhiteSpaceFormattingStrategy implements WhiteSpaceFormatti
return myReplaceDefaultStrategy;
}
public void addStrategy(@NotNull WhiteSpaceFormattingStrategy strategy) throws IllegalStateException {
public void addStrategy(@NotNull WhiteSpaceFormattingStrategy strategy) throws IllegalArgumentException {
if (myReplaceDefaultStrategy && strategy.replaceDefaultStrategy()) {
throw new IllegalStateException(String.format(
throw new IllegalArgumentException(String.format(
"Can't combine strategy '%s' with already registered strategies (%s). Reason: given strategy is marked to replace "
+ "all existing strategies but strategy with such characteristics is already registered", strategy, myStrategies
));