public boolean process()

in src/main/java/org/apache/struts/annotations/taglib/apt/TagAnnotationProcessor.java [72:157]


    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        // make sure all paramters were set
        checkOptions();

        // tags
        TypeElement tagAnnotationType = processingEnv.getElementUtils().getTypeElement(TAG);
        TypeElement attributeAnnotationType = processingEnv.getElementUtils().getTypeElement(TAG_ATTRIBUTE);
        TypeElement skipAnnotationType = processingEnv.getElementUtils().getTypeElement(TAG_SKIP_HIERARCHY);
        Set<? extends javax.lang.model.element.Element> tagDeclarations = roundEnv.getElementsAnnotatedWith(tagAnnotationType);
        Set<? extends javax.lang.model.element.Element> attributesDeclarations = roundEnv.getElementsAnnotatedWith(attributeAnnotationType);
        Set<? extends javax.lang.model.element.Element> skipDeclarations = roundEnv.getElementsAnnotatedWith(skipAnnotationType);

        // find Tags
        for (javax.lang.model.element.Element element : tagDeclarations) {
            Map<String, Object> values = getValues(element, tagAnnotationType);
            TypeElement type = (TypeElement) element;
            Tag tag = new Tag();
            tag.setDescription((String) values.get("description"));
            tag.setName((String) values.get("name"));
            tag.setTldBodyContent((String) values.get("tldBodyContent"));
            tag.setTldTagClass((String) values.get("tldTagClass"));
            tag.setDeclaredType(type.getQualifiedName().toString());
            tag.setAllowDynamicAttributes((Boolean) values.get("allowDynamicAttributes"));
            // add to map
            tags.put(type.getQualifiedName().toString(), tag);
        }

        //find attributes to be skipped
        for (javax.lang.model.element.Element declaration : skipDeclarations) {
            //types will be ignored when hierarchy is scanned
            if (declaration instanceof ExecutableElement) {
                ExecutableElement methodDeclaration = (ExecutableElement) declaration;
                String typeName = ((TypeElement) methodDeclaration.getEnclosingElement()).getQualifiedName().toString();
                String methodName = methodDeclaration.getSimpleName().toString();
                String name = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
                Tag tag = tags.get(typeName);
                if (tag != null) {
                    //if it is on an abstract class, there is no tag for it at this point
                    tags.get(typeName).addSkipAttribute(name);
                }
            }
        }

        // find Tags Attributes
        for (javax.lang.model.element.Element declaration : attributesDeclarations) {
            // type
            ExecutableElement methodDeclaration = (ExecutableElement) declaration;
            String typeName = ((TypeElement) methodDeclaration.getEnclosingElement()).getQualifiedName().toString();
            Map<String, Object> values = getValues(methodDeclaration,
                    attributeAnnotationType);
            // create Attribute and apply values found
            TagAttribute attribute = new TagAttribute();
            String name = (String) values.get("name");
            if (name == null || name.length() == 0) {
                // get name from method
                String methodName = methodDeclaration.getSimpleName().toString();
                name = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
            }
            values.put("name", name);
            populateTagAttributes(attribute, values);
            // add to map
            Tag parentTag = tags.get(typeName);
            if (parentTag != null) {
                tags.get(typeName).addTagAttribute(attribute);
            } else {
                // an abstract or base class
                parentTag = new Tag();
                parentTag.setDeclaredType(typeName);
                parentTag.setInclude(false);
                parentTag.addTagAttribute(attribute);
                tags.put(typeName, parentTag);
            }
        }

        // we can't process the hierarchy on the first pass because
        // apt does not guarantee that the base classes will be processed
        // before their subclasses
        for (Map.Entry<String, Tag> entry : tags.entrySet()) {
            processHierarchy(entry.getValue());
        }

        // save
        saveAsXml();
        saveTemplates();
        return true;
    }