src/share/classes/sun/rmi/rmic/iiop/PrintGenerator.java

Wed, 27 Apr 2016 01:21:28 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:21:28 +0800
changeset 0
7ef37b2cdcad
child 748
6845b95cba6b
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/corba/
changeset: 765:f46df0af2ca8
tag: jdk8u25-b17

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

mercurial