npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@contract-case/java-ast

v0.0.2

Published

This is a *temporary* fork of [@amplication/java-ast](https://github.com/amplication/java-ast). It exists to get fixes for the following issues:

Readme

@contract-case/java-ast

This is a temporary fork of @amplication/java-ast. It exists to get fixes for the following issues:

At the time of writing, there are open PRs for each issue:

  • https://github.com/amplication/ast-types/pull/9
  • https://github.com/amplication/ast-types/pull/6

However, these haven't yet had any activity, so I'm not sure if the project is maintained.

I'm not expecting to maintain this fork long term - hopefully the PRs will merge into the original repository.

Original readme follows.


@amplication/java-ast

A library for generating Java code through an abstract syntax tree (AST) approach. This library allows you to programmatically generate Java code in a type-safe manner.

Scope and Purpose

The Java AST library is not intended to cover all Java language functionality. Instead, it focuses on the elements needed to create foundation and boilerplate code with Amplication plugins. The library provides building blocks for generating well-structured Java code for common patterns and use cases.

When more specialized or custom code is needed, the CodeBlock class can be used as a generic node that can include any code as a string:

import { CodeBlock } from '@amplication/java-ast';

// Create a custom code block for specialized logic
const customLogic = new CodeBlock(`
  // Custom Java implementation
  try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
    String line;
    while ((line = reader.readLine()) != null) {
      processLine(line);
    }
  } catch (IOException e) {
    logger.error("Error reading file", e);
  }
`);

// Add to your class or method

Installation

npm install @amplication/java-ast

Building

Run nx build java-ast to build the library.

Running unit tests

Run nx test java-ast to execute the unit tests via Jest.

Publish to npm

In order to publish to npm @amplication/java-ast :

  1. Make sure to update the version in the package.json.
  2. Run the following:
# From the monorepo root folder
npm i

npx nx build java-ast

cd ./dist/libs/java-ast

To publish the package as "beta" run:

npm publish --access public --tag beta

To publish the package as "latest" run:


npm publish --access public
    

Features

  • Type-safe Java code generation
  • Support for all core Java constructs (classes, interfaces, enums, methods, fields, etc.)
  • Automatic import management
  • JavaDoc generation
  • Proper code formatting

Basic Usage

import {
  Class,
  Field,
  Method,
  Parameter,
  Type,
  Access,
  Annotation,
  ClassReference,
  CodeBlock,
  Writer
} from '@amplication/java-ast';

// Create a class
const userClass = new Class({
  name: 'User',
  packageName: 'com.example.model',
  access: Access.Public,
  annotations: [
    new Annotation({
      reference: new ClassReference({
        name: 'Entity',
        packageName: 'javax.persistence'
      })
    })
  ]
});

// Add fields
userClass.addField(new Field({
  name: 'id',
  type: Type.long(),
  access: Access.Private,
  annotations: [
    new Annotation({
      reference: new ClassReference({
        name: 'Id',
        packageName: 'javax.persistence'
      })
    }),
    new Annotation({
      reference: new ClassReference({
        name: 'GeneratedValue',
        packageName: 'javax.persistence'
      }),
      namedArguments: new Map([
        ['strategy', 'GenerationType.IDENTITY']
      ])
    })
  ]
}));

userClass.addField(new Field({
  name: 'username',
  type: Type.string(),
  access: Access.Private,
  javadoc: 'The username of the user.'
}));

// Add a constructor
userClass.addConstructor({
  access: Access.Public,
  parameters: [
    new Parameter({
      name: 'username',
      type: Type.string()
    })
  ],
  body: new CodeBlock({
    code: 'this.username = username;'
  })
});

// Add a method
userClass.addMethod(new Method({
  name: 'getUsername',
  access: Access.Public,
  parameters: [],
  returnType: Type.string(),
  body: new CodeBlock({
    code: 'return username;'
  })
}));

// Generate Java code
const writer = new Writer({ packageName: 'com.example.model' });
userClass.write(writer);
const javaCode = writer.toString();

console.log(javaCode);

The output will be:

package com.example.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    /**
     * The username of the user.
     */
    private String username;

    public User(String username) {
        this.username = username;
    }

    public String getUsername() {
        return username;
    }
}

Advanced Usage

Creating Interfaces

import { Interface, Method, Type, Access } from '@amplication/java-ast';

const repository = new Interface({
  name: 'UserRepository',
  packageName: 'com.example.repository',
  access: Access.Public,
  extends_: [
    new ClassReference({
      name: 'JpaRepository',
      packageName: 'org.springframework.data.jpa.repository'
    })
  ]
});

// Add methods to the interface
repository.addMethod(new Method({
  name: 'findByUsername',
  access: Access.Public,
  parameters: [
    new Parameter({
      name: 'username',
      type: Type.string()
    })
  ],
  returnType: Type.optional(Type.reference(
    new ClassReference({ name: 'User', packageName: 'com.example.model' })
  ))
}));

Creating Enums

import { Enum, Access } from '@amplication/java-ast';

const roleEnum = new Enum({
  name: 'Role',
  packageName: 'com.example.model',
  access: Access.Public,
  javadoc: 'User roles in the system.'
});

// Add enum values
roleEnum.addValue({ name: 'ADMIN' });
roleEnum.addValue({ name: 'USER' });
roleEnum.addValue({ name: 'GUEST' });

License

MIT