Package com.sun.mirror.apt

Examples of com.sun.mirror.apt.AnnotationProcessorEnvironment


        for (AnnotationTypeDeclaration atd : _atds)
        {
            if (atd.getSimpleName().equals("Control") )
            {
                AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
                Collection<Declaration> decls = env.getDeclarationsAnnotatedWith(atd);
                for (Declaration decl : decls)
                {
                    if ( decl instanceof FieldDeclaration )
                    {
                        FieldDeclaration fd = (FieldDeclaration)decl;
                        TypeDeclaration clientType = fd.getDeclaringType();
                        TypeMirror controlFieldType = fd.getType();
                        addControlType( clientsMap, clientType, controlFieldType );
                       
                        //
                        // If this field is public or protected, add the control type to any derived class.
                        //
                        Collection<Modifier> modifiers = fd.getModifiers();
                        if ( modifiers.contains( Modifier.PUBLIC ) || modifiers.contains( Modifier.PROTECTED ) )
                        {
                            Collection<TypeDeclaration> specifiedTypeDeclartions = env.getSpecifiedTypeDeclarations();
                            for (TypeDeclaration td : specifiedTypeDeclartions)
                            {
                                if ( td instanceof ClassDeclaration )
                                {
                                    ClassType superclass = ( ( ClassDeclaration ) td ).getSuperclass();
                                   
                                    while ( superclass != null )
                                    {
                                        if ( superclass.getDeclaration().equals( clientType ) )
                                        {
                                            addControlType( clientsMap, td, controlFieldType );
                                            break;
                                        }
                                       
                                        superclass = superclass.getSuperclass();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (atd.getSimpleName().equals("ControlReferences"))
            {
                Collection<Declaration> decls = getAnnotationProcessorEnvironment().getDeclarationsAnnotatedWith(atd);
                for (Declaration decl : decls)
                {
                    if ( decl instanceof TypeDeclaration )
                    {
                        TypeDeclaration clientType = (TypeDeclaration)decl;
                        Set<TypeMirror> controlTypes = clientsMap.get( clientType );
                        if ( controlTypes == null )
                        {
                            controlTypes = new HashSet<TypeMirror>();
                            clientsMap.put( clientType, controlTypes );
                        }

                        // Read ControlReferences annotation
                        AnnotationMirror controlMirror = null;
                        for (AnnotationMirror annot : clientType.getAnnotationMirrors())
                        {
                            if (annot.getAnnotationType().getDeclaration().getQualifiedName().equals(
                                    "org.apache.beehive.controls.api.bean.ControlReferences"))
                            {
                                controlMirror = annot;
                                break;
                            }
                        }

                        assert( controlMirror != null );

                        // Add each control type listed in the ControlReferences annotation
                        AptAnnotationHelper controlAnnot = new AptAnnotationHelper(controlMirror);
                        Collection<AnnotationValue> references = (Collection<AnnotationValue>)controlAnnot.getObjectValue("value");
                        if ( references != null )
                        {
                            for ( AnnotationValue av : references )
                            {
                                TypeMirror crType = (TypeMirror)av.getValue();
                                controlTypes.add( crType );
                            }
                        }
                    }
                }
            }
        }

        // For each client type:
        //   1 - emit a controls client manifest in the same dir as the client type's class.
        //   2 - emit a controls client initializer class in the same pkg/dir as the client type's class

        Filer f = getAnnotationProcessorEnvironment().getFiler();
        Set<TypeDeclaration> clientTypes = clientsMap.keySet();
        for ( TypeDeclaration clientType : clientTypes )
        {
            // Emit manifest

            String clientPkg = clientType.getPackage().getQualifiedName();
            File clientManifestName =
                new File( clientType.getSimpleName() + ControlClientManifest.FILE_EXTENSION );

            ControlClientManifest mf = new ControlClientManifest( clientType.getQualifiedName() );

            try
            {
                Set<TypeMirror> controlTypes = clientsMap.get( clientType );
                for ( TypeMirror controlType : controlTypes )
                {
                    InterfaceDeclaration controlIntfOrExt = getControlInterfaceOrExtension(controlType);
                    InterfaceDeclaration controlIntf = getMostDerivedControlInterface( controlIntfOrExt );

                    assert controlIntf != null : "Can't find most derived control intf for=" + controlIntfOrExt;

                    ControlInterface annot = controlIntf.getAnnotation(ControlInterface.class);
                    String defBinding = annot.defaultBinding();

                    defBinding = ControlBeanContext.resolveDefaultBinding( defBinding, controlIntf.getQualifiedName() );

                    mf.addControlType( controlIntfOrExt.getQualifiedName(), defBinding );
                }

                mf.emit( f, clientPkg, clientManifestName, null );
            }
            catch ( IOException ie )
            {
                printError( clientType, "controls.client.manifest.ioerror" );
                ie.printStackTrace( );
            }

            // Emit initializer

            AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
            Generator genClass = new AptControlClient( clientType, this );

            if ( genClass != null )
            {
                try
                {
                    List<GeneratorOutput> genList = genClass.getGenerateOutput(env.getFiler());
                    if (genList == null || genList.size() == 0)
                        return;

                    for (GeneratorOutput genOut : genList)
                    {
View Full Code Here


                // Compute the bean type name, and the associated interface name by stripping
                // the "Bean" suffix
                //
                String className = classType.toString();
                String intfName = className.substring(0, className.length() - 4);
                AnnotationProcessorEnvironment ape = getAnnotationProcessorEnvironment();
                InterfaceDeclaration id = (InterfaceDeclaration)ape.getTypeDeclaration(intfName);
                if (id == null)
                {
                    // The specified class name may not be fully qualified.  In this case, the
                    // best we can do is look for a best fit match against the input types
                    for (TypeDeclaration td :ape.getSpecifiedTypeDeclarations())
                    {
                        if (td instanceof InterfaceDeclaration &&
                            td.getSimpleName().equals(intfName))
                        {
                            return (InterfaceDeclaration)td;
View Full Code Here

        if (_generator == null)
        {
            //
            // Locate the class that wraps the Velocity code generation process
            //
            AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();

            try
            {
                _generator = new VelocityGenerator(env);
            }
View Full Code Here

    }

    @Override
    public void check(Declaration decl)
    {
        AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
        Generator genClass = null;
        if (decl.getAnnotation(ControlInterface.class) != null)
        {
            genClass = new AptControlInterface(decl, this);
        }
        else if (decl.getAnnotation(ControlExtension.class) != null)
        {
            genClass = new AptControlInterface(decl, this);

            // When a control extension is declared, values may be assigned to
            // the properties of the parent controls.  The property constraint
            // validator is called here to ensure all values assigned satisfy any
            // constraints declared in the properties.
            try
            {
                AnnotationConstraintAptValidator.validate(decl);
            }
            catch (IllegalArgumentException iae)
            {
                printError(decl, "propertyset.illegal.argument.error", iae.getMessage());
            }
           
        }
        else if (decl.getAnnotation(ControlImplementation.class) != null)
        {
            genClass = new AptControlImplementation(decl, this);
        }
        else if (decl.getAnnotation(PropertySet.class) != null)
        {
            new AptPropertySet(null, decl, this);
        }

        if ( genClass != null && !hasErrors() )
        {
            try
            {
                List<GeneratorOutput> genList = genClass.getCheckOutput(env.getFiler());
                if (genList == null || genList.size() == 0)
                    return;

                for (GeneratorOutput genOut : genList)
                {
View Full Code Here

    }

    @Override
    public void generate(Declaration decl)
    {
        AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
        Generator genClass = null;
        if (decl.getAnnotation(ControlInterface.class) != null)
        {
            genClass = new AptControlInterface(decl, this);
        }
        if (decl.getAnnotation(ControlExtension.class) != null)
        {
            genClass = new AptControlInterface(decl, this);
        }
        else if (decl.getAnnotation(ControlImplementation.class) != null)
        {
            genClass = new AptControlImplementation(decl, this);
        }
       
        if ( genClass != null )
        {
            try
            {
                List<GeneratorOutput> genList = genClass.getGenerateOutput(env.getFiler());
                if (genList == null || genList.size() == 0)
                    return;

                for (GeneratorOutput genOut : genList)
                {
View Full Code Here

        if (_generator == null)
        {
            //
            // Locate the class that wraps the Velocity code generation process
            //
            AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();

            try
            {
                _generator = new VelocityGenerator(env);
            }
View Full Code Here

        for (AnnotationTypeDeclaration atd : _atds)
        {
            if (atd.getSimpleName().equals("Control") )
            {
                AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
                Collection<Declaration> decls = env.getDeclarationsAnnotatedWith(atd);
                for (Declaration decl : decls)
                {
                    if ( decl instanceof FieldDeclaration )
                    {
                        FieldDeclaration fd = (FieldDeclaration)decl;
                        TypeDeclaration clientType = fd.getDeclaringType();
                        TypeMirror controlFieldType = fd.getType();
                        addControlType( clientsMap, clientType, controlFieldType );

                        /*
                        If this field is public or protected, add the control type to any derived class.  Private
                        fields are also included here as private controls in superclasses may be exposed through public
                        or protected methods to subclasses
                        */
                        Collection<Modifier> modifiers = fd.getModifiers();
                        if (modifiers.contains( Modifier.PUBLIC ) ||
                            modifiers.contains( Modifier.PROTECTED ) ||
                            modifiers.contains( Modifier.PRIVATE) )
                        {
                            Collection<TypeDeclaration> specifiedTypeDeclartions = env.getSpecifiedTypeDeclarations();
                            for (TypeDeclaration td : specifiedTypeDeclartions)
                            {
                                if ( td instanceof ClassDeclaration )
                                {
                                    ClassType superclass = ( ( ClassDeclaration ) td ).getSuperclass();

                                    while ( superclass != null )
                                    {
                                        if ( superclass.getDeclaration().equals( clientType ) )
                                        {
                                            addControlType( clientsMap, td, controlFieldType );
                                            break;
                                        }

                                        superclass = superclass.getSuperclass();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (atd.getSimpleName().equals("ControlReferences"))
            {
                Collection<Declaration> decls = getAnnotationProcessorEnvironment().getDeclarationsAnnotatedWith(atd);
                for (Declaration decl : decls)
                {
                    if ( decl instanceof TypeDeclaration )
                    {
                        TypeDeclaration clientType = (TypeDeclaration)decl;
                        Set<TypeMirror> controlTypes = clientsMap.get( clientType );
                        if ( controlTypes == null )
                        {
                            controlTypes = new HashSet<TypeMirror>();
                            clientsMap.put( clientType, controlTypes );
                        }

                        // Read ControlReferences annotation
                        AnnotationMirror controlMirror = null;
                        for (AnnotationMirror annot : clientType.getAnnotationMirrors())
                        {
                            if (annot.getAnnotationType().getDeclaration().getQualifiedName().equals(
                                    "org.apache.beehive.controls.api.bean.ControlReferences"))
                            {
                                controlMirror = annot;
                                break;
                            }
                        }

                        assert( controlMirror != null );

                        // Add each control type listed in the ControlReferences annotation
                        AptAnnotationHelper controlAnnot = new AptAnnotationHelper(controlMirror);
                        Collection<AnnotationValue> references = (Collection<AnnotationValue>)controlAnnot.getObjectValue("value");
                        if ( references != null )
                        {
                            for ( AnnotationValue av : references )
                            {
                                TypeMirror crType = (TypeMirror)av.getValue();
                                controlTypes.add( crType );
                            }
                        }
                    }
                }
            }
        }

        // For each client type:
        //   1 - emit a controls client manifest in the same dir as the client type's class.
        //   2 - emit a controls client initializer class in the same pkg/dir as the client type's class

        Filer f = getAnnotationProcessorEnvironment().getFiler();
        Set<TypeDeclaration> clientTypes = clientsMap.keySet();
        for ( TypeDeclaration clientType : clientTypes )
        {
            // Emit manifest

            String clientPkg = clientType.getPackage().getQualifiedName();
            File clientManifestName =
                new File( clientType.getSimpleName() + ControlClientManifest.FILE_EXTENSION );

            ControlClientManifest mf = new ControlClientManifest( clientType.getQualifiedName() );

            try
            {
                Set<TypeMirror> controlTypes = clientsMap.get( clientType );
                for ( TypeMirror controlType : controlTypes )
                {
                    InterfaceDeclaration controlIntfOrExt = getControlInterfaceOrExtension(controlType);
                    InterfaceDeclaration controlIntf = getMostDerivedControlInterface( controlIntfOrExt );

                    assert controlIntf != null : "Can't find most derived control intf for=" + controlIntfOrExt;

                    ControlInterface annot = controlIntf.getAnnotation(ControlInterface.class);
                    String defBinding = annot.defaultBinding();

                    defBinding = ControlBeanContext.resolveDefaultBinding( defBinding, controlIntf.getQualifiedName() );

                    mf.addControlType( controlIntfOrExt.getQualifiedName(), defBinding );
                }

                mf.emit( f, clientPkg, clientManifestName, null );
            }
            catch ( IOException ie )
            {
                printError( clientType, "controls.client.manifest.ioerror" );
                ie.printStackTrace( );
            }

            // Emit initializer

            AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
            Generator genClass = new AptControlClient( clientType, this );

            if ( genClass != null )
            {
                try
                {
                    List<GeneratorOutput> genList = genClass.getGenerateOutput(env.getFiler());
                    if (genList == null || genList.size() == 0)
                        return;

                    for (GeneratorOutput genOut : genList)
                    {
View Full Code Here

                //
                // Compute the bean type name, and the associated interface name by stripping
                // the "Bean" suffix
                //
                String className = classType.toString();
                AnnotationProcessorEnvironment ape = getAnnotationProcessorEnvironment();
                InterfaceDeclaration id = null;
                String intfName = null;
                if (className.length() > 4) {
                    intfName = className.substring(0, className.length() - 4);
                    id = (InterfaceDeclaration)ape.getTypeDeclaration(intfName);
                }

                if (id == null && intfName != null)
                {
                    // The specified class name may not be fully qualified.  In this case, the
                    // best we can do is look for a best fit match against the input types
                    for (TypeDeclaration td :ape.getSpecifiedTypeDeclarations())
                    {
                        if (td instanceof InterfaceDeclaration &&
                            td.getSimpleName().equals(intfName))
                        {
                            return (InterfaceDeclaration)td;
View Full Code Here

     */
    protected CodeGenerator getGenerator() {

        if (_generator == null) {
            /* Locate the class that wraps the Velocity code generation process */
            AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();

            try {
                _generator = new VelocityGenerator(env);
            }
            catch (Exception e) {
View Full Code Here

    }

    @Override
    public void check(Declaration decl)
    {
        AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
        Generator genClass = null;
        if (decl.getAnnotation(ControlInterface.class) != null)
        {
            genClass = new AptControlInterface(decl, this);
        }
        else if (decl.getAnnotation(ControlExtension.class) != null)
        {
            genClass = new AptControlInterface(decl, this);

            // When a control extension is declared, values may be assigned to
            // the properties of the parent controls.  The property constraint
            // validator is called here to ensure all values assigned satisfy any
            // constraints declared in the properties.
            try
            {
                AnnotationConstraintAptValidator.validate(decl);
            }
            catch (IllegalArgumentException iae)
            {
                printError(decl, "propertyset.illegal.argument.error", iae.getMessage());
            }
           
        }
        else if (decl.getAnnotation(ControlImplementation.class) != null)
        {
            genClass = new AptControlImplementation(decl, this);
        }
        else if (decl.getAnnotation(PropertySet.class) != null)
        {
            new AptPropertySet(null, decl, this);
        }

        if ( genClass != null && !hasErrors() )
        {
            try
            {
                List<GeneratorOutput> genList = genClass.getCheckOutput(env.getFiler());
                if (genList == null || genList.size() == 0)
                    return;

                for (GeneratorOutput genOut : genList)
                {
View Full Code Here

TOP

Related Classes of com.sun.mirror.apt.AnnotationProcessorEnvironment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.