package jp.gr.java_conf.daisy.ajax_mutator;

import java.util.HashSet;
import java.util.Set;

import jp.gr.java_conf.daisy.ajax_mutator.detector.EventAttacherDetector;
import jp.gr.java_conf.daisy.ajax_mutator.mutatable.EventAttachment;

import org.mozilla.javascript.ast.AstNode;
import org.mozilla.javascript.ast.FunctionCall;
import org.mozilla.javascript.ast.NodeVisitor;

public class MutateVisitor implements NodeVisitor {
	Set<EventAttacherDetector> eventAttacherDetectors;
	public MutateVisitor(Set<EventAttacherDetector> eventAttacherDetectors) {
		this.eventAttacherDetectors 
			= new HashSet<EventAttacherDetector>(eventAttacherDetectors);
	}
	
	@Override
	public boolean visit(AstNode node) {
		if (node instanceof FunctionCall) {
			return visit((FunctionCall) node);
		}
		return true;
	}
	
	public boolean visit(FunctionCall call) {
		for (EventAttacherDetector detector: eventAttacherDetectors) {
			EventAttachment attachment = detector.detect(call);
			if (attachment != null) {
				System.out.println(attachment);
				return false;
			}
		}
		return true;
	}
}
@@ -42,34 +42,8 @@
 r;%0A%0A
-import java.util.HashSet;%0A
 impo
@@ -60,16 +60,16 @@
 il.Set;%0A
+
 %0Aimport 
@@ -344,16 +344,64 @@
 sitor;%0A%0A
+import com.google.common.collect.ImmutableSet;%0A%0A
 public c
@@ -445,16 +445,39 @@
 itor %7B%0A%09
+private final Immutable
 Set%3CEven
@@ -519,16 +519,18 @@
 ectors;%0A
+%09%0A
 %09public 
@@ -629,49 +629,33 @@
 tors
- 
 %0A%09%09%09= 
-new HashSet%3CEventAttacherDetector%3E
+ImmutableSet.copyOf
 (eve

set eventAttacherDetector immutable