From the course: Coding Smarter with JetBrains AI Assistant

Contextual code suggestions: How AI understands your project

From the course: Coding Smarter with JetBrains AI Assistant

Contextual code suggestions: How AI understands your project

- [Instructor] Do you want to know how the JetBrains AI Assistant seems to know exactly what you're trying to build? It's not magic, it's context. Unlike traditional auto complete that only looks at the current line, the JetBrains AI Assistant examines your entire code base. It reads your existing classes, understands your architectural patterns, and learns from your coding style. Let's see what this looks like in practice. Here, we have a typical e-commerce project structure. There are controllers, data transfer objects, exceptions, repositories, services, lots of code to dive into. Let's go to the product service implementation class. Here, we have several service methods, one for creating a product, finding a product in different ways, updating products. Let's add a new method to this class. When I start typing this new method, the AI doesn't just suggest any generic code. It suggests code that fits perfectly with my existing domain model. Here, that's a find-by-category name method. Let's tab to complete it. It can also write the implementation. Here, it creates code that works with my existing product and category classes. This implementation isn't just completing syntax. The JetBrains AI Assistant understands the business logic of my application. But how is it doing this? The AI assistant builds this understanding through several layers of analysis. First, it examines your project structure. It identifies your packages, understands your separation of concerns, and recognizes common patterns like MVC or layered architecture. Then it analyzes your code relationships. If you have a class that extends another class or implements an interface, the AI understands this and will suggest appropriate query methods and annotations. It also learns from your naming conventions and coding style. If you consistently use CamelCase for variables and prefer builder patterns for object creation, the AI will mirror these preferences and its suggestions. In the find-category-by-name method, it uses the same validation pattern and exception handling I've established in this class. Now, to get the most out of these contextual suggestions, I have a few tips. First, keep your project well organized. The AI performs better when your code follows clear patterns and conventions. Be sure to use meaningful class names and method names. The AI uses these as semantic clues. A class named, payment processor, will receive very different suggestions than one named data handler. It's also important to keep related functionality together. When your domain objects, services, and repositories are properly organized, the AI can make much smarter connections between them. AI will recognize the libraries you're using, whether that's Spring Boot, Jackson, or JUnit, and it'll tailor its suggestions accordingly. Maintaining consistent error handling patterns can also help the AI suggest similar approaches and new code. It can also be helpful to write descriptive comments for complex business logic. The AI will read your comments and use them to understand the intent behind your code. With this level of contextual intelligence, the JetBrains AI Assistant becomes much more than just auto complete. It's like having a coding partner that actually gets what you're building.

Contents