Revert "Made getRequiredTokens and getAcceptableTokens as abstract, issue #655" as we will do that in 7.0 version

This reverts commit efac6bf023.
This commit is contained in:
Roman Ivanov 2015-08-25 05:30:17 -07:00
parent 34c2bf22b7
commit eec72ee84c
2 changed files with 47 additions and 2 deletions

View File

@ -22,6 +22,8 @@ package com.puppycrawl.tools.checkstyle.api;
import java.util.Collections;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import com.google.common.collect.Sets;
import com.puppycrawl.tools.checkstyle.Utils;
@ -70,17 +72,25 @@ public abstract class Check extends AbstractViolationReporter {
* The configurable token set.
* Used to protect Checks against malicious users who specify an
* unacceptable token set in the configuration file.
* The default implementation returns the check's default tokens.
* @return the token set this check is designed for.
* @see TokenTypes
*/
public abstract int[] getAcceptableTokens();
public int[] getAcceptableTokens() {
final int[] defaultTokens = getDefaultTokens();
final int[] copy = new int[defaultTokens.length];
System.arraycopy(defaultTokens, 0, copy, 0, defaultTokens.length);
return copy;
}
/**
* The tokens that this check must be registered for.
* @return the token set this must be registered for.
* @see TokenTypes
*/
public abstract int[] getRequiredTokens();
public int[] getRequiredTokens() {
return ArrayUtils.EMPTY_INT_ARRAY;
}
/**
* Adds a set of tokens the check is interested in.

View File

@ -20,10 +20,45 @@
package com.puppycrawl.tools.checkstyle.api;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Assert;
import org.junit.Test;
public class CheckTest {
@Test
public void testGetRequiredTokens() {
Check check = new Check() {
@Override
public int[] getDefaultTokens() {
return ArrayUtils.EMPTY_INT_ARRAY;
}
@Override
public int[] getRequiredTokens() {
return super.getRequiredTokens();
}
};
// Eventually it will become clear abstract method
Assert.assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, check.getRequiredTokens());
}
@Test
public void testGetAcceptable() {
Check check = new Check() {
@Override
public int[] getDefaultTokens() {
return ArrayUtils.EMPTY_INT_ARRAY;
}
@Override
public int[] getAcceptableTokens() {
return super.getAcceptableTokens();
}
};
// Eventually it will become clear abstract method
Assert.assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, check.getAcceptableTokens());
}
@Test
public void testVisitToken() {
Check check = new Check() {