TNSFileParser { @NotNull public ASTNode parse(String input) { TNSNodeBuilder builder = virtualFile != null ? new TNSNodeBuilder(virtualFile, input) : new TNSNodeBuilder(filePath, input); return parser.parse(TNSPsiTokenTypes.FILE, builder); } TNSFileParser();  TNSFileParser(String filePath);  TNSFileParser(VirtualFile virtualFile); @NotNull ASTNode parse(String input);  }
@Test public void test_tns_psi() throws IOException { String content = StringUtils.file2string(new File(base, "tns5.ora")); TNSFileParser parser = new TNSFileParser(); ASTNode root = parser.parse(content); assertNotNull(root); ASTNode[] nodes = root.getChildren(TokenSet.create(TNSTypesAdopted.NET_SERVICE_DESC)); assertEquals(6, nodes.length); NetServiceDesc e1 = (NetServiceDesc) nodes[0].getPsi(); assertEquals("net_service_name", e1.getNetworkAlias()); assertEquals(2, e1.getAddressInfos().length); assertEquals(3, e1.getAddressInfos()[0].getElements().length); assertEquals(3, e1.getAddressInfos()[1].getElements().length); assertEquals("tcp", e1.getAddressInfos()[0].findElementByName("PRoToCOL").getElementValue()); assertEquals("sales1-svr", e1.getAddressInfos()[0].findElementByName("HOST").getElementValue()); assertEquals("1521", e1.getAddressInfos()[0].findElementByName("PORT").getElementValue()); assertEquals("tcp", e1.getAddressInfos()[1].findElementByName("PRoToCOL").getElementValue()); assertEquals("sales2-svr", e1.getAddressInfos()[1].findElementByName("HOST").getElementValue()); assertEquals("1521", e1.getAddressInfos()[1].findElementByName("PORT").getElementValue()); NetServiceDesc e2 = (NetServiceDesc) nodes[1].getPsi(); assertEquals("net_service_name2", e2.getNetworkAlias()); assertEquals(2, e2.getAddressInfos().length); assertEquals(3, e2.getAddressInfos()[0].getElements().length); assertEquals(3, e2.getAddressInfos()[1].getElements().length); NetServiceDesc e3 = (NetServiceDesc) nodes[2].getPsi(); assertEquals("net_service_name3", e3.getNetworkAlias()); assertEquals(2, e3.getAddressInfos().length); assertEquals(3, e3.getAddressInfos()[0].getElements().length); assertEquals(3, e3.getAddressInfos()[1].getElements().length); assertEquals("tcp", e3.getAddressInfos()[0].findElementByName("PRoToCOL").getElementValue()); assertEquals("127.0.0.1", e3.getAddressInfos()[0].findElementByName("HOST").getElementValue()); assertEquals("1521", e3.getAddressInfos()[0].findElementByName("PORT").getElementValue()); NetServiceDesc e4 = (NetServiceDesc) nodes[3].getPsi(); assertEquals("net_service_name4", e4.getNetworkAlias()); assertEquals(2, e4.getAddressInfos().length); assertEquals(4, e4.getAddressInfos()[0].getElements().length); assertEquals(4, e4.getAddressInfos()[1].getElements().length); assertEquals("tcp", e4.getAddressInfos()[0].findElementByName("PRoToCOL").getElementValue()); assertEquals("sales1-server", e4.getAddressInfos()[0].findElementByName("HOST").getElementValue()); assertEquals("1521", e4.getAddressInfos()[0].findElementByName("PORT").getElementValue()); assertEquals("11784", e4.getAddressInfos()[0].findElementByName("SEND_BUF_SIZE").getElementValue()); NetServiceDesc e5 = (NetServiceDesc) nodes[4].getPsi(); NetServiceDesc e6 = (NetServiceDesc) nodes[5].getPsi(); assertEquals("net_service_name6", e6.getNetworkAlias()); assertEquals(2, e6.getAddressInfos().length); assertEquals(3, e6.getAddressInfos()[0].getElements().length); assertEquals(3, e6.getAddressInfos()[1].getElements().length); assertEquals("tcp", e6.getAddressInfos()[0].findElementByName("PRoToCOL").getElementValue()); assertEquals("hr1-server", e6.getAddressInfos()[0].findElementByName("HOST").getElementValue()); assertEquals("1521", e6.getAddressInfos()[0].findElementByName("PORT").getElementValue()); }