INRIA / INRIA/spoon

Feature(CtPackage): Implement null object for CtPackage

Open
#3,705 9 comments 0 reactions 0 assignees View on GitHub
feature good first issue refactor
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

### Problem
Sometimes code elements have no package and `getPackage` return nulls. This introduces null checks and surprises for new developers. https://github.com/INRIA/spoon/commit/84c84e16163ff18611f82c69d5246d642e3fed86 as seen here, package can be null.
### Solution
A null object[0],[1] could improve code quality. A comparable implementation is [NoSourcePosition](https://github.com/INRIA/spoon/blob/1de9318fcb97fa99ba18c3fd40025163a55df89b/src/main/java/spoon/reflect/cu/position/NoSourcePosition.java). `NoSourcePosition` removed all null checks for positions and improves the code quality.
### Your task
Design a null object and refactor old code. Find a solution for `getSimpleName()` as the empty String is reserved for default package.
The PR should include:
- Design a null object for CtPackage
- Improve already existing test code and remove unnecessary null checks

It's a good starter issue, feel free to give it a try and ping if you need help for some design decisions.
### Literatur/Links
[0] [https://en.wikipedia.org/wiki/Null_object_pattern](https://en.wikipedia.org/wiki/Null_object_pattern)
[1] [https://www.baeldung.com/java-null-object-pattern](https://www.baeldung.com/java-null-object-pattern)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.