1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-09-27 14:39:02 +00:00
plantuml/src/net/sourceforge/plantuml/BlockUmlBuilder.java

123 lines
3.9 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2015-04-07 18:18:37 +00:00
* (C) Copyright 2009-2014, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2010-11-15 20:35:36 +00:00
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4952 $
*
*/
package net.sourceforge.plantuml;
2011-01-29 15:09:35 +00:00
import java.io.File;
2010-11-15 20:35:36 +00:00
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
2011-01-29 15:09:35 +00:00
import java.util.HashSet;
2010-11-15 20:35:36 +00:00
import java.util.List;
2011-01-29 15:09:35 +00:00
import java.util.Set;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.preproc.Defines;
import net.sourceforge.plantuml.preproc.Preprocessor;
import net.sourceforge.plantuml.preproc.ReadLineReader;
import net.sourceforge.plantuml.preproc.UncommentReadLine;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.utils.StartUtils;
2010-11-15 20:35:36 +00:00
final public class BlockUmlBuilder {
private final List<BlockUml> blocks = new ArrayList<BlockUml>();
2011-01-29 15:09:35 +00:00
private final Set<File> usedFiles = new HashSet<File>();
2015-04-07 18:18:37 +00:00
private final UncommentReadLine reader2;
2010-11-15 20:35:36 +00:00
2015-04-07 18:18:37 +00:00
public BlockUmlBuilder(List<String> config, String charset, Defines defines, Reader reader, File newCurrentDir)
throws IOException {
2010-11-15 20:35:36 +00:00
Preprocessor includer = null;
try {
2015-04-07 18:18:37 +00:00
reader2 = new UncommentReadLine(new ReadLineReader(reader));
includer = new Preprocessor(reader2, charset, defines, usedFiles, newCurrentDir);
2010-11-15 20:35:36 +00:00
init(includer, config);
} finally {
if (includer != null) {
includer.close();
}
}
}
private void init(Preprocessor includer, List<String> config) throws IOException {
String s = null;
List<String> current = null;
2015-04-07 18:18:37 +00:00
boolean paused = false;
int startLine = 0;
2010-11-15 20:35:36 +00:00
while ((s = includer.readLine()) != null) {
2011-04-19 16:50:40 +00:00
if (StartUtils.isArobaseStartDiagram(s)) {
2010-11-15 20:35:36 +00:00
current = new ArrayList<String>();
2015-04-07 18:18:37 +00:00
paused = false;
startLine = includer.getLineNumber();
2010-11-15 20:35:36 +00:00
}
2015-04-07 18:18:37 +00:00
if (StartUtils.isArobasePauseDiagram(s)) {
paused = true;
reader2.setPaused(true);
}
if (current != null && paused == false) {
2010-11-15 20:35:36 +00:00
current.add(s);
2015-04-07 18:18:37 +00:00
} else if (paused) {
final String append = StartUtils.getPossibleAppend(s);
if (append != null) {
current.add(append);
}
}
if (StartUtils.isArobaseUnpauseDiagram(s)) {
paused = false;
reader2.setPaused(false);
2010-11-15 20:35:36 +00:00
}
2011-04-19 16:50:40 +00:00
if (StartUtils.isArobaseEndDiagram(s) && current != null) {
2010-11-15 20:35:36 +00:00
current.addAll(1, config);
2015-04-07 18:18:37 +00:00
blocks.add(new BlockUml(current, startLine));
2010-11-15 20:35:36 +00:00
current = null;
2015-04-07 18:18:37 +00:00
reader2.setPaused(false);
2010-11-15 20:35:36 +00:00
}
}
}
public List<BlockUml> getBlockUmls() {
return Collections.unmodifiableList(blocks);
}
2011-01-29 15:09:35 +00:00
public final Set<File> getIncludedFiles() {
return Collections.unmodifiableSet(usedFiles);
}
2010-11-15 20:35:36 +00:00
/*
2015-04-07 18:18:37 +00:00
* private List<String> getStrings(Reader reader) throws IOException { final List<String> result = new
* ArrayList<String>(); Preprocessor includer = null; try { includer = new Preprocessor(reader, defines); String s =
* null; while ((s = includer.readLine()) != null) { result.add(s); } } finally { if (includer != null) {
* includer.close(); } } return Collections.unmodifiableList(result); }
2010-11-15 20:35:36 +00:00
*/
}