Fix quality flaws

This commit is contained in:
Simon Brandhof 2012-10-23 11:12:33 +02:00
parent c408b3c0bf
commit 8a8788fb4e
19 changed files with 81 additions and 81 deletions

View File

@ -19,7 +19,7 @@
*/
package org.sonar.channel;
public abstract class Channel<OUTPUT> {
public abstract class Channel<O> {
/**
* Tries to consume the character stream at the current reading cursor position (provided by the {@link org.sonar.channel.CodeReader}). If
@ -31,5 +31,5 @@ public abstract class Channel<OUTPUT> {
* the OUTPUT that can be optionally fed by the Channel
* @return false if the Channel doesn't want to consume the character stream, true otherwise.
*/
public abstract boolean consume(CodeReader code, OUTPUT output);
public abstract boolean consume(CodeReader code, O output);
}

View File

@ -27,10 +27,10 @@ import java.io.Reader;
* declared for the CodeReader.
*
*/
public final class ChannelCodeReaderFilter<OUTPUT> extends CodeReaderFilter<OUTPUT> {
public final class ChannelCodeReaderFilter<O> extends CodeReaderFilter<O> {
@SuppressWarnings("unchecked")
private Channel<OUTPUT>[] channels = new Channel[0];
private Channel<O>[] channels = new Channel[0];
private CodeReader internalCodeReader;
@ -40,7 +40,7 @@ public final class ChannelCodeReaderFilter<OUTPUT> extends CodeReaderFilter<OUTP
* @param channels
* the different channels
*/
public ChannelCodeReaderFilter(Channel<OUTPUT>... channels) {
public ChannelCodeReaderFilter(Channel<O>... channels) {
super();
this.channels = channels;
}
@ -54,7 +54,7 @@ public final class ChannelCodeReaderFilter<OUTPUT> extends CodeReaderFilter<OUTP
* @param channels
* the different channels
*/
public ChannelCodeReaderFilter(OUTPUT output, Channel<OUTPUT>... channels) {
public ChannelCodeReaderFilter(O output, Channel<O>... channels) {
super(output);
this.channels = channels;
}
@ -82,7 +82,7 @@ public final class ChannelCodeReaderFilter<OUTPUT> extends CodeReaderFilter<OUTP
break;
}
boolean consumed = false;
for (Channel<OUTPUT> channel : channels) {
for (Channel<O> channel : channels) {
if (channel.consume(internalCodeReader, getOutput())) {
consumed = true;
break;

View File

@ -27,12 +27,12 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChannelDispatcher<OUTPUT> extends Channel<OUTPUT> {
public class ChannelDispatcher<O> extends Channel<O> {
private static final Logger LOG = LoggerFactory.getLogger(ChannelDispatcher.class);
private final boolean failIfNoChannelToConsumeOneCharacter;
private final Channel<OUTPUT>[] channels;
private final Channel<O>[] channels;
/**
* @deprecated in version 2.9. Please use the builder() method
@ -68,11 +68,11 @@ public class ChannelDispatcher<OUTPUT> extends Channel<OUTPUT> {
}
@Override
public boolean consume(CodeReader code, OUTPUT output) {
public boolean consume(CodeReader code, O output) {
int nextChar = code.peek();
while (nextChar != -1) {
boolean characterConsumed = false;
for (Channel<OUTPUT> channel : channels) {
for (Channel<O> channel : channels) {
if (channel.consume(code, output)) {
characterConsumed = true;
break;

View File

@ -33,18 +33,18 @@ import java.io.Reader;
* @see CodeBufferTest#testSeveralCodeReaderFilter()
*
*/
public abstract class CodeReaderFilter<OUTPUT> {
public abstract class CodeReaderFilter<O> {
private Reader reader;
private OUTPUT output;
private O output;
private CodeReaderConfiguration configuration;
public CodeReaderFilter() {
}
public CodeReaderFilter(OUTPUT output) {
public CodeReaderFilter(O output) {
this.output = output;
}
@ -72,7 +72,7 @@ public abstract class CodeReaderFilter<OUTPUT> {
*
* @return the output
*/
public OUTPUT getOutput() {
public O getOutput() {
return output;
}
@ -82,7 +82,7 @@ public abstract class CodeReaderFilter<OUTPUT> {
* @param output
* the output to set
*/
public void setOutput(OUTPUT output) {
public void setOutput(O output) {
this.output = output;
}

View File

@ -25,7 +25,7 @@ import java.util.regex.Pattern;
/**
* The RegexChannel can be used to be called each time the next characters in the character stream match a regular expression
*/
public abstract class RegexChannel<OUTPUT> extends Channel<OUTPUT> {
public abstract class RegexChannel<O> extends Channel<O> {
private final StringBuilder tmpBuilder = new StringBuilder();
private final Matcher matcher;
@ -41,7 +41,7 @@ public abstract class RegexChannel<OUTPUT> extends Channel<OUTPUT> {
}
@Override
public final boolean consume(CodeReader code, OUTPUT output) {
public final boolean consume(CodeReader code, O output) {
if (code.popTo(matcher, tmpBuilder) > 0) {
consume(tmpBuilder, output);
tmpBuilder.delete(0, tmpBuilder.length());
@ -59,6 +59,6 @@ public abstract class RegexChannel<OUTPUT> extends Channel<OUTPUT> {
* @param the
* OUPUT object which can be optionally fed
*/
protected abstract void consume(CharSequence token, OUTPUT output);
protected abstract void consume(CharSequence token, O output);
}

View File

@ -29,10 +29,10 @@ import java.util.Map;
/**
* @since 2.3
*/
public abstract class CheckFactory<CHECK> {
public abstract class CheckFactory<C> {
private Map<ActiveRule, CHECK> checkByActiveRule = Maps.newIdentityHashMap();
private Map<CHECK, ActiveRule> activeRuleByCheck = Maps.newIdentityHashMap();
private Map<ActiveRule, C> checkByActiveRule = Maps.newIdentityHashMap();
private Map<C, ActiveRule> activeRuleByCheck = Maps.newIdentityHashMap();
private RulesProfile profile;
private String repositoryKey;
@ -45,27 +45,27 @@ public abstract class CheckFactory<CHECK> {
checkByActiveRule.clear();
activeRuleByCheck.clear();
for (ActiveRule activeRule : profile.getActiveRulesByRepository(repositoryKey)) {
CHECK check = createCheck(activeRule);
C check = createCheck(activeRule);
checkByActiveRule.put(activeRule, check);
activeRuleByCheck.put(check, activeRule);
}
}
abstract CHECK createCheck(ActiveRule activeRule);
abstract C createCheck(ActiveRule activeRule);
public final String getRepositoryKey() {
return repositoryKey;
}
public final Collection<CHECK> getChecks() {
public final Collection<C> getChecks() {
return checkByActiveRule.values();
}
public final CHECK getCheck(ActiveRule activeRule) {
public final C getCheck(ActiveRule activeRule) {
return checkByActiveRule.get(activeRule);
}
public final ActiveRule getActiveRule(CHECK check) {
public final ActiveRule getActiveRule(C check) {
return activeRuleByCheck.get(check);
}
}

View File

@ -27,30 +27,30 @@ import java.util.TreeMap;
/**
* @since 1.10
*/
public class PropertiesBuilder<KEY, VALUE> {
public class PropertiesBuilder<K, V> {
private Metric metric;
private Map<KEY, VALUE> props;
private Map<K, V> props;
public PropertiesBuilder(Metric metric, Map<KEY, VALUE> map) {
this.props = new TreeMap<KEY, VALUE>(map);
public PropertiesBuilder(Metric metric, Map<K, V> map) {
this.props = new TreeMap<K, V>(map);
this.metric = metric;
}
public PropertiesBuilder(Metric metric) {
this.props = new TreeMap<KEY, VALUE>();
this.props = new TreeMap<K, V>();
this.metric = metric;
}
public PropertiesBuilder() {
this.props = new TreeMap<KEY, VALUE>();
this.props = new TreeMap<K, V>();
}
public PropertiesBuilder<KEY, VALUE> clear() {
public PropertiesBuilder<K, V> clear() {
this.props.clear();
return this;
}
public Map<KEY, VALUE> getProps() {
public Map<K, V> getProps() {
return props;
}
@ -58,17 +58,17 @@ public class PropertiesBuilder<KEY, VALUE> {
return metric;
}
public PropertiesBuilder<KEY, VALUE> setMetric(Metric metric) {
public PropertiesBuilder<K, V> setMetric(Metric metric) {
this.metric = metric;
return this;
}
public PropertiesBuilder<KEY, VALUE> add(KEY key, VALUE value) {
public PropertiesBuilder<K, V> add(K key, V value) {
props.put(key, value);
return this;
}
public PropertiesBuilder<KEY, VALUE> addAll(Map<KEY, VALUE> map) {
public PropertiesBuilder<K, V> addAll(Map<K, V> map) {
props.putAll(map);
return this;
}

View File

@ -326,11 +326,11 @@ public final class KeyValueFormat {
* @deprecated since 2.7
*/
@Deprecated
public static <KEY, VALUE> Map<KEY, VALUE> parse(String data, Transformer<KEY, VALUE> transformer) {
public static <K, V> Map<K, V> parse(String data, Transformer<K, V> transformer) {
Map<String, String> rawData = parse(data);
Map<KEY, VALUE> map = new HashMap<KEY, VALUE>();
Map<K, V> map = new HashMap<K, V>();
for (Map.Entry<String, String> entry : rawData.entrySet()) {
KeyValue<KEY, VALUE> keyVal = transformer.transform(entry.getKey(), entry.getValue());
KeyValue<K, V> keyVal = transformer.transform(entry.getKey(), entry.getValue());
if (keyVal != null) {
map.put(keyVal.getKey(), keyVal.getValue());
}

View File

@ -74,12 +74,12 @@ public class Squid implements DirectedGraphAccessor<SourceCode, SourceCodeEdge>,
externalCodeVisitors.add(pico.getComponent(visitor));
}
public <SCANNER extends CodeScanner> SCANNER register(Class<SCANNER> scannerClass) {
public <S extends CodeScanner> S register(Class<S> scannerClass) {
if(pico.getComponent(scannerClass) != null){
throw new IllegalStateException("The Squid SCANNER '" + scannerClass.getName() + "' can't be registered multiple times.");
}
addToPicocontainer(scannerClass);
SCANNER scanner = pico.getComponent(scannerClass);
S scanner = pico.getComponent(scannerClass);
for (Object clazz : scanner.getVisitorClasses()) {
addToPicocontainer((Class) clazz);
scanner.accept(pico.<CodeVisitor> getComponent((Class) clazz));

View File

@ -24,17 +24,17 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public abstract class CodeScanner<VISITOR extends CodeVisitor> {
public abstract class CodeScanner<V extends CodeVisitor> {
private List<CodeVisitor> visitors = new ArrayList<CodeVisitor>();
public abstract Collection<Class<? extends VISITOR>> getVisitorClasses();
public abstract Collection<Class<? extends V>> getVisitorClasses();
public void accept(CodeVisitor visitor) {
visitors.add(visitor);
}
public List<VISITOR> getVisitors() {
return (List<VISITOR>) visitors;
public List<V> getVisitors() {
return (List<V>) visitors;
}
}

View File

@ -203,20 +203,20 @@ public abstract class SourceCode implements Measurable, Comparable<SourceCode> {
return this;
}
public <SOURCECODE extends SourceCode> SOURCECODE getParent(Class<SOURCECODE> sourceCode) {
public <S extends SourceCode> S getParent(Class<S> sourceCode) {
if (parent == null) {
return null;
}
if (parent.getClass().equals(sourceCode)) {
return (SOURCECODE) parent;
return (S) parent;
}
return parent.getParent(sourceCode);
}
public <SOURCECODE extends SourceCode> SOURCECODE getAncestor(Class<SOURCECODE> withClass) {
SOURCECODE ancestor = getParent(withClass);
public <S extends SourceCode> S getAncestor(Class<S> withClass) {
S ancestor = getParent(withClass);
if (ancestor!=null) {
SOURCECODE parentAncestor = ancestor.getAncestor(withClass);
S parentAncestor = ancestor.getAncestor(withClass);
if (parentAncestor!=null) {
ancestor = parentAncestor;
}

View File

@ -26,12 +26,12 @@ public final class ChannelMatchers {
private ChannelMatchers() {
}
public static <OUTPUT> ChannelMatcher<OUTPUT> consume(String sourceCode, OUTPUT output) {
return new ChannelMatcher<OUTPUT>(sourceCode, output);
public static <O> ChannelMatcher<O> consume(String sourceCode, O output) {
return new ChannelMatcher<O>(sourceCode, output);
}
public static <OUTPUT> ChannelMatcher<OUTPUT> consume(CodeReader codeReader, OUTPUT output) {
return new ChannelMatcher<OUTPUT>(codeReader, output);
public static <O> ChannelMatcher<O> consume(CodeReader codeReader, O output) {
return new ChannelMatcher<O>(codeReader, output);
}
public static ReaderHasNextCharMatcher hasNextChar(char nextChar) {

View File

@ -45,12 +45,12 @@ public class Sonar {
return connector;
}
public <MODEL extends Model> MODEL find(Query<MODEL> query) {
public <M extends Model> M find(Query<M> query) {
String json = connector.execute(query);
MODEL result = null;
M result = null;
if (json != null) {
try {
Unmarshaller<MODEL> unmarshaller = Unmarshallers.forModel(query.getModelClass());
Unmarshaller<M> unmarshaller = Unmarshallers.forModel(query.getModelClass());
result = unmarshaller.toModel(json);
} catch (Exception e) {
throw new UnmarshalException(query, json, e);
@ -59,14 +59,14 @@ public class Sonar {
return result;
}
public <MODEL extends Model> List<MODEL> findAll(Query<MODEL> query) {
public <M extends Model> List<M> findAll(Query<M> query) {
String json = connector.execute(query);
List<MODEL> result;
List<M> result;
if (json == null) {
result = Collections.emptyList();
} else {
try {
Unmarshaller<MODEL> unmarshaller = Unmarshallers.forModel(query.getModelClass());
Unmarshaller<M> unmarshaller = Unmarshallers.forModel(query.getModelClass());
result = unmarshaller.toModels(json);
} catch (Exception e) {
throw new UnmarshalException(query, json, e);
@ -75,12 +75,12 @@ public class Sonar {
return result;
}
public <MODEL extends Model> MODEL create(CreateQuery<MODEL> query) {
public <M extends Model> M create(CreateQuery<M> query) {
String json = connector.execute(query);
MODEL result = null;
M result = null;
if (json != null) {
try {
Unmarshaller<MODEL> unmarshaller = Unmarshallers.forModel(query.getModelClass());
Unmarshaller<M> unmarshaller = Unmarshallers.forModel(query.getModelClass());
result = unmarshaller.toModel(json);
} catch (Exception e) {
throw new UnmarshalException(query, json, e);

View File

@ -24,7 +24,7 @@ import java.util.Date;
/**
* @since 2.2
*/
public abstract class AbstractQuery<MODEL extends Model> {
public abstract class AbstractQuery<M extends Model> {
/**
* Default timeout for waiting data, in milliseconds.
@ -72,7 +72,7 @@ public abstract class AbstractQuery<MODEL extends Model> {
*
* @since 2.10
*/
public final AbstractQuery<MODEL> setTimeoutMilliseconds(int i) {
public final AbstractQuery<M> setTimeoutMilliseconds(int i) {
this.timeoutMilliseconds = (i < 0 ? 0 : i);
return this;
}
@ -91,7 +91,7 @@ public abstract class AbstractQuery<MODEL extends Model> {
*
* @since 2.10
*/
public final AbstractQuery<MODEL> setLocale(String locale) {
public final AbstractQuery<M> setLocale(String locale) {
this.locale = locale;
return this;
}

View File

@ -24,8 +24,8 @@ package org.sonar.wsclient.services;
*
* @since 2.2
*/
public abstract class CreateQuery<MODEL extends Model> extends AbstractQuery<MODEL> {
public abstract class CreateQuery<M extends Model> extends AbstractQuery<M> {
public abstract Class<MODEL> getModelClass();
public abstract Class<M> getModelClass();
}

View File

@ -22,8 +22,8 @@ package org.sonar.wsclient.services;
/**
* @since 2.1
*/
public abstract class Query<MODEL extends Model> extends AbstractQuery<MODEL> {
public abstract class Query<M extends Model> extends AbstractQuery<M> {
public abstract Class<MODEL> getModelClass();
public abstract Class<M> getModelClass();
}

View File

@ -24,8 +24,8 @@ package org.sonar.wsclient.services;
*
* @since 2.6
*/
public abstract class UpdateQuery<MODEL extends Model> extends AbstractQuery<MODEL> {
public abstract class UpdateQuery<M extends Model> extends AbstractQuery<M> {
public abstract Class<MODEL> getModelClass();
public abstract Class<M> getModelClass();
}

View File

@ -25,11 +25,11 @@ import org.sonar.wsclient.services.WSUtils;
import java.util.ArrayList;
import java.util.List;
public abstract class AbstractUnmarshaller<MODEL extends Model> implements Unmarshaller<MODEL> {
public abstract class AbstractUnmarshaller<M extends Model> implements Unmarshaller<M> {
public final MODEL toModel(String json) {
public final M toModel(String json) {
WSUtils utils = WSUtils.getINSTANCE();
MODEL result = null;
M result = null;
Object array = utils.parse(json);
if (utils.getArraySize(array) >= 1) {
Object elt = utils.getArrayElement(array, 0);
@ -41,9 +41,9 @@ public abstract class AbstractUnmarshaller<MODEL extends Model> implements Unmar
}
public final List<MODEL> toModels(String json) {
public final List<M> toModels(String json) {
WSUtils utils = WSUtils.getINSTANCE();
List<MODEL> result = new ArrayList<MODEL>();
List<M> result = new ArrayList<M>();
Object array = utils.parse(json);
for (int i = 0; i < utils.getArraySize(array); i++) {
Object elt = utils.getArrayElement(array, i);
@ -54,5 +54,5 @@ public abstract class AbstractUnmarshaller<MODEL extends Model> implements Unmar
return result;
}
protected abstract MODEL parse(Object elt);
protected abstract M parse(Object elt);
}

View File

@ -70,7 +70,7 @@ public final class Unmarshallers {
unmarshallers.put(Authentication.class, new AuthenticationUnmarshaller());
}
public static <MODEL extends Model> Unmarshaller<MODEL> forModel(Class<MODEL> modelClass) {
public static <M extends Model> Unmarshaller<M> forModel(Class<M> modelClass) {
return unmarshallers.get(modelClass);
}
}