.NAME Explicit import

.DESCRIPTION

Always use explicit import such as:
	import java.io.basic;

never use generic import such as:
	import java.io.*;

.SEVERITY Advisory

.COMMAND tcl

.CODE

proc compute {standardName tree} {
	
	set formalism [::logiscope::treeFormalism $tree]

	set opList {}
	::logiscope::forobj op $formalism formalismOperator {
		lappend opList [::logiscope::opName $op]
	}
	# find the operators in the tree that are generic_name operators
	# generic name are forbidden and can be present only in an import
	filterTree $tree [list opNameIs generic_name]
}

# opNameIs adds a rule violation if the operator of the tree is opName
proc opNameIs {opName tree} {
	set op [::logiscope::treeOperator $tree]
	if {[string equal [::logiscope::opName $op] $opName]} {
		# add a violation on the parent (import_stmt) instead of the generic_stmt itself.
		::logiscope::addViolation [::logiscope::treeParent $tree]
		return 0
	}
	return 1
}

# filterTree applies callback to tree, and recurses on tree's sons
proc filterTree {tree callback} {
	if {[eval $callback [list $tree]]} {
		::logiscope::forobj son $tree treeChild {
			filterTree $son $callback
    	}
	}
}

