jdk/src/share/classes/sun/tools/java/Environment.java
author ntoda
Thu, 31 Jul 2014 17:01:24 -0700
changeset 25799 1afc4675dc75
parent 23740 1d63a6c00b26
permissions -rw-r--r--
8044867: Fix raw and unchecked lint warnings in sun.tools.* Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.java;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Stack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.tools.tree.Context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
//JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
//end JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This class defines the environment for a compilation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * It is used to load classes, resolve class names and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * report errors. It is an abstract class, a subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * must define implementations for some of the functions.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * An environment has a source object associated with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * This is the thing against which errors are reported, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * is usually a file name, a field or a class.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Environments can be nested to change the source object.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * WARNING: The contents of this source file are not part of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * supported API.  Code that depends on them does so at its own risk:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * they are subject to change or removal without notice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author      Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class Environment implements Constants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * The actual environment to which everything is forwarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    Environment env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * External character encoding name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    String encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * The object that is currently being parsed/compiled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * It is either a file name (String) or a field (MemberDefinition)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * or a class (ClassDeclaration or ClassDefinition).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    Object source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public Environment(Environment env, Object source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (env != null && env.env != null && env.getClass() == this.getClass())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            env = env.env;      // a small optimization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        this.env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        this.source = source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public Environment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        this(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Tells whether an Identifier refers to a package which should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * exempt from the "exists" check in Imports#resolve().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public boolean isExemptPackage(Identifier id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return env.isExemptPackage(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Return a class declaration given a fully qualified class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public ClassDeclaration getClassDeclaration(Identifier nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return env.getClassDeclaration(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Return a class definition given a fully qualified class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Should be called only with 'internal' class names, i.e., the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * of a call to 'resolveName' or a synthetic class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public final ClassDefinition getClassDefinition(Identifier nm) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (nm.isInner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            ClassDefinition c = getClassDefinition(nm.getTopName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            Identifier tail = nm.getFlatName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        walkTail:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            while (tail.isQualified()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                tail = tail.getTail();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                Identifier head = tail.getHead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                //System.out.println("CLASS: " + c + " HEAD: " + head + " TAIL: " + tail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                String hname = head.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                // If the name is of the form 'ClassName.N$localName', where N is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                // a number, the field 'N$localName' may not necessarily be a member
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                // of the class named by 'ClassName', but might be a member of some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                // inaccessible class contained within it.  We use 'getLocalClass'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                // to do the lookup in this case.  This is part of a fix for bugid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                // 4054523 and 4030421.  See also 'BatchEnvironment.makeClassDefinition'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                // This should also work for anonymous class names of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                // 'ClassName.N'.  Note that the '.' qualifications get converted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                // '$' characters when determining the external name of the class and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                // the name of the class file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                if (hname.length() > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    && Character.isDigit(hname.charAt(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    ClassDefinition localClass = c.getLocalClass(hname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    if (localClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                        c = localClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                        continue walkTail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    for (MemberDefinition f = c.getFirstMatch(head);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                         f != null; f = f.getNextMatch()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                        if (f.isInnerClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                            c = f.getInnerClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                            continue walkTail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                throw new ClassNotFound(Identifier.lookupInner(c.getName(), head));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            //System.out.println("FOUND " + c + " FOR " + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return getClassDeclaration(nm).getClassDefinition(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Return a class declaration given a type. Only works for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * class types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public ClassDeclaration getClassDeclaration(Type t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return getClassDeclaration(t.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Return a class definition given a type. Only works for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * class types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public final ClassDefinition getClassDefinition(Type t) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return getClassDefinition(t.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Check if a class exists (without actually loading it).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * (Since inner classes cannot in general be examined without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * loading source, this method does not accept inner names.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public boolean classExists(Identifier nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return env.classExists(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public final boolean classExists(Type t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return !t.isType(TC_CLASS) || classExists(t.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Get the package path for a package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public Package getPackage(Identifier pkg) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return env.getPackage(pkg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Load the definition of a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public void loadDefinition(ClassDeclaration c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        env.loadDefinition(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Return the source of the environment (ie: the thing being compiled/parsed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public final Object getSource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Resolve a type. Make sure that all the classes referred to by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * the type have a definition.  Report errors.  Return true if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * the type is well-formed.  Presently used for types appearing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * in member declarations, which represent named types internally as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * qualified identifiers.  Type names appearing in local variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * declarations and within expressions are represented as identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * or field expressions, and are resolved by 'toType', which delegates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * handling of the non-inner portion of the name to this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * In 'toType', the various stages of qualification are represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * separate AST nodes.  Here, we are given a single identifier which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * contains the entire qualification structure.  It is not possible in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * general to set the error location to the exact position of a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * that is in error, so an error message must refer to the entire qualified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * name.  An attempt to keep track of the string length of the components of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * the name and to offset the location accordingly fails because the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * prefix of the name may have been rewritten by an earlier call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * 'resolveName'.  See 'SourceMember.resolveTypeStructure'.  The situation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * is actually even worse than this, because only a single location is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * passed in for an entire declaration, which may contain many type names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * All error messages are thus poorly localized.  These checks should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * done while traversing the parse tree for the type, not the type descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * DESIGN NOTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * As far as I can tell, the two-stage resolution of names represented in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * string form is an artifact of the late implementation of inner classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * and the use of mangled names internally within the compiler.  All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * qualified names should have their hiearchical structure made explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * in the parse tree at the phase at which they are presented for static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * semantic checking.  This would affect class names appearing in 'extends',
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * 'implements', and 'throws' clauses, as well as in member declarations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public boolean resolve(long where, ClassDefinition c, Type t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        switch (t.getTypeCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
          case TC_CLASS: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            ClassDefinition def;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                Identifier nm = t.getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                if (!nm.isQualified() && !nm.isInner() && !classExists(nm)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    resolve(nm);        // elicit complaints about ambiguity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                def = getQualifiedClassDefinition(where, nm, c, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                if (!c.canAccess(this, def.getClassDeclaration())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    // Reported error location may be imprecise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    // if the name is qualified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    error(where, "cant.access.class", def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    return true; // return false later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                def.noteUsedBy(c, where, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            } catch (AmbiguousClass ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                error(where, "ambig.class", ee.name1, ee.name2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            } catch (ClassNotFound e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                // For now, report "class.and.package" only when the code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                // is going to fail anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    if (e.name.isInner() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                            getPackage(e.name.getTopName()).exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                        env.error(where, "class.and.package",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                  e.name.getTopName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                } catch (IOException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    env.error(where, "io.exception", "package check");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                // This error message is also emitted for 'new' expressions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                // error(where, "class.not.found", e.name, "declaration");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                error(where, "class.not.found.no.context", e.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
          case TC_ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            return resolve(where, c, t.getElementType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
          case TC_METHOD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            boolean ok = resolve(where, c, t.getReturnType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            Type args[] = t.getArgumentTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            for (int i = args.length ; i-- > 0 ; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                ok &= resolve(where, c, args[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            return ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Given its fully-qualified name, verify that a class is defined and accessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Used to check components of qualified names in contexts where a class is expected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Like 'resolve', but is given a single type name, not a type descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public boolean resolveByName(long where, ClassDefinition c, Identifier nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return resolveByName(where, c, nm, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public boolean resolveExtendsByName(long where, ClassDefinition c, Identifier nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return resolveByName(where, c, nm, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    private boolean resolveByName(long where, ClassDefinition c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                 Identifier nm, boolean isExtends) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        ClassDefinition def;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if (!nm.isQualified() && !nm.isInner() && !classExists(nm)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                resolve(nm);    // elicit complaints about ambiguity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            def = getQualifiedClassDefinition(where, nm, c, isExtends);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            ClassDeclaration decl = def.getClassDeclaration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            if (!((!isExtends && c.canAccess(this, decl))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                  ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                  (isExtends && c.extendsCanAccess(this, decl)))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                error(where, "cant.access.class", def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                return true; // return false later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        } catch (AmbiguousClass ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            error(where, "ambig.class", ee.name1, ee.name2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        } catch (ClassNotFound e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            // For now, report "class.and.package" only when the code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            // is going to fail anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                if (e.name.isInner() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    getPackage(e.name.getTopName()).exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    env.error(where, "class.and.package",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                              e.name.getTopName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            } catch (IOException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                env.error(where, "io.exception", "package check");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            error(where, "class.not.found", e.name, "type name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Like 'getClassDefinition(env)', but check access on each component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Currently called only by 'resolve' above.  It is doubtful that calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * to 'getClassDefinition(env)' are appropriate now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public final ClassDefinition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    getQualifiedClassDefinition(long where,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                Identifier nm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                                ClassDefinition ctxClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                                boolean isExtends) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (nm.isInner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            ClassDefinition c = getClassDefinition(nm.getTopName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            Identifier tail = nm.getFlatName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        walkTail:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            while (tail.isQualified()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                tail = tail.getTail();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                Identifier head = tail.getHead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                // System.out.println("CLASS: " + c + " HEAD: " + head + " TAIL: " + tail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                String hname = head.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                // Handle synthesized names of local and anonymous classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                // See 'getClassDefinition(env)' above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                if (hname.length() > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                    && Character.isDigit(hname.charAt(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    ClassDefinition localClass = c.getLocalClass(hname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    if (localClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                        c = localClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                        continue walkTail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    for (MemberDefinition f = c.getFirstMatch(head);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                         f != null; f = f.getNextMatch()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                        if (f.isInnerClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                            ClassDeclaration rdecl = c.getClassDeclaration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                            c = f.getInnerClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                            ClassDeclaration fdecl = c.getClassDeclaration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                            // This check is presumably applicable even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                            // original source-code name (expanded by 'resolveNames')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                            // was a simple, unqualified name.  Hopefully, JLS 2e
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                            // will clarify the matter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                            if ((!isExtends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                                 && !ctxClass.canAccess(env, fdecl))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                                ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                (isExtends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                                 && !ctxClass.extendsCanAccess(env, fdecl))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                                // Reported error location is imprecise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                                env.error(where, "no.type.access", head, rdecl, ctxClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                            // The JLS 6.6.2 restrictions on access to protected members
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                            // depend in an essential way upon the syntactic form of the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                            // Since the compiler has previously expanded the class names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                            // here into fully-qualified form ('resolveNames'), this check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                            // cannot be performed here.  Unfortunately, the original names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                            // are clobbered during 'basicCheck', which is also the phase that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                            // resolves the inheritance structure, required to implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                            // access restrictions.  Pending a large-scale revision of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                            // name-resolution machinery, we forgo this check, with the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                            // that the JLS 6.6.2 restrictions are not enforced for some cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                            // of qualified access to inner classes.  Some qualified names are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                            // resolved elsewhere via a different mechanism, and will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                            // treated correctly -- see 'FieldExpression.checkCommon'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                            /*---------------------------------------*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                            if (f.isProtected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                                Type rty = Type.tClass(rdecl.getName()); // hack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                                if (!ctxClass.protectedAccess(env, f, rty)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                    // Reported error location is imprecise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                    env.error(where, "invalid.protected.type.use",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                                              head, ctxClass, rty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                            *---------------------------------------*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                            continue walkTail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                throw new ClassNotFound(Identifier.lookupInner(c.getName(), head));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            //System.out.println("FOUND " + c + " FOR " + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return getClassDeclaration(nm).getClassDefinition(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * Resolve the names within a type, returning the adjusted type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Adjust class names to reflect scoping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Do not report errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * NOTE: It would be convenient to check for errors here, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * verifying that each component of a qualified name exists and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * accessible.  Why must this be done in a separate phase?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * If the 'synth' argument is true, indicating that the member whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * type is being resolved is synthetic, names are resolved with respect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * to the package scope.  (Fix for 4097882)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public Type resolveNames(ClassDefinition c, Type t, boolean synth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        if (tracing) dtEvent("Environment.resolveNames: " + c + ", " + t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        switch (t.getTypeCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
          case TC_CLASS: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            Identifier name = t.getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            Identifier rname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            if (synth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                rname = resolvePackageQualifiedName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                rname = c.resolveName(this, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            if (name != rname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                t = Type.tClass(rname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
          case TC_ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            t = Type.tArray(resolveNames(c, t.getElementType(), synth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
          case TC_METHOD: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            Type ret = t.getReturnType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            Type rret = resolveNames(c, ret, synth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            Type args[] = t.getArgumentTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            Type rargs[] = new Type[args.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            boolean changed = (ret != rret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            for (int i = args.length ; i-- > 0 ; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                Type arg = args[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                Type rarg = resolveNames(c, arg, synth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                rargs[i] = rarg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                if (arg != rarg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    changed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            if (changed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                t = Type.tMethod(rret, rargs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        return t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Resolve a class name, using only package and import directives.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * Report no errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    public Identifier resolveName(Identifier name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        // This logic is pretty exactly parallel to that of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        // ClassDefinition.resolveName().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        if (name.isQualified()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            // Try to resolve the first identifier component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            // because inner class names take precedence over
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            // package prefixes.  (Cf. ClassDefinition.resolveName.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            Identifier rhead = resolveName(name.getHead());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            if (rhead.hasAmbigPrefix()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                // The first identifier component refers to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                // ambiguous class.  Limp on.  We throw away the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                // rest of the classname as it is irrelevant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                // (part of solution for 4059855).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                return rhead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            if (!this.classExists(rhead)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                return this.resolvePackageQualifiedName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                return this.getClassDefinition(rhead).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    resolveInnerClass(this, name.getTail());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            } catch (ClassNotFound ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                // return partially-resolved name someone else can fail on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                return Identifier.lookupInner(rhead, name.getTail());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            return resolve(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        } catch (AmbiguousClass ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            // Don't force a resolution of the name if it is ambiguous.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            // Forcing the resolution would tack the current package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            // name onto the front of the class, which would be wrong.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            // Instead, mark the name as ambiguous and let a later stage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            // find the error by calling env.resolve(name).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            // (part of solution for 4059855).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            if (name.hasAmbigPrefix()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                return name.addAmbigPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        } catch (ClassNotFound ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            // last chance to make something halfway sensible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            Imports imports = getImports();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            if (imports != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                return imports.forceResolve(this, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * Discover if name consists of a package prefix, followed by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * name of a class (that actually exists), followed possibly by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * some inner class names.  If we can't find a class that exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * return the name unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * This routine is used after a class name fails to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * be resolved by means of imports or inner classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * However, import processing uses this routine directly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * since import names must be exactly qualified to start with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public final Identifier resolvePackageQualifiedName(Identifier name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        Identifier tail = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            if (classExists(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            if (!name.isQualified()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                name = (tail == null) ? name : Identifier.lookup(name, tail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                tail = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            Identifier nm = name.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            tail = (tail == null)? nm: Identifier.lookup(nm, tail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            name = name.getQualifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (tail != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            name = Identifier.lookupInner(name, tail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * Resolve a class name, using only package and import directives.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    public Identifier resolve(Identifier nm) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if (env == null)  return nm;    // a pretty useless no-op
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        return env.resolve(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * Get the imports used to resolve class names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    public Imports getImports() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (env == null)  return null; // lame default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        return env.getImports();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * Create a new class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    public ClassDefinition makeClassDefinition(Environment origEnv, long where,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                               IdentifierToken name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                               String doc, int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                               IdentifierToken superClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                               IdentifierToken interfaces[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                                               ClassDefinition outerClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        if (env == null)  return null; // lame default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        return env.makeClassDefinition(origEnv, where, name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                                       doc, modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                                       superClass, interfaces, outerClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * Create a new field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    public MemberDefinition makeMemberDefinition(Environment origEnv, long where,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                                               ClassDefinition clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                                               String doc, int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                                               Type type, Identifier name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                                               IdentifierToken argNames[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                                               IdentifierToken expIds[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                                               Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        if (env == null)  return null; // lame default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        return env.makeMemberDefinition(origEnv, where, clazz, doc, modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                                       type, name, argNames, expIds, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Returns true if the given method is applicable to the given arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    public boolean isApplicable(MemberDefinition m, Type args[]) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        Type mType = m.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        if (!mType.isType(TC_METHOD))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        Type mArgs[] = mType.getArgumentTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        if (args.length != mArgs.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        for (int i = args.length ; --i >= 0 ;)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            if (!isMoreSpecific(args[i], mArgs[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * Returns true if "best" is in every argument at least as good as "other"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    public boolean isMoreSpecific(MemberDefinition best, MemberDefinition other)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
           throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        Type bestType = best.getClassDeclaration().getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        Type otherType = other.getClassDeclaration().getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        boolean result = isMoreSpecific(bestType, otherType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                      && isApplicable(other, best.getType().getArgumentTypes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        // System.out.println("isMoreSpecific: " + best + "/" + other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        //                      + " => " + result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * Returns true if "from" is a more specific type than "to"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    public boolean isMoreSpecific(Type from, Type to) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        return implicitCast(from, to);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * Return true if an implicit cast from this type to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * the given type is allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
23740
1d63a6c00b26 8039864: Fix fallthrough lint warnings in other libs
darcy
parents: 5506
diff changeset
   651
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    public boolean implicitCast(Type from, Type to) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        if (from == to)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        int toTypeCode = to.getTypeCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        switch(from.getTypeCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        case TC_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            if (toTypeCode == TC_SHORT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        case TC_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        case TC_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            if (toTypeCode == TC_INT) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        case TC_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            if (toTypeCode == TC_LONG) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        case TC_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            if (toTypeCode == TC_FLOAT) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        case TC_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            if (toTypeCode == TC_DOUBLE) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        case TC_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        case TC_NULL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            return to.inMask(TM_REFERENCE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        case TC_ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            if (!to.isType(TC_ARRAY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                return (to == Type.tObject || to == Type.tCloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                           || to == Type.tSerializable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                // both are arrays.  recurse down both until one isn't an array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    from = from.getElementType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    to = to.getElementType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                } while (from.isType(TC_ARRAY) && to.isType(TC_ARRAY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                if (  from.inMask(TM_ARRAY|TM_CLASS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                      && to.inMask(TM_ARRAY|TM_CLASS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    return isMoreSpecific(from, to);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                    return (from.getTypeCode() == to.getTypeCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        case TC_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            if (toTypeCode == TC_CLASS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                ClassDefinition fromDef = getClassDefinition(from);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                ClassDefinition toDef = getClassDefinition(to);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                return toDef.implementedBy(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                                           fromDef.getClassDeclaration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * Return true if an explicit cast from this type to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * the given type is allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    public boolean explicitCast(Type from, Type to) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        if (implicitCast(from, to)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        if (from.inMask(TM_NUMBER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            return to.inMask(TM_NUMBER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        if (from.isType(TC_CLASS) && to.isType(TC_CLASS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            ClassDefinition fromClass = getClassDefinition(from);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            ClassDefinition toClass = getClassDefinition(to);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            if (toClass.isFinal()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                return fromClass.implementedBy(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                                               toClass.getClassDeclaration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            if (fromClass.isFinal()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                return toClass.implementedBy(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                                             fromClass.getClassDeclaration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            // The code here used to omit this case.  If both types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            // involved in a cast are interfaces, then JLS 5.5 requires
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            // that we do a simple test -- make sure none of the methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            // in toClass and fromClass have the same signature but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            // different return types.  (bug number 4028359)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            if (toClass.isInterface() && fromClass.isInterface()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                return toClass.couldImplement(fromClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            return toClass.isInterface() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                   fromClass.isInterface() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                   fromClass.superClassOf(this, toClass.getClassDeclaration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        if (to.isType(TC_ARRAY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            if (from.isType(TC_ARRAY))  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                Type t1 = from.getElementType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                Type t2 = to.getElementType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                while ((t1.getTypeCode() == TC_ARRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                       && (t2.getTypeCode() == TC_ARRAY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                    t1 = t1.getElementType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                    t2 = t2.getElementType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                if (t1.inMask(TM_ARRAY|TM_CLASS) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                    t2.inMask(TM_ARRAY|TM_CLASS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                    return explicitCast(t1, t2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            } else if (from == Type.tObject || from == Type.tCloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                          || from == Type.tSerializable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * Flags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    public int getFlags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        return env.getFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * Debugging flags.  There used to be a method debug()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * that has been replaced because -g has changed meaning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * (it now cooperates with -O and line number, variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * range and source file info can be toggled separately).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    public final boolean debug_lines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        return (getFlags() & F_DEBUG_LINES) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    public final boolean debug_vars() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        return (getFlags() & F_DEBUG_VARS) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    public final boolean debug_source() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        return (getFlags() & F_DEBUG_SOURCE) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * Optimization flags.  There used to be a method optimize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * that has been replaced because -O has changed meaning in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * javac to be replaced with -O and -O:interclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    public final boolean opt() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        return (getFlags() & F_OPT) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    public final boolean opt_interclass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        return (getFlags() & F_OPT_INTERCLASS) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * Verbose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    public final boolean verbose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        return (getFlags() & F_VERBOSE) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * Dump debugging stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    public final boolean dump() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        return (getFlags() & F_DUMP) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * Verbose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    public final boolean warnings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        return (getFlags() & F_WARNINGS) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * Dependencies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    public final boolean dependencies() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        return (getFlags() & F_DEPENDENCIES) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * Print Dependencies to stdout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    public final boolean print_dependencies() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        return (getFlags() & F_PRINT_DEPENDENCIES) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * Deprecation warnings are enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    public final boolean deprecation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        return (getFlags() & F_DEPRECATION) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * Do not support virtual machines before version 1.2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * This option is not supported and is only here for testing purposes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    public final boolean version12() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        return (getFlags() & F_VERSION12) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * Floating point is strict by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    public final boolean strictdefault() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        return (getFlags() & F_STRICTDEFAULT) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * Release resources, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    public void shutdown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        if (env != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            env.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * Issue an error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     *  source   - the input source, usually a file name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     *  offset   - the offset in the source of the error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     *  err      - the error number (as defined in this interface)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     *  arg1     - an optional argument to the error (null if not applicable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     *  arg2     - a second optional argument to the error (null if not applicable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     *  arg3     - a third optional argument to the error (null if not applicable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    public void error(Object source, long where, String err, Object arg1, Object arg2, Object arg3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        env.error(source, where, err, arg1, arg2, arg3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    public final void error(long where, String err, Object arg1, Object arg2, Object arg3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        error(source, where, err, arg1, arg2, arg3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    public final void error(long where, String err, Object arg1, Object arg2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        error(source, where, err, arg1, arg2, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    public final void error(long where, String err, Object arg1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        error(source, where, err, arg1, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    public final void error(long where, String err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        error(source, where, err, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * Output a string. This can either be an error message or something
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * for debugging. This should be used instead of println.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    public void output(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        env.output(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    private static boolean debugging = (System.getProperty("javac.debug") != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    public static void debugOutput(Object msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        if (Environment.debugging)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            System.out.println(msg.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * set character encoding name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    public void setCharacterEncoding(String encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        this.encoding = encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * Return character encoding name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    public String getCharacterEncoding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        return encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * Return major version to use in generated class files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    public short getMajorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        if (env==null) return JAVA_DEFAULT_VERSION;  // needed for javah
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        return env.getMajorVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * Return minor version to use in generated class files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    public short getMinorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        if (env==null) return JAVA_DEFAULT_MINOR_VERSION;  // needed for javah
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        return env.getMinorVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
// JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     *  get coverage flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    public final boolean coverage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        return (getFlags() & F_COVERAGE) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     *  get flag of generation the coverage data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    public final boolean covdata() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        return (getFlags() & F_COVDATA) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * Return the coverage data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    public File getcovFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        return env.getcovFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
// end JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * Debug tracing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * Currently, this code is used only for tracing the loading and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * checking of classes, particularly the demand-driven aspects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * This code should probably be integrated with 'debugOutput' above,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * but we need to give more thought to the issue of classifying debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * messages and allowing those only those of interest to be enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * Calls to these methods are generally conditioned on the final variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * 'Constants.tracing', which allows the calls to be completely omitted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * in a production release to avoid space and time overhead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    private static boolean dependtrace =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                (System.getProperty("javac.trace.depend") != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    public void dtEnter(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        if (dependtrace) System.out.println(">>> " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    public void dtExit(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        if (dependtrace) System.out.println("<<< " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    public void dtEvent(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        if (dependtrace) System.out.println(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * Enable diagnostic dump of class modifier bits, including those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * in InnerClasses attributes, as they are written to the classfile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * In the future, may also enable dumping field and method modifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    private static boolean dumpmodifiers =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                (System.getProperty("javac.dump.modifiers") != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    public boolean dumpModifiers() { return dumpmodifiers; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
}