Package com.sun.mirror.declaration

Examples of com.sun.mirror.declaration.TypeDeclaration


                {
                    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


                for (Declaration decl : decls)
                {
                    if ( decl instanceof FieldDeclaration )
                    {
                        FieldDeclaration fd = (FieldDeclaration)decl;
                        TypeDeclaration clientType = fd.getDeclaringType();
                        TypeMirror controlFieldType = fd.getType();
                        addControlType( clientsMap, clientType, controlFieldType );

                        /*
                        Add the control type to any derived class.  Fields with
                        private and default (package) access are also included
                        here as the controls in superclasses may be exposed
                        through public or protected methods to subclasses.
                        */
                        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

        // declaration on the associated control interface
        //
        DeclaredType fieldType = (DeclaredType)_fieldDecl.getType();
        Iterator<TypeMirror> paramBoundIter = fieldType.getActualTypeArguments().iterator();

        TypeDeclaration intfDecl = (TypeDeclaration)_controlIntf.getTypeDeclaration();
        Iterator<TypeParameterDeclaration> paramDeclIter =
                                            intfDecl.getFormalTypeParameters().iterator();

        //
        // Iterate through them in parallel, creating a mapping from the original formal
        // type parameter name to the actual bound type.  In parallel, also build up a
        // representation of the bound type declaration.
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

        // 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

            t.accept(ats);
        }

        // Turn collection of ClassSymbols into Collection of apt decls
        for (ClassSymbol cs : ats.specifiedDeclCollection) {
            TypeDeclaration decl = aptenv.declMaker.getTypeDeclaration(cs);
            spectypedecls.add(decl);
        }

        for (ClassSymbol cs : ats.declCollection) {
            TypeDeclaration decl = aptenv.declMaker.getTypeDeclaration(cs);
            typedecls.add(decl);
        }

        unmatchedAnnotations.addAll(ats.getAnnotationSet());

        // Process input class files
        for(ClassSymbol cs : classes) {
            TypeDeclaration decl = aptenv.declMaker.getTypeDeclaration(cs);
            // System.out.println("Adding a class to spectypedecls");
            spectypedecls.add(decl);
            typedecls.add(decl);
            computeAnnotationSet(cs, unmatchedAnnotations);
        }

        if (options.get("-XListAnnotationTypes") != null) {
            out.println("Set of annotations found:" +
                        (new TreeSet<String>(unmatchedAnnotations)).toString());
        }

        AnnotationProcessorEnvironmentImpl trivAPE =
            new AnnotationProcessorEnvironmentImpl(spectypedecls, typedecls, origOptions, context);

        if (options.get("-XListDeclarations") != null) {
            out.println("Set of Specified Declarations:" +
                        spectypedecls);

            out.println("Set of Included Declarations: " +
                           typedecls);
        }

        if (options.get("-print") != null) {
            if (spectypedecls.size() == 0 )
                throw new UsageMessageNeededException();

            // Run the printing processor
            AnnotationProcessor proc = (new BootstrapAPF()).getProcessorFor(new HashSet<AnnotationTypeDeclaration>(),
                                                                            trivAPE);
            proc.process();
        } else {
            // Discovery process

            // List of annotation processory factory instances
            java.util.Iterator providers = null;
            {
                /*
                 * If a factory is provided by the user, the
                 * "-factory" and "-factorypath" options are not used.
                 *
                 * Otherwise, if the "-factory" option is used, search
                 * the appropriate path for the named class.
                 * Otherwise, use sun.misc.Service to implement the
                 * default discovery policy.
                 */

                java.util.List<AnnotationProcessorFactory> list =
                    new LinkedList<AnnotationProcessorFactory>();
                String factoryName = options.get("-factory");

                if (providedFactory != null) {
                    list.add(providedFactory);
                    providers = list.iterator();
                } else if (factoryName != null) {
                    try {
                        AnnotationProcessorFactory factory =
                            (AnnotationProcessorFactory) (aptCL.loadClass(factoryName).newInstance());
                        list.add(factory);
                    } catch (ClassNotFoundException cnfe) {
                        bark.aptWarning("FactoryNotFound", factoryName);
                    } catch (ClassCastException cce) {
                        bark.aptWarning("FactoryWrongType", factoryName);
                    } catch (Exception e ) {
                        bark.aptWarning("FactoryCantInstantiate", factoryName);
                    } catch(Throwable t) {
                        throw new AnnotationProcessingError(t);
                    }

                    providers = list.iterator();
                } else
                    providers = sun.misc.Service.providers(AnnotationProcessorFactory.class, aptCL);
            }

            java.util.Map<AnnotationProcessorFactory, Set<AnnotationTypeDeclaration>> factoryToAnnotation =
                new LinkedHashMap<AnnotationProcessorFactory, Set<AnnotationTypeDeclaration>>();

            if (!providers.hasNext() && productiveFactories.size() == 0) {
                if (unmatchedAnnotations.size() > 0)
                    bark.aptWarning("NoAnnotationProcessors");
                if (spectypedecls.size() == 0)
                    throw new UsageMessageNeededException();
                return; // no processors; nothing else to do
            } else {
                // If there are no annotations, still give
                // processors that match everything a chance to
                // run.

                if(unmatchedAnnotations.size() == 0)
                    unmatchedAnnotations.add("");

                Set<String> emptyStringSet = new HashSet<String>();
                emptyStringSet.add("");
                emptyStringSet = Collections.unmodifiableSet(emptyStringSet);

                while (providers.hasNext() ) {
                    Object provider = providers.next();
                    try {
                        Set<String> matchedStrings = new HashSet<String>();

                        AnnotationProcessorFactory apf = (AnnotationProcessorFactory) provider;
                        Collection<String> supportedTypes = apf.supportedAnnotationTypes();

                        Collection<Pattern> supportedTypePatterns = new LinkedList<Pattern>();
                        for(String s: supportedTypes)
                            supportedTypePatterns.add(importStringToPattern(s));

                        for(String s: unmatchedAnnotations) {
                            for(Pattern p: supportedTypePatterns) {
                                if (p.matcher(s).matches()) {
                                    matchedStrings.add(s);
                                    break;
                                }
                            }
                        }

                        unmatchedAnnotations.removeAll(matchedStrings);

                        if (options.get("-XPrintFactoryInfo") != null) {
                            out.println("Factory " + apf.getClass().getName() +
                                        " matches " +
                                        ((matchedStrings.size() == 0)?
                                         "nothing.": matchedStrings));
                        }

                        if (matchedStrings.size() > 0) {
                            // convert annotation names to annotation
                            // type decls
                            Set<AnnotationTypeDeclaration> atds = new HashSet<AnnotationTypeDeclaration>();

                            // If a "*" processor is called on the
                            // empty string, pass in an empty set of
                            // annotation type declarations.
                            if (!matchedStrings.equals(emptyStringSet)) {
                                for(String s: matchedStrings) {
                                    TypeDeclaration decl = aptenv.declMaker.getTypeDeclaration(s);
                                    AnnotationTypeDeclaration annotdecl;
                                    if (decl == null) {
                                        bark.aptError("DeclarationCreation", s);
                                    } else {
                                        try {
View Full Code Here

    public TypeMirror ref(Class c) {
        if(c.isArray())
            return env.getTypeUtils().getArrayType( ref(c.getComponentType()) );
        if(c.isPrimitive())
            return getPrimitive(c);
        TypeDeclaration t = env.getTypeDeclaration(getSourceClassName(c));
        // APT only operates on a set of classes used in the compilation,
        // and it won't recognize additional classes (even if they are visible from javac)
        // and return null.
        //
        // this is causing a problem where we check if a type is collection.
View Full Code Here

   * Load the qname of the referenced root element declaration.
   *
   * @return the qname of the referenced root element declaration.
   */
  protected QName loadRef() {
    TypeDeclaration declaration = null;
    String elementDeclaration;
    DecoratedTypeMirror refType;
    try {
      if ((xmlElementRef != null) && (xmlElementRef.type() != XmlElementRef.DEFAULT.class)) {
        Class typeClass = xmlElementRef.type();
        elementDeclaration = typeClass.getName();
        declaration = getEnv().getTypeDeclaration(typeClass.getName());
        refType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(getEnv().getTypeUtils().getDeclaredType(declaration));
      }
      else {
        TypeMirror accessorType = getBareAccessorType();
        elementDeclaration = accessorType.toString();
        if (accessorType instanceof DeclaredType) {
          declaration = ((DeclaredType) accessorType).getDeclaration();
        }
        refType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(accessorType);
      }
    }
    catch (MirroredTypeException e) {
      //This exception implies the ref is within the source base.
      TypeMirror typeMirror = e.getTypeMirror();
      elementDeclaration = typeMirror.toString();
      if (typeMirror instanceof DeclaredType) {
        declaration = ((DeclaredType) typeMirror).getDeclaration();
      }
      refType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(typeMirror);
    }

    QName refQName = null;
    if (refType.isInstanceOf(JAXBElement.class.getName())) {
      String localName = xmlElementRef != null && !"##default".equals(xmlElementRef.name()) ? xmlElementRef.name() : null;
      String namespace = xmlElementRef != null ? xmlElementRef.namespace() : "";
      if (localName == null) {
        throw new ValidationException(getPosition(), "Member " + getName() + " of " + getTypeDefinition().getQualifiedName() + ": @XmlElementRef annotates a type JAXBElement without specifying the name of the JAXB element.");
      }
      refQName = new QName(namespace, localName);
    }
    else if (declaration instanceof ClassDeclaration && declaration.getAnnotation(XmlRootElement.class) != null) {
      ClassDeclaration classDeclaration = (ClassDeclaration) declaration;
      RootElementDeclaration refElement = new RootElementDeclaration(classDeclaration, ((EnunciateFreemarkerModel) FreemarkerModel.get()).findTypeDefinition(classDeclaration));
      refQName = new QName(refElement.getNamespace(), refElement.getName());
    }

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.