langtools/src/share/classes/com/sun/tools/apt/mirror/declaration/DeclarationImpl.java
author darcy
Thu, 25 Feb 2010 11:04:11 -0800
changeset 5003 fd0b30cdbe5c
parent 3378 22011d9a9398
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
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 2004-2005 Sun Microsystems, Inc.  All Rights Reserved.
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.mirror.declaration;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.lang.annotation.Annotation;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.ArrayList;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.LinkedList;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.util.Collection;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import java.util.EnumSet;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.mirror.declaration.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.mirror.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.apt.mirror.AptEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.apt.mirror.util.SourcePositionImpl;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.javac.comp.AttrContext;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import com.sun.tools.javac.comp.Env;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import com.sun.tools.javac.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import com.sun.tools.javac.util.Name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
import com.sun.tools.javac.util.Position;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
import static com.sun.mirror.declaration.Modifier.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
import static com.sun.tools.javac.code.Kinds.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * Implementation of Declaration
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 */
3378
22011d9a9398 6381698: Warn of decommissioning of apt
darcy
parents: 10
diff changeset
    55
@SuppressWarnings("deprecation")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
public abstract class DeclarationImpl implements Declaration {
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    protected final AptEnv env;
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    public final Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
5003
fd0b30cdbe5c 6929645: Address various findbugs warnings in langtools
darcy
parents: 3378
diff changeset
    61
    protected static final DeclarationFilter identityFilter =
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
            new DeclarationFilter();
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * "sym" should be completed before this constructor is called.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    protected DeclarationImpl(AptEnv env, Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        this.env = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        this.sym = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * <p> ParameterDeclarationImpl overrides this implementation.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    public boolean equals(Object obj) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        if (obj instanceof DeclarationImpl) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
            DeclarationImpl that = (DeclarationImpl) obj;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            return sym == that.sym && env == that.env;
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     * <p> ParameterDeclarationImpl overrides this implementation.
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    public int hashCode() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        return sym.hashCode() + env.hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    public String getDocComment() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        // Our doc comment is contained in a map in our toplevel,
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        // indexed by our tree.  Find our enter environment, which gives
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        // us our toplevel.  It also gives us a tree that contains our
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        // tree:  walk it to find our tree.  This is painful.
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        Env<AttrContext> enterEnv = getEnterEnv();
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        if (enterEnv == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        JCTree tree = TreeInfo.declarationFor(sym, enterEnv.tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        return enterEnv.toplevel.docComments.get(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    public Collection<AnnotationMirror> getAnnotationMirrors() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        Collection<AnnotationMirror> res =
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            new ArrayList<AnnotationMirror>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        for (Attribute.Compound a : sym.getAnnotationMirrors()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
            res.add(env.declMaker.getAnnotationMirror(a, this));
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        return res;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     * Overridden by ClassDeclarationImpl to handle @Inherited.
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    public <A extends Annotation> A getAnnotation(Class<A> annoType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        return getAnnotation(annoType, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    protected <A extends Annotation> A getAnnotation(Class<A> annoType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
                                                     Symbol annotated) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        if (!annoType.isAnnotation()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
            throw new IllegalArgumentException(
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
                                "Not an annotation type: " + annoType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        String name = annoType.getName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        for (Attribute.Compound attr : annotated.getAnnotationMirrors()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
            if (name.equals(attr.type.tsym.flatName().toString())) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
                return AnnotationProxyMaker.generateAnnotation(env, attr,
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
                                                               annoType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    // Cache for modifiers.
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    private EnumSet<Modifier> modifiers = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    public Collection<Modifier> getModifiers() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        if (modifiers == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
            modifiers = EnumSet.noneOf(Modifier.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
            long flags = AptEnv.getFlags(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
            if (0 != (flags & Flags.PUBLIC))       modifiers.add(PUBLIC);
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
            if (0 != (flags & Flags.PROTECTED))    modifiers.add(PROTECTED);
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
            if (0 != (flags & Flags.PRIVATE))      modifiers.add(PRIVATE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
            if (0 != (flags & Flags.ABSTRACT))     modifiers.add(ABSTRACT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
            if (0 != (flags & Flags.STATIC))       modifiers.add(STATIC);
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
            if (0 != (flags & Flags.FINAL))        modifiers.add(FINAL);
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
            if (0 != (flags & Flags.TRANSIENT))    modifiers.add(TRANSIENT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
            if (0 != (flags & Flags.VOLATILE))     modifiers.add(VOLATILE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
            if (0 != (flags & Flags.SYNCHRONIZED)) modifiers.add(SYNCHRONIZED);
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
            if (0 != (flags & Flags.NATIVE))       modifiers.add(NATIVE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
            if (0 != (flags & Flags.STRICTFP))     modifiers.add(STRICTFP);
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        return modifiers;
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * Overridden in some subclasses.
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    public String getSimpleName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        return sym.name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public SourcePosition getPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        // Find the toplevel.  From there use a tree-walking utility
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        // that finds the tree for our symbol, and with it the position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        Env<AttrContext> enterEnv = getEnterEnv();
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        if (enterEnv == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        JCTree.JCCompilationUnit toplevel = enterEnv.toplevel;
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        JavaFileObject sourcefile = toplevel.sourcefile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        if (sourcefile == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        int pos = TreeInfo.positionFor(sym, toplevel);
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        return new SourcePositionImpl(sourcefile, pos, toplevel.lineMap);
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     * Applies a visitor to this declaration.
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     * @param v the visitor operating on this declaration
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    public void accept(DeclarationVisitor v) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        v.visitDeclaration(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    private Collection<Symbol> members = null;  // cache for getMembers()
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     * Returns the symbols of type or package members (and constructors)
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     * that are not synthetic or otherwise unwanted.
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
     * Caches the result if "cache" is true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    protected Collection<Symbol> getMembers(boolean cache) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        if (members != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
            return members;
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
        LinkedList<Symbol> res = new LinkedList<Symbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        for (Scope.Entry e = sym.members().elems; e != null; e = e.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
            if (e.sym != null && !unwanted(e.sym)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
                res.addFirst(e.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        return cache ? (members = res) : res;
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     * Tests whether this is a symbol that should never be seen by clients,
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     * such as a synthetic class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     * Note that a class synthesized by the compiler may not be flagged as
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     * synthetic:  see bugid 4959932.
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    private static boolean unwanted(Symbol s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        return AptEnv.hasFlag(s, Flags.SYNTHETIC) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
               (s.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                !DeclarationMaker.isJavaIdentifier(s.name.toString()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     * Returns this declaration's enter environment, or null if it
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     * has none.
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    private Env<AttrContext> getEnterEnv() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        // Get enclosing class of sym, or sym itself if it is a class
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        // or package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        TypeSymbol ts = (sym.kind != PCK)
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
                        ? sym.enclClass()
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
                        : (PackageSymbol) sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        return (ts != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
                ? env.enter.getEnv(ts)
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
                : null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
}