corba/src/jdk.rmic/share/classes/sun/rmi/rmic/iiop/PrintGenerator.java
author bpb
Fri, 12 Aug 2016 14:35:56 -0700
changeset 40442 e97e9982be6d
parent 25862 a5e25d68f971
permissions -rw-r--r--
8152966: ClassCastException when adding IFD to the TIFFDirectory before the image write Summary: Move the private method getDirectoryAsIFD(TIFFDirectory) from the API class TIFFDirectory to a public method in the internal class TIFFIFD and replace all casts of TIFFDirectory to TIFFIFD with its invocation Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
package sun.rmi.rmic.iiop;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.io.File;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.io.OutputStreamWriter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import sun.tools.java.CompilerError;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import sun.tools.java.ClassDefinition;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import sun.rmi.rmic.IndentingWriter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import sun.rmi.rmic.Main;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
 * An IDL generator for rmic.
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
 * @author      Bryan Atsatt
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
public class PrintGenerator implements sun.rmi.rmic.Generator,
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
                                       sun.rmi.rmic.iiop.Constants {
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
    private static final int JAVA = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
    private static final int IDL = 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
    private static final int BOTH = 2;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
    private int whatToPrint; // Initialized in parseArgs.
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
    private boolean global = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
    private boolean qualified = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
    private boolean trace = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
    private boolean valueMethods = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
    private IndentingWriter out;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
     * Default constructor for Main to use.
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
    public PrintGenerator() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
        OutputStreamWriter writer = new OutputStreamWriter(System.out);
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
        out = new IndentingWriter (writer);
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
     * Examine and consume command line arguments.
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
     * @param argv The command line arguments. Ignore null
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
     * @param error Report any errors using the main.error() methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
     * @return true if no errors, false otherwise.
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
    public boolean parseArgs(String argv[], Main main) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
        for (int i = 0; i < argv.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
            if (argv[i] != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
                String arg = argv[i].toLowerCase();
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
                if (arg.equals("-xprint")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
                    whatToPrint = JAVA;
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
                    argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
                    if (i+1 < argv.length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
                        if (argv[i+1].equalsIgnoreCase("idl")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
                            argv[++i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
                            whatToPrint = IDL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
                        } else if (argv[i+1].equalsIgnoreCase("both")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
                            argv[++i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
                            whatToPrint = BOTH;
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
                } else if (arg.equals("-xglobal")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
                    global = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
                    argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
                } else if (arg.equals("-xqualified")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
                    qualified = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
                    argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
                } else if (arg.equals("-xtrace")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
                    trace = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
                    argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
                } else if (arg.equals("-xvaluemethods")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
                    valueMethods = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
                    argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
     * Generate output. Any source files created which need compilation should
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
     * be added to the compiler environment using the addGeneratedFile(File)
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
     * method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
     * @param env       The compiler environment
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
     * @param cdef      The definition for the implementation class or interface from
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
     *              which to generate output
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
     * @param destDir   The directory for the root of the package hierarchy
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
     *                          for generated files. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    public void generate(sun.rmi.rmic.BatchEnvironment env, ClassDefinition cdef, File destDir) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
        BatchEnvironment ourEnv = (BatchEnvironment) env;
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
        ContextStack stack = new ContextStack(ourEnv);
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
        stack.setTrace(trace);
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
        if (valueMethods) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
            ourEnv.setParseNonConforming(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
        // Get our top level type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
        CompoundType topType = CompoundType.forCompound(cdef,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
        if (topType != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
                                // Collect up all the compound types...
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
                Type[] theTypes = topType.collectMatching(TM_COMPOUND);
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
                for (int i = 0; i < theTypes.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
                    out.pln("\n-----------------------------------------------------------\n");
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
                    Type theType = theTypes[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
                    switch (whatToPrint) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
                    case JAVA:  theType.println(out,qualified,false,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
                        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
                    case IDL:   theType.println(out,qualified,true,global);
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
                        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
                    case BOTH:  theType.println(out,qualified,false,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
                        theType.println(out,qualified,true,global);
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
                        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
                    default:    throw new CompilerError("Unknown type!");
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
                out.flush();
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
            } catch (IOException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
                throw new CompilerError("PrintGenerator caught " + e);
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
}