Package com.sun.mirror.declaration

Examples of com.sun.mirror.declaration.TypeDeclaration


            }
        }

        public String getPackage() {
            if (declaration instanceof TypeDeclaration) {
                TypeDeclaration typeDeclaration = (TypeDeclaration) declaration;
                return typeDeclaration.getPackage().getQualifiedName();
            } else if (declaration instanceof FieldDeclaration || declaration instanceof MethodDeclaration) {
                MemberDeclaration memberDeclaration = (MemberDeclaration) declaration;
                return memberDeclaration.getDeclaringType().getPackage().getQualifiedName();
            } else {
                return null;
View Full Code Here


                if (type instanceof DeclaredType == false) {
                    throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
                }

                TypeDeclaration td = ((DeclaredType) type).getDeclaration();
                //
                // abort if Map!!! No further checking can be done.
                //
                if (td.getQualifiedName().equals("java.util.Map")) {
                    return;
                }

                Collection<? extends MethodDeclaration> methods =
                        DeclarationFilter.FILTER_PUBLIC.filter(td.getMethods());
                for (MethodDeclaration m : methods) {
                    String upperFirst = paramNameQualifiers[i].substring(0,1).toUpperCase();
                    if (paramNameQualifiers[i].length() > 1) {
                        upperFirst = upperFirst + paramNameQualifiers[i].substring(1);
                    }
                    if (m.getSimpleName().equals("get" + upperFirst)
                        || m.getSimpleName().equals("is" + upperFirst)) {
                        getterMethod = m;
                    }
                }

                if (getterMethod == null) {
                    Collection<FieldDeclaration> fields =
                            DeclarationFilter.FILTER_PUBLIC.filter(td.getFields());
                    for (FieldDeclaration fd : fields) {
                        if (fd.getSimpleName().equals(paramNameQualifiers[i])) {
                            field = fd;
                        }
                    }
View Full Code Here

                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 )
View Full Code Here

    {
        TypeMirror fieldType = f.getType();

        // Make sure that this field doesn't try to override another that's inherited.
        String fieldName = f.getSimpleName();
        TypeDeclaration declaringType = f.getDeclaringType();

        if ( declaringType instanceof ClassDeclaration )
        {
            for ( ClassType i = ( ( ClassDeclaration ) declaringType ).getSuperclass(); i != null; i = i.getSuperclass() )
            {
                ClassDeclaration decl = i.getDeclaration();

                if ( decl != null )
                {
                    for ( FieldDeclaration baseClassField : decl.getFields() )
                    {
                        if ( fieldName.equals( baseClassField.getSimpleName() ) )
                        {
                            Collection<Modifier> modifiers = baseClassField.getModifiers();

                            if ( modifiers.contains( Modifier.PROTECTED ) || modifiers.contains( Modifier.PUBLIC ) )
                            {
                                printError( f, "control.field.override", decl.getQualifiedName() );
                            }
                        }
                    }
                }
            }
        }

        // Valid control field instances can be of an interface type
        // or a class type.
        if ( fieldType instanceof InterfaceType )
        {
            // Valid interface type decls must be annotated w/ @ControlInterface
            // or @ControlExtension.
            Declaration fieldTypeDecl = ((InterfaceType)fieldType).getDeclaration();
            if ( fieldTypeDecl.getAnnotation(ControlInterface.class) == null &&
                 fieldTypeDecl.getAnnotation(ControlExtension.class) == null )
                printError( f, "control.field.bad.interfacetype" );
        }
        else if ( fieldType instanceof ClassType )
        {
            // Valid class type decls must implements the ControlBean API.

            // Walk the implementation inheritance hierarchy, seeing if one of the
            // classes implements ControlBean. 
            //
            // REVIEW: Does NOT check if the interfaces might implement ControlBean!
            // This is unnecessary for our impl, since our generated bean class directly
            // implements ControlBean, but other impls may choose to do otherwise.
            boolean foundControlBean = false;
            ClassType classType = (ClassType)fieldType;

            if (classType.getDeclaration() != null)
            {
                outer: while ( classType != null )
                {
                    Collection<InterfaceType> intfs = classType.getSuperinterfaces();
                    for ( InterfaceType intfType : intfs )
                    {
                        if ( intfType.getDeclaration().getQualifiedName().equals( "org.apache.beehive.controls.api.bean.ControlBean" ) )
                        {
                            foundControlBean = true;
                            break outer;
                        }
                    }
                    classType = classType.getSuperclass();
                }
                if ( !foundControlBean )
                    printError( f, "control.field.bad.classtype" );

                // Valid generated beans should only "implement" the control interface/extension, and no others
                classType = (ClassType)fieldType;
                Collection<InterfaceType> intfs = classType.getSuperinterfaces();
                if ( intfs.size() != 1 )
                {
                    printError( f, "control.field.bad.classtype.badinterface" );
                }

                for ( InterfaceType intfType : intfs )
                {
                    if ( intfType.getDeclaration().getAnnotation(ControlExtension.class) == null &&
                         intfType.getDeclaration().getAnnotation(ControlInterface.class) == null)
                    {
                        printError( f, "control.field.bad.classtype.badinterface");
                    }
                }
            }
            else
            {
                // TODO: This could be a ControlBean type that is going to be generated by
                // the current APT processing iteration.  It should be possible to do more
                // specific verification here using the getTypeDeclaration API on
                // AnnotationProcessorEnvironment.  In any event, the implementation of
                // getControlInterface will properly handle this case, and if it cannot a
                // malformed type error will be generated.
            }
         }
         else
         {
             printError( f, "control.field.bad.type" );
         }

         // Enforce any versioning requirements this control field has.
         //
         // Since our generate() does some detailed grovelling of control types, make sure that
         // will not result in an error by doing that grovelling now.  Control types may be
         // malformed if the source for those types has errors (yet the apt type may still exist!).
         try
         {
             InterfaceDeclaration controlIntfOrExt = getControlInterfaceOrExtension(fieldType);
             InterfaceDeclaration controlIntf = getMostDerivedControlInterface( controlIntfOrExt );

             if ( controlIntf != null )
             {
                 enforceVersionRequired( f, controlIntf );
             }
             else
             {
                 printError( f, "control.field.type.malformed" );
             }
         }
         catch ( CodeGenerationException cge )
         {
             printError( f, "control.field.type.malformed" );
         }

         assert declaringType != null : "Field " + f + " has no declaring type!";

         if ( declaringType.getDeclaringType() != null )
             printError( f, "control.field.in.inner.class" );

        Collection<Modifier> mods = f.getModifiers();

         if ( mods.contains( Modifier.TRANSIENT ))
View Full Code Here

                {
                    try
                    {
                        String declClassName = decl.getQualifiedName();

                        TypeDeclaration owningClass = decl.getDeclaringType();
                        if (owningClass != null)
                            declClassName = owningClass.getQualifiedName() + "$" + decl.getSimpleName();
                           
                      Class clazz = Class.forName(declClassName);
                      Annotation a = d.getAnnotation(clazz);
                      validateMembership(a);
                    }
                    catch (ClassNotFoundException cnfe)
                    {
                        //should not happen
                    }
                }
            }
        }

        // If the declaration is a class or interface, validate its methods
        // and fields.
        if (d instanceof TypeDeclaration)
        {
            TypeDeclaration td = ((TypeDeclaration) d);
            for (Declaration md : td.getMethods())
                validate(md);
            for (Declaration fd : td.getFields())
                validate(fd);
        }
        // If the delcaration is a method, validate its parameters.
        else if (d instanceof MethodDeclaration)
        {
View Full Code Here

        // This is required because it must be possible to bind the types of events immediately
        // upon construction of the bean... there is no opportunity to separately specify
        // parameterization for the event set for the purpose of creating listeners, client
        // notifiers, etc.
        //
        TypeDeclaration intfDecl = controlIntf.getTypeDeclaration();
        for (TypeParameterDeclaration estpd : _eventSet.getFormalTypeParameters())
        {
            boolean found = false;
            for (TypeParameterDeclaration citpd : intfDecl.getFormalTypeParameters())
            {
                if (estpd.getSimpleName().equals(citpd.getSimpleName()))
                {
                    found = true;
                    break;
View Full Code Here

        //
        // Add the intrinsic/base property set
        //

        TypeDeclaration basePropsDecl =
            _ap.getAnnotationProcessorEnvironment().getTypeDeclaration( "org.apache.beehive.controls.api.properties.BaseProperties" );
        if ( basePropsDecl != null )
        {
            propSets.add( new AptPropertySet( null, basePropsDecl, _ap ) );
        }

        //
        // Add external property sets
        //
        ExternalPropertySets extPropsAnnotation = _intfDecl.getAnnotation(ExternalPropertySets.class);
        if ( extPropsAnnotation != null )
        {
            if (isExtension())
            {
                _ap.printError( _intfDecl, "extpropertyset.illegal.usage" );
            }

            try
            {
                Class[] extProps = extPropsAnnotation.value();
            }
            catch ( MirroredTypesException mte )
            {
                Collection<String> extProps = mte.getQualifiedNames();
                for ( String extPropName : extProps )
                {
                    TypeDeclaration extPropDecl = _ap.getAnnotationProcessorEnvironment().getTypeDeclaration( extPropName );
                    if ( extPropDecl != null )
                    {
                        AptPropertySet extPropSet = new AptPropertySet( null, extPropDecl, _ap );
                        propSets.add( extPropSet );
                    }
View Full Code Here

        //
        // The field can either be declared as the bean type or the public interface type.
        // If it is the bean type, then we need to reflect to find the public interface
        // type it implements.
        //
        TypeDeclaration typeDecl = ((DeclaredType)controlType).getDeclaration();
        InterfaceDeclaration controlIntf = null;

        //
        // It is possible that the declared type is associated with a to-be-generated
        // bean type.  In this case, look for the associated control interface on the
View Full Code Here

                if (type instanceof DeclaredType == false) {
                    throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
                }

                TypeDeclaration td = ((DeclaredType) type).getDeclaration();
                //
                // abort if Map!!! No further checking can be done.
                //
                if (td.getQualifiedName().equals("java.util.Map")) {
                    return;
                }

                Collection<? extends MethodDeclaration> methods =
                        DeclarationFilter.FILTER_PUBLIC.filter(td.getMethods());
                for (MethodDeclaration m : methods) {
                    String upperFirst = paramNameQualifiers[i].substring(0,1).toUpperCase();
                    if (paramNameQualifiers[i].length() > 1) {
                        upperFirst = upperFirst + paramNameQualifiers[i].substring(1);
                    }
                    if (m.getSimpleName().equals("get" + upperFirst)
                        || m.getSimpleName().equals("is" + upperFirst)) {
                        getterMethod = m;
                    }
                }

                if (getterMethod == null) {
                    Collection<FieldDeclaration> fields =
                            DeclarationFilter.FILTER_PUBLIC.filter(td.getFields());
                    for (FieldDeclaration fd : fields) {
                        if (fd.getSimpleName().equals(paramNameQualifiers[i])) {
                            field = fd;
                        }
                    }
View Full Code Here

                if (type instanceof DeclaredType == false) {
                    throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
                }

                TypeDeclaration td = ((DeclaredType) type).getDeclaration();
                //
                // abort if Map!!! No further checking can be done.
                //
                if (td.getQualifiedName().equals("java.util.Map")) {
                    return;
                }

                Collection<? extends MethodDeclaration> methods =
                        DeclarationFilter.FILTER_PUBLIC.filter(td.getMethods());
                for (MethodDeclaration m : methods) {
                    String upperFirst = paramNameQualifiers[i].substring(0,1).toUpperCase();
                    if (paramNameQualifiers[i].length() > 1) {
                        upperFirst = upperFirst + paramNameQualifiers[i].substring(1);
                    }
                    if (m.getSimpleName().equals("get" + upperFirst)
                        || m.getSimpleName().equals("is" + upperFirst)) {
                        getterMethod = m;
                    }
                }

                if (getterMethod == null) {
                    Collection<FieldDeclaration> fields =
                            DeclarationFilter.FILTER_PUBLIC.filter(td.getFields());
                    for (FieldDeclaration fd : fields) {
                        if (fd.getSimpleName().equals(paramNameQualifiers[i])) {
                            field = fd;
                        }
                    }
View Full Code Here

TOP

Related Classes of com.sun.mirror.declaration.TypeDeclaration

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.