public Object onCheck()

in ti/phase2/jars/core/src/java/org/apache/ti/compiler/internal/grammar/WebappPathType.java [65:158]


    public Object onCheck(AnnotationTypeElementDeclaration valueDecl, AnnotationValue value,
                          AnnotationInstance[] parentAnnotations, MemberDeclaration classMember, int annotationArrayIndex)
            throws FatalCompileTimeException {
        String filePath = (String) value.getValue();

        //
        // First make sure it's a valid URI.
        //
        try {
            URI uri = new URI(filePath);
            filePath = uri.getPath(); // decodes the path
        } catch (URISyntaxException e) {
            addError(value, "error.invalid-uri", e.getLocalizedMessage());

            return null;
        }

        //
        // The path will be null for an 'opaque' URI, like "news:comp.lang.java".
        //
        if ((filePath == null) || (filePath.length() == 0)) {
            return null;
        }

        //
        // Make sure it's a filetype that should exist on the filesystem.  If not, ignore it.
        //
        if (!checkAnyExtension() && !isCheckableExtension(filePath)) {
            return null;
        }

        boolean fileExists = true;
        TypeDeclaration outerClass = CompilerUtils.getOutermostClass(classMember);
        File fileToCheck = null;

        if (filePath.charAt(0) == '/') // relative to webapp root
         {
            if (_pathMustBeRelative) {
                addError(value, "error.relative-uri");
            }

            if (filePath.endsWith(JPF_FILE_EXTENSION_DOT)) {
                TypeDeclaration type = CompilerUtils.inferTypeFromPath(filePath, getEnv());
                fileToCheck = (type != null) ? CompilerUtils.getSourceFile(type, false) : null;

                // Note that if we can't infer the file from the type, we'll fall through to the next case, where
                // we actually look for the file in the webapp.
            }

            if (fileToCheck == null) {
                File jpfSourceFile = CompilerUtils.getSourceFile(CompilerUtils.getOuterClass(classMember), false);

                //
                // We don't always have the source file for the classMember's containing class (e.g., when this class
                // extends a class that's on classpath but not sourcepath).  If we don't have the source, just ignore.
                //
                if (jpfSourceFile != null) {
                    fileToCheck = CompilerUtils.getWebappRelativeFile(filePath, allowFileInPageFlowSourceDir(), getEnv());

                    if ((fileToCheck != null) && !fileToCheck.exists() && !(ignoreDirectories() && fileToCheck.isDirectory())) {
                        fileExists = false;
                    }
                }
            }
        }
        //
        // If the class being compiled is abstract, don't print warnings for relative-path files that aren't
        // found.  The derived class might have them.
        //
        else if ((filePath.indexOf('/') != 0) && !outerClass.hasModifier(Modifier.ABSTRACT)) {
            CompilerUtils.Mutable retFileToCheck = new CompilerUtils.Mutable();
            fileExists = checkRelativePath(filePath, outerClass, retFileToCheck, ignoreDirectories(),
                                           allowFileInPageFlowSourceDir(), getEnv());
            fileToCheck = (File) retFileToCheck.get();
        }

        if (fileExists) {
            if (fileToCheck != null) {
                runAdditionalChecks(fileToCheck, value);
            }
        } else {
            if (doFatalError()) {
                addError(value, "error.file-not-found", filePath);
            } else {
                addWarning(value, "warning.file-not-found", filePath);
            }
        }

        if (fileToCheck != null) {
            _flowControllerInfo.addReferencedFile(fileToCheck);
        }

        return null;
    }