Examples of AnnotationProcessorEnvironment


Examples of com.sun.mirror.apt.AnnotationProcessorEnvironment

    }

    @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

Examples of com.sun.mirror.apt.AnnotationProcessorEnvironment

        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

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 );

                        /*
                        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 )
                {
                    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 = ControlUtils.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

Examples of com.sun.mirror.apt.AnnotationProcessorEnvironment

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

Examples of com.sun.mirror.apt.AnnotationProcessorEnvironment

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

Examples of com.sun.mirror.apt.AnnotationProcessorEnvironment

   * @param classDeclaration The class declaration.
   * @param fqn              The FQN.
   * @return Whether the class declaration is an instance of the declared type of the given fully-qualified name.
   */
  protected boolean isInstanceOf(ClassDeclaration classDeclaration, String fqn) {
    AnnotationProcessorEnvironment env = Context.getCurrentEnvironment();
    Types utils = env.getTypeUtils();
    DeclaredType declaredType = utils.getDeclaredType(env.getTypeDeclaration(classDeclaration.getQualifiedName()));
    DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaredType);
    return decorated.isInstanceOf(fqn);
  }
View Full Code Here

Examples of com.sun.mirror.apt.AnnotationProcessorEnvironment

    if (specifiedType != null) {
      if (!isChoice) {
        DecoratedTypeMirror accessorType = (DecoratedTypeMirror) super.getAccessorType();

        if (accessorType.isCollection()) {
          AnnotationProcessorEnvironment ape = Context.getCurrentEnvironment();
          Types types = ape.getTypeUtils();
          if (specifiedType instanceof PrimitiveType) {
            specifiedType = types.getPrimitiveType(((PrimitiveType) specifiedType).getKind());
          }
          else {
            specifiedType = types.getDeclaredType(ape.getTypeDeclaration(((DeclaredType) specifiedType).getDeclaration().getQualifiedName()));
          }
          specifiedType = TypeMirrorDecorator.decorate(types.getDeclaredType(ape.getTypeDeclaration(((DeclaredType) accessorType).getDeclaration().getQualifiedName()), specifiedType));
        }
        else if (accessorType.isArray() && !(specifiedType instanceof ArrayType)) {
          Types types = Context.getCurrentEnvironment().getTypeUtils();
          if (specifiedType instanceof PrimitiveType) {
            specifiedType = types.getPrimitiveType(((PrimitiveType) specifiedType).getKind());
View Full Code Here

Examples of com.sun.mirror.apt.AnnotationProcessorEnvironment

    if (specifiedType != null) {
      if (!isChoice) {
        DecoratedTypeMirror accessorType = (DecoratedTypeMirror) super.getAccessorType();

        if (accessorType.isCollection()) {
          AnnotationProcessorEnvironment ape = Context.getCurrentEnvironment();
          Types types = ape.getTypeUtils();
          if (specifiedType instanceof PrimitiveType) {
            specifiedType = types.getPrimitiveType(((PrimitiveType) specifiedType).getKind());
          }
          else {
            specifiedType = types.getDeclaredType(ape.getTypeDeclaration(((DeclaredType) specifiedType).getDeclaration().getQualifiedName()));
          }
          specifiedType = TypeMirrorDecorator.decorate(types.getDeclaredType(ape.getTypeDeclaration(((DeclaredType) accessorType).getDeclaration().getQualifiedName()), specifiedType));
        }
        else if (accessorType.isArray() && !(specifiedType instanceof ArrayType)) {
          Types types = Context.getCurrentEnvironment().getTypeUtils();
          if (specifiedType instanceof PrimitiveType) {
            specifiedType = types.getPrimitiveType(((PrimitiveType) specifiedType).getKind());
View Full Code Here

Examples of com.sun.mirror.apt.AnnotationProcessorEnvironment

   *
   * @param clazz The class.
   * @return The accessor type.
   */
  protected TypeMirror getAccessorType(Class clazz) {
    AnnotationProcessorEnvironment env = Context.getCurrentEnvironment();
    TypeMirror undecorated;
    if (clazz.isPrimitive()) {
      if (Boolean.TYPE == clazz) {
        undecorated = env.getTypeUtils().getPrimitiveType(PrimitiveType.Kind.BOOLEAN);
      }
      else if (Byte.TYPE == clazz) {
        undecorated = env.getTypeUtils().getPrimitiveType(PrimitiveType.Kind.BYTE);
      }
      else if (Character.TYPE == clazz) {
        undecorated = env.getTypeUtils().getPrimitiveType(PrimitiveType.Kind.CHAR);
      }
      else if (Double.TYPE == clazz) {
        undecorated = env.getTypeUtils().getPrimitiveType(PrimitiveType.Kind.DOUBLE);
      }
      else if (Float.TYPE == clazz) {
        undecorated = env.getTypeUtils().getPrimitiveType(PrimitiveType.Kind.FLOAT);
      }
      else if (Integer.TYPE == clazz) {
        undecorated = env.getTypeUtils().getPrimitiveType(PrimitiveType.Kind.INT);
      }
      else if (Long.TYPE == clazz) {
        undecorated = env.getTypeUtils().getPrimitiveType(PrimitiveType.Kind.LONG);
      }
      else if (Short.TYPE == clazz) {
        undecorated = env.getTypeUtils().getPrimitiveType(PrimitiveType.Kind.SHORT);
      }
      else {
        throw new IllegalArgumentException("Unknown primitive type: " + clazz.getName());
      }
    }
    else if (clazz.isArray()) {
      undecorated = env.getTypeUtils().getArrayType(getAccessorType(clazz.getComponentType()));
    }
    else {
      TypeDeclaration typeDeclaration = env.getTypeDeclaration(clazz.getName());
      //todo: worry about the formal type parameters?
      undecorated = env.getTypeUtils().getDeclaredType(typeDeclaration);
    }

    return TypeMirrorDecorator.decorate(undecorated);
  }
View Full Code Here

Examples of com.sun.mirror.apt.AnnotationProcessorEnvironment

      DecoratedTypeMirror returnTypeMirror;
      TypeHint hintInfo = getAnnotation(TypeHint.class);
      if (hintInfo != null) {
        try {
          Class hint = hintInfo.value();
          AnnotationProcessorEnvironment env = net.sf.jelly.apt.Context.getCurrentEnvironment();
          if (TypeHint.NO_CONTENT.class.equals(hint)) {
            returnTypeMirror = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(env.getTypeUtils().getVoidType());
          }
          else {
            String hintName = hint.getName();

            if (TypeHint.NONE.class.equals(hint)) {
              hintName = hintInfo.qualifiedName();
            }

            if (!"##NONE".equals(hintName)) {
              TypeDeclaration type = env.getTypeDeclaration(hintName);
              returnTypeMirror = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(env.getTypeUtils().getDeclaredType(type));
            }
            else {
              returnTypeMirror = (DecoratedTypeMirror) getReturnType();
            }
          }
        }
        catch (MirroredTypeException e) {
          returnTypeMirror = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(e.getTypeMirror());
        }
        returnTypeMirror.setDocComment(((DecoratedTypeMirror) getReturnType()).getDocComment());
      }
      else {
        returnTypeMirror = (DecoratedTypeMirror) getReturnType();

        if (getJavaDoc().get("returnWrapped") != null) { //support jax-doclets. see http://jira.codehaus.org/browse/ENUNCIATE-690
          String fqn = getJavaDoc().get("returnWrapped").get(0);
          AnnotationProcessorEnvironment env = net.sf.jelly.apt.Context.getCurrentEnvironment();
          TypeDeclaration type = env.getTypeDeclaration(fqn);
          if (type != null) {
            returnTypeMirror = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(env.getTypeUtils().getDeclaredType(type));
          }
        }

        // in the case where the return type is com.sun.jersey.api.JResponse,
        // we can use the type argument to get the entity type
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.