<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: javaFactory</title>
    <description>The latest articles on DEV Community by javaFactory (@java_factory_dev).</description>
    <link>https://dev.to/java_factory_dev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3062774%2F6b41c213-195b-4745-abaf-9576d5ef5d47.png</url>
      <title>DEV Community: javaFactory</title>
      <link>https://dev.to/java_factory_dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/java_factory_dev"/>
    <language>en</language>
    <item>
      <title>400 Lines of code in 20s, all test passed ( llm code generator )</title>
      <dc:creator>javaFactory</dc:creator>
      <pubDate>Tue, 20 May 2025 08:09:49 +0000</pubDate>
      <link>https://dev.to/java_factory_dev/400-lines-of-code-in-20s-all-test-passed-llm-code-generator--49le</link>
      <guid>https://dev.to/java_factory_dev/400-lines-of-code-in-20s-all-test-passed-llm-code-generator--49le</guid>
      <description>&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/ReBCXKOpW3M"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Hi, I'm the developer of JavaFactory — a code generation tool that automates Java development using LLMs.&lt;/p&gt;

&lt;h3&gt;
  
  
  What this solves (that others don't)
&lt;/h3&gt;

&lt;p&gt;Most AI code tools I've tried (like Cursor, Copilot, etc.) produce general-purpose code that's often unusable in real-world projects.&lt;br&gt;&lt;br&gt;
They might write code quickly, but the result is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;unpredictable,&lt;/li&gt;
&lt;li&gt;hard to maintain,&lt;/li&gt;
&lt;li&gt;and often completely wrong ( not usable ).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I built something different:&lt;br&gt;&lt;br&gt;
A tool where I can &lt;strong&gt;explicitly define patterns&lt;/strong&gt; and &lt;strong&gt;precisely control which classes are referenced&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Yes, it takes some upfront work to define the rules.&lt;br&gt;&lt;br&gt;
But the result?&lt;br&gt;&lt;br&gt;
→ Code that's testable, maintainable, and consistent with your actual architecture.&lt;/p&gt;

&lt;h3&gt;
  
  
  Demo:
&lt;/h3&gt;

&lt;p&gt;In this demo, 400 lines of Java code (including tests) were generated in 20 seconds.&lt;br&gt;&lt;br&gt;
All tests passed without manual edits.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;If you're tired of copy-pasting boilerplate and want AI that respects your structure — give this a try.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🔗 GitHub: &lt;a href="https://github.com/JavaFactoryPluginDev/javafactory-plugin" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;br&gt;
🔌 IntelliJ Plugin: &lt;a href="https://plugins.jetbrains.com/plugin/27246-javafactory" rel="noopener noreferrer"&gt;JetBrains Marketplace&lt;/a&gt;  &lt;/p&gt;

</description>
      <category>llm</category>
      <category>java</category>
      <category>spring</category>
    </item>
    <item>
      <title>I Built an IntelliJ Plugin That Automatically Generates Code (Pattern-Based with LLM)</title>
      <dc:creator>javaFactory</dc:creator>
      <pubDate>Wed, 14 May 2025 11:28:30 +0000</pubDate>
      <link>https://dev.to/java_factory_dev/i-built-an-intellij-plugin-that-automatically-generates-code-pattern-based-with-llm-3nc6</link>
      <guid>https://dev.to/java_factory_dev/i-built-an-intellij-plugin-that-automatically-generates-code-pattern-based-with-llm-3nc6</guid>
      <description>&lt;p&gt;&lt;strong&gt;5s of auto code generation demo&lt;/strong&gt;&lt;br&gt;
  &lt;iframe src="https://www.youtube.com/embed/ruSfG5YHmH4"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;When you're developing in Java, how much of your work truly requires creativity?&lt;br&gt;&lt;br&gt;
Do you sometimes find yourself following the same pattern, just swapping out data specs?&lt;/p&gt;

&lt;p&gt;In my experience, about 50% of the work in the early stages of development requires human judgment and insight.&lt;br&gt;&lt;br&gt;
But in many cases, the roles of each class could be boiled down to a simple set of rules—sometimes even just a one-page guide.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To me, this kind of implementation work started to feel repetitive and mechanical&lt;/strong&gt;,&lt;br&gt;&lt;br&gt;
so I decided to build a tool that automates it using LLMs.&lt;/p&gt;
&lt;h2&gt;
  
  
  Applying to Layered Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmqqfzbehv4efxp0iacf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmqqfzbehv4efxp0iacf.png" alt="layered architecture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is my view of layered architecture.&lt;br&gt;&lt;br&gt;
In the diagram above, I believe that once the red components are defined, it may be possible to automate the generation of the blue components.&lt;/p&gt;

&lt;p&gt;For example, here’s the system prompt I use to generate test code for the domain layer:&lt;/p&gt;
&lt;h4&gt;
  
  
  system prompt
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## Goal
Write a unit test class for the given domain implementation class,

You will be provided with:

1. A domain-level interface that defines the expected behaviors
2. The implementation class of the interface
3. Fixtures for dependency injection (DI)
4. A set of referenced classes (e.g., data models, enums, utilities)

## Rules
- Write test methods for every method declared in the interface.
- Each test cover at least one success case and optionally edge/failure cases.
- Inject fixture objects when instantiating the implementation class. (Fake... class if possible)
- Use pure Java with JUnit 5.
- Annotate each test with @DisplayName using Korean to describe the test purpose.
- Do not invent helper methods, factories, or mock behavior beyond what is defined.

## Output Format
Return only:
- One complete `.java` class
- No markdown
- No external explanations or comments

## Output Example
class DefaultUserReaderTest {

    private UserAuthRepository userAuthRepository;
    private UserInfoRepository userInfoRepository;
    private DefaultUserReader userReader;

    @BeforeEach
    void setup() {
        userAuthRepository =  FakeUserAuthRepository.getInstance();
        userInfoRepository = FakeUserInfoRepository.getInstance();
        userReader = new DefaultUserReader(userAuthRepository, userInfoRepository);
    }

    @Test
    @DisplayName("read(Long userId) with valid userId should return User")
    void readById_whenValidUserId_thenReturnUser() {

        var authInfo = userAuthRepository.save(UserAuthEntity.of(
                1L,
                "username",
                "pw",
                Set.of(UserRole.NORMAL)
        ));

        var userInfo = userInfoRepository.save(UserInfoEntity.of(
           1L,
                1L,
                Location.EUNPYUNG,
                UserType.USER
        ));


        var user = userReader.read(authInfo.getId());

        assertNotNull(user);
        assertEquals(user.getId(), authInfo.getId());
        assertEquals(user.getNickname(), authInfo.getUsername());
        assertEquals(user.getUserType(), userInfo.getUserType());
        assertEquals(user.getLocation(), userInfo.getLocation());
        assertTrue(user.getRoles().contains(UserRole.NORMAL));
    }

    @Test
    @DisplayName("read(Long userId) with invalid userId should return null")
    void readById_whenInvalidUserId_thenReturnNull() {

        var userNoExist = userReader.read(Long.MAX_VALUE);
        assertNull(userNoExist);
    }

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;While it doesn't cover every case, I was able to generate code quite effectively by using a system prompt like the one above and referencing the appropriate implementation sources.&lt;br&gt;&lt;br&gt;
(Of course, minor adjustments like fixing import paths were needed—but it worked very well as a first draft.)&lt;/p&gt;
&lt;h4&gt;
  
  
  Result Example (Generated via LLM Automation)
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
public class DefaultUserReaderTest {

    private UserAuthRepository userAuthRepository;
    private UserInfoRepository userInfoRepository;
    private DefaultUserReader userReader;

    @BeforeEach
    void setup() {
        userAuthRepository =  FakeUserAuthRepository.getInstance();
        userInfoRepository = FakeUserInfoRepository.getInstance();
        userReader = new DefaultUserReader(userAuthRepository, userInfoRepository);
    }

    @Test
    @DisplayName("read(Long userId) with valid userId should return User")
    void readById_whenValidUserId_thenReturnUser() {

        var authInfo = userAuthRepository.save(UserAuthEntity.of(
                1L,
                "username",
                "pw",
                Set.of(UserRole.NORMAL)
        ));

        var userInfo = userInfoRepository.save(UserInfoEntity.of(
           1L,
                1L,
                Location.EUNPYUNG,
                UserType.USER
        ));


        var user = userReader.read(authInfo.getId());

        assertNotNull(user);
        assertEquals(user.getId(), authInfo.getId());
        assertEquals(user.getNickname(), authInfo.getUsername());
        assertEquals(user.getUserType(), userInfo.getUserType());
        assertEquals(user.getLocation(), userInfo.getLocation());
        assertTrue(user.getRoles().contains(UserRole.NORMAL));
    }

    @Test
    @DisplayName("read(Long userId) with invalid userId should return null")
    void readById_whenInvalidUserId_thenReturnNull() {
        var userNoExist = userReader.read(Long.MAX_VALUE);
        assertNull(userNoExist);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Turning the Idea into a Tool
&lt;/h3&gt;

&lt;p&gt;To turn this idea into a working tool, I found that three key components were essential:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Allowing users to define their own patterns&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamically collecting code references at runtime&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sending prompts to GPT-4o&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Defining Custom Patterns
&lt;/h4&gt;

&lt;p&gt;It’s clear that not every developer will agree with the rules in the system prompt example above.&lt;br&gt;&lt;br&gt;
Everyone has their own way of writing code, so allowing full customization of the rules is essential.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx18w8gkvyelg8gadmfcm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx18w8gkvyelg8gadmfcm.png" alt="custom own patterns"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image above shows the &lt;strong&gt;Pattern Definition Panel&lt;/strong&gt; in my plugin.&lt;br&gt;&lt;br&gt;
Users can define system prompts for each code generation task using the following components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Goal&lt;/strong&gt;: The objective of the task&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rules&lt;/strong&gt;: The generation logic&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Output Format&lt;/strong&gt;: Desired output structure&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example (Shot)&lt;/strong&gt;: Few-shot code examples&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition, users can specify what information should be included in the prompt based on &lt;strong&gt;annotation types&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;These configurations are saved under the &lt;code&gt;.idea/&lt;/code&gt; directory as XML files,&lt;br&gt;&lt;br&gt;
making them reusable across sessions.&lt;/p&gt;
&lt;h4&gt;
  
  
  Referencing Code Automatically
&lt;/h4&gt;

&lt;p&gt;When writing a test or implementation class, developers often reference 5 to 20 other classes within a single file—often without even realizing it.&lt;br&gt;&lt;br&gt;
To support automation, there needed to be a mechanism to &lt;strong&gt;automatically collect and accurately provide those references at runtime&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpoayjqymf5feep9gwimq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpoayjqymf5feep9gwimq.png" alt="demo- generate implmentation and tests"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image above shows an example using the &lt;code&gt;@JavaFactory&lt;/code&gt; annotation,&lt;br&gt;&lt;br&gt;
which defines what role a class plays and what other classes it is related to within a given API context.&lt;/p&gt;

&lt;p&gt;This annotation is designed to support rules like the following:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"When generating a test for a target API, include all referenced APIs and their implementation classes in the prompt."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With this approach, the LLM can receive &lt;strong&gt;complete and precise reference sources&lt;/strong&gt; required for accurate code generation.&lt;/p&gt;

&lt;p&gt;For more details on how reference collection works, see the guide below:&lt;/p&gt;

&lt;p&gt;🔗 &lt;a href="https://github.com/JavaFactoryPluginDev/javafactory-plugin/blob/master/docs/crawl_java_files.md" rel="noopener noreferrer"&gt;Reference Collection Rules&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Sending Prompts to GPT-4o
&lt;/h4&gt;

&lt;p&gt;After testing several LLM models, &lt;strong&gt;GPT-4o consistently produced the most stable and reliable code&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Lower-tier models often struggled with code structure and syntax, and many failed to produce even usable first drafts.&lt;/p&gt;

&lt;p&gt;Below is an actual result of generating &lt;strong&gt;an implementation and test class for a domain-level API&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/66dr99BUPFY"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Insights
&lt;/h3&gt;

&lt;p&gt;Here are some personal takeaways from building this project.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Tasks with shallow reasoning—code or otherwise—will eventually be automated.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In many types of work, if the pattern for a task can be defined within just 2–3 pages of documentation,&lt;br&gt;&lt;br&gt;
then GPT-4o is already capable of reducing the burden through partial automation.&lt;br&gt;&lt;br&gt;
(Of course, human review is still necessary—for now.)&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;LLMs love interfaces.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This became especially clear when defining reference scopes for code generation.&lt;br&gt;&lt;br&gt;
If you base your prompt on a concrete implementation, it can bring in an unlimited cascade of dependencies.&lt;br&gt;&lt;br&gt;
But when using interfaces, the boundary is clear and well-defined—&lt;br&gt;&lt;br&gt;
making it easier for LLMs to reason within a &lt;strong&gt;stable, constrained scope&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpwb0m9gsm8w4akvmp1zn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpwb0m9gsm8w4akvmp1zn.png" alt="bad case of reference lookup"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcsoopuz1pb3aqg9rz82e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcsoopuz1pb3aqg9rz82e.png" alt="good case of reference lookup"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;Business process automation pays off..** &lt;em&gt;(Just my opinion.)&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Links
&lt;/h3&gt;

&lt;p&gt;If you find the project useful or interesting, a star on GitHub would be appreciated.&lt;br&gt;&lt;br&gt;
You're welcome to download it and try it out.&lt;/p&gt;

&lt;p&gt;Also, I realize that the reference collection mechanism might still feel a bit complex from the user's perspective.&lt;br&gt;&lt;br&gt;
If you have any ideas or suggestions to make it better, I'd love to hear them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/JavaFactoryPluginDev/javafactory-plugin" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://plugins.jetbrains.com/plugin/27246-javafactory" rel="noopener noreferrer"&gt;JetBrains Marketplace&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JavaFactoryPluginDev/javafactory-plugin/discussions" rel="noopener noreferrer"&gt;Discussion&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>webdev</category>
      <category>ai</category>
      <category>llm</category>
    </item>
  </channel>
</rss>
