SelfSymbolImpl extends SymbolImpl { @Override public void removeUsages() { super.removeUsages(); classScope.instanceAttributesByName.values().forEach(SymbolImpl::removeUsages); } SelfSymbolImpl(String name, Scope classScope); @Override void removeUsages();  }
@Test public void removeUsages() { FileInput fileInput = parse( "class A:", " def foo(self):", " self.foo = 42" ); FunctionDef method = PythonTestUtils.getLastDescendant(fileInput, tree -> tree.is(Tree.Kind.FUNCDEF)); Parameter selfParameterTree = method.parameters().nonTuple().get(0); Symbol selfSymbol = selfParameterTree.name().symbol(); ((SymbolImpl) selfSymbol).removeUsages(); assertThat(selfSymbol.usages()).isEmpty(); ClassDef classDef = PythonTestUtils.getLastDescendant(fileInput, tree -> tree.is(Tree.Kind.CLASSDEF)); assertThat(classDef.instanceFields()).isNotEmpty(); assertThat(classDef.instanceFields()).allMatch(symbol -> symbol.usages().isEmpty()); }