Skip to content

Commit

Permalink
Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
YTG1234 committed Nov 7, 2020
1 parent 0754430 commit 02c0ea7
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,86 @@
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;

/**
* A check that verifies that all Mixin methods have a configurable annotation (by default {@code FromModule}).
*
* @author YTG1234
* @since 1.0.0
*/
public class FromModuleCheck extends AbstractCheck {
/**
* The configurable annotation.
*
* @since 2.0.0
*/
private String annotation = "FromModule";

/**
* A setter method for {@link #annotation}.
*
* @param annotation The required annotation for Mixin injections.
*
* @see #annotation
* @since 2.0.0
*/
public void setAnnotation(String annotation) {
this.annotation = annotation;
}

/**
* Returns the default token a check is interested in. Only used if the
* configuration for a check does not define the tokens.
*
* @return the default tokens
*
* @see TokenTypes
* @since 1.0.0
*/
@Override
public int[] getDefaultTokens() {
return new int[] {TokenTypes.METHOD_DEF};
}

/**
* 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
* @since 1.0.0
*/
@Override
public int[] getAcceptableTokens() {
return getRequiredTokens();
return getDefaultTokens();
}

/**
* The tokens that this check must be registered for.
*
* @return the token set this must be registered for.
*
* @see TokenTypes
* @since 1.0.0
*/
@Override
public int[] getRequiredTokens() {
return getDefaultTokens();
}

/**
* Visits all {@link TokenTypes#METHOD_DEF} tokens in the file structure.
* <p>
* For each token, looks for annotation tokens. If one (or more) Mixin injection annotation is present,
* the {@link FromModuleCheck#annotation required annotation} is required on the method.
* </p>
*
* @param ast The token to visit.
*
* @since 1.0.0
*/
@Override
public void visitToken(DetailAST ast) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,107 @@
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;

/**
* <p>
* A check that forces all subclasses of a {@link #superclass configurable superclass} to
* have a certain {@link #suffix configurable suffix} at the end of their name.
* </p>
*
* <em>This check is not used in proton.</em>
*
* @author YTG1234
* @since 2.0.0
*/
public class ModuleSuffixCheck extends AbstractCheck {
/**
* The superclass of which its subclasses must have {@link #suffix a suffix}.
*
* @since 2.0.0
*/
private String superclass = "ProtonModule";
/**
* The suffix that subclasses of the {@link #superclass} must have.
*
* @since 2.0.0
*/
private String suffix = "Module";

/**
* A setter for {@link #superclass}.
*
* @param superclass The new superclass value.
*
* @see #superclass
*/
public void setSuperclass(String superclass) {
this.superclass = superclass;
}

/**
* A setter for {@link #suffix}
*
* @param suffix The new suffix.
*
* @see #suffix
*/
public void setSuffix(String suffix) {
this.suffix = suffix;
}

/**
* Returns the default token a check is interested in. Only used if the
* configuration for a check does not define the tokens.
*
* @return the default tokens
*
* @see TokenTypes
* @since 2.0.0
*/
@Override
public int[] getDefaultTokens() {
return new int[] {TokenTypes.CLASS_DEF};
}

/**
* Returns the default token a check is interested in. Only used if the
* configuration for a check does not define the tokens.
*
* @return the default tokens
*
* @see TokenTypes
* @since 2.0.0
*/
@Override
public int[] getAcceptableTokens() {
return getDefaultTokens();
}

/**
* Returns the default token a check is interested in. Only used if the
* configuration for a check does not define the tokens.
*
* @return the default tokens
*
* @see TokenTypes
* @since 2.0.0
*/
@Override
public int[] getRequiredTokens() {
return getDefaultTokens();
}

/**
* Called for every {@link TokenTypes#CLASS_DEF} token.
* <p>
* For each token, looks for an extends clause that contains {@link #superclass},
* and logs an error if the class name doesn't end with {@link #suffix}
* </p>
*
* @param ast The token.
*
* @see #superclass
* @see #suffix
*/
@Override
public void visitToken(DetailAST ast) {
if (ast.findFirstToken(TokenTypes.EXTENDS_CLAUSE) == null) return;
Expand Down

0 comments on commit 02c0ea7

Please sign in to comment.