jdk/src/share/classes/sun/tools/javac/BatchEnvironment.java
author prr
Tue, 15 Jul 2014 11:22:14 -0700
changeset 25522 10d789df41bb
parent 5506 202f599c92aa
child 25799 1afc4675dc75
permissions -rw-r--r--
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes Reviewed-by: psandoz, prr Contributed-by: otaviopolianasantana@gmail.com
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, 2004, 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.javac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.tools.java.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.tools.tree.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.tools.java.Package;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Main environment of the batch version of the Java compiler,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * this needs more work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * WARNING: The contents of this source file are not part of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * supported API.  Code that depends on them does so at its own risk:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * they are subject to change or removal without notice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
@Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
class BatchEnvironment extends Environment implements ErrorConsumer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * The stream where error message are printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    OutputStream out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * The path we use for finding source files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected ClassPath sourcePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * The path we use for finding class (binary) files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected ClassPath binaryPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * A hashtable of resource contexts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    Hashtable packages = new Hashtable(31);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * The classes, in order of appearance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    Vector classesOrdered = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * The classes, keyed by ClassDeclaration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    Hashtable classes = new Hashtable(351);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public int flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Major and minor versions to use for generated class files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Environments that extend BatchEnvironment (such as javadoc's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Env class) get the default values below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * javac itself may override these versions with values determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * from the command line "-target" option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public short majorVersion = JAVA_DEFAULT_VERSION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public short minorVersion = JAVA_DEFAULT_MINOR_VERSION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
// JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * coverage data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public File covFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
// end JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * The number of errors and warnings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public int nerrors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public int nwarnings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public int ndeprecations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * A list of files containing deprecation warnings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    Vector deprecationFiles = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         * writes out error messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        ErrorConsumer errorConsumer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Old constructors -- these constructors build a BatchEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * with an old-style class path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public BatchEnvironment(ClassPath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this(System.out, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public BatchEnvironment(OutputStream out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                            ClassPath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        this(out, path, (ErrorConsumer) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public BatchEnvironment(OutputStream out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                            ClassPath path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                            ErrorConsumer errorConsumer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this(out, path, path, errorConsumer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * New constructors -- these constructors build a BatchEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * with a source path and a binary path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public BatchEnvironment(ClassPath sourcePath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                            ClassPath binaryPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        this(System.out, sourcePath, binaryPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public BatchEnvironment(OutputStream out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                            ClassPath sourcePath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                            ClassPath binaryPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        this(out, sourcePath, binaryPath, (ErrorConsumer) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public BatchEnvironment(OutputStream out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                            ClassPath sourcePath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                            ClassPath binaryPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                            ErrorConsumer errorConsumer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this.out = out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        this.sourcePath = sourcePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        this.binaryPath = binaryPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        this.errorConsumer = (errorConsumer == null) ? this : errorConsumer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    static BatchEnvironment create(OutputStream out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                   String srcPathString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                   String classPathString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                   String sysClassPathString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                   String extDirsString){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        ClassPath[] classPaths = classPaths(srcPathString, classPathString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                            sysClassPathString, extDirsString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return new BatchEnvironment(out, classPaths[0], classPaths[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    protected static ClassPath[] classPaths(String srcPathString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                            String classPathString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                            String sysClassPathString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                            String extDirsString) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        // Create our source classpath and our binary classpath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        ClassPath sourcePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        ClassPath binaryPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        StringBuffer binaryPathBuffer = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (classPathString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            // The env.class.path property is the user's CLASSPATH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            // environment variable, and it set by the wrapper (ie,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            // javac.exe).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            classPathString = System.getProperty("env.class.path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (classPathString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                classPathString = ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (srcPathString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            srcPathString = classPathString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (sysClassPathString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            sysClassPathString = System.getProperty("sun.boot.class.path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            if (sysClassPathString == null) { // shouldn't happen; recover gracefully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                sysClassPathString = classPathString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        appendPath(binaryPathBuffer, sysClassPathString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (extDirsString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            extDirsString = System.getProperty("java.ext.dirs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (extDirsString != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            StringTokenizer st = new StringTokenizer(extDirsString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                                     File.pathSeparator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            while (st.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                String dirName = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                File dir = new File(dirName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                if (!dirName.endsWith(File.separator)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    dirName += File.separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                if (dir.isDirectory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    String[] files = dir.list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    for (int i = 0; i < files.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        String name = files[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        if (name.endsWith(".jar")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                            appendPath(binaryPathBuffer, dirName + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        appendPath(binaryPathBuffer, classPathString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        sourcePath = new ClassPath(srcPathString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        binaryPath = new ClassPath(binaryPathBuffer.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return new ClassPath[]{sourcePath, binaryPath};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private static void appendPath(StringBuffer buf, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (str.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            if (buf.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                buf.append(File.pathSeparator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            buf.append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Return flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public int getFlags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Return major version to use for generated class files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public short getMajorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return majorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Return minor version to use for generated class files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public short getMinorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return minorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
// JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Return coverage data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public File getcovFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return covFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
// end JCOV
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Return an enumeration of all the currently defined classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * in order of appearance to getClassDeclaration().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public Enumeration getClasses() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return classesOrdered.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * A set of Identifiers for all packages exempt from the "exists"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * check in Imports#resolve().  These are the current packages for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * all classes being compiled as of the first call to isExemptPackage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    private Set exemptPackages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Tells whether an Identifier refers to a package which should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * exempt from the "exists" check in Imports#resolve().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public boolean isExemptPackage(Identifier id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (exemptPackages == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            // Collect a list of the packages of all classes currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            // being compiled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            setExemptPackages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return exemptPackages.contains(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Set the set of packages which are exempt from the exists check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * in Imports#resolve().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    private void setExemptPackages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        // The JLS gives us the freedom to define "accessibility" of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        // a package in whatever manner we wish.  After the evaluation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        // of bug 4093217, we have decided to consider a package P
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        // accessible if either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        // 1. The directory corresponding to P exists on the classpath.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        // 2. For any class C currently being compiled, C belongs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        //    package P.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        // 3. For any class C currently being compiled, C belongs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        //    package Q and Q is a subpackage of P.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        // In order to implement this, we collect the current packages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        // (and prefixes) of all packages we have found so far.  These
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        // will be exempt from the "exists" check in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        // sun.tools.java.Imports#resolve().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        exemptPackages = new HashSet(101);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        // Add all of the current packages and their prefixes to our set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        for (Enumeration e = getClasses(); e.hasMoreElements(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            ClassDeclaration c = (ClassDeclaration) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            if (c.getStatus() == CS_PARSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                SourceClass def = (SourceClass) c.getClassDefinition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                if (def.isLocal())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                Identifier pkg = def.getImports().getCurrentPackage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                // Add the name of this package and all of its prefixes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                // to our set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                while (pkg != idNull && exemptPackages.add(pkg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    pkg = pkg.getQualifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        // Before we go any further, we make sure java.lang is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        // accessible and that it is not ambiguous.  These checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        // are performed for "ordinary" packages in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // sun.tools.java.Imports#resolve().  The reason we perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        // them specially for java.lang is that we want to report
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        // the error once, and outside of any particular file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        // Check to see if java.lang is accessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (!exemptPackages.contains(idJavaLang)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            // Add java.lang to the set of exempt packages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            exemptPackages.add(idJavaLang);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                if (!getPackage(idJavaLang).exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    // java.lang doesn't exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    error(0, "package.not.found.strong", idJavaLang);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            } catch (IOException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                // We got an IO exception checking to see if the package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                // java.lang exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                error(0, "io.exception.package", idJavaLang);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        // Next we ensure that java.lang is not both a class and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        // a package.  (Fix for 4101529)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        // This change has been backed out because, on WIN32, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        // failed to take character case into account.  It will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        // be put back in later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        // Identifier resolvedName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        //   resolvePackageQualifiedName(idJavaLang);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        // Identifier topClassName = resolvedName.getTopName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        //     //if (Imports.importable(topClassName, env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        // if (Imports.importable(topClassName, this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        //    // It is a package and a class.  Emit the error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        //    error(0, "package.class.conflict.strong",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        //            idJavaLang, topClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        //    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        // }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * Get a class, given the fully qualified class name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public ClassDeclaration getClassDeclaration(Identifier nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return getClassDeclaration(Type.tClass(nm));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public ClassDeclaration getClassDeclaration(Type t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        ClassDeclaration c = (ClassDeclaration)classes.get(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            classes.put(t, c = new ClassDeclaration(t.getClassName()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            classesOrdered.addElement(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * Check if a class exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Applies only to package members (non-nested classes).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public boolean classExists(Identifier nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if (nm.isInner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            nm = nm.getTopName();       // just in case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        Type t = Type.tClass(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            ClassDeclaration c = (ClassDeclaration)classes.get(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            return (c != null) ? c.getName().equals(nm) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                getPackage(nm.getQualifier()).classExists(nm.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Generate a new name similar to the given one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Do it in such a way that repeated compilations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * the same source generate the same series of names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    // This code does not perform as stated above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    // Correction below is part of fix for bug id 4056065.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    // NOTE: The method 'generateName' has now been folded into its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    // single caller, 'makeClassDefinition', which appears later in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    // this file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /*--------------------------*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public Identifier generateName(ClassDefinition outerClass, Identifier nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        Identifier outerNm = outerClass.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        Identifier flat = outerNm.getFlatName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        Identifier stem = Identifier.lookup(outerNm.getQualifier(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                                            flat.getHead());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        for (int i = 1; ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            String name = i + (nm.equals(idNull) ? "" : SIG_INNERCLASS + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            Identifier nm1 = Identifier.lookupInner(stem,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                                    Identifier.lookup(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            if (classes.get(Type.tClass(nm1)) == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                return nm1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    *--------------------------*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * Get the package path for a package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public Package getPackage(Identifier pkg) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        Package p = (Package)packages.get(pkg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (p == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            packages.put(pkg, p = new Package(sourcePath, binaryPath, pkg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * Parse a source file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    public void parseFile(ClassFile file) throws FileNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        long tm = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        InputStream input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        BatchParser p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        if (tracing) dtEnter("parseFile: PARSING SOURCE " + file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        Environment env = new Environment(this, file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            input = file.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            env.setCharacterEncoding(getCharacterEncoding());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            //      p = new BatchParser(e, new BufferedInputStream(input));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            p = new BatchParser(env, input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        } catch(IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            if (tracing) dtEvent("parseFile: IO EXCEPTION " + file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            throw new FileNotFoundException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            p.parseFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            throw new CompilerError(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            input.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            // We're turn with the input, so ignore this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (verbose()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            tm = System.currentTimeMillis() - tm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            output(Main.getText("benv.parsed_in", file.getPath(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                Long.toString(tm)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        if (p.classes.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            // The JLS allows a file to contain no compilation units --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            // that is, it allows a file to contain no classes or interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            // In this case, we are still responsible for checking that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            // imports resolve properly.  The way the compiler is organized,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            // this is the last point at which we still have enough information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            // to do so. (Fix for 4041851).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            p.imports.resolve(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            // In an attempt to see that classes which come from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            // same source file are all recompiled when any one of them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            // would be recompiled (when using the -depend option) we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            // introduce artificial dependencies between these classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            // We do this by calling the addDependency() method, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            // adds a (potentially unused) class reference to the constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            // pool of the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            // Previously, we added a dependency from every class in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            // file, to every class in the file.  This introduced, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            // total, a quadratic number of potentially bogus constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            // pool entries.  This was bad.  Now we add our artificial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            // dependencies in such a way that the classes are connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            // in a circle.  While single links is probably sufficient, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            // code below adds double links just to be diligent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            // (Fix for 4108286).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            // Note that we don't chain in inner classes.  The links
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            // between them and their outerclass should be sufficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            // here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            // (Fix for 4107960).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            // The dependency code was previously in BatchParser.java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            Enumeration e = p.classes.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            // first will not be an inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            ClassDefinition first = (ClassDefinition) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            if (first.isInnerClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                throw new CompilerError("BatchEnvironment, first is inner");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            ClassDefinition current = first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            ClassDefinition next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            while (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                next = (ClassDefinition) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                // Don't chain in inner classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                if (next.isInnerClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                current.addDependency(next.getClassDeclaration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                next.addDependency(current.getClassDeclaration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                current = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            // Make a circle.  Don't bother to add a dependency if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            // is only one class in the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            if (current != first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                current.addDependency(first.getClassDeclaration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                first.addDependency(current.getClassDeclaration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        if (tracing) dtExit("parseFile: SOURCE PARSED " + file);
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
     * Load a binary file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    BinaryClass loadFile(ClassFile file) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        long tm = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        InputStream input = file.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        BinaryClass c = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        if (tracing) dtEnter("loadFile: LOADING CLASSFILE " + file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            DataInputStream is =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                new DataInputStream(new BufferedInputStream(input));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            c = BinaryClass.load(new Environment(this, file), is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                                 loadFileFlags());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        } catch (ClassFormatError e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            error(0, "class.format", file.getPath(), e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            if (tracing) dtExit("loadFile: CLASS FORMAT ERROR " + file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        } catch (java.io.EOFException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            // If we get an EOF while processing a class file, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            // it has been truncated.  We let other I/O errors pass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            // through.  Fix for 4088443.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            error(0, "truncated.class", file.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        input.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        if (verbose()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            tm = System.currentTimeMillis() - tm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            output(Main.getText("benv.loaded_in", file.getPath(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                                Long.toString(tm)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        if (tracing) dtExit("loadFile: CLASSFILE LOADED " + file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Default flags for loadFile.  Subclasses may override this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    int loadFileFlags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        return 0;
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
     * Load a binary class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    boolean needsCompilation(Hashtable check, ClassDeclaration c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        switch (c.getStatus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
          case CS_UNDEFINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if (tracing) dtEnter("needsCompilation: UNDEFINED " + c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            loadDefinition(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            return needsCompilation(check, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
          case CS_UNDECIDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            if (tracing) dtEnter("needsCompilation: UNDECIDED " + c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            if (check.get(c) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                check.put(c, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                BinaryClass bin = (BinaryClass)c.getClassDefinition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                for (Enumeration e = bin.getDependencies() ; e.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                    ClassDeclaration dep = (ClassDeclaration)e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    if (needsCompilation(check, dep)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                        // It must be source, dependencies need compilation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                        c.setDefinition(bin, CS_SOURCE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                        if (tracing) dtExit("needsCompilation: YES (source) " + c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            if (tracing) dtExit("needsCompilation: NO (undecided) " + c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
          case CS_BINARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                dtEnter("needsCompilation: BINARY " + c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                dtExit("needsCompilation: NO (binary) " + c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        if (tracing) dtExit("needsCompilation: YES " + c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * Load the definition of a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * or at least determine how to load it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * The caller must repeat calls to this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * until it the state converges to CS_BINARY, CS_PARSED, or the like..
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @see ClassDeclaration#getClassDefinition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    public void loadDefinition(ClassDeclaration c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        if (tracing) dtEnter("loadDefinition: ENTER " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                             c.getName() + ", status " + c.getStatus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        switch (c.getStatus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
          case CS_UNDEFINED: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                dtEvent("loadDefinition: STATUS IS UNDEFINED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            Identifier nm = c.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            Package pkg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                pkg = getPackage(nm.getQualifier());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                // If we can't get at the package, then we'll just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                // have to set the class to be not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                c.setDefinition(null, CS_NOTFOUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                error(0, "io.exception", c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                    dtExit("loadDefinition: IO EXCEPTION (package)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            ClassFile binfile = pkg.getBinaryFile(nm.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            if (binfile == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                // must be source, there is no binary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                c.setDefinition(null, CS_SOURCE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    dtExit("loadDefinition: MUST BE SOURCE (no binary) " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                           c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            ClassFile srcfile = pkg.getSourceFile(nm.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            if (srcfile == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    dtEvent("loadDefinition: NO SOURCE " + c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                BinaryClass bc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    bc = loadFile(binfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                    // If we can't access the binary, set the class to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    // be not found.  (bug id 4030497)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    c.setDefinition(null, CS_NOTFOUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    error(0, "io.exception", binfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                    if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                        dtExit("loadDefinition: IO EXCEPTION (binary)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                if ((bc != null) && !bc.getName().equals(nm)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                    error(0, "wrong.class", binfile.getPath(), c, bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                    bc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                    if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                        dtEvent("loadDefinition: WRONG CLASS (binary)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                if (bc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    // no source nor binary found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    c.setDefinition(null, CS_NOTFOUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                    if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                        dtExit("loadDefinition: NOT FOUND (source or binary)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                // Couldn't find the source, try the one mentioned in the binary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                if (bc.getSource() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                    srcfile = new ClassFile(new File((String)bc.getSource()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                    // Look for the source file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                    srcfile = pkg.getSourceFile(srcfile.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                    if ((srcfile != null) && srcfile.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                        if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                            dtEvent("loadDefinition: FILENAME IN BINARY " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                                    srcfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                        if (srcfile.lastModified() > binfile.lastModified()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                            // must be source, it is newer than the binary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                            c.setDefinition(bc, CS_SOURCE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                            if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                                dtEvent("loadDefinition: SOURCE IS NEWER " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                                        srcfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                            bc.loadNested(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                            if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                                dtExit("loadDefinition: MUST BE SOURCE " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                                       c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                        if (dependencies()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                            c.setDefinition(bc, CS_UNDECIDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                            if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                dtEvent("loadDefinition: UNDECIDED " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                                        c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                            c.setDefinition(bc, CS_BINARY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                            if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                                dtEvent("loadDefinition: MUST BE BINARY " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                                        c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                        bc.loadNested(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                        if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                            dtExit("loadDefinition: EXIT " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                                   c.getName() + ", status " + c.getStatus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                // It must be binary, there is no source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                c.setDefinition(bc, CS_BINARY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                    dtEvent("loadDefinition: MUST BE BINARY (no source) " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                                     c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                bc.loadNested(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                    dtExit("loadDefinition: EXIT " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                           c.getName() + ", status " + c.getStatus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            BinaryClass bc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                if (srcfile.lastModified() > binfile.lastModified()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                    // must be source, it is newer than the binary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                    c.setDefinition(null, CS_SOURCE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                    if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                        dtEvent("loadDefinition: MUST BE SOURCE (younger than binary) " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                                c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                bc = loadFile(binfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                error(0, "io.exception", binfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                    dtEvent("loadDefinition: IO EXCEPTION (binary)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            if ((bc != null) && !bc.getName().equals(nm)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                error(0, "wrong.class", binfile.getPath(), c, bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                bc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                    dtEvent("loadDefinition: WRONG CLASS (binary)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            if (bc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                Identifier name = bc.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                if (name.equals(c.getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                    if (dependencies()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                        c.setDefinition(bc, CS_UNDECIDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                        if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                            dtEvent("loadDefinition: UNDECIDED " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                        c.setDefinition(bc, CS_BINARY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                        if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                            dtEvent("loadDefinition: MUST BE BINARY " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    c.setDefinition(null, CS_NOTFOUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                    if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                        dtEvent("loadDefinition: NOT FOUND (source or binary)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                    if (dependencies()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                        getClassDeclaration(name).setDefinition(bc, CS_UNDECIDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                        if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                            dtEvent("loadDefinition: UNDECIDED " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                        getClassDeclaration(name).setDefinition(bc, CS_BINARY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                        if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                            dtEvent("loadDefinition: MUST BE BINARY " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                c.setDefinition(null, CS_NOTFOUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                    dtEvent("loadDefinition: NOT FOUND (source or binary)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            if (bc != null && bc == c.getClassDefinition())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                bc.loadNested(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            if (tracing) dtExit("loadDefinition: EXIT " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                                c.getName() + ", status " + c.getStatus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
          case CS_UNDECIDED: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            if (tracing) dtEvent("loadDefinition: STATUS IS UNDECIDED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            Hashtable tab = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            if (!needsCompilation(tab, c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                // All undecided classes that this class depends on must be binary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                for (Enumeration e = tab.keys() ; e.hasMoreElements() ; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    ClassDeclaration dep = (ClassDeclaration)e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                    if (dep.getStatus() == CS_UNDECIDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                        // must be binary, dependencies need compilation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                        dep.setDefinition(dep.getClassDefinition(), CS_BINARY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                        if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                            dtEvent("loadDefinition: MUST BE BINARY " + dep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            if (tracing) dtExit("loadDefinition: EXIT " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                                c.getName() + ", status " + c.getStatus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
          case CS_SOURCE: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            if (tracing) dtEvent("loadDefinition: STATUS IS SOURCE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            ClassFile srcfile = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            Package pkg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            if (c.getClassDefinition() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                // Use the source file name from the binary class file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                    pkg = getPackage(c.getName().getQualifier());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                    srcfile = pkg.getSourceFile((String)c.getClassDefinition().getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                    error(0, "io.exception", c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                    if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                        dtEvent("loadDefinition: IO EXCEPTION (package)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                if (srcfile == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                    String fn = (String)c.getClassDefinition().getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                    srcfile = new ClassFile(new File(fn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                // Get a source file name from the package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                Identifier nm = c.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                    pkg = getPackage(nm.getQualifier());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                    srcfile = pkg.getSourceFile(nm.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                } catch (IOException e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                    error(0, "io.exception", c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                    if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                        dtEvent("loadDefinition: IO EXCEPTION (package)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                if (srcfile == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                    // not found, there is no source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                    c.setDefinition(null, CS_NOTFOUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                    if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                        dtExit("loadDefinition: SOURCE NOT FOUND " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                               c.getName() + ", status " + c.getStatus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                parseFile(srcfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                error(0, "io.exception", srcfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                if (tracing) dtEvent("loadDefinition: IO EXCEPTION (source)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            if ((c.getClassDefinition() == null) || (c.getStatus() == CS_SOURCE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                // not found after parsing the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                error(0, "wrong.source", srcfile.getPath(), c, pkg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                c.setDefinition(null, CS_NOTFOUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                    dtEvent("loadDefinition: WRONG CLASS (source) " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                            c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            if (tracing) dtExit("loadDefinition: EXIT " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                                c.getName() + ", status " + c.getStatus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        if (tracing) dtExit("loadDefinition: EXIT " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                            c.getName() + ", status " + c.getStatus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * Create a new class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    public ClassDefinition makeClassDefinition(Environment toplevelEnv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                                               long where,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                                               IdentifierToken name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                                               String doc, int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                                               IdentifierToken superClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                                               IdentifierToken interfaces[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                                               ClassDefinition outerClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        Identifier nm = name.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        long nmpos = name.getWhere();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        Identifier pkgNm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        String mangledName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        ClassDefinition localContextClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        // Provide name for a local class.  This used to be set after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        // the class was created, but it is needed for checking within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        // the class constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        // NOTE: It seems that we could always provide the simple name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        // and thereby avoid the test in 'ClassDefinition.getLocalName()'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        // for the definedness of the local name.  There, if the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        // name is not set, a simple name is extracted from the result of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        // 'getName()'.  That name can potentially change, however, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        // it is ultimately derived from 'ClassType.className', which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        // set by 'Type.changeClassName'.  Better leave this alone...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        Identifier localName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        if (nm.isQualified() || nm.isInner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            pkgNm = nm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        } else if ((modifiers & (M_LOCAL | M_ANONYMOUS)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            // Inaccessible class.  Create a name of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            // 'PackageMember.N$localName' or 'PackageMember.N'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            // Note that the '.' will be converted later to a '$'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            //   pkgNm = generateName(outerClass, nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            localContextClass = outerClass.getTopClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            // Always use the smallest number in generating the name that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            // renders the complete name unique within the top-level class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            // This is required to make the names more predictable, as part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            // of a serialization-related workaround, and satisfies an obscure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            // requirement that the name of a local class be of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            // 'PackageMember$1$localName' when this name is unique.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            for (int i = 1 ; ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                mangledName = i + (nm.equals(idNull) ? "" : SIG_INNERCLASS + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                if (localContextClass.getLocalClass(mangledName) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            Identifier outerNm = localContextClass.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            pkgNm = Identifier.lookupInner(outerNm, Identifier.lookup(mangledName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            //System.out.println("LOCAL CLASS: " + pkgNm + " IN " + localContextClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            if ((modifiers & M_ANONYMOUS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                localName = idNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                // Local class has a locally-scoped name which is independent of pkgNm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                localName = nm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        } else if (outerClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            // Accessible inner class.  Qualify name with surrounding class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            pkgNm = Identifier.lookupInner(outerClass.getName(), nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            pkgNm = nm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        // Find the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        ClassDeclaration c = toplevelEnv.getClassDeclaration(pkgNm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        // Make sure this is the first definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        if (c.isDefined()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            toplevelEnv.error(nmpos, "class.multidef",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                              c.getName(), c.getClassDefinition().getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            // Don't mess with the existing class declarations with same name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            c = new ClassDeclaration (pkgNm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        if (superClass == null && !pkgNm.equals(idJavaLangObject)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            superClass = new IdentifierToken(idJavaLangObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        ClassDefinition sourceClass =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            new SourceClass(toplevelEnv, where, c, doc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                            modifiers, superClass, interfaces,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                            (SourceClass) outerClass, localName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        if (outerClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            // It is a member of its enclosing class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            outerClass.addMember(toplevelEnv, new SourceMember(sourceClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            // Record local (or anonymous) class in the class whose name will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            // serve as the prefix of the local class name.  This is necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            // so that the class may be retrieved from its name, which does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            // fully represent the class nesting structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            // See 'ClassDefinition.getClassDefinition'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            // This is part of a fix for bugid 4054523 and 4030421.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            if ((modifiers & (M_LOCAL | M_ANONYMOUS)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                localContextClass.addLocalClass(sourceClass, mangledName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        // The local name of an anonymous or local class used to be set here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        // with a call to 'setLocalName'.  This has been moved to the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        // for 'SourceClass', which now takes a 'localName' argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        return sourceClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * Create a new field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    public MemberDefinition makeMemberDefinition(Environment origEnv, long where,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                                               ClassDefinition clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                                               String doc, int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                                               Type type, Identifier name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                                               IdentifierToken argNames[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                                               IdentifierToken expIds[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                                               Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        if (tracing) dtEvent("makeMemberDefinition: " + name + " IN " + clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        Vector v = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        if (argNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            v = new Vector(argNames.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            for (int i = 0 ; i < argNames.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                v.addElement(argNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        SourceMember f = new SourceMember(where, clazz, doc, modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                                        type, name, v, expIds, (Node)value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        clazz.addMember(origEnv, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * Release resources in classpath.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    public void shutdown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            if (sourcePath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                sourcePath.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            if (binaryPath != null && binaryPath != sourcePath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                binaryPath.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        } catch (IOException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            output(Main.getText("benv.failed_to_close_class_path",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                                ee.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        sourcePath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        binaryPath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        super.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * Error String
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    public
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    String errorString(String err, Object arg1, Object arg2, Object arg3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        String key = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        if(err.startsWith("warn."))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            key = "javac.err." + err.substring(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            key = "javac.err." + err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        return Main.getText(key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                            arg1 != null ? arg1.toString() : null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                            arg2 != null ? arg2.toString() : null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                            arg3 != null ? arg3.toString() : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * The filename where the last errors have occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    String errorFileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * List of outstanding error messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    ErrorMessage errors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * Insert an error message in the list of outstanding error messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * The list is sorted on input position and contains no duplicates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     * The return value indicates whether or not the message was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * actually inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * The method flushErrors() used to check for duplicate error messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * It would only detect duplicates if they were contiguous.  Removing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * non-contiguous duplicate error messages is slightly less complicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * at insertion time, so the functionality was moved here.  This also
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * saves a miniscule number of allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    protected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    boolean insertError(long where, String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        //output("ERR = " + message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        if (errors == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            ||  errors.where > where) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            // If the list is empty, or the error comes before any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            // errors, insert it at the beginning of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            ErrorMessage newMsg = new ErrorMessage(where, message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            newMsg.next = errors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            errors = newMsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        } else if (errors.where == where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                   && errors.message.equals(message)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            // The new message is an exact duplicate of the first message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            // in the list.  Don't insert it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            // Okay, we know that the error doesn't come first.  Walk
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            // the list until we find the right position for insertion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            ErrorMessage current = errors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            ErrorMessage next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            while ((next = current.next) != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                   && next.where < where) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                current = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            // Now walk over any errors with the same location, looking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            // for duplicates.  If we find a duplicate, don't insert the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            // error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            while ((next = current.next) != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                   && next.where == where) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                if (next.message.equals(message)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                    // We have found an exact duplicate.  Don't bother to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                    // insert the error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                current = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            // Now insert after current.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            ErrorMessage newMsg = new ErrorMessage(where, message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            newMsg.next = current.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            current.next = newMsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        // Indicate that the insertion occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    private int errorsPushed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * Maximum number of errors to print.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    public int errorLimit = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    private boolean hitErrorLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * Flush outstanding errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        public void pushError(String errorFileName, int line, String message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                                    String referenceText, String referenceTextPointer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                int limit = errorLimit + nwarnings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                if (++errorsPushed >= limit && errorLimit >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                    if (!hitErrorLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                        hitErrorLimit = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                        output(errorString("too.many.errors",
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 5506
diff changeset
  1175
                                           errorLimit,null,null));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                if (errorFileName.endsWith(".java")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                    output(errorFileName + ":" + line + ": " + message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                    output(referenceText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                    output(referenceTextPointer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                    // It wasn't really a source file (probably an error or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                    // warning because of a malformed or badly versioned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                    // class file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                    output(errorFileName + ": " + message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    public void flushErrors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        if (errors == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        boolean inputAvail = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        // Read the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        char data[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        int dataLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        // A malformed file encoding could cause a CharConversionException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        // If something bad happens while trying to find the source file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        // don't bother trying to show lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            FileInputStream in = new FileInputStream(errorFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            data = new char[in.available()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            InputStreamReader reader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                (getCharacterEncoding() != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                 new InputStreamReader(in, getCharacterEncoding()) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                 new InputStreamReader(in));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            dataLength = reader.read(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            reader.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            inputAvail = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        } catch(IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            // inputAvail will not be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        // Report the errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        for (ErrorMessage msg = errors ; msg != null ; msg = msg.next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            // There used to be code here which checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            // for duplicate error messages.  This functionality
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            // has been moved to the method insertError().  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            // the comments on that method for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            int ln = (int) (msg.where >>> WHEREOFFSETBITS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            int off = (int) (msg.where & ((1L << WHEREOFFSETBITS) - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            if (off > dataLength)  off = dataLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            String referenceString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            String markerString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            if(inputAvail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                int i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                for (i = off ; (i > 0) && (data[i - 1] != '\n') && (data[i - 1] != '\r') ; i--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                for (j = off ; (j < dataLength) && (data[j] != '\n') && (data[j] != '\r') ; j++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                referenceString = new String(data, i, j - i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                char strdata[] = new char[(off - i) + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                for (j = i ; j < off ; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                    strdata[j-i] = (data[j] == '\t') ? '\t' : ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                strdata[off-i] = '^';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                markerString = new String(strdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            errorConsumer.pushError(errorFileName, ln, msg.message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                                        referenceString, markerString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        errors = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * Report error
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    public
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    void reportError(Object src, long where, String err, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        if (src == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            if (errorFileName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                flushErrors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                errorFileName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            if (err.startsWith("warn.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                if (warnings()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                    nwarnings++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                    output(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            output("error: " + msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            nerrors++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            flags |= F_ERRORSREPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        } else if (src instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            String fileName = (String)src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            // Flush errors if we've moved on to a new file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            if (!fileName.equals(errorFileName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                flushErrors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                errorFileName = fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            // Classify `err' as a warning, deprecation warning, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            // error message.  Proceed accordingly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            if (err.startsWith("warn.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                if (err.indexOf("is.deprecated") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                    // This is a deprecation warning.  Add `src' to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                    // list of files with deprecation warnings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                    if (!deprecationFiles.contains(src)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                        deprecationFiles.addElement(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                    // If we are reporting deprecations, try to add it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                    // to our list.  Otherwise, just increment the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                    // deprecation count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                    if (deprecation()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                        if (insertError(where, msg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                            ndeprecations++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                        ndeprecations++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                    // This is a regular warning.  If we are reporting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                    // warnings, try to add it to the list.  Otherwise, just
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                    // increment the warning count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                    if (warnings()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                        if (insertError(where, msg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                            nwarnings++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                        nwarnings++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                // This is an error.  Try to add it to the list of errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                // If it isn't a duplicate, increment our error count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                if (insertError(where, msg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                    nerrors++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                    flags |= F_ERRORSREPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        } else if (src instanceof ClassFile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            reportError(((ClassFile)src).getPath(), where, err, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        } else if (src instanceof Identifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            reportError(src.toString(), where, err, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        } else if (src instanceof ClassDeclaration) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                reportError(((ClassDeclaration)src).getClassDefinition(this), where, err, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            } catch (ClassNotFound e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                reportError(((ClassDeclaration)src).getName(), where, err, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        } else if (src instanceof ClassDefinition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            ClassDefinition c = (ClassDefinition)src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            if (!err.startsWith("warn.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                c.setError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            reportError(c.getSource(), where, err, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        } else if (src instanceof MemberDefinition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            reportError(((MemberDefinition)src).getClassDeclaration(), where, err, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            output(src + ":error=" + err + ":" + msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * Issue an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    public void error(Object source, long where, String err, Object arg1, Object arg2, Object arg3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        if (errorsPushed >= errorLimit + nwarnings) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            // Don't bother to queue any more errors if they won't get printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        if (System.getProperty("javac.dump.stack") != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
            output("javac.err."+err+": "+errorString(err, arg1, arg2, arg3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            new Exception("Stack trace").printStackTrace(new PrintStream(out));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        reportError(source, where, err, errorString(err, arg1, arg2, arg3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     * Output a string. This can either be an error message or something
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    public void output(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        PrintStream out =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            this.out instanceof PrintStream ? (PrintStream)this.out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                                            : new PrintStream(this.out, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        out.println(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
}