Skip to content

Commit

Permalink
style: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ymind committed Sep 23, 2020
1 parent dea20fc commit c811e0d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 31 deletions.
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
rootProject.name = 'semantic-commit'

Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import team.yi.tools.semanticcommit.CommitUtils;
import team.yi.tools.semanticcommit.model.GitCommit;
import team.yi.tools.semanticcommit.model.IssueRef;
import team.yi.tools.semanticcommit.model.MentionRef;
import team.yi.tools.semanticcommit.model.ReleaseCommit;
import team.yi.tools.semanticcommit.model.ReleaseCommitLocale;
import team.yi.tools.semanticcommit.parser.lexer.CommitLexer;
import team.yi.tools.semanticcommit.parser.lexer.LexerConstants;
import team.yi.tools.semanticcommit.parser.lexer.Token;
import team.yi.tools.semanticcommit.parser.lexer.TokenKind;

import java.io.IOException;
import team.yi.tools.semanticcommit.model.*;
import team.yi.tools.semanticcommit.parser.lexer.*;

import java.util.List;
import java.util.Locale;

Expand All @@ -25,7 +17,7 @@ public class CommitParser extends Parser<ReleaseCommit, CommitLexer> {
private final List<String> closeIssueActions;
private ReleaseCommit releaseCommit;

public CommitParser(final CommitParserSettings settings, final GitCommit gitCommit) throws IOException {
public CommitParser(final CommitParserSettings settings, final GitCommit gitCommit) {
super(new CommitLexer(gitCommit.getMessage(), settings.getCloseIssueActions()));

this.settings = settings;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/team/yi/tools/semanticcommit/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import team.yi.tools.semanticcommit.parser.lexer.Lexer;
import team.yi.tools.semanticcommit.parser.lexer.Token;
import team.yi.tools.semanticcommit.parser.lexer.TokenKind;
import team.yi.tools.semanticcommit.parser.lexer.*;

import java.text.MessageFormat;
import java.util.Objects;
Expand Down Expand Up @@ -42,6 +40,7 @@ public void reset() {

public abstract T parse();

@SuppressWarnings("UnusedReturnValue")
protected Token consume() {
final Token old = this.current;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CommitLexer(final File file, final Charset charset, final List<String> cl
this(new String(Files.readAllBytes(file.toPath()), charset).trim(), closeIssueActions);
}

public CommitLexer(final String contents, final List<String> closeIssueActions) throws IOException {
public CommitLexer(final String contents, final List<String> closeIssueActions) {
super(contents);

this.closeIssueActions = closeIssueActions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public CommitLocaleLexer(final File file, final Charset charset) throws IOExcept
super(file, charset);
}

public CommitLocaleLexer(final String contents) throws IOException {
public CommitLocaleLexer(final String contents) {
super(contents);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;
import java.util.*;

@SuppressWarnings("PMD.TooManyMethods")
public abstract class Lexer {
Expand Down Expand Up @@ -123,6 +121,7 @@ protected final void consume(final int count) {
}
}

@SuppressWarnings("SameParameterValue")
protected final Token createToken(final TokenKind kind, final char value) {
return this.createToken(kind, String.valueOf(value));
}
Expand Down Expand Up @@ -190,6 +189,7 @@ else if (LexerConstants.DOT == ch && !hasDot && Character.isDigit(this.la(1))) {
return this.createToken(hasDot ? TokenKind.numberDouble : TokenKind.numberInteger);
}

@SuppressWarnings("SameParameterValue")
protected final String pick(final int start, final int maxLength) {
int i = start;
final StringBuilder b = new StringBuilder();
Expand All @@ -213,6 +213,7 @@ protected final String pickWhitespace(final int start) {
return pickWhitespace(start, Integer.MAX_VALUE);
}

@SuppressWarnings("SameParameterValue")
protected final String pickWhitespace(final int start, final int maxLength) {
int i = start;
final StringBuilder b = new StringBuilder();
Expand All @@ -236,6 +237,7 @@ protected final String pickNumberInteger(final int start) {
return pickNumberInteger(start, Integer.MAX_VALUE);
}

@SuppressWarnings("SameParameterValue")
protected final String pickNumberInteger(final int start, final int maxLength) {
int i = start;
final StringBuilder b = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ScopeProfileLexer(final File file, final Charset charset) throws IOExcept
super(file, charset);
}

public ScopeProfileLexer(final String contents) throws IOException {
public ScopeProfileLexer(final String contents) {
super(contents);
}

Expand Down
12 changes: 3 additions & 9 deletions src/test/java/team/yi/tools/GitCommitParserTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@
import org.apache.commons.lang3.time.DateUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import team.yi.tools.semanticcommit.model.GitCommit;
import team.yi.tools.semanticcommit.model.GitDate;
import team.yi.tools.semanticcommit.model.GitPersonIdent;
import team.yi.tools.semanticcommit.model.ReleaseCommit;
import team.yi.tools.semanticcommit.model.*;
import team.yi.tools.semanticcommit.parser.CommitParser;
import team.yi.tools.semanticcommit.parser.CommitParserSettings;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.*;
import java.text.ParseException;
import java.util.Date;

Expand All @@ -42,9 +37,8 @@ public void init() throws URISyntaxException, ParseException, IOException {
final GitPersonIdent committerIdent = new GitPersonIdent(commitTime, "ymind", "ymind.chan@yi.team");
final String hashFull = "02ce19bbbf7058f474f760fe4a4447301190dea9";
final String message = new String(Files.readAllBytes(path), UTF_8).trim();
final Boolean isMerge = false;

final GitCommit gitCommit = new GitCommit(hashFull, commitTime, message, isMerge, authorIdent, committerIdent);
final GitCommit gitCommit = new GitCommit(hashFull, commitTime, message, false, authorIdent, committerIdent);
final CommitParserSettings settings = CommitParserSettings.builder().build();

this.parser = new CommitParser(settings, gitCommit);
Expand Down

0 comments on commit c811e0d

Please sign in to comment.