package com.cflint.plugins.core;

import javax.swing.plaf.synth.SynthScrollBarUI;

import ro.fortsoft.pf4j.Extension;
import net.htmlparser.jericho.Element;
import cfml.parsing.cfscript.CFExpression;
import cfml.parsing.cfscript.CFFunctionExpression;
import cfml.parsing.cfscript.script.CFExpressionStatement;
import cfml.parsing.cfscript.script.CFScriptStatement;

import com.cflint.BugInfo;
import com.cflint.BugList;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;

@Extension
public class WriteDumpChecker extends CFLintScannerAdapter {
	final String severity = "INFO";

	
	
	@Override
	public void expression(final CFExpression expression, final Context context,
			final BugList bugs) {
		
		if(expression instanceof CFFunctionExpression){
			final CFFunctionExpression functionExpression = (CFFunctionExpression) expression;
			if(functionExpression.getFunctionName().equalsIgnoreCase("writeDump")){
				final int lineNo = functionExpression.getLine() + context.startLine() - 1;
				writeDump(lineNo, context, bugs);
			}
		}
		
	}

//	@Override
//	public void expression(final CFScriptStatement expression, final Context context, final BugList bugs) {
//		if (expression instanceof CFExpressionStatement) {
//			String code = ((CFExpressionStatement) expression).getExpression().Decompile(0);
//			int lineNo = ((CFExpressionStatement) expression).getLine() + context.startLine() - 1;
//
//			if (code.toLowerCase().contains("writedump(")) {
//				writeDump(lineNo, context, bugs);
//			}
//		}
//	}

//	@Override
//	public void element(final Element element, final Context context, final BugList bugs) {
//		if (element.getName().equals("cfset")) {
//			String content = element.getStartTag().getTagContent().toString();
//			int lineNo = element.getSource().getRow(element.getBegin());
//
//			if (content.toLowerCase().contains("writedump(")) {
//				writeDump(lineNo, context, bugs);
//			}
//		}
//	}

	protected void writeDump(final int lineNo, final Context context, final BugList bugs) {
		bugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("AVOID_USING_WRITEDUMP")
			.setSeverity(severity).setFilename(context.getFilename())
			.setMessage("WriteDump statement at line " + lineNo + ". Avoid using writeDump in production code.")
			.build());
	}
}
@@ -913,18 +913,8 @@
 uals
-IgnoreCase
 (%22wr
@@ -1062,883 +1062,8 @@
 %09%7D%0A%0A
-//%09@Override%0A//%09public void expression(final CFScriptStatement expression, final Context context, final BugList bugs) %7B%0A//%09%09if (expression instanceof CFExpressionStatement) %7B%0A//%09%09%09String code = ((CFExpressionStatement) expression).getExpression().Decompile(0);%0A//%09%09%09int lineNo = ((CFExpressionStatement) expression).getLine() + context.startLine() - 1;%0A//%0A//%09%09%09if (code.toLowerCase().contains(%22writedump(%22)) %7B%0A//%09%09%09%09writeDump(lineNo, context, bugs);%0A//%09%09%09%7D%0A//%09%09%7D%0A//%09%7D%0A%0A//%09@Override%0A//%09public void element(final Element element, final Context context, final BugList bugs) %7B%0A//%09%09if (element.getName().equals(%22cfset%22)) %7B%0A//%09%09%09String content = element.getStartTag().getTagContent().toString();%0A//%09%09%09int lineNo = element.getSource().getRow(element.getBegin());%0A//%0A//%09%09%09if (content.toLowerCase().contains(%22writedump(%22)) %7B%0A//%09%09%09%09writeDump(lineNo, context, bugs);%0A//%09%09%09%7D%0A//%09%09%7D%0A//%09%7D%0A%0A
 %09pro

Clean up code