Skip to content
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

[FEATURE] @NotYetImplemented Annotation #3751

Open
mintdaniel42 opened this issue Sep 21, 2024 · 0 comments
Open

[FEATURE] @NotYetImplemented Annotation #3751

mintdaniel42 opened this issue Sep 21, 2024 · 0 comments

Comments

@mintdaniel42
Copy link

When developing software, we often have methods that have not yet been implemented. Most of them have a return value that needs to be returned. Of course it is possible to just let the program return null, but that could crash the whole program.

public int calculateScore() {
  return null;
}

So what else can we do when we need to make a return statement?
We can simply throw an exception.

public int calculateScore() {
  throw new UnsupportedOperationException();
}

It can be annoying during development to have to switch back and forth between the code we're working on and the throw statement, because it won't compile if a throw statement prevents further code from executing.

public int calculateScore() {
  throw new UnsupportedOperationException();
  int a = 10;
  int b = 32;
  return a + b;
}

What if we could just annotate a method with @NotYetImplemented and Lombok would replace all existing code inside the function with an exception?

@NotYetImplemented
public int calculateScore() {
  int a = 10;
  int b = 32;
  return a + b;
}

would be replaced by

@NotYetImplemented
public int calculateScore() {
  throw new UnsupportedOperationException();
}

We could even modify the exception class to use our own exceptions

@NotYetImplemented(exception = NotYetImplementedException.class)
public int calculateScore() {
  throw new UnsupportedOperationException();
}

When using BuildConfig plugins, we could even specify to generate the throw statement only when a special flag is set

@NotYetImplemented(flag = BuildConfig.production)
public int calculateScore() {
  throw new UnsupportedOperationException();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant