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

97 lines
3.0 KiB
Java
Raw Normal View History

2018-09-23 12:15:14 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2018-09-23 12:15:14 +00:00
*
* Project Info: http://plantuml.com
2019-03-29 22:14:07 +00:00
*
2018-09-23 12:15:14 +00:00
* If you like this project or if you find it useful, you can support us at:
2019-03-29 22:14:07 +00:00
*
2018-09-23 12:15:14 +00:00
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
2019-03-29 22:14:07 +00:00
*
2018-09-23 12:15:14 +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
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* 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
*
*/
2019-03-29 22:14:07 +00:00
package net.sourceforge.plantuml.tim;
2018-09-23 12:15:14 +00:00
import java.nio.charset.Charset;
2019-03-29 22:14:07 +00:00
import java.util.List;
2020-03-18 10:50:02 +00:00
import java.util.Set;
2018-09-23 12:15:14 +00:00
2019-06-26 19:24:49 +00:00
import net.sourceforge.plantuml.DefinitionsContainer;
2019-03-29 22:14:07 +00:00
import net.sourceforge.plantuml.StringLocated;
import net.sourceforge.plantuml.log.Logger;
2019-04-21 20:40:01 +00:00
import net.sourceforge.plantuml.preproc.Defines;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.preproc.FileWithSuffix;
2019-03-29 22:14:07 +00:00
import net.sourceforge.plantuml.preproc.ImportedFiles;
2018-09-23 12:15:14 +00:00
2019-03-29 22:14:07 +00:00
public class TimLoader {
2018-09-23 12:15:14 +00:00
2019-03-29 22:14:07 +00:00
private final TContext context;
private final TMemory global = new TMemoryGlobal();
2019-05-24 19:59:31 +00:00
private boolean preprocessorError;
2019-08-26 17:07:21 +00:00
private List<StringLocated> resultList;
2018-09-23 12:15:14 +00:00
public TimLoader(ImportedFiles importedFiles, Defines defines, Charset charset,
2020-01-12 22:13:17 +00:00
DefinitionsContainer definitionsContainer) {
2019-06-26 19:24:49 +00:00
this.context = new TContext(importedFiles, defines, charset, definitionsContainer);
2020-01-12 22:13:17 +00:00
try {
defines.copyTo(global);
} catch (EaterException e) {
Logger.error(e);
2020-01-12 22:13:17 +00:00
}
2018-09-23 12:15:14 +00:00
}
2020-03-18 10:50:02 +00:00
public Set<FileWithSuffix> load(List<StringLocated> list) {
2020-03-03 22:29:34 +00:00
// CodeIteratorImpl.indentNow(list);
try {
2020-04-19 16:04:39 +00:00
context.executeLines(global, list, null, false);
2020-03-03 22:29:34 +00:00
} catch (EaterExceptionLocated e) {
context.getResultList().add(e.getLocation().withErrorPreprocessor(e.getMessage()));
changeLastLine(context.getDebug(), e.getMessage());
this.preprocessorError = true;
2018-09-23 12:15:14 +00:00
}
2019-08-26 17:07:21 +00:00
this.resultList = context.getResultList();
2020-03-18 10:50:02 +00:00
return context.getFilesUsedCurrent();
2019-05-24 19:59:31 +00:00
}
private void changeLastLine(List<StringLocated> list, String message) {
final int num = list.size() - 1;
final StringLocated last = list.get(num);
list.set(num, last.withErrorPreprocessor(message));
}
2019-08-26 17:07:21 +00:00
public final List<StringLocated> getResultList() {
return resultList;
2019-05-24 19:59:31 +00:00
}
public final List<StringLocated> getDebug() {
return context.getDebug();
}
public final boolean isPreprocessorError() {
return preprocessorError;
2018-09-23 12:15:14 +00:00
}
}