private String jxrFilter()

in maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java [966:1053]


    private String jxrFilter(String line) {
        JavaFile jf;

        try {
            // if the current file isn't set then just return
            if (this.getCurrentFilename() == null) {
                return line;
            }

            jf = fileManager.getFile(this.getCurrentFilename());
        } catch (IOException e) {
            e.printStackTrace();
            return line;
        }

        Set<String> packages = new HashSet<>();

        // get the imported packages
        for (ImportType importType : jf.getImportTypes()) {
            packages.add(importType.getPackage());
        }

        // add the current package.
        packages.add(jf.getPackageType().getName());

        List<StringEntry> words = SimpleWordTokenizer.tokenize(line);

        // go through each word and then match them to the correct class if necessary.
        for (StringEntry word : words) {
            for (String pkg : packages) {
                // get the package from the PackageManager because this will hold
                // the version with the classes also.

                PackageType currentImport = packageManager.getPackageType(pkg);

                // the package here might in fact be null because it wasn't parsed out
                // this might be something that is either not included or is part
                // of another package and wasn't parsed out.

                if (currentImport == null) {
                    continue;
                }

                // see if the current word is within the package

                // at this point the word could be a fully qualified package name
                // (FQPN) or an imported package name.

                String wordName = word.toString();

                if (wordName.indexOf('.') != -1) {
                    // if there is a "." in the string then we have to assume
                    // it is a package.

                    String fqpnPackage = wordName.substring(0, wordName.lastIndexOf('.'));
                    String fqpnClass = wordName.substring(wordName.lastIndexOf('.') + 1);

                    // note. since this is a reference to a full package then
                    // it doesn't have to be explicitly imported so this information
                    // is useless. Instead just see if it was parsed out.

                    PackageType pt = packageManager.getPackageType(fqpnPackage);

                    if (pt != null) {
                        ClassType ct = pt.getClassType(fqpnClass);

                        if (ct != null) {
                            // OK. the user specified a full package to be imported
                            // that is in the package manager so it is time to
                            // link to it.

                            line = xrLine(line, pt.getName(), ct);
                        }
                    }

                    if (fqpnPackage.equals(currentImport.getName()) && currentImport.getClassType(fqpnClass) != null) {
                        // then the package we are currently in is the one specified in the string
                        // and the import class is correct.
                        line = xrLine(line, pkg, currentImport.getClassType(fqpnClass));
                    }
                } else if (currentImport.getClassType(wordName) != null) {
                    line = xrLine(line, pkg, currentImport.getClassType(wordName));
                }
            }
        }

        return importFilter(line);
    }