SrcSymbolResolver implements SymbolResolver { @Override public Optional<PropertyDefinition> findDefinition(PropertyReference propertyReference) { String name = propertyReference.contextName() + "." + propertyReference.getName(); if (propertyDefinitions.containsKey(name)) { return Optional.of(propertyDefinitions.get(name)); } 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 findDefinitionPositiveCase() throws IOException { TurinFile turinFile = new Parser().parse(this.getClass().getResourceAsStream("/basicManga.to")); SrcSymbolResolver srcSymbolResolver = new SrcSymbolResolver(ImmutableList.of(turinFile)); PropertyReference propertyReference = createMock(PropertyReference.class); EasyMock.expect(propertyReference.contextName()).andReturn("manga"); EasyMock.expect(propertyReference.getName()).andReturn("name"); replayAll(); SymbolResolver symbolResolver = new InFileSymbolResolver(JdkTypeResolver.getInstance()); ResolverRegistry.INSTANCE.record(turinFile, symbolResolver); Optional<PropertyDefinition> optionalDefinition = srcSymbolResolver.findDefinition(propertyReference); assertEquals(true, optionalDefinition.isPresent()); PropertyDefinition definition = optionalDefinition.get(); assertEquals("name", definition.getName()); assertEquals(true, definition.getType().isReferenceTypeUsage()); assertEquals("java.lang.String", definition.getType().asReferenceTypeUsage().getQualifiedName()); }
@Test public void findDefinitionNegativeCase() throws IOException { TurinFile turinFile = new Parser().parse(this.getClass().getResourceAsStream("/basicManga.to")); SrcSymbolResolver srcSymbolResolver = new SrcSymbolResolver(ImmutableList.of(turinFile)); PropertyReference propertyReference = createMock(PropertyReference.class); EasyMock.expect(propertyReference.contextName()).andReturn("not_manga"); EasyMock.expect(propertyReference.getName()).andReturn("name"); replayAll(); Optional<PropertyDefinition> optionalDefinition = srcSymbolResolver.findDefinition(propertyReference); assertEquals(false, optionalDefinition.isPresent()); }