From 023d908578fd8ef6dce19053dfe6cba5148bf5fd Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Sun, 27 May 2007 20:17:59 +0000 Subject: [PATCH] Support the sending of output to stdout. --- .../spinellis/umlgraph/doclet/ClassGraph.java | 42 +++++++++++-------- src/org/umlgraph/doclet/ClassGraph.java | 42 +++++++++++-------- 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/src/gr/spinellis/umlgraph/doclet/ClassGraph.java b/src/gr/spinellis/umlgraph/doclet/ClassGraph.java index 8d866fd..2c608ed 100644 --- a/src/gr/spinellis/umlgraph/doclet/ClassGraph.java +++ b/src/gr/spinellis/umlgraph/doclet/ClassGraph.java @@ -23,6 +23,7 @@ package gr.spinellis.umlgraph.doclet; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; +import java.io.OutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; @@ -849,13 +850,12 @@ class ClassGraph { Options opt = optionProvider.getOptionsFor(type.asClassDoc()); if (opt.matchesCollPackageExpression(type.qualifiedTypeName())) { Type[] argTypes = getInterfaceTypeArguments(collectionClassDoc, type); - if (argTypes != null && argTypes.length == 1) { + if (argTypes != null && argTypes.length == 1 && !argTypes[0].isPrimitive()) return new FieldRelationInfo(argTypes[0].asClassDoc(), true); - } + argTypes = getInterfaceTypeArguments(mapClassDoc, type); - if (argTypes != null && argTypes.length == 2) { + if (argTypes != null && argTypes.length == 2 && !argTypes[1].isPrimitive()) return new FieldRelationInfo(argTypes[1].asClassDoc(), true); - } } return new FieldRelationInfo(type.asClassDoc(), false); @@ -978,21 +978,27 @@ class ClassGraph { * @throws IOException */ public void prologue() throws IOException { Options opt = optionProvider.getGlobalOptions(); - // prepare output file. Use the output file name as a full path unless the output - // directory is specified - File file = null; - if (opt.outputDirectory != null) - file = new File(opt.outputDirectory, opt.outputFileName); - else - file = new File(opt.outputFileName); - // make sure the output directory are there, otherwise create them - if (file.getParentFile() != null - && !file.getParentFile().exists()) - file.getParentFile().mkdirs(); - FileOutputStream fos = new FileOutputStream(file); - + OutputStream os = null; + + if (opt.outputFileName.equals("-")) + os = System.out; + else { + // prepare output file. Use the output file name as a full path unless the output + // directory is specified + File file = null; + if (opt.outputDirectory != null) + file = new File(opt.outputDirectory, opt.outputFileName); + else + file = new File(opt.outputFileName); + // make sure the output directory are there, otherwise create them + if (file.getParentFile() != null + && !file.getParentFile().exists()) + file.getParentFile().mkdirs(); + os = new FileOutputStream(file); + } + // print plologue - w = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(fos), opt.outputEncoding)); + w = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(os), opt.outputEncoding)); w.println( "#!/usr/local/bin/dot\n" + "#\n" + diff --git a/src/org/umlgraph/doclet/ClassGraph.java b/src/org/umlgraph/doclet/ClassGraph.java index 8d866fd..2c608ed 100644 --- a/src/org/umlgraph/doclet/ClassGraph.java +++ b/src/org/umlgraph/doclet/ClassGraph.java @@ -23,6 +23,7 @@ package gr.spinellis.umlgraph.doclet; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; +import java.io.OutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; @@ -849,13 +850,12 @@ class ClassGraph { Options opt = optionProvider.getOptionsFor(type.asClassDoc()); if (opt.matchesCollPackageExpression(type.qualifiedTypeName())) { Type[] argTypes = getInterfaceTypeArguments(collectionClassDoc, type); - if (argTypes != null && argTypes.length == 1) { + if (argTypes != null && argTypes.length == 1 && !argTypes[0].isPrimitive()) return new FieldRelationInfo(argTypes[0].asClassDoc(), true); - } + argTypes = getInterfaceTypeArguments(mapClassDoc, type); - if (argTypes != null && argTypes.length == 2) { + if (argTypes != null && argTypes.length == 2 && !argTypes[1].isPrimitive()) return new FieldRelationInfo(argTypes[1].asClassDoc(), true); - } } return new FieldRelationInfo(type.asClassDoc(), false); @@ -978,21 +978,27 @@ class ClassGraph { * @throws IOException */ public void prologue() throws IOException { Options opt = optionProvider.getGlobalOptions(); - // prepare output file. Use the output file name as a full path unless the output - // directory is specified - File file = null; - if (opt.outputDirectory != null) - file = new File(opt.outputDirectory, opt.outputFileName); - else - file = new File(opt.outputFileName); - // make sure the output directory are there, otherwise create them - if (file.getParentFile() != null - && !file.getParentFile().exists()) - file.getParentFile().mkdirs(); - FileOutputStream fos = new FileOutputStream(file); - + OutputStream os = null; + + if (opt.outputFileName.equals("-")) + os = System.out; + else { + // prepare output file. Use the output file name as a full path unless the output + // directory is specified + File file = null; + if (opt.outputDirectory != null) + file = new File(opt.outputDirectory, opt.outputFileName); + else + file = new File(opt.outputFileName); + // make sure the output directory are there, otherwise create them + if (file.getParentFile() != null + && !file.getParentFile().exists()) + file.getParentFile().mkdirs(); + os = new FileOutputStream(file); + } + // print plologue - w = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(fos), opt.outputEncoding)); + w = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(os), opt.outputEncoding)); w.println( "#!/usr/local/bin/dot\n" + "#\n" +