JSymbol implements Symbol { @Override public final Symbol owner() { if (owner == null) { owner = convertOwner(); } return owner; } JSymbol(JSema sema, IBinding binding); @Override final boolean equals(Object obj); @Override final int hashCode(); @Override final String name(); @Override final Symbol owner(); @Override final Type type(); @Override final boolean isVariableSymbol(); @Override final boolean isTypeSymbol(); @Override final boolean isMethodSymbol(); @Override final boolean isPackageSymbol(); @Override final boolean isStatic(); @Override final boolean isFinal(); @Override final boolean isEnum(); @Override final boolean isInterface(); @Override final boolean isAbstract(); @Override final boolean isPublic(); @Override final boolean isPrivate(); @Override final boolean isProtected(); @Override final boolean isPackageVisibility(); @Override final boolean isDeprecated(); @Override final boolean isVolatile(); @Override final boolean isUnknown(); @Override final SymbolMetadata metadata(); @Nullable @Override final TypeSymbol enclosingClass(); @Override final List<IdentifierTree> usages(); @Nullable @Override Tree declaration();  }
@Test void owner() { JavaTree.CompilationUnitTreeImpl cu = test("class C1 { int f; class C2 { } void m(int p) { class C3 { } } }"); ClassTreeImpl c1 = (ClassTreeImpl) cu.types().get(0); VariableTreeImpl f = (VariableTreeImpl) c1.members().get(0); ClassTreeImpl c2 = (ClassTreeImpl) c1.members().get(1); MethodTreeImpl m = (MethodTreeImpl) c1.members().get(2); VariableTreeImpl p = (VariableTreeImpl) m.parameters().get(0); ClassTreeImpl c3 = (ClassTreeImpl) m.block().body().get(0); assertThat(cu.sema.typeSymbol(c1.typeBinding)) .as("of top-level class") .hasOwner(cu.sema.packageSymbol(c1.typeBinding.getPackage())); assertThat(cu.sema.typeSymbol(c2.typeBinding)) .as("of nested class") .hasOwner(cu.sema.typeSymbol(c1.typeBinding)); assertThat(cu.sema.typeSymbol(c3.typeBinding)) .as("of local class") .hasOwner(cu.sema.methodSymbol(m.methodBinding)); assertThat(cu.sema.methodSymbol(m.methodBinding)) .as("of method") .hasOwner(cu.sema.typeSymbol(c1.typeBinding)); assertThat(cu.sema.variableSymbol(f.variableBinding)) .as("of field") .hasOwner(cu.sema.typeSymbol(c1.typeBinding)); assertThat(cu.sema.variableSymbol(p.variableBinding)) .as("of method parameter") .hasOwner(cu.sema.methodSymbol(m.methodBinding)); }