BrightSide Workbench Full Report + Source Code
AbstractMacroProcessor.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.parser.processor;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.turro.elephant.impl.util.FileUtil;
26 import org.turro.elephant.impl.util.Files;
27 import org.turro.marker.ElephantMarker;
28 import org.turro.parser.Macro;
29 import org.turro.parser.MacroMap;
30 
35 public abstract class AbstractMacroProcessor implements IMacroProcessor {
36 
37  protected MacroMap macros = new MacroMap();
38 
40  initParser();
41  }
42 
43  public MacroMap getMacros() {
44  return macros;
45  }
46 
47  @Override
48  public Macro getMacro(String name) {
49  return macros.get(name);
50  }
51 
52  @Override
53  public void process(MacroProcessorContext context) {
54  doProcess(context);
55  }
56 
57  public abstract String getName();
58  protected abstract void doProcess(MacroProcessorContext context);
59  protected abstract void explainMacros(MacroMap macros);
60 
61  protected void prepareProperties(ElephantMarker marker, String properties) {
62  try {
63  File file = Files.file(marker.getConstructor(), properties + ".properties");
64  if(file.exists()) {
65  marker.put("props", FileUtil.getOrderedProperties(file));
66  }
67  } catch (IOException ex) {
68  Logger.getLogger(AbstractMacroProcessor.class.getName()).log(Level.SEVERE, null, ex);
69  }
70  }
71 
72  private void initParser() {
74  }
75 
76 }
static Properties getOrderedProperties(File file)
Definition: FileUtil.java:180
static File file(IConstructor constructor, String file)
Definition: Files.java:71
Object put(Object key, Object value)
void prepareProperties(ElephantMarker marker, String properties)
abstract void explainMacros(MacroMap macros)
abstract void doProcess(MacroProcessorContext context)