Skip to content

Lightweight APIs to analyze Java projects just with it's Symbol Table #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions .devcontainer/devcontainer.json → .devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"name": "CLDK TypeScript SDK (Bun)",
"image": "oven/bun:latest",
"name": "CLDK TypeScript SDK (Node+Bun+Java)",
"image": "mcr.microsoft.com/devcontainers/javascript-node:20-bookworm",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "20"
},
"ghcr.io/devcontainers/features/java:1": {
"version": "11"
}
},
"postCreateCommand": "curl -fsSL https://bun.sh/install | bash && export BUN_INSTALL=$HOME/.bun && export PATH=$BUN_INSTALL/bin:$PATH && bun install",
"customizations": {
"vscode": {
"extensions": [
Expand All @@ -23,9 +21,5 @@
}
}
},
"postCreateCommand": "bun install",
"workspaceFolder": "/workspace",
"mounts": [
"source=${localWorkspaceFolder},target=/workspace,type=bind"
]
"workspaceFolder": "/workspaces/typescript-sdk"
}
26 changes: 26 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test and Coverage

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Bun
uses: oven-sh/setup-bun@v1

- name: Install dependencies
run: bun install

- name: Run tests with coverage
run: bun run test:withCoverage

- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
continue-on-error: false
run: bun run test

- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2

- name: Generate Changelog
id: gen_changelog
uses: mikepenz/release-changelog-builder-action@v5
Expand Down
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 120
}
55 changes: 28 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,43 @@
</picture>

<p align='center'>
<a href="https://arxiv.org/abs/2410.13007">
<img src="https://img.shields.io/badge/arXiv-2410.13007-b31b1b?style=for-the-badge" />
</a>
<a href="https://opensource.org/licenses/Apache-2.0">
<img src="https://img.shields.io/badge/License-Apache%202.0-green?style=for-the-badge" />
</a>
<a href="https://codellm-devkit.info">
<img src="https://img.shields.io/badge/GitHub%20Pages-Docs-blue?style=for-the-badge" />
</a>
<a href="https://www.npmjs.com/package/@codellm-devkit/cldk">
<img src="https://img.shields.io/npm/v/@codellm-devkit/cldk?color=crimson&logo=npm&style=for-the-badge" />
</a>
<a href="https://discord.com/channels/1333486179667935403/1334150434348208208">
<img src="https://dcbadge.limes.pink/api/server/https://discord.gg/zEjz9YrmqN?style=for-the-badge"/>
</a>
<a href="https://codellm-devkit.info">
<img src="https://img.shields.io/badge/GitHub%20Pages-Docs-blue?" />
</a>
<a href="https://www.npmjs.com/package/@codellm-devkit/cldk">
<img src="https://img.shields.io/npm/v/@codellm-devkit/cldk?color=crimson&logo=npm&" />
</a>
<a href="https://coveralls.io/github/codellm-devkit/typescript-sdk?branch=main">
<img src="https://img.shields.io/coveralls/github/codellm-devkit/typescript-sdk/main?"/>
</a>
<a href="https://opensource.org/licenses/Apache-2.0">
<img src="https://img.shields.io/badge/License-Apache%202.0-green?" />
</a>
</p>


**A framework that bridges the gap between traditional program analysis tools and Large Language Models (LLMs) specialized for code (CodeLLMs).**

### Overview

This is the TypeScript SDK for the Codellm-Devkit (CLDK). The SDK provides a unified interface for integrating outputs from various analysis tools and preparing them for effective use by CodeLLMs. It allows developers to streamline the process of transforming raw code into actionable insights.

### 📦 Installation

To install the SDK, you can use bun, npm, or yarn. Run the following command in your terminal:
To install the SDK, you can use bun, npm, or yarn. Run the following command in your terminal:

1. Using npm

```bash
npm i @codellm-devkit/cldk
```

2. Using yarn

```bash
yarn add @codellm-devkit/cldk
```

3. Using bun
3. Using bun
```bash
bun add @codellm-devkit/cldk
```
Expand All @@ -65,7 +64,7 @@ This is the TypeScript SDK for the Codellm-Devkit (CLDK). The SDK provides a uni
This creates a minimal `package.json` instantly.

3. Install `@codellm-devkit/cldk`

```bash
bun add @codellm-devkit/cldk
```
Expand All @@ -74,17 +73,17 @@ This is the TypeScript SDK for the Codellm-Devkit (CLDK). The SDK provides a uni

```typescript
import { CLDK } from "cldk";

// Initialize Java analysis
const analysis = CLDK.for("java").analysis({
projectPath: "/path/to/your/java/project",
analysisLevel: "Symbol Table",
projectPath: "/path/to/your/java/project",
analysisLevel: "Symbol Table",
});

// Retrieve structured application model
const jApplication = await analysis.getApplication();
console.log("Parsed JApplication:", jApplication);

// Retrieve the symbol table
const symbolTable = await analysis.getSymbolTable();
console.log("Symbol Table:", symbolTable);
Expand All @@ -101,6 +100,7 @@ This is the TypeScript SDK for the Codellm-Devkit (CLDK). The SDK provides a uni
#### Developing Locally (with Bun)

1. Clone the repository:

```bash
git clone https://github.com/codellm-devkit/typescript-sdk.git
cd typescript-sdk
Expand All @@ -112,6 +112,7 @@ This is the TypeScript SDK for the Codellm-Devkit (CLDK). The SDK provides a uni
```
_Note: follow any post-installation instructions to complete the installation_
3. Install the dependencies

```bash
bun install
```
Expand All @@ -126,8 +127,8 @@ This is the TypeScript SDK for the Codellm-Devkit (CLDK). The SDK provides a uni
1. If you don't, ensure you have Docker/Podman and a compatible editor (e.g., VS Code) with the Dev Containers extension installed.

2. Open the repository in your editor. When prompted, reopen the project in the dev container. The devcontainer is configured to come pre-installed with bun and all the necessary dependencies.

3. You can start by run tests:
```bash
bun run test
```
```
5 changes: 0 additions & 5 deletions bunfig.toml

This file was deleted.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"homepage": "https://github.com/codellm-devkit/typescript-sdk#readme",
"scripts": {
"build": "bun build ./src/index.ts --outdir ./dist",
"test": "bun test --preload ./test/conftest.ts --timeout=600000 --verbose",
"test": "bun test --verbose --coverage --preload ./test/conftest.ts --timeout=600000",
"test:withCoverage": "bun test --verbose --coverage --coverage-reporter=lcov --preload ./test/conftest.ts --timeout=600000",
"clean": "rm -rf dist coverage *.lock"
},
"files": [
Expand All @@ -36,15 +37,18 @@
"@types/jsonstream": "^0.8.33",
"JSONStream": "^1.3.5",
"bun": "^1.2.10",
"c8": "^10.1.3",
"chalk": "^5.4.1",
"extract-zip": "^2.0.1",
"fast-glob": "^3.3.3",
"graphology": "^0.26.0",
"loglevel": "^1.9.2",
"signale": "^1.4.0",
"zod": "^3.24.3"
},
"testing": {
"java-test-applications-path": "./test-applications/java",
"c-test-applications-path": "./test-applications/c",
"python-test-applications-path": "./test-applications/python"
}
}
}
108 changes: 61 additions & 47 deletions src/CLDK.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,71 @@
import {JavaAnalysis} from "./analysis/java";
import {spawnSync} from "node:child_process";
import { JavaAnalysis } from "./analysis/java";
import { spawnSync } from "node:child_process";

export class CLDK {
/**
* The programming language of choice
*/
private language: string;
/**
* The programming language of choice
*/
private language: string;

constructor(language: string) {
this.language = language;
}
constructor(language: string) {
this.language = language;
}

/**
* A static for method to create a new instance of the CLDK class
*/
public static for(language: string): CLDK {
return new CLDK(language);
}
/**
* A static for method to create a new instance of the CLDK class
*/
public static for(language: string): CLDK {
return new CLDK(language);
}

/**
* Get the programming language of the CLDK instance
*/
public getLanguage(): string {
return this.language;
}
/**
* Get the programming language of the CLDK instance
*/
public getLanguage(): string {
return this.language;
}

/**
* Implementation of the analysis method
*/
public analysis({ projectPath, analysisLevel }: { projectPath: string, analysisLevel: string }): JavaAnalysis {
if (this.language === "java") {
this.makeSureJavaIsInstalled();
return new JavaAnalysis({
projectDir: projectPath,
analysisLevel: analysisLevel,
});
} else {
throw new Error(`Analysis support for ${this.language} is not implemented yet.`);
}
/**
* Implementation of the analysis method
*/
public analysis({
projectPath,
analysisLevel,
}: {
projectPath: string;
analysisLevel: string;
}): JavaAnalysis {
if (this.language === "java") {
this.makeSureJavaIsInstalled();
return new JavaAnalysis({
projectDir: projectPath,
analysisLevel: analysisLevel,
});
} else {
throw new Error(
`Analysis support for ${this.language} is not implemented yet.`
);
}
}

private makeSureJavaIsInstalled(): Promise<void> {
try {
const result = spawnSync("java", ["-version"], {encoding: "utf-8", stdio: "pipe"});
if (result.error) {
throw result.error;
}
if (result.status !== 0) {
throw new Error(result.stderr || "Java is not installed. Please install Java 11+ to be able to analyze java projects.");
}
} catch (e: any) {
throw new Error(e.message || String(e));
}
return Promise.resolve();
private makeSureJavaIsInstalled(): Promise<void> {
try {
const result = spawnSync("java", ["-version"], {
encoding: "utf-8",
stdio: "pipe",
});
if (result.error) {
throw result.error;
}
if (result.status !== 0) {
throw new Error(
result.stderr ||
"Java is not installed. Please install Java 11+ to be able to analyze java projects."
);
}
} catch (e: any) {
throw new Error(e.message || String(e));
}
return Promise.resolve();
}
}
Loading