Skip to content

Commit

Permalink
Issue #4725: fix all violations from the tenth part of idea violations
Browse files Browse the repository at this point in the history
  • Loading branch information
vasylieva authored and romani committed Jul 24, 2017
1 parent a516373 commit 1d9b547
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 65 deletions.
15 changes: 10 additions & 5 deletions config/intellij-idea-inspections.xml
Expand Up @@ -590,7 +590,9 @@
<inspection_tool class="DuplicateThrows" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="DuplicatedBeanNamesInspection" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="DuplicatedDataProviderNames" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="Duplicates" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="Duplicates" enabled="true" level="ERROR" enabled_by_default="true" >
<scope name="Tests" level="ERROR" enabled="false" />
</inspection_tool>
<inspection_tool class="DynamicRegexReplaceableByCompiledPattern" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Tests" level="WARNING" enabled="false" />
</inspection_tool>
Expand Down Expand Up @@ -679,6 +681,7 @@
<!-- there is false-positive, and rest cases are result of our loading modules by reflection
that throws Error. Error is not always jvm problem, bunch of libraries throw Error instead of Exception -->
<inspection_tool class="ErrorRethrown" enabled="false" level="ERROR" enabled_by_default="false" />
<!--we do not use this tool-->
<inspection_tool class="Eslint" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="ExceptionCaughtLocallyJS" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="ExceptionFromCatchWhichDoesntWrap" enabled="true" level="WARNING" enabled_by_default="true">
Expand Down Expand Up @@ -780,6 +783,7 @@
<inspection_tool class="FunctionWithMultipleReturnPointsJS" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="GherkinBrokenTableInspection" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="GherkinMisplacedBackground" enabled="true" level="WARNING" enabled_by_default="true" />
<!--we do not use this tool-->
<inspection_tool class="GjsLint" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="GrDeprecatedAPIUsage" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="GrEqualsBetweenInconvertibleTypes" enabled="true" level="ERROR" enabled_by_default="true" />
Expand Down Expand Up @@ -1084,7 +1088,7 @@
<inspection_tool class="InnerClassVariableHidesOuterClassVariable" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_ignoreInvisibleFields" value="true" />
</inspection_tool>
<inspection_tool class="InnerHTMLJS" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="InnerHTMLJS" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="InstanceGuardedByStatic" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="InstanceMethodNamingConvention" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_regex" value="[a-z][A-Za-z\d]*" />
Expand Down Expand Up @@ -1164,11 +1168,11 @@
<inspection_tool class="JSDeprecatedSymbols" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="JSDuplicatedDeclaration" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="JSFileReferences" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="JSHint" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="JSHint" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="JSJQueryEfficiency" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="JSLastCommaInArrayLiteral" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="JSLastCommaInObjectLiteral" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="JSLint" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="JSLint" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="JSMethodCanBeStatic" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="JSMismatchedCollectionQueryUpdate" enabled="true" level="ERROR" enabled_by_default="true">
<option name="queries" value="trace,write,forEach" />
Expand Down Expand Up @@ -1280,6 +1284,7 @@
<inspection_tool class="JpaObjectClassSignatureInspection" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="JpaQlInspection" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="JpaQueryApiInspection" enabled="true" level="WARNING" enabled_by_default="true" />
<!--we do not use this tool-->
<inspection_tool class="Jscs" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="JsfJamExtendsClassInconsistencyInspection" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="JsfManagedBeansInconsistencyInspection" enabled="true" level="WARNING" enabled_by_default="true" />
Expand Down Expand Up @@ -2263,7 +2268,7 @@
<!-- we can not use try-with-resources till we switch to jacoco for code coverage -->
<inspection_tool class="TryFinallyCanBeTryWithResources" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="TryWithIdenticalCatches" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="TsLint" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="TsLint" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="TypeCustomizer" enabled="true" level="ERROR" enabled_by_default="true" />
<!-- we like implementation to be concrete, we do not like a lot of abstractions -->
<inspection_tool class="TypeMayBeWeakened" enabled="false" level="ERROR" enabled_by_default="false">
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -2262,6 +2262,7 @@
</targetClasses>
<targetTests>
<param>com.puppycrawl.tools.checkstyle.utils.*</param>
<param>com.puppycrawl.tools.checkstyle.checks.coding.*</param>
<param>com.puppycrawl.tools.checkstyle.AstTreeStringPrinterTest</param>
<param>com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest</param>
<param>com.puppycrawl.tools.checkstyle.DetailNodeTreeStringPrinterTest</param>
Expand Down
Expand Up @@ -29,6 +29,7 @@
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CheckUtils;

/**
* Catching java.lang.Exception, java.lang.Error or java.lang.RuntimeException
Expand Down Expand Up @@ -57,15 +58,8 @@ public final class IllegalCatchCheck extends AbstractCheck {
*/
public void setIllegalClassNames(final String... classNames) {
illegalClassNames.clear();
for (final String name : classNames) {
illegalClassNames.add(name);
final int lastDot = name.lastIndexOf('.');
if (lastDot > 0 && lastDot < name.length() - 1) {
final String shortName = name
.substring(name.lastIndexOf('.') + 1);
illegalClassNames.add(shortName);
}
}
illegalClassNames.addAll(
CheckUtils.parseClassNames(classNames));
}

@Override
Expand Down
Expand Up @@ -29,6 +29,7 @@
import com.puppycrawl.tools.checkstyle.api.FullIdent;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.AnnotationUtility;
import com.puppycrawl.tools.checkstyle.utils.CheckUtils;

/**
* <p>
Expand Down Expand Up @@ -80,15 +81,9 @@ public final class IllegalThrowsCheck extends AbstractCheck {
*/
public void setIllegalClassNames(final String... classNames) {
illegalClassNames.clear();
for (final String name : classNames) {
illegalClassNames.add(name);
final int lastDot = name.lastIndexOf('.');
if (lastDot > 0 && lastDot < name.length() - 1) {
final String shortName = name
.substring(name.lastIndexOf('.') + 1);
illegalClassNames.add(shortName);
}
}
illegalClassNames.addAll(
CheckUtils.parseClassNames(classNames));

}

@Override
Expand Down
Expand Up @@ -20,7 +20,9 @@
package com.puppycrawl.tools.checkstyle.utils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

import antlr.collections.AST;
Expand Down Expand Up @@ -458,4 +460,24 @@ else if (tokenType == TokenTypes.LITERAL_PRIVATE) {
}
return accessModifier;
}

/**
* Create set of class names and short class names.
*
* @param classNames array of class names.
* @return set of class names and short class names.
*/
public static Set<String> parseClassNames(String... classNames) {
final Set<String> illegalClassNames = new HashSet<>();
for (final String name : classNames) {
illegalClassNames.add(name);
final int lastDot = name.lastIndexOf('.');
if (lastDot != -1 && lastDot < name.length() - 1) {
final String shortName = name
.substring(name.lastIndexOf('.') + 1);
illegalClassNames.add(shortName);
}
}
return illegalClassNames;
}
}
36 changes: 14 additions & 22 deletions src/main/java/com/puppycrawl/tools/checkstyle/utils/ScopeUtils.java
Expand Up @@ -98,27 +98,7 @@ else if (type == TokenTypes.LITERAL_NEW) {
* @return a {@code boolean} value
*/
public static boolean isInInterfaceBlock(DetailAST node) {
boolean returnValue = false;

// Loop up looking for a containing interface block
for (DetailAST token = node.getParent();
token != null && !returnValue;
token = token.getParent()) {

final int type = token.getType();

if (type == TokenTypes.INTERFACE_DEF) {
returnValue = true;
}
else if (type == TokenTypes.CLASS_DEF
|| type == TokenTypes.ENUM_DEF
|| type == TokenTypes.ANNOTATION_DEF
|| type == TokenTypes.LITERAL_NEW) {
break;
}
}

return returnValue;
return isInBlockOf(node, TokenTypes.INTERFACE_DEF);
}

/**
Expand All @@ -128,19 +108,31 @@ else if (type == TokenTypes.CLASS_DEF
* @return a {@code boolean} value
*/
public static boolean isInAnnotationBlock(DetailAST node) {
return isInBlockOf(node, TokenTypes.ANNOTATION_DEF);
}

/**
* Returns whether a node is directly contained within a specified block.
*
* @param node the node to check if directly contained within a specified block.
* @param tokenType type of token.
* @return a {@code boolean} value
*/
private static boolean isInBlockOf(DetailAST node, int tokenType) {
boolean returnValue = false;

// Loop up looking for a containing interface block
for (DetailAST token = node.getParent();
token != null && !returnValue;
token = token.getParent()) {
final int type = token.getType();
if (type == TokenTypes.ANNOTATION_DEF) {
if (type == tokenType) {
returnValue = true;
}
else if (type == TokenTypes.CLASS_DEF
|| type == TokenTypes.ENUM_DEF
|| type == TokenTypes.INTERFACE_DEF
|| type == TokenTypes.ANNOTATION_DEF
|| type == TokenTypes.LITERAL_NEW) {
break;
}
Expand Down
44 changes: 24 additions & 20 deletions src/site/resources/js/anchors.js
@@ -1,23 +1,27 @@
'use strict';
/*jslint browser: true*/
/*global window */
(function () {
"use strict";
window.addEventListener("load", function () {
var url = window.location.href;
var anchors = document.getElementsByTagName("h2");
[].forEach.call(anchors, function (anchorItem) {
var name = anchorItem.childNodes[0].name;
var link = "" + url + "#" + name + "";

function main() {
var url = window.location.href;
var anchors = document.getElementsByTagName('h2');
var mass = [];
for (var i = 0; i < anchors.length; i++) {
mass.push(anchors[i].childNodes[0].name);
}
var links = [];
for(i = 0; i < mass.length; i++) {
links.push('' + url + '#' + mass[i] + '');
}
for(i = 0; i < anchors.length; i++) {
var anchor = document.createElement('div');
anchor.className = 'anchor';
anchor.innerHTML += '<a href="' + links[i] + '"><img src="images/anchor.png"></a>';
anchors[i].appendChild(anchor);
}
var a = document.createElement("a");
a.setAttribute("href", link);

}
var image = document.createElement("img");
image.setAttribute("src", "images/anchor.png");

var anchor = document.createElement("div");
anchor.className = "anchor";

a.appendChild(image);
anchor.appendChild(a);
anchorItem.appendChild(anchor);
});
});
}());

window.addEventListener('load', main);
Expand Up @@ -29,8 +29,10 @@

import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.junit.Test;

Expand Down Expand Up @@ -304,6 +306,15 @@ public void testParseDouble() throws Exception {
assertEquals(59.0, CheckUtils.parseDouble("073L", TokenTypes.NUM_LONG), 0);
}

@Test
public void testParseClassNames() {
final String className = "I.am.class.name.with.dot.in.the.end.";
final Set<String> result = CheckUtils.parseClassNames(className);
final Set<String> expected = new HashSet<>();
expected.add(className);
assertEquals("Result is not expected", expected, result);
}

private static File getPath(String filename) {
return new File("src/test/resources/com/puppycrawl/tools/checkstyle/utils/checkutils/"
+ filename);
Expand Down

0 comments on commit 1d9b547

Please sign in to comment.