Skip to content

Commit

Permalink
Fix quality flaws
Browse files Browse the repository at this point in the history
  • Loading branch information
racodond committed Aug 25, 2016
1 parent dc9236b commit 4f703ad
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ private TreeCheckTest() {
public static Collection<CheckMessage> getIssues(String relativePath, CssCheck check, Charset charset) {
File file = new File(relativePath);

CssTree CssTree = (CssTree) CssParserBuilder.createParser(charset).parse(file);
CssVisitorContext context = new CssVisitorContext(CssTree, file);
CssTree tree = (CssTree) CssParserBuilder.createParser(charset).parse(file);
CssVisitorContext context = new CssVisitorContext(tree, file);
List<Issue> issues = check.scanFile(context);

return getCheckMessages(issues);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ private boolean isFontFaceRuleToBeChecked(AtRuleTree tree) {

private boolean definesScrPropertyWithUrl(List<PropertyDeclarationTree> declarations) {
for (PropertyDeclarationTree declaration : declarations)
if (declaration.property().standardProperty() instanceof Src) {
if (!declaration.value().valueElementsOfType(UriTree.class).isEmpty()) {
return true;
}
if (declaration.property().standardProperty() instanceof Src
&& !declaration.value().valueElementsOfType(UriTree.class).isEmpty()) {
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public class RuleDescriptionsGenerator {
.build();

public void generateHtmlRuleDescription(String templatePath, String outputPath) throws IOException {
try {
Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputPath), UTF_8));
try (OutputStream fileOutputStream = new FileOutputStream(outputPath)) {
Writer writer = new BufferedWriter(new OutputStreamWriter(fileOutputStream, UTF_8));
writer.write(replaceTags(FileUtils.readFileToString(new File(templatePath), UTF_8)));
writer.flush();
writer.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class UseShorthandPropertyCheck extends SubscriptionVisitorCheck {

private final Map<String, PropertyTree> declaredProperties = new HashMap<>();

@Override
public List<Tree.Kind> nodesToVisit() {
return ImmutableList.of(
Tree.Kind.RULESET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@ private static void tokens(LexerlessGrammarBuilder b) {
}

private static void spacing(LexerlessGrammarBuilder b) {
String COMMENT_REGEX = "(?:/\\*[\\s\\S]*?\\*/)";
String COMMENT2_REGEX = "(?:\\<\\!--[\\s\\S]*?--\\>)";
String commentRegex1 = "(?:/\\*[\\s\\S]*?\\*/)";
String commentRegex2 = "(?:\\<\\!--[\\s\\S]*?--\\>)";

b.rule(SPACING).is(
b.skippedTrivia(b.regexp("(?<!\\\\)[\\s]*+")),
b.zeroOrMore(
b.commentTrivia(b.regexp("(?:" + COMMENT_REGEX + "|" + COMMENT2_REGEX + ")")),
b.commentTrivia(b.regexp("(?:" + commentRegex1 + "|" + commentRegex2 + ")")),
b.skippedTrivia(b.regexp("(?<!\\\\)[\\s]*+"))));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public StandardAtRule standardAtRule() {
}

private Vendor setVendor() {
for (Vendor vendor : Vendor.values()) {
if (atKeyword.keyword().text().toLowerCase(Locale.ENGLISH).startsWith(vendor.getPrefix())) {
return vendor;
for (Vendor v : Vendor.values()) {
if (atKeyword.keyword().text().toLowerCase(Locale.ENGLISH).startsWith(v.getPrefix())) {
return v;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public final boolean is(Tree.Kind... kind) {
*/
public abstract Iterator<Tree> childrenIterator();

@Override
public String treeValue() {
StringBuilder value = new StringBuilder();
Iterator<Tree> children = childrenIterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public List<Tree> parameterElements() {
}

private Vendor setVendor() {
for (Vendor vendor : Vendor.values()) {
if (function.text().toLowerCase(Locale.ENGLISH).startsWith(vendor.getPrefix())) {
return vendor;
for (Vendor v : Vendor.values()) {
if (function.text().toLowerCase(Locale.ENGLISH).startsWith(v.getPrefix())) {
return v;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public Vendor vendor() {
}

private Vendor setVendorPrefix() {
for (Vendor vendor : Vendor.values()) {
if (text().toLowerCase(Locale.ENGLISH).startsWith(vendor.getPrefix())) {
return vendor;
for (Vendor v : Vendor.values()) {
if (text().toLowerCase(Locale.ENGLISH).startsWith(v.getPrefix())) {
return v;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ private String setHack() {
}

private Vendor setVendorPrefix() {
for (Vendor vendor : Vendor.values()) {
if (property.text().toLowerCase(Locale.ENGLISH).startsWith(vendor.getPrefix())) {
return vendor;
for (Vendor v : Vendor.values()) {
if (property.text().toLowerCase(Locale.ENGLISH).startsWith(v.getPrefix())) {
return v;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public List<Tree> parameterElements() {
}

private Vendor setVendor() {
for (Vendor vendor : Vendor.values()) {
if (function.text().toLowerCase(Locale.ENGLISH).startsWith(vendor.getPrefix())) {
return vendor;
for (Vendor v : Vendor.values()) {
if (function.text().toLowerCase(Locale.ENGLISH).startsWith(v.getPrefix())) {
return v;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public Vendor vendor() {
}

private Vendor setVendor() {
for (Vendor vendor : Vendor.values()) {
if (identifier.text().toLowerCase(Locale.ENGLISH).startsWith(vendor.getPrefix())) {
return vendor;
for (Vendor v : Vendor.values()) {
if (identifier.text().toLowerCase(Locale.ENGLISH).startsWith(v.getPrefix())) {
return v;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ public List<Tree> valueElements() {
return allValueElements;
}

@Override
public <T extends Tree> List<T> valueElementsOfType(Class<T> treeType) {
return allValueElements.stream()
.filter(e -> treeType.isAssignableFrom(e.getClass()))
.map(treeType::cast)
.collect(Collectors.toList());
}

@Override
public <T extends Tree> Optional<T> firstValueElementOfType(Class<T> treeType) {
return allValueElements.stream()
.filter(e -> treeType.isAssignableFrom(e.getClass()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public List<Tree.Kind> nodesToVisit() {
public void visitNode(Tree tree) {
for (SyntaxTrivia trivia : ((SyntaxToken) tree).trivias()) {
if (!commentAnalyser.isBlank(commentAnalyser.getContents(trivia.text()))) {
String[] commentLines = commentAnalyser.getContents(trivia.text()).split("(\r)?\n|\r", -1);
String[] comments = commentAnalyser.getContents(trivia.text()).split("(\r)?\n|\r", -1);
int lineNumber = trivia.line();
for (String commentLine : commentLines) {
for (String commentLine : comments) {
if (commentLine.contains("NOSONAR")) {
noSonarLines.add(lineNumber);
} else if (!commentAnalyser.isBlank(commentLine)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ enum MATCHER {
PREFIX("^="),
SUFFIX("$=");

private static final Map<String, MATCHER> LOOKUP = new HashMap<>();

static {
for (MATCHER matcher : MATCHER.values())
LOOKUP.put(matcher.getValue(), matcher);
}

private String value;

MATCHER(String value) {
Expand All @@ -42,17 +49,9 @@ public String getValue() {
return value;
}

private static final Map<String, MATCHER> LOOKUP = new HashMap<>();

static {
for (MATCHER matcher : MATCHER.values())
LOOKUP.put(matcher.getValue(), matcher);
}

public static MATCHER getType(String value) {
return LOOKUP.get(value);
}

}

SyntaxToken attributeMatcher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ enum COMBINATOR {
FOLLOWING_SIBLING("~"),
COLUMN("||");

private static final Map<String, COMBINATOR> LOOKUP = new HashMap<>();

static {
for (COMBINATOR combinator : COMBINATOR.values())
LOOKUP.put(combinator.getValue(), combinator);
}

private String value;

COMBINATOR(String value) {
Expand All @@ -42,17 +49,9 @@ public String getValue() {
return value;
}

private static final Map<String, COMBINATOR> LOOKUP = new HashMap<>();

static {
for (COMBINATOR combinator : COMBINATOR.values())
LOOKUP.put(combinator.getValue(), combinator);
}

public static COMBINATOR getType(String value) {
return LOOKUP.get(value.trim());
}

}

SyntaxToken combinator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public interface SyntaxToken extends Tree {

String text();

String treeValue();

List<SyntaxTrivia> trivias();

int line();
Expand Down

0 comments on commit 4f703ad

Please sign in to comment.