import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
-public class CheckLoggingUtil {
+public final class CheckLoggingUtil {
public static final String LOGGER_TYPE_NAME = Logger.class.getSimpleName();
public static final String LOGGER_TYPE_FULL_NAME = Logger.class.getName();
public static final String LOGGER_VAR_NAME = "LOG";
private static final List<String> LOG_METHODS = Lists.newArrayList("LOG.debug", "LOG.info", "LOG.error", "LOG.warn", "LOG.trace");
- private CheckLoggingUtil() {}
+ private CheckLoggingUtil() {
+ throw new UnsupportedOperationException("Utility class should not be instantiated!");
+ }
public static String getTypeName(final DetailAST aAST) {
final FullIdent ident = CheckUtils.createFullType(aAST.findFirstToken(TokenTypes.TYPE));
@Override
public void visitToken(DetailAST aAST) {
final String methodName = CheckLoggingUtil.getMethodName(aAST);
- if(CheckLoggingUtil.isLogMethod(methodName)) {
+ if (CheckLoggingUtil.isLogMethod(methodName)) {
final String logMessage = aAST.findFirstToken(TokenTypes.ELIST).getFirstChild().getFirstChild().getText();
int placeholdersCount = placeholdersCount(logMessage);
int argumentsCount = aAST.findFirstToken(TokenTypes.ELIST).getChildCount(TokenTypes.EXPR) - 1;
final String lastArg = aAST.findFirstToken(TokenTypes.ELIST).getLastChild().getFirstChild().getText();
- if(hasCatchBlockParentWithArgument(lastArg, aAST) || hasMethodDefinitionWithExceptionArgument(lastArg, aAST)) {
+ if (hasCatchBlockParentWithArgument(lastArg, aAST) || hasMethodDefinitionWithExceptionArgument(lastArg,
+ aAST)) {
argumentsCount--;
}
- if(placeholdersCount > argumentsCount) {
+ if (placeholdersCount > argumentsCount) {
log(aAST.getLineNo(), LOG_MESSAGE);
}
}
while(parent != null && parent.getType() != TokenTypes.LITERAL_CATCH) {
parent = parent.getParent();
}
- if(parent != null) {
- if(parent.findFirstToken(TokenTypes.PARAMETER_DEF) != null &&
- parent.findFirstToken(TokenTypes.PARAMETER_DEF).findFirstToken(TokenTypes.IDENT).getText().equals(argumentName)) {
- return true;
- }
+ if (parent != null && parent.findFirstToken(TokenTypes.PARAMETER_DEF) != null &&
+ parent.findFirstToken(TokenTypes.PARAMETER_DEF).findFirstToken(TokenTypes.IDENT).getText().equals
+ (argumentName)) {
+ return true;
}
return false;
}
while(parent != null && parent.getType() != TokenTypes.METHOD_DEF) {
parent = parent.getParent();
}
- if(parent != null) {
- if(parent.findFirstToken(TokenTypes.PARAMETERS).findFirstToken(TokenTypes.PARAMETER_DEF) != null) {
- DetailAST paramDef = parent.findFirstToken(TokenTypes.PARAMETERS).getFirstChild();
- while(paramDef != null) {
- if(paramDef.getType() == TokenTypes.PARAMETER_DEF) {
- final String paramName = paramDef.findFirstToken(TokenTypes.IDENT).getText();
- if(paramName.equals(argumentName) && isExceptionType(paramDef)) {
- return true;
- }
+ if (parent != null && parent.findFirstToken(TokenTypes.PARAMETERS).findFirstToken(TokenTypes.PARAMETER_DEF)
+ != null) {
+ DetailAST paramDef = parent.findFirstToken(TokenTypes.PARAMETERS).getFirstChild();
+ while(paramDef != null) {
+ if (paramDef.getType() == TokenTypes.PARAMETER_DEF) {
+ final String paramName = paramDef.findFirstToken(TokenTypes.IDENT).getText();
+ if (paramName.equals(argumentName) && isExceptionType(paramDef)) {
+ return true;
}
- paramDef = paramDef.getNextSibling();
}
+ paramDef = paramDef.getNextSibling();
}
}
return false;
}
private boolean isExceptionType(final DetailAST parameterDef) {
- if(parameterDef != null) {
+ if (parameterDef != null) {
final DetailAST type = parameterDef.findFirstToken(TokenTypes.TYPE);
- if(type != null && type.findFirstToken(TokenTypes.IDENT) != null) {
+ if (type != null && type.findFirstToken(TokenTypes.IDENT) != null) {
final String argumentType = type.findFirstToken(TokenTypes.IDENT).getText();
- if(argumentType.contains(EXCEPTION_TYPE)) {
+ if (argumentType.contains(EXCEPTION_TYPE)) {
return true;
}
}
@Override
public void visitToken(DetailAST aAST) {
- if(aAST.getType() == TokenTypes.VARIABLE_DEF) {
+ if (aAST.getType() == TokenTypes.VARIABLE_DEF) {
if (CheckLoggingUtil.isAFieldVariable(aAST)) {
final String typeName = CheckLoggingUtil.getTypeName(aAST);
if (typeName.contains("." + LOGGER_TYPE_NAME) && !typeName.equals(LOGGER_TYPE_FULL_NAME)) {
log(aAST.getLineNo(), LOG_MESSAGE);
}
}
- } else if(aAST.getType() == TokenTypes.IMPORT) {
+ } else if (aAST.getType() == TokenTypes.IMPORT) {
final String importType = aAST.getFirstChild().findFirstToken(TokenTypes.IDENT).getText();
- if(importType.equals(CheckLoggingUtil.LOGGER_TYPE_NAME)) {
+ if (importType.equals(CheckLoggingUtil.LOGGER_TYPE_NAME)) {
final String importIdent = aAST.getFirstChild().getFirstChild().getLastChild().getText();
- if(!importIdent.equals(SLF4J)) {
+ if (!importIdent.equals(SLF4J)) {
log(aAST.getLineNo(), LOG_MESSAGE);
}
}
@Override
public void visitToken(DetailAST aAST) {
- if (CheckLoggingUtil.isAFieldVariable(aAST) && CheckLoggingUtil.isLoggerType(aAST) && !hasPrivatStaticFinalModifier(aAST)) {
+ if (CheckLoggingUtil.isAFieldVariable(aAST) && CheckLoggingUtil.isLoggerType(aAST)
+ && !hasPrivatStaticFinalModifier(aAST)) {
log(aAST.getLineNo(), LOG_MESSAGE);
}
}
private boolean hasPrivatStaticFinalModifier(DetailAST aAST) {
DetailAST modifiers = aAST.findFirstToken(TokenTypes.MODIFIERS);
- if(modifiers != null) {
- if(modifiers.branchContains(TokenTypes.LITERAL_PRIVATE) && modifiers.branchContains(TokenTypes.LITERAL_STATIC)
- && modifiers.branchContains(TokenTypes.FINAL)) {
- return true;
- }
+ if (modifiers != null && modifiers.branchContains(TokenTypes.LITERAL_PRIVATE) && modifiers.branchContains
+ (TokenTypes.LITERAL_STATIC) && modifiers.branchContains(TokenTypes.FINAL)) {
+ return true;
}
return false;
}
DataContainerContextNode<AugmentationIdentifier> {
public AugmentationContextNode(final AugmentationSchema augmentation, final DataNodeContainer schema) {
- // super();
super(augmentationIdentifierFrom(augmentation), augmentationProxy(augmentation, schema), null);
}
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-public class DataSchemaContextTree {
+public final class DataSchemaContextTree {
private static final LoadingCache<SchemaContext, DataSchemaContextTree> TREES = CacheBuilder.newBuilder()
.weakKeys()
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.LinkedList;
+import java.util.List;
import javax.annotation.Nullable;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.common.QName;
private final AbstractStringInstanceIdentifierCodec codec;
private final String data;
- private final LinkedList<PathArgument> product = new LinkedList<>();
+ private final List<PathArgument> product = new LinkedList<>();
private DataSchemaContextNode<?> current;
private int offset;