in src/languages/java.ts [558:598]
public override propertyAccessExpression(
node: ts.PropertyAccessExpression,
renderer: JavaRenderer,
submoduleRef: SubmoduleReference | undefined,
): OTree {
const rightHandSide = renderer.convert(node.name);
// If a submodule access, then just render the name, we emitted a * import of the expression segment already.
if (submoduleRef != null) {
return rightHandSide;
}
let parts: Array<OTree | string | undefined>;
const leftHandSide = renderer.textOf(node.expression);
// Suppress the LHS of the dot operator if it matches an alias for a module import.
if (this.dropPropertyAccesses.has(leftHandSide) || renderer.currentContext.discardPropertyAccess) {
parts = [rightHandSide];
} else if (leftHandSide === 'this') {
// for 'this', assume this is a field, and access it directly
parts = ['this', '.', rightHandSide];
} else {
let convertToGetter = renderer.currentContext.convertPropertyToGetter !== false;
// See if we're not accessing an enum member or public static readonly property (const).
if (isEnumAccess(renderer.typeChecker, node)) {
convertToGetter = false;
}
if (isStaticReadonlyAccess(renderer.typeChecker, node)) {
convertToGetter = false;
}
// add a 'get' prefix to the property name, and change the access to a method call, if required
const renderedRightHandSide = convertToGetter ? `get${capitalize(node.name.text)}()` : rightHandSide;
// strip any trailing ! from the left-hand side, as they're not meaningful in Java
parts = [renderer.convert(node.expression), '.', renderedRightHandSide];
}
return new OTree(parts);
}