package gumtree.spoon.builder;

import com.github.gumtreediff.tree.ITree;
import spoon.reflect.declaration.CtModifiable;
import spoon.reflect.declaration.CtVariable;
import spoon.reflect.declaration.ModifierKind;
import spoon.reflect.visitor.CtInheritanceScanner;

/** responsible to add additional nodes
 * only overrides scan* to add new nodes */
class NodeCreator extends CtInheritanceScanner {
	private final TreeScanner builder;

	NodeCreator(TreeScanner builder) {
		this.builder = builder;
	}

	@Override
	public void scanCtModifiable(CtModifiable m) {
		ITree modifiers = builder.createNode("Modifiers", "");
		modifiers.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, m);
		for (ModifierKind kind : m.getModifiers()) {
			ITree modifier = builder.createNode("Modifier", kind.toString());
			modifier.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, m);
			modifiers.addChild(modifier);
		}
		builder.addSiblingNode(modifiers);

	}

	@Override
	public <T> void scanCtVariable(CtVariable<T> e) {
		ITree variableType = builder.createNode("VARIABLE_TYPE", e.getType().getQualifiedName());
		variableType.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, e.getType());
		builder.addSiblingNode(variableType);
	}
}

@@ -67,16 +67,59 @@
 .ITree;%0A
+import spoon.reflect.declaration.CtMethod;%0A
 import s
@@ -1243,11 +1243,338 @@
 ype);%0A%09%7D
+%0A%0A%09@Override%0A%09public %3CT%3E void visitCtMethod(CtMethod%3CT%3E e) %7B%0A%09%09// add the return type of the method%0A%09%09ITree returnType = builder.createNode(%22RETURN_TYPE%22, e.getType().getQualifiedName());%0A%09%09returnType.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, e.getType());%0A%09%09builder.addSiblingNode(returnType);%0A%09%09super.visitCtMethod(e);%0A%09%7D
 %0A%7D%0A

add the return type in the gumtree tree (#32)