JSymbol implements Symbol { @Override public final Type type() { switch (binding.getKind()) { case IBinding.PACKAGE: return null; case IBinding.TYPE: return sema.type((ITypeBinding) binding); case IBinding.VARIABLE: ITypeBinding variableType = ((IVariableBinding) binding).getType(); return variableType != null ? sema.type(variableType) : Symbols.unknownType; case IBinding.METHOD: return Symbols.unknownType; default: throw new IllegalStateException(unexpectedBinding()); } } 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 type() { JavaTree.CompilationUnitTreeImpl cu = test("class C { int f; void m() {} }"); ClassTreeImpl c = (ClassTreeImpl) cu.types().get(0); VariableTreeImpl field = (VariableTreeImpl) c.members().get(0); MethodTreeImpl method = (MethodTreeImpl) c.members().get(1); assertThat(cu.sema.typeSymbol(c.typeBinding).owner()) .isOfSameTypeAs(c.symbol().owner()) .isHavingNullType(); assertThat(cu.sema.typeSymbol(c.typeBinding)) .isOfType(cu.sema.type(c.typeBinding)); assertThat(cu.sema.variableSymbol(field.variableBinding)) .isOfType(cu.sema.type(field.variableBinding.getType())); assertThat(cu.sema.methodSymbol(method.methodBinding)).isOfUnknownType(); }
@Test void var_type_as_local_variable() { JavaTree.CompilationUnitTreeImpl cu = test("class C {void m() { var v = new java.util.ArrayList<String>(); }}"); ClassTreeImpl c = (ClassTreeImpl) cu.types().get(0); MethodTreeImpl method = (MethodTreeImpl) c.members().get(0); VariableTreeImpl variable = (VariableTreeImpl) method.block().body().get(0); assertThat(variable.type().symbolType().symbol()) .isOfType("java.util.ArrayList"); assertThat(variable.symbol()) .isOfType("java.util.ArrayList"); assertThat(cu.sema.variableSymbol(variable.variableBinding)) .isOfType(cu.sema.type(variable.variableBinding.getType())); }