Output class import

@param def definition
@param out Writer
@throws IOException ioException
773257
@Override
   public void writeImport(Definition def, Writer out) throws IOException
   {
      out.write("package " + def.getRaPackage() + ";\n\n");
      if (def.isSupportInbound())
      {
         out.write("import " + def.getRaPackage() + ".inflow." + def.getActivationClass() + ";\n");
         out.write("import " + def.getRaPackage() + ".inflow." + def.getAsClass() + ";\n\n");
         if (def.getVersion().equals("1.5"))
         {
            out.write("import java.util.Collections;\n");
            out.write("import java.util.HashMap;\n");
            out.write("import java.util.Map;\n");
            writeEol(out);
         }
         else if (def.getVersion().equals("1.6") || def.getVersion().equals("1.7"))
         {
            out.write("import java.util.concurrent.ConcurrentHashMap;\n");
            writeEol(out);
         }
      }
      importLogging(def, out);

      out.write("import javax.resource.ResourceException;\n");
      out.write("import javax.resource.spi.ActivationSpec;\n");
      if (def.isUseAnnotation() &&
            def.getAuthenMechanisms() != null && def.getAuthenMechanisms().size() > 0)
      {
         out.write("import javax.resource.spi.AuthenticationMechanism;\n");
         out.write("import javax.resource.spi.AuthenticationMechanism.CredentialInterface;\n");
      }
      out.write("import javax.resource.spi.BootstrapContext;\n");
      if (def.isUseAnnotation())
      {
         importConfigProperty(def, out);
         out.write("import javax.resource.spi.Connector;\n");
      }
      out.write("import javax.resource.spi.ResourceAdapter;\n");
      out.write("import javax.resource.spi.ResourceAdapterInternalException;\n");
      if (def.isUseAnnotation() &&
            def.getSecurityPermissions() != null && def.getSecurityPermissions().size() > 0)
      {
         out.write("import javax.resource.spi.SecurityPermission;\n");
      }
      if (def.isUseAnnotation() && def.isSupportOutbound())
      {
         out.write("import javax.resource.spi.TransactionSupport;\n");
      }
      out.write("import javax.resource.spi.endpoint.MessageEndpointFactory;\n\n");
      out.write("import javax.transaction.xa.XAResource;\n\n");

   }
956649
private void writeImports() {

    for (String importType : importTypes) {
      writer.append("import %s;", importType).eol();
    }
    writer.eol();
  }
12247
public void writeClassAndObject (Output output, Object object) {
		if (output == null) throw new IllegalArgumentException("output cannot be null.");
		beginObject();
		try {
			if (object == null) {
				writeClass(output, null);
				return;
			}
			Registration registration = writeClass(output, object.getClass());
			if (references && writeReferenceOrNull(output, object, false)) return;
			if (TRACE || (DEBUG && depth == 1)) log("Write", object, output.position());
			registration.getSerializer().write(this, output, object);
		} finally {
			if (--depth == 0 && autoReset) reset();
		}
	}
141716
public void writeClassFile(OutputStream out, ClassSymbol c)
        throws IOException, PoolOverflow, StringOverflow {
        Assert.check((c.flags() & COMPOUND) == 0);
        databuf.reset();
        poolbuf.reset();
        signatureGen.reset();
        pool = c.pool;
        innerClasses = null;
        innerClassesQueue = null;
        bootstrapMethods = new LinkedHashMap<>();

        Type supertype = types.supertype(c.type);
        List<Type> interfaces = types.interfaces(c.type);
        List<Type> typarams = c.type.getTypeArguments();

        int flags;
        if (c.owner.kind == MDL) {
            flags = ACC_MODULE;
        } else {
            flags = adjustFlags(c.flags() & ~DEFAULT);
            if ((flags & PROTECTED) != 0) flags |= PUBLIC;
            flags = flags & ClassFlags & ~STRICTFP;
            if ((flags & INTERFACE) == 0) flags |= ACC_SUPER;
        }

        if (dumpClassModifiers) {
            PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
            pw.println();
            pw.println("CLASSFILE  " + c.getQualifiedName());
            pw.println("---" + flagNames(flags));
        }
        databuf.appendChar(flags);

        if (c.owner.kind == MDL) {
            PackageSymbol unnamed = ((ModuleSymbol) c.owner).unnamedPackage;
            databuf.appendChar(pool.put(new ClassSymbol(0, names.module_info, unnamed)));
        } else {
            databuf.appendChar(pool.put(c));
        }
        databuf.appendChar(supertype.hasTag(CLASS) ? pool.put(supertype.tsym) : 0);
        databuf.appendChar(interfaces.length());
        for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail)
            databuf.appendChar(pool.put(l.head.tsym));
        int fieldsCount = 0;
        int methodsCount = 0;
        for (Symbol sym : c.members().getSymbols(NON_RECURSIVE)) {
            switch (sym.kind) {
            case VAR: fieldsCount++; break;
            case MTH: if ((sym.flags() & HYPOTHETICAL) == 0) methodsCount++;
                      break;
            case TYP: enterInner((ClassSymbol)sym); break;
            default : Assert.error();
            }
        }

        if (c.trans_local != null) {
            for (ClassSymbol local : c.trans_local) {
                enterInner(local);
            }
        }

        databuf.appendChar(fieldsCount);
        writeFields(c.members());
        databuf.appendChar(methodsCount);
        writeMethods(c.members());

        int acountIdx = beginAttrs();
        int acount = 0;

        boolean sigReq =
            typarams.length() != 0 || supertype.allparams().length() != 0;
        for (List<Type> l = interfaces; !sigReq && l.nonEmpty(); l = l.tail)
            sigReq = l.head.allparams().length() != 0;
        if (sigReq) {
            int alenIdx = writeAttr(names.Signature);
            if (typarams.length() != 0) signatureGen.assembleParamsSig(typarams);
            signatureGen.assembleSig(supertype);
            for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail)
                signatureGen.assembleSig(l.head);
            databuf.appendChar(pool.put(signatureGen.toName()));
            signatureGen.reset();
            endAttr(alenIdx);
            acount++;
        }

        if (c.sourcefile != null && emitSourceFile) {
            int alenIdx = writeAttr(names.SourceFile);
            // WHM 6/29/1999: Strip file path prefix.  We do it here at
            // the last possible moment because the sourcefile may be used
            // elsewhere in error diagnostics. Fixes 4241573.
            //databuf.appendChar(c.pool.put(c.sourcefile));
            String simpleName = PathFileObject.getSimpleName(c.sourcefile);
            databuf.appendChar(c.pool.put(names.fromString(simpleName)));
            endAttr(alenIdx);
            acount++;
        }

        if (genCrt) {
            // Append SourceID attribute
            int alenIdx = writeAttr(names.SourceID);
            databuf.appendChar(c.pool.put(names.fromString(Long.toString(getLastModified(c.sourcefile)))));
            endAttr(alenIdx);
            acount++;
            // Append CompilationID attribute
            alenIdx = writeAttr(names.CompilationID);
            databuf.appendChar(c.pool.put(names.fromString(Long.toString(System.currentTimeMillis()))));
            endAttr(alenIdx);
            acount++;
        }

        acount += writeFlagAttrs(c.flags());
        acount += writeJavaAnnotations(c.getRawAttributes());
        acount += writeTypeAnnotations(c.getRawTypeAttributes(), false);
        acount += writeEnclosingMethodAttribute(c);
        if (c.owner.kind == MDL) {
            acount += writeModuleAttribute(c);
            acount += writeFlagAttrs(c.owner.flags() & ~DEPRECATED);
        }
        acount += writeExtraClassAttributes(c);

        poolbuf.appendInt(JAVA_MAGIC);

        if (c.owner.kind == MDL) {
            // temporarily overide to force use of v53 for module-info.class
            poolbuf.appendChar(0);
            poolbuf.appendChar(53);
        } else {
            poolbuf.appendChar(target.minorVersion);
            poolbuf.appendChar(target.majorVersion);
        }

        writePool(c.pool);

        if (innerClasses != null) {
            writeInnerClasses();
            acount++;
        }

        if (!bootstrapMethods.isEmpty()) {
            writeBootstrapMethods();
            acount++;
        }

        endAttrs(acountIdx, acount);

        poolbuf.appendBytes(databuf.elems, 0, databuf.length);
        out.write(poolbuf.elems, 0, poolbuf.length);

        pool = c.pool = null; // to conserve space
     }
1072227
void generateAntIvyXml(Definition def, String outputDir)
   {
      try
      {
         FileWriter antfw = Utils.createFile("build.xml", outputDir);
         BuildIvyXmlGen bxGen = new BuildIvyXmlGen();
         bxGen.generate(def, antfw);
         antfw.close();

         FileWriter ivyfw = Utils.createFile("ivy.xml", outputDir);
         IvyXmlGen ixGen = new IvyXmlGen();
         ixGen.generate(def, ivyfw);
         ivyfw.close();

         FileWriter ivySettingsfw = Utils.createFile("ivy.settings.xml", outputDir);
         IvySettingsXmlGen isxGen = new IvySettingsXmlGen();
         isxGen.generate(def, ivySettingsfw);
         ivySettingsfw.close();
      }
      catch (IOException ioe)
      {
         ioe.printStackTrace();
      }
   }
151263
void generateMultiAdminObjectClassCode(Definition def, String className, int num)
   {
      if (className == null || className.equals(""))
         return;

      try
      {
         String clazzName = this.getClass().getPackage().getName() + ".code." + className + "CodeGen";

         Class<?> clazz = Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader());
         AbstractCodeGen codeGen = (AbstractCodeGen) clazz.newInstance();

         String javaFile = "";
         if (codeGen instanceof AoImplCodeGen)
         {
            ((AoImplCodeGen) codeGen).setNumOfAo(num);
            javaFile = def.getAdminObjects().get(num).getAdminObjectClass() + ".java";
         }
         else if (codeGen instanceof AoInterfaceCodeGen)
         {
            ((AoInterfaceCodeGen) codeGen).setNumOfAo(num);
            javaFile = def.getAdminObjects().get(num).getAdminObjectInterface() + ".java";
         }

         FileWriter fw = Utils.createSrcFile(javaFile, def.getRaPackage(), def.getOutputDir());
         codeGen.generate(def, fw);

         fw.flush();
         fw.close();
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
   }
873550
public void write(XMLStreamWriter writer, AttributeDefinition<?> def) throws XMLStreamException {
      write(writer, def, def.xmlName());
   }
248448
private void writeConnection(Definition def, Writer out, int indent) throws IOException
   {
      writeWithIndent(out, indent, "/** \n");
      writeWithIndent(out, indent, " * Get connection from factory\n");
      writeWithIndent(out, indent, " *\n");
      writeWithIndent(out, indent,
            " * @return " + def.getMcfDefs().get(getNumOfMcf()).getConnInterfaceClass() + " instance\n");
      writeWithIndent(out, indent, " * @exception ResourceException Thrown if a connection can't be obtained\n");
      writeWithIndent(out, indent, " */\n");

      writeWithIndent(out, indent, "public " + def.getMcfDefs().get(getNumOfMcf()).getConnInterfaceClass() +
            " getConnection() throws ResourceException;\n");
   }
307073
private void writeMethod(Definition def, Writer out, int indent) throws IOException
   {
      if (def.getMcfDefs().get(getNumOfMcf()).isDefineMethodInConnection())
      {
         if (def.getMcfDefs().get(getNumOfMcf()).getMethods().size() > 0)
         {
            for (MethodForConnection method : def.getMcfDefs().get(getNumOfMcf()).getMethods())
            {
               writeMethodSignature(out, indent, method);
               writeLeftCurlyBracket(out, indent);
               writeLogging(def, out, indent + 1, "trace", method.getMethodName());

               if (!method.getReturnType().equals("void"))
               {
                  writeEol(out);
                  if (BasicType.isPrimitiveType(method.getReturnType()))
                  {
                     writeWithIndent(out, indent + 1, "return " + BasicType.defaultValue(method.getReturnType()) + ";");
                  }
                  else
                  {
                     writeWithIndent(out, indent + 1, "return null;");
                  }
               }

               writeRightCurlyBracket(out, indent);
            }
         }
      }
      else
      {
         writeSimpleMethodSignature(out, indent, " * Call me", "void callMe()");
         writeLeftCurlyBracket(out, indent);
         writeLogging(def, out, indent + 1, "trace", "callMe");
         writeRightCurlyBracket(out, indent);
      }
   }
1155426
void writeConstructor(Definition def, Writer out, int indent) throws IOException
   {
      writeSimpleMethodSignature(out, indent, " * Default constructor", "public " + getClassName(def) + "()");
      writeLeftCurlyBracket(out, indent);

      writeWithIndent(out, indent + 1, "this.mbeanServer = null;\n");
      writeWithIndent(out, indent + 1, "this.objectName = \"" + def.getDefaultValue() + ",class=HelloWorld\";\n");
      writeWithIndent(out, indent + 1, "this.registered = false;\n\n");

      writeRightCurlyBracket(out, indent);
      writeEol(out);
   }
150289
private void writeOutbound(Definition def, Writer out, int indent) throws IOException
   {
      writeIndent(out, indent);
      out.write("<outbound-resourceadapter>");
      writeEol(out);

      for (int num = 0; num < def.getMcfDefs().size(); num++)
      {

         writeIndent(out, indent + 1);
         out.write("<connection-definition>");
         writeEol(out);
         writeIndent(out, indent + 2);
         out.write("<managedconnectionfactory-class>" + def.getRaPackage() + "." +
               def.getMcfDefs().get(num).getMcfClass() + "</managedconnectionfactory-class>");
         writeEol(out);
         writeConfigPropsXml(def.getMcfDefs().get(num).getMcfConfigProps(), out, indent + 2);

         if (!def.getMcfDefs().get(num).isUseCciConnection())
         {
            writeIndent(out, indent + 2);
            out.write("<connectionfactory-interface>" + def.getRaPackage() + "." +
                  def.getMcfDefs().get(num).getCfInterfaceClass() + "</connectionfactory-interface>");
            writeEol(out);
            writeIndent(out, indent + 2);
            out.write("<connectionfactory-impl-class>" + def.getRaPackage() + "." +
                  def.getMcfDefs().get(num).getCfClass() + "</connectionfactory-impl-class>");
            writeEol(out);
            writeIndent(out, indent + 2);
            out.write("<connection-interface>" + def.getRaPackage() + "." +
                  def.getMcfDefs().get(num).getConnInterfaceClass() + "</connection-interface>");
            writeEol(out);
            writeIndent(out, indent + 2);
            out.write("<connection-impl-class>" + def.getRaPackage() + "." +
                  def.getMcfDefs().get(num).getConnImplClass() + "</connection-impl-class>");
            writeEol(out);
         }
         else
         {
            writeIndent(out, indent + 2);
            out.write("<connectionfactory-interface>javax.resource.cci.ConnectionFactory"
                  + "</connectionfactory-interface>");
            writeEol(out);
            writeIndent(out, indent + 2);
            out.write("<connectionfactory-impl-class>" + def.getRaPackage() + "." +
                  def.getMcfDefs().get(num).getCciConnFactoryClass() + "</connectionfactory-impl-class>");
            writeEol(out);
            writeIndent(out, indent + 2);
            out.write("<connection-interface>javax.resource.cci.Connection</connection-interface>");
            writeEol(out);
            writeIndent(out, indent + 2);
            out.write("<connection-impl-class>" + def.getRaPackage() + "." +
                  def.getMcfDefs().get(num).getCciConnClass() + "</connection-impl-class>");
            writeEol(out);
         }
         writeIndent(out, indent + 1);
         out.write("</connection-definition>");
         writeEol(out);
      }
      writeIndent(out, indent + 1);
      out.write("<transaction-support>" + def.getSupportTransaction() + "</transaction-support>");
      writeEol(out);

      if (def.getAuthenMechanisms() != null && def.getAuthenMechanisms().size() > 0)
      {
         for (int i = 0; i < def.getAuthenMechanisms().size(); i++)
         {
            writeIndent(out, indent + 1);
            out.write("<authentication-mechanism>");
            writeEol(out);
            writeIndent(out, indent + 2);
            out.write("<authentication-mechanism-type>" + def.getAuthenMechanisms().get(i).getAuthMechanism() +
                  "</authentication-mechanism-type>");
            writeEol(out);
            writeIndent(out, indent + 2);
            out.write("<credential-interface>");
            if (def.getAuthenMechanisms().get(i).getCredentialInterface().equals("GSSCredential"))
               out.write("org.ietf.jgss.GSSCredential");
            else
               out.write("javax.resource.spi.security." + def.getAuthenMechanisms().get(i).getCredentialInterface());
            out.write("</credential-interface>");
            writeEol(out);
            writeIndent(out, indent + 1);
            out.write("</authentication-mechanism>");
            writeEol(out);
         }
      }

      writeIndent(out, indent + 1);
      out.write("<reauthentication-support>" + def.isSupportReauthen() + "</reauthentication-support>");
      writeEol(out);
      writeIndent(out, indent);
      out.write("</outbound-resourceadapter>");
      writeEol(out);
   }
1014077
private void writeGetConnection(Definition def, Writer out, int indent) throws IOException
   {
      String connInterface = def.getMcfDefs().get(0).getConnInterfaceClass();
      String cfInterface = def.getMcfDefs().get(0).getCfInterfaceClass();

      writeWithIndent(out, indent, "/**\n");
      writeWithIndent(out, indent, " * GetConnection\n");
      writeWithIndent(out, indent, " * @return " + connInterface);
      writeEol(out);
      writeWithIndent(out, indent, " */\n");
      writeWithIndent(out, indent, "private " + connInterface + " getConnection() throws Exception");
      writeLeftCurlyBracket(out, indent);
      writeWithIndent(out, indent + 1, "InitialContext context = new InitialContext();\n");
      writeIndent(out, indent + 1);
      out.write(cfInterface + " factory = (" + cfInterface +
            ")context.lookup(JNDI_NAME);\n");
      writeIndent(out, indent + 1);
      out.write(connInterface + " conn = factory.getConnection();\n");
      writeWithIndent(out, indent + 1, "if (conn == null)");
      writeLeftCurlyBracket(out, indent + 1);
      writeIndent(out, indent + 2);
      out.write("throw new RuntimeException(\"No connection\");");
      writeRightCurlyBracket(out, indent + 1);

      writeWithIndent(out, indent + 1, "return conn;");

      writeRightCurlyBracket(out, indent);
   }
1143369
@Override
   void writeEquals(Definition def, Writer out, int indent) throws IOException
   {
      writeIndent(out, indent);
      out.write("/** \n");
      writeIndent(out, indent);
      out.write(" * Indicates whether some other object is equal to this one.\n");
      writeIndent(out, indent);
      out.write(" * @param other The reference object with which to compare.\n");
      writeIndent(out, indent);
      out.write(" * @return true if this object is the same as the obj argument, false otherwise.\n");
      writeIndent(out, indent);
      out.write(" */\n");

      writeIndent(out, indent);
      out.write("@Override\n");
      writeIndent(out, indent);
      out.write("public boolean equals(Object other)");
      writeLeftCurlyBracket(out, indent);
      writeWithIndent(out, indent + 1, "if (other == null)\n");
      writeWithIndent(out, indent + 2, "return false;\n");
      writeWithIndent(out, indent + 1, "if (other == this)\n");
      writeWithIndent(out, indent + 2, "return true;\n");
      writeWithIndent(out, indent + 1, "if (!(other instanceof " + getClassName(def) + "))\n");
      writeWithIndent(out, indent + 2, "return false;\n");

      writeWithIndent(out, indent + 1, "boolean result = true;\n");

      if (getConfigProps(def).size() > 0)
      {
         writeIndent(out, indent + 1);
         out.write(getClassName(def) + " obj = (" + getClassName(def) + ")other;\n");
      }

      for (int i = 0; i < getConfigProps(def).size(); i++)
      {
         writeWithIndent(out, indent + 1, "if (result)");
         writeLeftCurlyBracket(out, indent + 1);
         writeWithIndent(out, indent + 2, "if (" + getConfigProps(def).get(i).getName() + " == null)\n");
         writeWithIndent(out, indent + 3,
               "result = obj.get" + upcaseFirst(getConfigProps(def).get(i).getName()) + "() == null;\n");

         writeWithIndent(out, indent + 2, "else\n");
         writeWithIndent(out, indent + 3, "result = " + getConfigProps(def).get(i).getName() + ".equals(obj.get" +
               upcaseFirst(getConfigProps(def).get(i).getName()) + "());");
         writeRightCurlyBracket(out, indent + 1);
      }
      writeWithIndent(out, indent + 1, "return result;");
      writeRightCurlyBracket(out, indent);
      //writeEol(out);
   }
631089
public void outputTerms() throws DITAOTException {
        StringBuilder buff = new StringBuilder(outputFileRoot);
        AbstractWriter abstractWriter = null;

        if (indexClass != null && indexClass.length() > 0) {
            //Instantiate the class value
            Class<?> anIndexClass;
            try {
                anIndexClass = Class.forName( indexClass );
                abstractWriter = (AbstractWriter) anIndexClass.newInstance();
                final IDitaTranstypeIndexWriter indexWriter = (IDitaTranstypeIndexWriter) anIndexClass.newInstance();

                //RFE 2987769 Eclipse index-see
                try {

                    ((AbstractExtendDitaWriter) abstractWriter).setPipelineHashIO(this.getPipelineHashIO());

                } catch (final ClassCastException e) {
                    javaLogger.info(e.getMessage());
                    javaLogger.info(e.toString());
                    e.printStackTrace();

                }


                buff = new StringBuilder(indexWriter.getIndexFileName(outputFileRoot));


            } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                e.printStackTrace();
            }


        } else {
            throw new IllegalArgumentException("Index writer class not defined");
        }

        //Even if there is no term in the list create an empty index file
        //otherwise the compiler will report error.
        abstractWriter.setLogger(javaLogger);
        ((IDitaTranstypeIndexWriter) abstractWriter).setTermList(this.getTermList());
        abstractWriter.write(new File(buff.toString()));
    }
415286
function outputModuleDefinitions (module, headWasOutput)
  {
    for (var i = 0, m = module.bodies.length; i < m; ++i) {
      var bodyPath = module.bodyPaths[i];
      if (!bodyPath)
        console.log (module.name, i, module.bodies.length, module.bodyPaths);
      // Skip bodies who's corresponding file was already output.
      if (context.outputtedFiles[bodyPath])
        continue;
      context.outputtedFiles[bodyPath] = true;

      var body = module.optimize ?
        optimize (module.bodies[i], bodyPath, module)
        : {status: STAT.INDENTED, data: module.bodies[i]};

      if (i || !headWasOutput)
        traceOutput.push (LINE, '// File: ' + bodyPath, LINE, '');
      traceOutput.push (conditionalIndent (body));
    }
  }
837898
private void writeMethods(Definition def, Writer out, int indent) throws IOException
   {
      if (def.getMcfDefs().get(0).isDefineMethodInConnection())
      {
         if (def.getMcfDefs().get(0).getMethods().size() > 0)
         {
            for (MethodForConnection method : def.getMcfDefs().get(0).getMethods())
            {
               writeMethodSignature(out, indent, method);

               writeLeftCurlyBracket(out, indent);
               writeIndent(out, indent + 1);
               if (!method.getReturnType().equals("void"))
               {
                  out.write("return ");
               }
               out.write("getConnection()." + method.getMethodName() + "(");
               int paramSize = method.getParams().size();
               for (int i = 0; i < paramSize; i++)
               {
                  MethodParam param = method.getParams().get(i);
                  out.write(param.getName());
                  if (i + 1 < paramSize)
                     out.write(", ");
               }
               out.write(");\n");

               writeRightCurlyBracket(out, indent);
            }
         }
      }
      else
      {
         writeSimpleMethodSignature(out, indent, " * Call me", "public void callMe()");
         writeLeftCurlyBracket(out, indent);
         writeWithIndent(out, indent + 1, "try");
         writeLeftCurlyBracket(out, indent + 1);
         writeWithIndent(out, indent + 2, "getConnection().callMe();");
         writeRightCurlyBracket(out, indent + 1);
         writeWithIndent(out, indent + 1, "catch (Exception e)");
         writeLeftCurlyBracket(out, indent + 1);
         writeRightCurlyBracket(out, indent + 1);
         writeRightCurlyBracket(out, indent);
      }
   }
1038782
private void writeObject(ObjectOutputStream out) throws IOException {
        ClassRef.write(out, type);
        out.writeUTF(name);
        out.writeObject(val);
    }