Example usage for org.apache.commons.lang StringUtils containsIgnoreCase

List of usage examples for org.apache.commons.lang StringUtils containsIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils containsIgnoreCase.

Prototype

public static boolean containsIgnoreCase(String str, String searchStr) 

Source Link

Document

Checks if String contains a search String irrespective of case, handling null.

Usage

From source file:org.sonar.cxx.checks.CommentContainsPatternChecker.java

public void visitToken(Token token) {
    for (Trivia trivia : token.getTrivia()) {
        String comment = trivia.getToken().getOriginalValue();
        if (StringUtils.containsIgnoreCase(comment, pattern)) {
            String[] lines = comment.split("\r\n?|\n");

            for (int i = 0; i < lines.length; i++) {
                if (StringUtils.containsIgnoreCase(lines[i], pattern) && !isLetterAround(lines[i], pattern)) {
                    check.getContext().createLineViolation(check, message, trivia.getToken().getLine() + i);
                }/*from   w ww . j  a v a 2  s.c om*/
            }
        }
    }
}

From source file:org.sonar.dotnet.tools.commons.visualstudio.ModelFactory.java

/**
 * Generates a list of projects from the path of the visual studio projects files (.csproj)
 * //from  w  w  w .  ja  va 2s.  c o m
 * @param projectFile
 *          the project file
 * @param projectName
 *          the name of the project
 * @throws DotNetToolsException
 * @throws FileNotFoundException
 *           if the file was not found
 */
public static VisualStudioProject getProject(File projectFile, String projectName,
        List<String> buildConfigurations) throws FileNotFoundException, DotNetToolsException {

    VisualStudioProject project = new VisualStudioProject();
    project.setProjectFile(projectFile);
    project.setName(projectName);
    File projectDir = projectFile.getParentFile();

    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();

    // This is a workaround to avoid Xerces class-loading issues
    ClassLoader savedClassloader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(xpath.getClass().getClassLoader());
    try {
        // We define the namespace prefix for Visual Studio
        xpath.setNamespaceContext(new VisualStudioNamespaceContext());

        if (buildConfigurations != null) {
            Map<String, File> buildConfOutputDirMap = new HashMap<String, File>();
            for (String config : buildConfigurations) {
                XPathExpression configOutputExpression = xpath.compile(
                        "/vst:Project/vst:PropertyGroup[contains(@Condition,'" + config + "')]/vst:OutputPath");
                String configOutput = extractProjectProperty(configOutputExpression, projectFile);
                buildConfOutputDirMap.put(config, new File(projectDir, configOutput));
            }
            project.setBuildConfOutputDirMap(buildConfOutputDirMap);
        }

        XPathExpression projectTypeExpression = xpath.compile("/vst:Project/vst:PropertyGroup/vst:OutputType");
        XPathExpression assemblyNameExpression = xpath
                .compile("/vst:Project/vst:PropertyGroup/vst:AssemblyName");
        XPathExpression rootNamespaceExpression = xpath
                .compile("/vst:Project/vst:PropertyGroup/vst:RootNamespace");
        XPathExpression debugOutputExpression = xpath
                .compile("/vst:Project/vst:PropertyGroup[contains(@Condition,'Debug')]/vst:OutputPath");
        XPathExpression releaseOutputExpression = xpath
                .compile("/vst:Project/vst:PropertyGroup[contains(@Condition,'Release')]/vst:OutputPath");
        XPathExpression silverlightExpression = xpath
                .compile("/vst:Project/vst:PropertyGroup/vst:SilverlightApplication");

        // Extracts the properties of a Visual Studio Project
        String typeStr = extractProjectProperty(projectTypeExpression, projectFile);
        String silverlightStr = extractProjectProperty(silverlightExpression, projectFile);
        String assemblyName = extractProjectProperty(assemblyNameExpression, projectFile);
        String rootNamespace = extractProjectProperty(rootNamespaceExpression, projectFile);
        String debugOutput = extractProjectProperty(debugOutputExpression, projectFile);
        String releaseOutput = extractProjectProperty(releaseOutputExpression, projectFile);

        // Assess if the artifact is a library or an executable
        ArtifactType type = ArtifactType.LIBRARY;
        if (StringUtils.containsIgnoreCase(typeStr, "exe")) {
            type = ArtifactType.EXECUTABLE;
        }
        // The project is populated
        project.setProjectFile(projectFile);
        project.setType(type);
        project.setDirectory(projectDir);
        project.setAssemblyName(assemblyName);
        project.setRootNamespace(rootNamespace);
        project.setDebugOutputDir(new File(projectDir, debugOutput));
        project.setReleaseOutputDir(new File(projectDir, releaseOutput));

        if (StringUtils.isNotEmpty(silverlightStr)) {
            project.setSilverlightProject(true);
        }

        project.setBinaryReferences(getBinaryReferences(xpath, projectFile));

        assessTestProject(project, testProjectNamePattern);

        return project;
    } catch (XPathExpressionException xpee) {
        throw new DotNetToolsException("Error while processing the project " + projectFile, xpee);
    } finally {
        // Replaces the class loader after usage
        Thread.currentThread().setContextClassLoader(savedClassloader);
    }
}

From source file:org.sonar.erlang.checks.CommentContainsPatternChecker.java

public void visitToken(Token token) {
    for (Trivia trivia : token.getTrivia()) {
        String comment = trivia.getToken().getOriginalValue();
        for (String pattern : patterns) {
            if (StringUtils.containsIgnoreCase(comment, pattern)) {
                String[] lines = comment.split("\r\n?|\n");
                for (int i = 0; i < lines.length; i++) {
                    if (StringUtils.containsIgnoreCase(lines[i], pattern)) {
                        check.getContext().createLineViolation(check, message, trivia.getToken().getLine() + i);
                    }/*w w  w.j  a  v  a2 s  .  c  o m*/
                }
            }
        }
    }
}

From source file:org.sonar.java.checks.CommentContainsPatternChecker.java

public void checkTrivia(SyntaxTrivia syntaxTrivia) {
    String comment = syntaxTrivia.comment();
    if (StringUtils.containsIgnoreCase(comment, pattern)) {
        String[] lines = comment.split("\r\n?|\n");
        for (int i = 0; i < lines.length; i++) {
            if (StringUtils.containsIgnoreCase(lines[i], pattern) && !isLetterAround(lines[i], pattern)) {
                newCheck.addIssue(syntaxTrivia.startLine() + i, message);
            }/*ww w.j  a  v  a2  s . co  m*/
        }
    }
}

From source file:org.sonar.java.checks.TrailingCommentCheck.java

private static boolean containsExcludedPattern(String comment) {
    for (String excludePattern : EXCLUDED_PATTERNS) {
        if (StringUtils.containsIgnoreCase(comment, excludePattern)) {
            return true;
        }/* w  ww  . j a v a  2  s.  com*/
    }
    return false;
}

From source file:org.sonar.java.se.NullableAnnotationUtilsTest.java

private static void testMethods(Symbol.MethodSymbol s) {
    String name = s.name();//from  www .  j  av a 2s .co  m
    boolean annotatedNonNull = isAnnotatedNonNull(s);
    if (StringUtils.containsIgnoreCase(name, "ReturnNonNull")) {
        assertThat(annotatedNonNull).as(s + " should be recognized as returning NonNull.").isTrue();
    } else {
        assertThat(annotatedNonNull).as(s + " should NOT be recognized as returning NonNull.").isFalse();
    }
    boolean globallyAnnotatedParameterNonNull = isGloballyAnnotatedParameterNonNull(s);
    if (StringUtils.containsIgnoreCase(name, "nonNullParameters")) {
        assertThat(globallyAnnotatedParameterNonNull).as(s + " should be recognized as NonNull for parameters.")
                .isTrue();
    } else {
        assertThat(globallyAnnotatedParameterNonNull)
                .as(s + " should NOT be recognized as NonNull for parameters.").isFalse();
    }
}

From source file:org.sonar.javascript.checks.CommentContainsPatternChecker.java

public void visitToken(SyntaxToken token) {
    for (SyntaxTrivia trivia : token.trivias()) {
        String comment = trivia.text();
        if (StringUtils.containsIgnoreCase(comment, pattern)) {
            String[] lines = comment.split("\r\n?|\n");

            for (int i = 0; i < lines.length; i++) {
                if (StringUtils.containsIgnoreCase(lines[i], pattern) && !isLetterAround(lines[i], pattern)) {
                    check.addIssue(new LineIssue(check, trivia.line() + i, message));
                }/*from   w w w. ja v a 2s  . c  o m*/
            }
        }
    }
}

From source file:org.sonar.jproperties.checks.CommentContainsPatternChecker.java

@Override
public void visitComment(SyntaxTrivia trivia) {
    String comment = trivia.text();
    if (StringUtils.containsIgnoreCase(comment, pattern) && !isLetterAround(comment, pattern)) {
        addPreciseIssue(trivia, message);
    }/*from w  w  w .ja va  2s .c om*/
}

From source file:org.sonar.php.checks.MethodNameReturningBooleanCheck.java

private static boolean isReturningBoolean(MethodDeclarationTree methodDeclaration) {
    for (SyntaxTrivia comment : ((PHPTree) methodDeclaration).getFirstToken().trivias()) {
        for (String line : comment.text().split(LexicalConstant.LINE_TERMINATOR)) {

            if (StringUtils.containsIgnoreCase(line, RETURN_TAG)) {
                return returnsBoolean(line);
            }//www. j  a  v  a 2  s . com
        }
    }
    return false;
}

From source file:org.sonar.php.checks.utils.AbstractCommentContainsPatternCheck.java

@Override
public void visitTrivia(SyntaxTrivia trivia) {
    String comment = trivia.text();

    if (StringUtils.containsIgnoreCase(comment, pattern())) {
        String[] lines = comment.split("\r\n?|\n");

        for (int i = 0; i < lines.length; i++) {
            if (StringUtils.containsIgnoreCase(lines[i], pattern()) && !isLetterAround(lines[i])) {
                createIssue(trivia.line() + i);
            }//from  w ww.  j  a  v  a2 s.c om
        }
    }
}