langtools/src/share/classes/com/sun/tools/javac/code/Lint.java
author mcimadamore
Mon, 29 Sep 2008 12:00:29 +0100
changeset 1358 a51c5f89f8af
parent 735 372aa565a221
child 1360 fd574e4926e3
permissions -rw-r--r--
6747671: -Xlint:rawtypes Summary: add an Xlint option for detecting all raw types usages (ccc-approved) Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
735
372aa565a221 6719955: Update copyright year
xdono
parents: 168
diff changeset
     2
 * Copyright 2005-2008 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.javac.code;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.EnumSet;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.HashMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.Map;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.util.Context;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.util.Options;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.util.Pair;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import static com.sun.tools.javac.code.Flags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * A class for handling -Xlint suboptions and @SuppresssWarnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *  you write code that depends on this, you do so at your own risk.
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
public class Lint
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
{
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    /** The context key for the root Lint object. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    protected static final Context.Key<Lint> lintKey = new Context.Key<Lint>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /** Get the root Lint instance. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    public static Lint instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        Lint instance = context.get(lintKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
            instance = new Lint(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * Returns the result of combining the values in this object with
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     * the given annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    public Lint augment(Attribute.Compound attr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        return augmentor.augment(this, attr);
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     * Returns the result of combining the values in this object with
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * the given annotations.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    public Lint augment(List<Attribute.Compound> attrs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        return augmentor.augment(this, attrs);
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     * Returns the result of combining the values in this object with
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     * the given annotations and flags.
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    public Lint augment(List<Attribute.Compound> attrs, long flags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        Lint l = augmentor.augment(this, attrs);
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        if ((flags & DEPRECATED) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            if (l == this)
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
                l = new Lint(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
            l.values.remove(LintCategory.DEPRECATION);
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
            l.suppressedValues.add(LintCategory.DEPRECATION);
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        return l;
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    private final AugmentVisitor augmentor;
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    private final EnumSet<LintCategory> values;
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    private final EnumSet<LintCategory> suppressedValues;
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    private static Map<String, LintCategory> map = new HashMap<String,LintCategory>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    protected Lint(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        // initialize values according to the lint options
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        Options options = Options.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        values = EnumSet.noneOf(LintCategory.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        for (Map.Entry<String, LintCategory> e: map.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
            if (options.lint(e.getKey()))
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
                values.add(e.getValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        suppressedValues = EnumSet.noneOf(LintCategory.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        context.put(lintKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        augmentor = new AugmentVisitor(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    protected Lint(Lint other) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        this.augmentor = other.augmentor;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        this.values = other.values.clone();
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        this.suppressedValues = other.suppressedValues.clone();
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        return "Lint:[values" + values + " suppressedValues" + suppressedValues + "]";
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * Categories of warnings that can be generated by the compiler.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    public enum LintCategory {
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
         * Warn about use of unnecessary casts.
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        CAST("cast"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
         * Warn about use of deprecated items.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        DEPRECATION("deprecation"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
         * Warn about items which are documented with an {@code @deprecated} JavaDoc
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
         * comment, but which do not have {@code @Deprecated} annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        DEP_ANN("dep-ann"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
         * Warn about division by constant integer 0.
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        DIVZERO("divzero"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
         * Warn about empty statement after if.
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        EMPTY("empty"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
         * Warn about falling through from one case of a switch statement to the next.
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        FALLTHROUGH("fallthrough"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
         * Warn about finally clauses that do not terminate normally.
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        FINALLY("finally"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
         * Warn about issues regarding method overrides.
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        OVERRIDES("overrides"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
         * Warn about invalid path elements on the command line.
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
         * Such warnings cannot be suppressed with the SuppressWarnings
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
         * annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        PATH("path"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
         * Warn about Serializable classes that do not provide a serial version ID.
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        SERIAL("serial"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
         * Warn about unchecked operations on raw types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
         */
1358
a51c5f89f8af 6747671: -Xlint:rawtypes
mcimadamore
parents: 735
diff changeset
   186
        UNCHECKED("unchecked"),
a51c5f89f8af 6747671: -Xlint:rawtypes
mcimadamore
parents: 735
diff changeset
   187
a51c5f89f8af 6747671: -Xlint:rawtypes
mcimadamore
parents: 735
diff changeset
   188
        /**
a51c5f89f8af 6747671: -Xlint:rawtypes
mcimadamore
parents: 735
diff changeset
   189
         * Warn about unchecked operations on raw types.
a51c5f89f8af 6747671: -Xlint:rawtypes
mcimadamore
parents: 735
diff changeset
   190
         */
a51c5f89f8af 6747671: -Xlint:rawtypes
mcimadamore
parents: 735
diff changeset
   191
        RAW("rawtypes");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        LintCategory(String option) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
            this.option = option;
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
            map.put(option, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        static LintCategory get(String option) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            return map.get(option);
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   202
        public final String option;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     * Checks if a warning category is enabled. A warning category may be enabled
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
     * on the command line, or by default, and can be temporarily disabled with
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
     * the SuppressWarnings annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    public boolean isEnabled(LintCategory lc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        return values.contains(lc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     * Checks is a warning category has been specifically suppressed, by means
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     * of the SuppressWarnings annotation, or, in the case of the deprecated
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     * category, whether it has been implicitly suppressed by virtue of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     * current entity being itself deprecated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    public boolean isSuppressed(LintCategory lc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        return suppressedValues.contains(lc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    protected static class AugmentVisitor implements Attribute.Visitor {
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        private final Context context;
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        private Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        private Lint parent;
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        private Lint lint;
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        AugmentVisitor(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
            // to break an ugly sequence of initialization dependencies,
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
            // we defer the initialization of syms until it is needed
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
            this.context = context;
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        Lint augment(Lint parent, Attribute.Compound attr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
            initSyms();
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            this.parent = parent;
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            lint = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            attr.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
            return (lint == null ? parent : lint);
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        Lint augment(Lint parent, List<Attribute.Compound> attrs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
            initSyms();
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
            this.parent = parent;
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
            lint = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
            for (Attribute.Compound a: attrs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
                a.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            return (lint == null ? parent : lint);
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        private void initSyms() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
            if (syms == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
                syms = Symtab.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        private void suppress(LintCategory lc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
            if (lint == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                lint = new Lint(parent);
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
            lint.suppressedValues.add(lc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
            lint.values.remove(lc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        public void visitConstant(Attribute.Constant value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
            if (value.type.tsym == syms.stringType.tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
                LintCategory lc = LintCategory.get((String) (value.value));
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
                if (lc != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
                    suppress(lc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        public void visitClass(Attribute.Class clazz) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        // If we find a @SuppressWarnings annotation, then we continue
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        // walking the tree, in order to suppress the individual warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        // specified in the @SuppressWarnings annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        public void visitCompound(Attribute.Compound compound) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            if (compound.type.tsym == syms.suppressWarningsType.tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
                for (List<Pair<MethodSymbol,Attribute>> v = compound.values;
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
                     v.nonEmpty(); v = v.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                    Pair<MethodSymbol,Attribute> value = v.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
                    if (value.fst.name.toString().equals("value"))
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
                        value.snd.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
        public void visitArray(Attribute.Array array) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
            for (Attribute value : array.values)
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
                value.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        public void visitEnum(Attribute.Enum e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        public void visitError(Attribute.Error e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
}