langtools/src/share/classes/com/sun/tools/apt/comp/Apt.java
author darcy
Thu, 25 Feb 2010 11:04:11 -0800
changeset 5003 fd0b30cdbe5c
parent 4937 2fc03fb01efa
child 5520 86e4b9a9da40
permissions -rw-r--r--
6929645: Address various findbugs warnings in langtools Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
2212
1d3dc0e0ba0c 6814575: Update copyright year
xdono
parents: 1870
diff changeset
     2
 * Copyright 2004-2009 Sun Microsystems, Inc.  All Rights Reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.apt.comp;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import com.sun.tools.javac.comp.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.tree.TreeScanner;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.util.Context;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.apt.util.Bark;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.util.Position;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import java.util.regex.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import java.lang.reflect.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import java.lang.reflect.InvocationTargetException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import java.io.IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import com.sun.tools.apt.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import com.sun.tools.apt.comp.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
import com.sun.mirror.declaration.TypeDeclaration;
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
import com.sun.mirror.declaration.AnnotationTypeDeclaration;
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
import com.sun.mirror.apt.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
// import com.sun.mirror.apt.AnnotationProcessorFactory;
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
import com.sun.mirror.apt.AnnotationProcessors;
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
import com.sun.tools.apt.mirror.AptEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
import com.sun.tools.apt.mirror.apt.FilerImpl;
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
import com.sun.tools.apt.mirror.apt.AnnotationProcessorEnvironmentImpl;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
import static com.sun.tools.apt.mirror.declaration.DeclarationMaker.isJavaIdentifier;
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 * Apt compiler phase.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *  If you write code that depends on this, you do so at your own
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *  risk.  This code and its internal interfaces are subject to change
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 *  or deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 */
3378
22011d9a9398 6381698: Warn of decommissioning of apt
darcy
parents: 2212
diff changeset
    68
@SuppressWarnings("deprecation")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
public class Apt extends ListBuffer<Env<AttrContext>> {
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    java.util.Set<String> genSourceFileNames = new java.util.LinkedHashSet<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    public java.util.Set<String> getSourceFileNames() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        return genSourceFileNames;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    /** List of names of generated class files.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    java.util.Set<String> genClassFileNames  = new java.util.LinkedHashSet<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    public java.util.Set<String> getClassFileNames() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        return genClassFileNames;
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    /* AptEnvironment */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    AptEnv aptenv;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    private Context context;
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    /** The context key for the todo list. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    protected static final Context.Key<Apt> aptKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        new Context.Key<Apt>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /** Get the Apt instance for this context. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    public static Apt instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        Apt instance = context.get(aptKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            instance = new Apt(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /** Create a new apt list. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    protected Apt(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        this.context = context;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        context.put(aptKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        aptenv = AptEnv.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * Used to scan javac trees to build data structures needed for
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     * bootstrapping the apt environment.  In particular:
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     * <ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     * <li> Generate list of canonical names of annotation types that
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     * appear in source files given on the command line
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     * <li> Collect list of javac symbols representing source files
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * given on the command line
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     * </ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    static class AptTreeScanner extends TreeScanner {
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        // Set of fully qualified names of annotation types present in
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        // examined source
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        private Set<String> annotationSet;
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        // Symbols to build bootstrapping declaration list
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        private Collection<ClassSymbol> specifiedDeclCollection;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        private Collection<ClassSymbol> declCollection;
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        public Set<String> getAnnotationSet() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
            return annotationSet;
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        public AptTreeScanner() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
            annotationSet = new  LinkedHashSet<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
            specifiedDeclCollection = new LinkedHashSet<ClassSymbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
            declCollection = new LinkedHashSet<ClassSymbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        public void visitTopLevel(JCTree.JCCompilationUnit tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            super.visitTopLevel(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
            // Print out contents -- what are we dealing with?
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            for(JCTree d: tree.defs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
                if (d instanceof JCTree.JCClassDecl)
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
                    specifiedDeclCollection.add(((JCTree.JCClassDecl) d).sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        public void visitBlock(JCTree.JCBlock tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
            ; // Do nothing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        // should add nested classes to packages, etc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        public void visitClassDef(JCTree.JCClassDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
            if (tree.sym == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                // could be an anon class w/in an initializer
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
            super.visitClassDef(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
            declCollection.add(tree.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        public void visitMethodDef(JCTree.JCMethodDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
            super.visitMethodDef(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        public void visitVarDef(JCTree.JCVariableDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
            super.visitVarDef(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        public void visitAnnotation(JCTree.JCAnnotation tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
            super.visitAnnotation(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
            annotationSet.add(tree.type.tsym.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    Set<String> computeAnnotationSet(Collection<ClassSymbol> classSymbols) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        Set<String> annotationSet = new HashSet<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        for(ClassSymbol classSymbol: classSymbols) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
            computeAnnotationSet(classSymbol, annotationSet);
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        return annotationSet;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    void computeAnnotationSet(Symbol symbol, Set<String> annotationSet) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        if (symbol != null ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
            if (symbol.getAnnotationMirrors() != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
                for(Attribute.Compound compound: symbol.getAnnotationMirrors())
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
                    annotationSet.add(compound.type.tsym.toString()); // should fullName be used instead of toString?
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            if (symbol instanceof Symbol.MethodSymbol) // add parameter annotations
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
                for(Symbol param: ((MethodSymbol) symbol).params())
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
                    computeAnnotationSet(param, annotationSet);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            if (symbol.members() != null) {
3999
e2a905534c4b 6886348: apt incorrectly uses Scope.table
jjg
parents: 3378
diff changeset
   204
                for(Scope.Entry e = symbol.members().elems; e != null; e = e.sibling)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
                    computeAnnotationSet(e.sym, annotationSet);
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    public void main(com.sun.tools.javac.util.List<JCTree.JCCompilationUnit> treeList,
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
                     ListBuffer<ClassSymbol> classes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
                     Map<String, String> origOptions,
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
                     ClassLoader aptCL,
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
                     AnnotationProcessorFactory providedFactory,
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                     java.util.Set<Class<? extends AnnotationProcessorFactory> > productiveFactories) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        Bark bark = Bark.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        java.io.PrintWriter out = bark.warnWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        Options options = Options.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        Collection<TypeDeclaration> spectypedecls =     new LinkedHashSet<TypeDeclaration>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        Collection<TypeDeclaration> typedecls =         new LinkedHashSet<TypeDeclaration>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        Set<String> unmatchedAnnotations =              new LinkedHashSet<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        Set<AnnotationTypeDeclaration> emptyATDS =      Collections.emptySet();
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
        Set<Class<? extends AnnotationProcessorFactory> > currentRoundFactories =
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
            new LinkedHashSet<Class<? extends AnnotationProcessorFactory> >();
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        // Determine what annotations are present on the input source
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        // files, create collections of specified type declarations,
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        // and type declarations.
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        AptTreeScanner ats = new AptTreeScanner();
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        for(JCTree t: treeList) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
            t.accept(ats);
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        // Turn collection of ClassSymbols into Collection of apt decls
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        for (ClassSymbol cs : ats.specifiedDeclCollection) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
            TypeDeclaration decl = aptenv.declMaker.getTypeDeclaration(cs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            spectypedecls.add(decl);
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        for (ClassSymbol cs : ats.declCollection) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
            TypeDeclaration decl = aptenv.declMaker.getTypeDeclaration(cs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
            typedecls.add(decl);
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        unmatchedAnnotations.addAll(ats.getAnnotationSet());
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        // Process input class files
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        for(ClassSymbol cs : classes) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            TypeDeclaration decl = aptenv.declMaker.getTypeDeclaration(cs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            // System.out.println("Adding a class to spectypedecls");
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
            spectypedecls.add(decl);
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
            typedecls.add(decl);
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
            computeAnnotationSet(cs, unmatchedAnnotations);
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
        if (options.get("-XListAnnotationTypes") != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
            out.println("Set of annotations found:" +
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                        (new TreeSet<String>(unmatchedAnnotations)).toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        AnnotationProcessorEnvironmentImpl trivAPE =
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
            new AnnotationProcessorEnvironmentImpl(spectypedecls, typedecls, origOptions, context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        if (options.get("-XListDeclarations") != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
            out.println("Set of Specified Declarations:" +
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
                        spectypedecls);
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
            out.println("Set of Included Declarations: " +
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
                           typedecls);
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        if (options.get("-print") != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
            if (spectypedecls.size() == 0 )
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
                throw new UsageMessageNeededException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            // Run the printing processor
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
            AnnotationProcessor proc = (new BootstrapAPF()).getProcessorFor(new HashSet<AnnotationTypeDeclaration>(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
                                                                            trivAPE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
            proc.process();
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
            // Discovery process
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
            // List of annotation processory factory instances
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 10
diff changeset
   285
            java.util.Iterator<AnnotationProcessorFactory> providers = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
            {
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
                /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
                 * If a factory is provided by the user, the
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
                 * "-factory" and "-factorypath" options are not used.
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
                 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
                 * Otherwise, if the "-factory" option is used, search
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
                 * the appropriate path for the named class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
                 * Otherwise, use sun.misc.Service to implement the
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
                 * default discovery policy.
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
                 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
                java.util.List<AnnotationProcessorFactory> list =
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
                    new LinkedList<AnnotationProcessorFactory>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
                String factoryName = options.get("-factory");
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
                if (providedFactory != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
                    list.add(providedFactory);
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
                    providers = list.iterator();
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
                } else if (factoryName != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
                    try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
                        AnnotationProcessorFactory factory =
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
                            (AnnotationProcessorFactory) (aptCL.loadClass(factoryName).newInstance());
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
                        list.add(factory);
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
                    } catch (ClassNotFoundException cnfe) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
                        bark.aptWarning("FactoryNotFound", factoryName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
                    } catch (ClassCastException cce) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
                        bark.aptWarning("FactoryWrongType", factoryName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
                    } catch (Exception e ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
                        bark.aptWarning("FactoryCantInstantiate", factoryName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
                    } catch(Throwable t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
                        throw new AnnotationProcessingError(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
                    providers = list.iterator();
1870
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 1789
diff changeset
   320
                } else {
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 1789
diff changeset
   321
                    @SuppressWarnings("unchecked")
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 1789
diff changeset
   322
                    Iterator<AnnotationProcessorFactory> iter =
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 1789
diff changeset
   323
                            sun.misc.Service.providers(AnnotationProcessorFactory.class, aptCL);
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 1789
diff changeset
   324
                    providers = iter;
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 1789
diff changeset
   325
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 1789
diff changeset
   326
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
            java.util.Map<AnnotationProcessorFactory, Set<AnnotationTypeDeclaration>> factoryToAnnotation =
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
                new LinkedHashMap<AnnotationProcessorFactory, Set<AnnotationTypeDeclaration>>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
            if (!providers.hasNext() && productiveFactories.size() == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
                if (unmatchedAnnotations.size() > 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
                    bark.aptWarning("NoAnnotationProcessors");
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
                if (spectypedecls.size() == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
                    throw new UsageMessageNeededException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
                return; // no processors; nothing else to do
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
                // If there are no annotations, still give
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
                // processors that match everything a chance to
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
                // run.
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
                if(unmatchedAnnotations.size() == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
                    unmatchedAnnotations.add("");
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
                Set<String> emptyStringSet = new HashSet<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
                emptyStringSet.add("");
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
                emptyStringSet = Collections.unmodifiableSet(emptyStringSet);
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
                while (providers.hasNext() ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
                    Object provider = providers.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
                    try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
                        Set<String> matchedStrings = new HashSet<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
                        AnnotationProcessorFactory apf = (AnnotationProcessorFactory) provider;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
                        Collection<String> supportedTypes = apf.supportedAnnotationTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                        Collection<Pattern> supportedTypePatterns = new LinkedList<Pattern>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                        for(String s: supportedTypes)
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                            supportedTypePatterns.add(importStringToPattern(s));
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
                        for(String s: unmatchedAnnotations) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
                            for(Pattern p: supportedTypePatterns) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
                                if (p.matcher(s).matches()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
                                    matchedStrings.add(s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
                                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
                                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
                            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
                        unmatchedAnnotations.removeAll(matchedStrings);
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
                        if (options.get("-XPrintFactoryInfo") != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
                            out.println("Factory " + apf.getClass().getName() +
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
                                        " matches " +
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
                                        ((matchedStrings.size() == 0)?
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
                                         "nothing.": matchedStrings));
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
                        if (matchedStrings.size() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
                            // convert annotation names to annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
                            // type decls
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
                            Set<AnnotationTypeDeclaration> atds = new HashSet<AnnotationTypeDeclaration>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
                            // If a "*" processor is called on the
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
                            // empty string, pass in an empty set of
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
                            // annotation type declarations.
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
                            if (!matchedStrings.equals(emptyStringSet)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
                                for(String s: matchedStrings) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
                                    TypeDeclaration decl = aptenv.declMaker.getTypeDeclaration(s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
                                    AnnotationTypeDeclaration annotdecl;
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
                                    if (decl == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
                                        bark.aptError("DeclarationCreation", s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
                                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
                                        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
                                            annotdecl = (AnnotationTypeDeclaration)decl;
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
                                            atds.add(annotdecl);
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
                                        } catch (ClassCastException cce) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
                                            bark.aptError("BadDeclaration", s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
                                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
                                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
                                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
                            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
                            currentRoundFactories.add(apf.getClass());
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
                            productiveFactories.add(apf.getClass());
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
                            factoryToAnnotation.put(apf, atds);
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
                        } else if (productiveFactories.contains(apf.getClass())) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
                            // If a factory provided a processor in a
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
                            // previous round but doesn't match any
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
                            // annotations this round, call it with an
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
                            // empty set of declarations.
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
                            currentRoundFactories.add(apf.getClass());
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
                            factoryToAnnotation.put(apf, emptyATDS );
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
                        if (unmatchedAnnotations.size() == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
                            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
                    } catch (ClassCastException cce) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
                        bark.aptWarning("BadFactory", cce);
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
                unmatchedAnnotations.remove("");
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
            // If the set difference of productiveFactories and
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
            // currentRoundFactories is non-empty, call the remaining
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
            // productive factories with an empty set of declarations.
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
            {
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
                java.util.Set<Class<? extends AnnotationProcessorFactory> > neglectedFactories =
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
                    new LinkedHashSet<Class<? extends AnnotationProcessorFactory>>(productiveFactories);
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
                neglectedFactories.removeAll(currentRoundFactories);
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
                for(Class<? extends AnnotationProcessorFactory> working : neglectedFactories) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
                    try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
                        AnnotationProcessorFactory factory = working.newInstance();
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
                        factoryToAnnotation.put(factory, emptyATDS);
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
                    } catch (Exception e ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
                        bark.aptWarning("FactoryCantInstantiate", working.getName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
                    } catch(Throwable t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
                        throw new AnnotationProcessingError(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
            if (unmatchedAnnotations.size() > 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
                bark.aptWarning("AnnotationsWithoutProcessors", unmatchedAnnotations);
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
            Set<AnnotationProcessor> processors = new LinkedHashSet<AnnotationProcessor>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
            // If there were no source files AND no factory matching "*",
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
            // make sure the usage message is printed
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
            if (spectypedecls.size() == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
                factoryToAnnotation.keySet().size() == 0 )
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
                throw new UsageMessageNeededException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
            try {
5003
fd0b30cdbe5c 6929645: Address various findbugs warnings in langtools
darcy
parents: 4937
diff changeset
   460
                for(Map.Entry<AnnotationProcessorFactory, Set<AnnotationTypeDeclaration>> entry :
fd0b30cdbe5c 6929645: Address various findbugs warnings in langtools
darcy
parents: 4937
diff changeset
   461
                        factoryToAnnotation.entrySet()) {
fd0b30cdbe5c 6929645: Address various findbugs warnings in langtools
darcy
parents: 4937
diff changeset
   462
                    AnnotationProcessorFactory  apFactory = entry.getKey();
fd0b30cdbe5c 6929645: Address various findbugs warnings in langtools
darcy
parents: 4937
diff changeset
   463
                    AnnotationProcessor processor = apFactory.getProcessorFor(entry.getValue(),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
                                                                              trivAPE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
                    if (processor != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
                        processors.add(processor);
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
                    else
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
                        bark.aptWarning("NullProcessor", apFactory.getClass().getName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
            } catch(Throwable t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
                throw new AnnotationProcessingError(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
            LinkedList<AnnotationProcessor> temp = new LinkedList<AnnotationProcessor>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
            temp.addAll(processors);
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
            AnnotationProcessor proc = AnnotationProcessors.getCompositeAnnotationProcessor(temp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
                proc.process();
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
            } catch (Throwable t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
                throw new AnnotationProcessingError(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
            // Invoke listener callback mechanism
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
            trivAPE.roundComplete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
            FilerImpl filerimpl = (FilerImpl)trivAPE.getFiler();
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
            genSourceFileNames = filerimpl.getSourceFileNames();
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
            genClassFileNames = filerimpl.getClassFileNames();
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
            filerimpl.flush(); // Make sure new files are written out
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
     * Convert import-style string to regex matching that string.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
     * the string is a valid import-style string, return a regex that
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
     * won't match anything.
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
    Pattern importStringToPattern(String s) {
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 3999
diff changeset
   501
        if (com.sun.tools.javac.processing.JavacProcessingEnvironment.isValidImportString(s)) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 3999
diff changeset
   502
            return com.sun.tools.javac.processing.JavacProcessingEnvironment.validImportStringToPattern(s);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
        } else {
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 3999
diff changeset
   504
            Bark bark = Bark.instance(context);
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 3999
diff changeset
   505
            bark.aptWarning("MalformedSupportedString", s);
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 3999
diff changeset
   506
            return com.sun.tools.javac.processing.JavacProcessingEnvironment.noMatches;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
}