// For everything else generate a getter/setter method
AttributeDefinitionBuilder builder = AttributeDefinitionBuilder
.wrapped(this, attrClassName, null, attrName, declarationModel, declarationModel.isToplevel())
.is(Flags.PUBLIC, declarationModel.isShared());
final JCExpression initialValue;
final HasErrorException expressionError;
if (expression != null) {
expressionError = errors().getFirstExpressionErrorAndMarkBrokenness(expression.getExpression());
if (expressionError != null) {
initialValue = make().Erroneous();
} else {
initialValue = transformValueInit(
declarationModel, attrName, expression);
}
} else {
expressionError = null;
initialValue = transformValueInit(
declarationModel, attrName, expression);
}
// For captured local variable Values, use a VariableBox
if (Decl.isBoxedVariable(declarationModel)) {
if (expressionError != null) {
return List.<JCTree>of(this.makeThrowUnresolvedCompilationError(expressionError));
} else {
return List.<JCTree>of(makeVariableBoxDecl(
initialValue, declarationModel));
}
}
// For late-bound getters we only generate a declaration
if (block == null && expression == null && !Decl.isToplevel(declarationModel)) {
JCExpression typeExpr = makeJavaType(getGetterInterfaceType(declarationModel));
JCTree.JCVariableDecl var = makeVar(attrClassName, typeExpr, null);
return List.<JCTree>of(var);
}
// Set the local declarations annotation
if(decl != null){
List<JCAnnotation> scopeAnnotations;
if(Decl.isToplevel(declarationModel) && setterDecl != null){
scopeAnnotations = makeAtLocalDeclarations(decl, setterDecl);
}else{
scopeAnnotations = makeAtLocalDeclarations(decl);
}
builder.classAnnotations(scopeAnnotations);
}
// Remember the setter class if we generate a getter
if(Decl.isGetter(declarationModel)
&& declarationModel.isVariable()
&& Decl.isLocal(declarationModel)){
// we must have a setter class
Setter setter = ((Value)declarationModel).getSetter();
if(setter != null){
String setterClassName = Naming.getAttrClassName(setter, 0);
JCExpression setterClassNameExpr = naming.makeUnquotedIdent(setterClassName);
builder.setterClass(makeSelect(setterClassNameExpr, "class"));
}
}
if (declarationModel instanceof Setter
|| (declarationModel instanceof MethodOrValue
&& ((MethodOrValue)declarationModel).isParameter())) {
// For local setters
JCBlock setterBlock = makeSetterBlock(declarationModel, block, expression);
builder.setterBlock(setterBlock);
builder.skipGetter();
if(Decl.isLocal(decl)){
// we need to find back the Setter model for local setters, because
// in transformAttribute(Tree.TypedDeclaration decl, Tree.AttributeSetterDefinition setterDecl)
// we turn the declaration model from the Setter to its single parameter
Setter setter = (Setter) declarationModel.getContainer();
String getterClassName = Naming.getAttrClassName(setter.getGetter(), 0);
JCExpression getterClassNameExpr = naming.makeUnquotedIdent(getterClassName);
builder.isSetter(makeSelect(getterClassNameExpr, "class"));
}
} else {
if (Decl.isValue(declarationModel)) {
// For local and toplevel value attributes
if (!declarationModel.isVariable() && !declarationModel.isLate()) {
builder.immutable();
}
} else {
// For local and toplevel getters
JCBlock getterBlock = makeGetterBlock(declarationModel, block, expression);
builder.getterBlock(getterBlock);
if (Decl.isLocal(declarationModel)) {
// For local getters
builder.immutable();
} else {
// For toplevel getters
if (setterDecl != null) {
JCBlock setterBlock = makeSetterBlock(setterDecl.getDeclarationModel(),
setterDecl.getBlock(), setterDecl.getSpecifierExpression());
builder.setterBlock(setterBlock);
builder.userAnnotationsSetter(expressionGen().transform(setterDecl.getAnnotationList()));
} else {
builder.immutable();
}
}
}
}
builder.userAnnotations(expressionGen().transform(annotations));
if (Decl.isLocal(declarationModel)) {
if (expressionError != null) {
return List.<JCTree>of(this.makeThrowUnresolvedCompilationError(expressionError));
}
builder.classAnnotations(makeAtLocalDeclaration(declarationModel.getQualifier(), false));
if(initialValue != null)
builder.valueConstructor();
JCExpression typeExpr;
if (declarationModel instanceof Setter
|| (declarationModel instanceof MethodOrValue
&& ((MethodOrValue)declarationModel).isParameter())) {
typeExpr = makeQuotedIdent(attrClassName);
} else {