1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-02 00:20:49 +00:00
plantuml/src/net/sourceforge/plantuml/BlockUmlBuilder.java

151 lines
4.6 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2016-01-09 12:15:40 +00:00
* (C) Copyright 2009-2017, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2010-11-15 20:35:36 +00:00
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
2010-11-15 20:35:36 +00:00
* 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.
*
*
* Original Author: Arnaud Roques
*
*
*/
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;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.preproc.FileWithSuffix;
2010-11-15 20:35:36 +00:00
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
2017-04-05 17:37:42 +00:00
public final class BlockUmlBuilder implements DefinitionsContainer {
2010-11-15 20:35:36 +00:00
private final List<BlockUml> blocks = new ArrayList<BlockUml>();
2015-09-28 20:42:17 +00:00
private Set<FileWithSuffix> usedFiles = new HashSet<FileWithSuffix>();
2015-04-07 18:18:37 +00:00
private final UncommentReadLine reader2;
2017-04-05 17:37:42 +00:00
private final Defines defines;
2010-11-15 20:35:36 +00:00
2015-06-20 10:54:49 +00:00
public BlockUmlBuilder(List<String> config, String charset, Defines defines, Reader reader, File newCurrentDir,
String desc) throws IOException {
2010-11-15 20:35:36 +00:00
Preprocessor includer = null;
2017-04-05 17:37:42 +00:00
this.defines = defines;
2010-11-15 20:35:36 +00:00
try {
2018-06-12 20:50:45 +00:00
reader2 = new UncommentReadLine(ReadLineReader.create(reader, desc));
2017-11-20 16:10:36 +00:00
includer = new Preprocessor(config, reader2, charset, defines, newCurrentDir, this);
init(includer);
2010-11-15 20:35:36 +00:00
} finally {
if (includer != null) {
includer.close();
2015-06-07 10:23:10 +00:00
usedFiles = includer.getFilesUsed();
2010-11-15 20:35:36 +00:00
}
}
}
2015-09-28 20:42:17 +00:00
public BlockUmlBuilder(List<String> config, String charset, Defines defines, Reader reader) throws IOException {
2015-06-20 10:54:49 +00:00
this(config, charset, defines, reader, null, null);
}
2017-11-20 16:10:36 +00:00
private void init(Preprocessor includer) throws IOException {
2015-06-20 10:54:49 +00:00
CharSequence2 s = null;
List<CharSequence2> current2 = 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)) {
2015-06-20 10:54:49 +00:00
current2 = new ArrayList<CharSequence2>();
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);
}
2018-01-28 22:08:15 +00:00
if (StartUtils.isExit(s)) {
paused = true;
reader2.setPaused(true);
}
2015-06-20 10:54:49 +00:00
if (current2 != null && paused == false) {
current2.add(s);
2015-04-07 18:18:37 +00:00
} else if (paused) {
2015-06-20 10:54:49 +00:00
final CharSequence2 append = StartUtils.getPossibleAppend(s);
2015-04-07 18:18:37 +00:00
if (append != null) {
2015-06-20 10:54:49 +00:00
current2.add(append);
2015-04-07 18:18:37 +00:00
}
}
if (StartUtils.isArobaseUnpauseDiagram(s)) {
paused = false;
reader2.setPaused(false);
2010-11-15 20:35:36 +00:00
}
2015-06-20 10:54:49 +00:00
if (StartUtils.isArobaseEndDiagram(s) && current2 != null) {
2018-01-28 22:08:15 +00:00
if (paused) {
current2.add(s);
}
2017-11-20 16:10:36 +00:00
blocks.add(new BlockUml(current2, startLine/* - config.size() */, defines.cloneMe()));
2015-06-20 10:54:49 +00:00
current2 = null;
2015-04-07 18:18:37 +00:00
reader2.setPaused(false);
2010-11-15 20:35:36 +00:00
}
}
}
2017-11-20 16:10:36 +00:00
// private Collection<CharSequence2> convert(List<String> config, LineLocation location) {
// final List<CharSequence2> result = new ArrayList<CharSequence2>();
// for (String s : config) {
// result.add(new CharSequence2Impl(s, location));
// }
// return result;
// }
2015-06-20 10:54:49 +00:00
2010-11-15 20:35:36 +00:00
public List<BlockUml> getBlockUmls() {
return Collections.unmodifiableList(blocks);
}
2015-09-28 20:42:17 +00:00
public final Set<FileWithSuffix> getIncludedFiles() {
2011-01-29 15:09:35 +00:00
return Collections.unmodifiableSet(usedFiles);
}
2017-04-05 17:37:42 +00:00
public List<? extends CharSequence> getDefinition(String name) {
for (BlockUml block : blocks) {
if (block.isStartDef(name)) {
this.defines.importFrom(block.getLocalDefines());
2018-07-27 21:56:46 +00:00
return block.getDefinition(false);
2017-04-05 17:37:42 +00:00
}
}
return Collections.emptyList();
}
2010-11-15 20:35:36 +00:00
}