Skip to content

Commit b3dcfd2

Browse files
authored
Feature/java module (#161)
* Update deno.lock * Added tree-sitter-java package * Added testing support * Feature/java package resolver (#148) * Added tree-sitter-java package * Added testing support * Package resolver * Removed log in test * Feature/java package mapper (#149) * Package mapper * Import resolution * Feature/java import resolver (#150) * Changed file structure in mapper * Added ConcreteNode interface * Private class exclusion * Update .gitignore * Fixed java test files to be compilable * I don't understand anything of what's happening * Update .gitignore * Import resolver * Incredibly destructive spelling mistake * Added static member resolution * Fixed static imports * Added current package import * Feature/java invocation resolver (#151) * Fixed wildcard imports breaking queries * Invocation resolver * Absolute foolproof safety * Feature/java manifest (#153) * Keeping filepath in exportedsymbol * Dependency formatting * Manifest integration * I FORGOR 💀 * Update parsers.ts * Added java to init * Feature/init c java (#155) * Update init for C and Java * Fixed include directory specification * Extractor (#158) * Feature/java metrics (#159) * Added metrics * Fixed comment query * JSDoc comments (#160) * Filtered out files without declarations * Update README.md * Added Java extraction handler * Added java example * Updated formatting and fmt check
1 parent 221174c commit b3dcfd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3692
-7
lines changed

.github/workflows/lint_test_compile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: deno lint
2525

2626
- name: Deno fmt (check)
27-
run: deno fmt --check
27+
run: deno fmt --check --ignore=examples/java/websocket/**/*.html
2828

2929
tests:
3030
runs-on: ubuntu-latest

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ auditResponse.json
1515
napi-output/
1616
coverage/
1717
.vite/
18+
.mvn/
19+
target/
20+
.settings/
21+
.classpath

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ status:
5959
| ------------------ | -------------- |
6060
| Python | ✅ Supported |
6161
| C# | ✅ Supported |
62-
| C |In Progress |
63-
| Java | 🚧 In Progress |
62+
| C |Supported |
63+
| Java | ✅ Supported |
6464
| C++ | 🚧 In Progress |
6565
| PHP | 🚧 In Progress |
6666
| JavaScript | 🚧 In Progress |

deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"tree-sitter-c": "npm:tree-sitter-c@0.23.6",
1616
"tree-sitter-c-sharp": "npm:tree-sitter-c-sharp@^0.23.1",
1717
"tree-sitter-python": "npm:tree-sitter-python@^0.23.6",
18+
"tree-sitter-java": "npm:tree-sitter-java@^0.23.5",
1819
"yargs": "https://deno.land/x/yargs@v18.0.0-deno/deno.ts",
1920
"yargs-types": "https://deno.land/x/yargs@v18.0.0-deno/deno-types.ts",
2021
"zod": "npm:zod@^3.24.4"

examples/java/websocket/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# NAPI Java example
2+
3+
This example uses Spring's websocket sample artifact from the Maven repository.
4+
To experiment with it, simply run :
5+
6+
```Bash
7+
napi init
8+
```
9+
10+
in this folder and follow the instructions.

examples/java/websocket/pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>websocket</artifactId>
5+
<parent>
6+
<!-- Your own application should inherit from spring-boot-starter-parent -->
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<version>1.0.2.RELEASE</version>
10+
</parent>
11+
<groupId>napi</groupId>
12+
<name>Spring Boot WebSocket Sample</name>
13+
<description>Spring Boot WebSocket Sample</description>
14+
<version>1.0-SNAPSHOT</version>
15+
<url>http://projects.spring.io/spring-boot/</url>
16+
<organization>
17+
<name>Pivotal Software, Inc.</name>
18+
<url>http://www.spring.io</url>
19+
</organization>
20+
<properties>
21+
<main.basedir>${basedir}/../..</main.basedir>
22+
<java.version>1.7</java.version>
23+
</properties>
24+
<dependencies>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-websocket</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-actuator</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-test</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
</dependencies>
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-maven-plugin</artifactId>
44+
</plugin>
45+
</plugins>
46+
</build>
47+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2012-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package samples.websocket.client;
18+
19+
public interface GreetingService {
20+
21+
String getGreeting();
22+
23+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2012-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package samples.websocket.client;
18+
19+
import java.util.concurrent.CountDownLatch;
20+
21+
import org.apache.commons.logging.Log;
22+
import org.apache.commons.logging.LogFactory;
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.web.socket.TextMessage;
25+
import org.springframework.web.socket.WebSocketSession;
26+
import org.springframework.web.socket.handler.TextWebSocketHandler;
27+
28+
public class SimpleClientWebSocketHandler extends TextWebSocketHandler {
29+
30+
protected Log logger = LogFactory.getLog(SimpleClientWebSocketHandler.class);
31+
32+
private final GreetingService greetingService;
33+
34+
private final CountDownLatch latch;
35+
36+
@Autowired
37+
public SimpleClientWebSocketHandler(GreetingService greetingService,
38+
CountDownLatch latch) {
39+
this.greetingService = greetingService;
40+
this.latch = latch;
41+
}
42+
43+
@Override
44+
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
45+
TextMessage message = new TextMessage(this.greetingService.getGreeting());
46+
session.sendMessage(message);
47+
}
48+
49+
@Override
50+
public void handleTextMessage(WebSocketSession session, TextMessage message)
51+
throws Exception {
52+
this.logger.info("Received: " + message + " (" + this.latch.getCount() + ")");
53+
session.close();
54+
this.latch.countDown();
55+
}
56+
57+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2012-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package samples.websocket.client;
18+
19+
public class SimpleGreetingService implements GreetingService {
20+
21+
@Override
22+
public String getGreeting() {
23+
return "Hello world!";
24+
}
25+
26+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2012-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package samples.websocket.config;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
21+
import org.springframework.boot.builder.SpringApplicationBuilder;
22+
import org.springframework.boot.context.web.SpringBootServletInitializer;
23+
import org.springframework.context.annotation.Bean;
24+
import org.springframework.context.annotation.Configuration;
25+
import org.springframework.web.socket.WebSocketHandler;
26+
import org.springframework.web.socket.config.annotation.EnableWebSocket;
27+
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
28+
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
29+
import org.springframework.web.socket.handler.PerConnectionWebSocketHandler;
30+
31+
import samples.websocket.client.GreetingService;
32+
import samples.websocket.client.SimpleGreetingService;
33+
import samples.websocket.echo.DefaultEchoService;
34+
import samples.websocket.echo.EchoService;
35+
import samples.websocket.echo.EchoWebSocketHandler;
36+
import samples.websocket.snake.SnakeWebSocketHandler;
37+
38+
@Configuration
39+
@EnableAutoConfiguration
40+
@EnableWebSocket
41+
public class SampleWebSocketsApplication extends SpringBootServletInitializer implements
42+
WebSocketConfigurer {
43+
44+
@Override
45+
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
46+
registry.addHandler(echoWebSocketHandler(), "/echo").withSockJS();
47+
registry.addHandler(snakeWebSocketHandler(), "/snake").withSockJS();
48+
}
49+
50+
@Override
51+
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
52+
return application.sources(SampleWebSocketsApplication.class);
53+
}
54+
55+
public static void main(String[] args) {
56+
SpringApplication.run(SampleWebSocketsApplication.class, args);
57+
}
58+
59+
@Bean
60+
public EchoService echoService() {
61+
return new DefaultEchoService("Did you say \"%s\"?");
62+
}
63+
64+
@Bean
65+
public GreetingService greetingService() {
66+
return new SimpleGreetingService();
67+
}
68+
69+
@Bean
70+
public WebSocketHandler echoWebSocketHandler() {
71+
return new EchoWebSocketHandler(echoService());
72+
}
73+
74+
@Bean
75+
public WebSocketHandler snakeWebSocketHandler() {
76+
return new PerConnectionWebSocketHandler(SnakeWebSocketHandler.class);
77+
}
78+
79+
}

0 commit comments

Comments
 (0)