Skip to content

Commit

Permalink
Merge 0c055cb into 65e8237
Browse files Browse the repository at this point in the history
  • Loading branch information
a4sriniv committed Feb 12, 2016
2 parents 65e8237 + 0c055cb commit b7c410d
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 168 deletions.
17 changes: 4 additions & 13 deletions src/main/java/com/sleekbyte/tailor/Tailor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
import com.sleekbyte.tailor.integration.XcodeIntegrator;
import com.sleekbyte.tailor.listeners.BlankLineListener;
import com.sleekbyte.tailor.listeners.BraceStyleListener;
import com.sleekbyte.tailor.listeners.ConstantNamingListener;
import com.sleekbyte.tailor.listeners.DeclarationListener;
import com.sleekbyte.tailor.listeners.ErrorListener;
import com.sleekbyte.tailor.listeners.FileListener;
import com.sleekbyte.tailor.listeners.KPrefixListener;
import com.sleekbyte.tailor.listeners.TodoCommentListener;
import com.sleekbyte.tailor.listeners.lengths.MaxLengthListener;
import com.sleekbyte.tailor.listeners.lengths.MinLengthListener;
Expand Down Expand Up @@ -126,7 +123,9 @@ private List<SwiftBaseListener> createListeners(Set<Rules> enabledRules,
CommentExtractor commentExtractor = new CommentExtractor(tokenStream);
if (className.equals(FileListener.class.getName())) {
continue;
} else if (className.equals(CommentWhitespaceListener.class.getName())) {
}

if (className.equals(CommentWhitespaceListener.class.getName())) {
CommentWhitespaceListener commentWhitespaceListener = new CommentWhitespaceListener(printer,
commentExtractor.getSingleLineComments(), commentExtractor.getMultilineComments());
commentWhitespaceListener.analyze();
Expand All @@ -150,8 +149,6 @@ private List<SwiftBaseListener> createListeners(Set<Rules> enabledRules,

listeners.add(new MinLengthListener(printer, constructLengths, enabledRules));
listeners.add(new MaxLengthListener(printer, constructLengths, enabledRules));
DeclarationListener decListener = new DeclarationListener(listeners);
listeners.add(decListener);

return listeners;
}
Expand Down Expand Up @@ -210,13 +207,7 @@ private Optional<TopLevelContext> getParseTree(Optional<CommonTokenStream> token
*/
private void walkParseTree(List<SwiftBaseListener> listeners, TopLevelContext tree) {
ParseTreeWalker walker = new ParseTreeWalker();
for (SwiftBaseListener listener : listeners) {
// The following listeners are used by DeclarationListener to walk the tree
if (listener instanceof ConstantNamingListener || listener instanceof KPrefixListener) {
continue;
}
walker.walk(listener, tree);
}
listeners.forEach(listener -> walker.walk(listener, tree));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.sleekbyte.tailor.listeners;

import com.sleekbyte.tailor.antlr.SwiftBaseListener;
import com.sleekbyte.tailor.antlr.SwiftParser;
import com.sleekbyte.tailor.antlr.SwiftParser.IdentifierContext;
import com.sleekbyte.tailor.antlr.SwiftParser.TopLevelContext;
import com.sleekbyte.tailor.common.Location;
import com.sleekbyte.tailor.common.Messages;
import com.sleekbyte.tailor.common.Rules;
Expand All @@ -10,6 +11,8 @@
import com.sleekbyte.tailor.utils.ListenerUtil;
import org.antlr.v4.runtime.ParserRuleContext;

import java.util.List;

/**
* Parse tree listener for constant naming style checks.
*/
Expand All @@ -22,24 +25,29 @@ public ConstantNamingListener(Printer printer) {
}

@Override
public void enterIdentifier(SwiftParser.IdentifierContext ctx) {
String constantName = ctx.getText();
ParserRuleContext constantDecContext = ConstantDecHelper.getConstantDeclaration(ctx);
Location location = ListenerUtil.getContextStartLocation(ctx);

if (ConstantDecHelper.isGlobal(constantDecContext)
|| ConstantDecHelper.insideClass(constantDecContext)
|| ConstantDecHelper.insideStruct(constantDecContext)) {
if (!CharFormatUtil.isUpperCamelCase(constantName)
&& !CharFormatUtil.isLowerCamelCaseOrAcronym(constantName)) {
printer.error(Rules.CONSTANT_NAMING, Messages.GLOBAL + Messages.CONSTANT
+ Messages.GLOBAL_CONSTANT_NAMING, location);
}
} else {
if (!CharFormatUtil.isLowerCamelCaseOrAcronym(constantName)) {
printer.error(Rules.CONSTANT_NAMING, Messages.CONSTANT + Messages.LOWER_CAMEL_CASE, location);
public void enterTopLevel(TopLevelContext topLevelContext) {
List<IdentifierContext> names = DeclarationListener.getConstantNames(topLevelContext);

names.forEach(
ctx -> {
String constantName = ctx.getText();
ParserRuleContext constantDecContext = ConstantDecHelper.getConstantDeclaration(ctx);
Location location = ListenerUtil.getContextStartLocation(ctx);

if (ConstantDecHelper.isGlobal(constantDecContext)
|| ConstantDecHelper.insideClass(constantDecContext)
|| ConstantDecHelper.insideStruct(constantDecContext)) {
if (!CharFormatUtil.isUpperCamelCase(constantName)
&& !CharFormatUtil.isLowerCamelCaseOrAcronym(constantName)) {
printer.error(Rules.CONSTANT_NAMING, Messages.GLOBAL + Messages.CONSTANT
+ Messages.GLOBAL_CONSTANT_NAMING, location);
}
} else {
if (!CharFormatUtil.isLowerCamelCaseOrAcronym(constantName)) {
printer.error(Rules.CONSTANT_NAMING, Messages.CONSTANT + Messages.LOWER_CAMEL_CASE, location);
}
}
}
}
);
}

}
Loading

0 comments on commit b7c410d

Please sign in to comment.