/**
* Check a variable declaration.
*/
public void checkVariableDeclaration(IASNode iNode)
{
VariableNode var = (VariableNode)iNode;
ModifiersSet modifiersSet = var.getModifiers();
boolean isInFunction = SemanticUtils.isInFunction(iNode);
if (isInFunction)
{
checkForNamespaceInFunction(var, currentScope);
}
// Variable decls inside methods can't have attributes other than namespaces.
if ( isInFunction && modifiersSet != null)
{
IASNode site = var.getNameExpressionNode();
for ( ASModifier modifier : modifiersSet.getAllModifiers() )
{
if( modifier == ASModifier.NATIVE )
{
currentScope.addProblem(new NativeVariableProblem(site));
}
else if (modifier == ASModifier.DYNAMIC )
{
currentScope.addProblem(new DynamicNotOnClassProblem(site));
}
else if( modifier == ASModifier.FINAL )
{
currentScope.addProblem(new FinalOutsideClassProblem(site));
}
else if( modifier == ASModifier.OVERRIDE )
{
currentScope.addProblem(new InvalidOverrideProblem(site));
}
else if( modifier == ASModifier.VIRTUAL )
{
currentScope.addProblem(new VirtualOutsideClassProblem(site));
}
else if( modifier == ASModifier.STATIC )
{
currentScope.addProblem(new StaticOutsideClassProblem(site));
}
}
}
// Check for ambiguity.
IDefinition def = utils.getDefinition(var);
checkVariableForConflictingDefinitions(iNode, (VariableDefinition)def);
checkNamespaceOfDefinition(var, def, project);
/////////////////////////////////////
// Check for a type on the variable declaration
String type = var.getTypeName();
if (type.isEmpty()) // empty string means no declaration at all (not *)
{
// don't check things that didn't come from source. They tend to give false negatives
if (var.getStart() != var.getEnd())
{
// get a node that has the best display location for problem
IASNode location = var;
IExpressionNode nameExpression = var.getNameExpressionNode();
if (nameExpression != null)
location = nameExpression;
this.currentScope.addProblem( new VariableHasNoTypeDeclarationProblem(location, var.getShortName()));
}
}
// check if thise is an assignment in this declaration.
// If so, do checks on that
final ExpressionNodeBase rightNode = var.getAssignedValueNode();
if( var.isConst() && rightNode == null )
{
addProblem(new ConstNotInitializedProblem(var, var.getName()));
}
// if there is an initializer, check that the value is reasonable
if (rightNode != null)
{