Commit 8cef6ae2 authored by baueko's avatar baueko
Browse files

added treeVariables to codeBlock, changed toString method

parent 6391d95b
......@@ -24,8 +24,10 @@ public class JavaDeclarationsTreeElement {
return children;
}
public int childrenLength(){return children.size();}
public int childrenLength() {
return children.size();
}
public JavaDeclarationsTreeElement getParent() {
return parent;
}
......@@ -67,7 +69,7 @@ public class JavaDeclarationsTreeElement {
// TODO Fix Output
@Override
public String toString() {
return "\nvars: " + variables + "\nchilds: " + children + "\nendPos:" + end;
return "vars:" + variables + " childs:" + children + " endPos:[" + end.getLine() + "," + end.getColumn() + "]";
}
}
\ No newline at end of file
......@@ -23,6 +23,12 @@ public abstract class CodeBlock extends AbstractNode {
private String blob;
protected XMLElement javaTree;
private BlockType bt;
private JavaDeclarationsTreeElement variableDeclarations;
private static JavaDeclarationsTreeElement globalParserVariableDeclarations;
public JavaDeclarationsTreeElement getVariableDeclarations() {
return variableDeclarations;
}
public int getDebugId() {
return debugId;
......@@ -44,9 +50,11 @@ public abstract class CodeBlock extends AbstractNode {
// this.blob = " public class Parser{" + blob + "}";
try {
this.javaTree = JavaCompiler.parseJava(this.blob, this);
this.variableDeclarations = createVariableDeclarationList(javaTree);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public BlockType getBlockType() {
......@@ -55,12 +63,18 @@ public abstract class CodeBlock extends AbstractNode {
@Override
protected void putDescription(StringBuilder builder) {
builder.append(javaTree);
// builder.append(javaTree);
builder.append(variableDeclarations);
}
protected static JavaDeclarationsTreeElement createVariableDeclarationList(XMLElement elem) {
XMLElementTreeTransform treeTransform = new XMLElementTreeTransform(elem.right());
SyntaxTreeDFS.dfs(elem, treeTransform);
if (elem.getTagname().equals("Parser")) {
globalParserVariableDeclarations = treeTransform.getTreeTop();
// TODO kill global childs, copy!
}
// System.out.println("GLOBAL: " + globalParserVariableDeclarations);
return treeTransform.getTreeTop();
}
......@@ -84,44 +98,40 @@ public abstract class CodeBlock extends AbstractNode {
registerPreVisit("Block", (arg0, arg1) -> {
// neues Element hinzufügen und absteigen
Location l = arg1.get(arg1.size() - 1).right();
Location l;
if (arg1.size() > 0)
l = arg1.get(arg1.size() - 1).right();
else
l = arg0.right();
JavaDeclarationsTreeElement t = new JavaDeclarationsTreeElement(l, tree);
tree.addChild(t);
tree = t;
});
registerPostVisit("Block", (arg0, arg1) -> {
if (tree.getVariables()==null)
{
JavaDeclarationsTreeElement parent= tree.getParent();
if (tree.getVariables() == null) {
JavaDeclarationsTreeElement parent = tree.getParent();
int x = parent.childrenLength();
if(!(tree.getChildren()==null))
{
for (int i=0; i<tree.childrenLength(); i++)
{
if (!(tree.getChildren() == null)) {
for (int i = 0; i < tree.childrenLength(); i++) {
parent.addChild(tree.getChildren().get(i));
tree.getChildren().get(i).setParent(parent);
for (int j=0; j<x; j++)
{
if (parent.getChildren().get(j).equals(tree))
{
parent.getChildren().remove(j);
}
for (int j = 0; j < x; j++) {
if (parent.getChildren().get(j).equals(tree)) {
parent.getChildren().remove(j);
}
}
}
}
for (int i=0; i<x; i++)
{
List<JavaDeclarationsTreeElement> parentChildren=parent.getChildren();
if (parentChildren.get(i).equals(tree))
{
parentChildren.remove(i);
}
for (int i = 0; i < x; i++) {
List<JavaDeclarationsTreeElement> parentChildren = parent.getChildren();
if (parentChildren.get(i).equals(tree)) {
parentChildren.remove(i);
}
}
}
// TODO fix empty trees
// baum zurücksetzen und null-Bäume löschen
// wenn selber null und Kinder null/keine Kinder
......@@ -130,7 +140,7 @@ public abstract class CodeBlock extends AbstractNode {
// Im Children von Parents eigene Kinder eintragen und umgedreht
// aus Children von Parent löschen
// (Wenn selber nicht null -> nix tun)
tree = tree.getParent();
});
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment