Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / algorithm / CodeGenerator.java
yoichiro on 4 Apr 2020 1 KB ひな形を整えた
package algorithm;

import java.util.ArrayList;

import models.*;
import models.dataConstraintModel.IdentifierTemplate;
import models.dataFlowModel.*;

public class CodeGenerator {
	static public ArrayList<String> doGenerate(ResourceDependencyGraph graph) {
		ArrayList<String> codes = new ArrayList<>();
		codes.add("public class Main {");
		for (Node n : graph.getNodes()) {
			ResourceNode resource = (ResourceNode) n;
			String str = "\t" + "private "
					+ resource.getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase()
					+ resource.getIdentifierTemplate().getResourceName().substring(1) + " "
					+ resource.getIdentifierTemplate().getResourceName() + " = new "
					+ resource.getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase()
					+ resource.getIdentifierTemplate().getResourceName().substring(1) + "(";
			if (((StoreAttribute) resource.getAttribute()).isStored()) {
				for (Node pn : resource.getSuccessors()) {
					str += ((ResourceNode) pn).getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase() + ((ResourceNode) pn).getIdentifierTemplate().getResourceName().substring(1) + ",";
				}
			}
			str = str + ");";
			codes.add(str);
		}
		codes.add("}");
		for (Node n : graph.getNodes()) {
			ResourceNode resource = (ResourceNode) n;
			codes.add("public class " + resource.getIdentifierTemplate().getResourceName() + " {");
			codes.add("}");
		}
		return codes;
	}
}