in v2-migration/src/main/java/software/amazon/awssdk/v2migration/ChangeSdkType.java [384:443]
private Expression updateOuterClassTypes(Expression typeTree, JavaType targetType) {
if (!(typeTree instanceof J.FieldAccess)) {
return typeTree;
}
JavaType.FullyQualified type = (JavaType.FullyQualified) targetType;
if (type.getOwningClass() == null) {
// just a performance shortcut when this isn't an inner class
typeTree.withType(updateType(targetType));
}
Stack<Expression> typeStack = new Stack<>();
typeStack.push(typeTree);
Stack<JavaType.FullyQualified> attrStack = new Stack<>();
attrStack.push(type);
for (Expression t = ((J.FieldAccess) typeTree).getTarget(); ; ) {
typeStack.push(t);
if (t instanceof J.FieldAccess) {
if (Character.isUpperCase(((J.FieldAccess) t).getSimpleName().charAt(0))) {
if (attrStack.peek().getOwningClass() != null) {
attrStack.push(attrStack.peek().getOwningClass());
}
}
t = ((J.FieldAccess) t).getTarget();
} else if (t instanceof J.Identifier) {
if (Character.isUpperCase(((J.Identifier) t).getSimpleName().charAt(0))) {
if (attrStack.peek().getOwningClass() != null) {
attrStack.push(attrStack.peek().getOwningClass());
}
}
break;
}
}
Expression attributed = null;
for (Expression e = typeStack.pop(); ; e = typeStack.pop()) {
if (e instanceof J.Identifier) {
if (attrStack.size() == typeStack.size() + 1) {
attributed = ((J.Identifier) e).withType(attrStack.pop());
} else {
attributed = e;
}
} else if (e instanceof J.FieldAccess) {
if (attrStack.size() == typeStack.size() + 1) {
attributed = ((J.FieldAccess) e).withTarget(attributed)
.withType(attrStack.pop());
} else {
attributed = ((J.FieldAccess) e).withTarget(attributed);
}
}
if (typeStack.isEmpty()) {
break;
}
}
assert attributed != null;
return attributed;
}