currentHolder.addLocalVariable(variable);
variableName.setStaticElement(element);
} else {
SimpleIdentifier variableName = node.getName();
TopLevelVariableElementImpl variable;
if (isConst && hasInitializer) {
variable = new ConstTopLevelVariableElementImpl(variableName);
} else {
variable = new TopLevelVariableElementImpl(variableName);
}
element = variable;
currentHolder.addTopLevelVariable(variable);
variableName.setStaticElement(element);
}
element.setConst(isConst);
element.setFinal(isFinal);
if (hasInitializer) {
ElementHolder holder = new ElementHolder();
boolean wasInFieldContext = inFieldContext;
inFieldContext = false;
try {
visit(holder, node.getInitializer());
} finally {
inFieldContext = wasInFieldContext;
}
FunctionElementImpl initializer = new FunctionElementImpl(
node.getInitializer().getBeginToken().getOffset());
initializer.setFunctions(holder.getFunctions());
initializer.setLabels(holder.getLabels());
initializer.setLocalVariables(holder.getLocalVariables());
initializer.setSynthetic(true);
element.setInitializer(initializer);
holder.validate();
}
if (element instanceof PropertyInducingElementImpl) {
PropertyInducingElementImpl variable = (PropertyInducingElementImpl) element;
if (inFieldContext) {
((FieldElementImpl) variable).setStatic(matches(
((FieldDeclaration) node.getParent().getParent()).getStaticKeyword(),
Keyword.STATIC));
}
PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl(variable);
getter.setGetter(true);
currentHolder.addAccessor(getter);
variable.setGetter(getter);
if (!isFinal) {
PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl(variable);
setter.setSetter(true);
ParameterElementImpl parameter = new ParameterElementImpl(
"_" + variable.getName(),
variable.getNameOffset());
parameter.setSynthetic(true);
parameter.setParameterKind(ParameterKind.REQUIRED);
setter.setParameters(new ParameterElement[] {parameter});
currentHolder.addAccessor(setter);
variable.setSetter(setter);
}
}
return null;
}