Visual Studio Code - Java - Lombok - The method is undefined for the type

davidesp picture davidesp · Jul 14, 2018 · Viewed 9.7k times · Source

I downloaded the following project and imported it into Visual Studio Code:

https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example

I have a problem on the following class, when invoking: car.getName().

https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example/blob/d5c959162ed0f862a5dceb93f5957f92e052e062/server/src/main/java/com/okta/developer/demo/CoolCarController.java

which content is:

CoolCarController.java

package com.okta.developer.demo;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
import java.util.stream.Collectors;

@RestController
class CoolCarController {
    private CarRepository repository;

    public CoolCarController(CarRepository repository) {
        this.repository = repository;
    }

    @GetMapping("/cool-cars")
    @CrossOrigin(origins = "http://localhost:4200")
    public Collection<Car> coolCars() {
        return repository.findAll().stream()
                .filter(this::isCool)
                .collect(Collectors.toList());
    }

    private boolean isCool(Car car) {
        return !car.getName().equals("AMC Gremlin") &&
                !car.getName().equals("Triumph Stag") &&
                !car.getName().equals("Ford Pinto") &&
                !car.getName().equals("Yugo GV");
    }
}

here is also the content of:

Car.java

package com.okta.developer.demo;

import lombok.*;

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

@Entity
@Getter @Setter
@NoArgsConstructor
@ToString @EqualsAndHashCode
public class Car {
    @Id @GeneratedValue
    private Long id;
    private @NonNull String name;
}

As you can see on the image below, I'm getting the error:

[Java] The method getName() is undefined for the type Car

enter image description here

I think Visual Studio Code doesn't understand the package: lombok.

Any idea on how can I make Visual Studio Code understand that package?

Thanks!

Answer

davidesp picture davidesp · Jul 14, 2018

Ok, Installing extension: Lombok Annotations Support for VS Code (gabrielbb.vscode-lombok) did the trick.