SrcSymbolResolver implements SymbolResolver { @Override public Optional<TypeUsage> findTypeUsageIn(String typeName, Node context, SymbolResolver resolver) { if (typeDefinitions.containsKey(typeName)) { return Optional.of(new ReferenceTypeUsage(typeDefinitions.get(typeName))); } else { return Optional.empty(); } } SrcSymbolResolver(List<TurinFile> turinFiles); @Override SymbolResolver getParent(); @Override void setParent(SymbolResolver parent); @Override Optional<PropertyDefinition> findDefinition(PropertyReference propertyReference); @Override Optional<TypeDefinition> findTypeDefinitionIn(String typeName, Node context, SymbolResolver resolver); @Override Optional<TypeUsage> findTypeUsageIn(String typeName, Node context, SymbolResolver resolver); @Override Optional<JvmMethodDefinition> findJvmDefinition(FunctionCall functionCall); @Override Optional<Symbol> findSymbol(String name, Node context); @Override boolean existPackage(String packageName); @Override Optional<ContextDefinition> findContextSymbol(String contextName, Node context);  }
@Test public void findTypeUsageInPositiveCase() throws IOException { TurinFile turinFile = new Parser().parse(this.getClass().getResourceAsStream("/basicManga.to")); SrcSymbolResolver srcSymbolResolver = new SrcSymbolResolver(ImmutableList.of(turinFile)); SymbolResolver symbolResolver = new InFileSymbolResolver(JdkTypeResolver.getInstance()); Optional<TypeUsage> typeDefinition = srcSymbolResolver.findTypeUsageIn("manga.MangaCharacter", NoContext.getInstance(), symbolResolver); assertEquals(true, typeDefinition.isPresent()); assertEquals(true, typeDefinition.get().isReferenceTypeUsage()); assertEquals("manga.MangaCharacter", typeDefinition.get().asReferenceTypeUsage().getQualifiedName()); }
@Test public void findTypeUsageInNegativeCase() throws IOException { TurinFile turinFile = new Parser().parse(this.getClass().getResourceAsStream("/basicManga.to")); SrcSymbolResolver srcSymbolResolver = new SrcSymbolResolver(ImmutableList.of(turinFile)); SymbolResolver symbolResolver = new InFileSymbolResolver(JdkTypeResolver.getInstance()); Optional<TypeUsage> typeDefinition = srcSymbolResolver.findTypeUsageIn("not_manga.MangaCharacter", NoContext.getInstance(), symbolResolver); assertEquals(false, typeDefinition.isPresent()); }