Package com.sun.mirror.declaration

Examples of com.sun.mirror.declaration.TypeDeclaration


    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


  public static boolean isCollectionType( @NotNull TypeMirror type ) {
    if ( !( type instanceof DeclaredType ) ) {
      return false;
    }

    TypeDeclaration declaredType = ( ( DeclaredType ) type ).getDeclaration();
    if ( declaredType == null ) {
      return false;
    }

    if ( isCollection( declaredType.getQualifiedName() ) ) {
      return true;
    }

    for ( InterfaceType interfaceType : declaredType.getSuperinterfaces() ) {
      if ( isCollection( interfaceType.getDeclaration().getQualifiedName() ) ) {
        return true;
      }
    }
View Full Code Here

  public static boolean isSetType( @NotNull TypeMirror type ) {
    if ( !( type instanceof DeclaredType ) ) {
      return false;
    }

    TypeDeclaration declaredType = ( ( DeclaredType ) type ).getDeclaration();
    if ( declaredType == null ) {
      throw new IllegalArgumentException( "No declaration found for <" + type + ">" );
    }

    if ( isSet( declaredType.getQualifiedName() ) ) {
      return true;
    }

    for ( InterfaceType interfaceType : declaredType.getSuperinterfaces() ) {
      if ( isSet( interfaceType.getDeclaration().getQualifiedName() ) ) {
        return true;
      }
    }
View Full Code Here

  public static boolean isNumberType( @NotNull TypeMirror type ) {
    return NUMBER_TYPE_NAMES.contains( type.toString() );
  }

  public static boolean isInner( @NotNull ClassDeclaration classDeclaration ) {
    TypeDeclaration declaringType = classDeclaration.getDeclaringType();
    if ( declaringType == null ) {
      return false;
    }

    @NonNls
    String declarationAsString = classDeclaration.toString();
    @NonNls
    String declaringTypeAsString = declaringType.toString();
    if ( declarationAsString.equals( declaringTypeAsString ) ) {
      return false;
    }

    return declarationAsString.startsWith( declaringTypeAsString );
View Full Code Here

                final Set<TypeDeclaration> optionBeans = new HashSet<TypeDeclaration>();
                for (Declaration d : params) {
                    d.accept(new SimpleDeclarationVisitor() {
                        public void visitFieldDeclaration(FieldDeclaration f) {
                            TypeDeclaration dt = f.getDeclaringType();
                            optionBeans.add(dt);
                        }

                        public void visitMethodDeclaration(MethodDeclaration m) {
                            optionBeans.add(m.getDeclaringType());
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

            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<AnnotationProcessorFactory> 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 {
                    @SuppressWarnings("unchecked")
                    Iterator<AnnotationProcessorFactory> iter =
                            sun.misc.Service.providers(AnnotationProcessorFactory.class, aptCL);
                    providers = iter;

                }
            }

            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 static TypeMirror getCollectionParam( @NotNull TypeMirror type ) {
    if ( !( type instanceof DeclaredType ) ) {
      throw new IllegalStateException( "Invalid type: " + type );
    }

    TypeDeclaration declaredType = ( ( DeclaredType ) type ).getDeclaration();
    if ( declaredType == null ) {
      throw new IllegalStateException( "No declaration found for <" + type + ">" );
    }

    if ( isCollection( declaredType.getQualifiedName() ) ) {
      return getFirstTypeParam( ( DeclaredType ) type );
    }

    for ( InterfaceType interfaceType : declaredType.getSuperinterfaces() ) {
      if ( isCollection( interfaceType.getDeclaration().getQualifiedName() ) ) {
        return getFirstTypeParam( ( DeclaredType ) type );
      }
    }
View Full Code Here

  public static boolean isSetType( @NotNull TypeMirror type ) {
    if ( !( type instanceof DeclaredType ) ) {
      return false;
    }

    TypeDeclaration declaredType = ( ( DeclaredType ) type ).getDeclaration();
    if ( declaredType == null ) {
      throw new IllegalStateException( "No declaration found for <" + type + ">" );
    }

    if ( isSet( declaredType.getQualifiedName() ) ) {
      return true;
    }

    for ( InterfaceType interfaceType : declaredType.getSuperinterfaces() ) {
      if ( isSet( interfaceType.getDeclaration().getQualifiedName() ) ) {
        return true;
      }
    }
View Full Code Here

  public static boolean isCollectionType( @Nonnull TypeMirror type ) {
    if ( !( type instanceof DeclaredType ) ) {
      return false;
    }

    TypeDeclaration declaredType = ( ( DeclaredType ) type ).getDeclaration();
    if ( declaredType == null ) {
      return false;
    }

    if ( isCollection( declaredType.getQualifiedName() ) ) {
      return true;
    }

    for ( InterfaceType interfaceType : declaredType.getSuperinterfaces() ) {
      if ( isCollection( interfaceType.getDeclaration().getQualifiedName() ) ) {
        return true;
      }
    }
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.