public void visitConstantUtf8()

in src/main/java/org/apache/maven/shared/jar/classes/ImportVisitor.java [113:166]


    public void visitConstantUtf8(ConstantUtf8 constantUtf8) {
        String ret = constantUtf8.getBytes().trim();

        // empty strings are not class names.
        if (ret.length() <= 0) {
            return;
        }

        // Only valid characters please.
        if (!VALID_UTF8_PATTERN.matcher(ret).matches()) {
            return;
        }

        // only strings with '/' character are to be considered.
        if (ret.indexOf('/') == -1) {
            return;
        }

        // Strings that start with '/' are bad too
        // Seen when Pool has regex patterns.
        if (ret.charAt(0) == '/') {
            return;
        }

        // Make string more class-like.
        ret = ret.replace('/', '.');

        // Double ".." indicates a bad class fail-fast.
        // Seen when ConstantUTF8 Pool has regex patterns.
        if (ret.contains("..")) {
            return;
        }

        Matcher mat = QUALIFIED_IMPORT_PATTERN.matcher(ret);
        char prefix = ret.charAt(0);

        if (prefix == '(') {
            // A Method Declaration.

            // Loop for each Qualified Class found.
            while (mat.find()) {
                this.imports.add(mat.group(1));
            }
        } else {
            // A Variable Declaration.
            if (mat.find()) {
                // Add a UTF8 Qualified Class reference.
                this.imports.add(mat.group(1));
            } else {
                // Add a simple Class reference.
                this.imports.add(ret);
            }
        }
    }