-
Notifications
You must be signed in to change notification settings - Fork 12
Rework UI building #24
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of history on lombok:
The granural control with @Getter @Setter
was the first thing project lombok offered. However later on they added @Data
annotation.
From my experience it is better to have granural control only when you really need it. Whenever possible, write least amount of code. In otherwords, use annotations on top of the class.
As you read the code from top to down, you will see right away on the class that "ok there are getters and setters", instead of going through full class and finding out for yourself.
For example Spring framework (REST applications / Dependency injection) has most of its annotations on class level. I think it is like in 80% of the java applications today so java devs are very used to such practice.
@@ -33,7 +33,9 @@ private CommodityTab(String title) { | |||
} | |||
} | |||
|
|||
@Setter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future, if you end up with a class where you have 3-4 setters and maybe some instance variables you are not necessarily exposing already then it is ok practice to just add @Data
on the class itself not micromanaging individual properties with Getter/Setter functionality.
If there are some properties that you do not want to be made accessible through getters/setters then you can use
@Getter(value = AccessLevel.NONE)
@Setter(value = AccessLevel.NONE)
private Datatype myVariableName;
As the code is generated then having lombok generate a method that is not used vs human is wasting time on reading dead code - there is a difference. I would rather read less and have some dead functions in compile time. Most of the time it will not hurt anybody.
There are exceptions to everything of course. When you are writing a library for example then obviously the exposed api has to be thought through.
@@ -28,7 +26,7 @@ public static void fatal(Object logObject) { | |||
} | |||
|
|||
private static Logger getLogger() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unsure if this helper is necessary. Logging elevation should be switched via configuration files. As a developer, you have full control over that file. In release build you can toggle logging elevation to be OFF.
This is generally how it is used and appropriate configuration settings are then in log4j.properties file. https://docs.oracle.com/cd/E29578_01/webhelp/cas_webcrawler/src/cwcg_config_log4j_file.html
public class SomeClass {
private static final Logger LOG = Logger.getLogger(SomeClass.class);
This is an interesting workaround :D (below in the same file)
return Class.forName(Thread.currentThread().getStackTrace()[4].getClassName());
PS: I could do this change myself later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please. I wanted to have a no-brains logger without having to declare the logger in each class. Ideally, I'd like to have both class name, method and line number of the log:
fqdnClass.method(line number): message
stelnet.ui.Renderer.render(24): I have so much data but actual message is useless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please. I wanted to have a no-brains logger without having to declare the logger in each class.
I see. In that case this helper justifies itself. I am used to writing that extra line myself to show the intent. Matter of preference.
@@ -25,12 +26,14 @@ | |||
|
|||
public class ButtonManager { | |||
|
|||
@Getter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I would use class level @Getter
instead
@Getter
public class ButtonManager {
@@ -3,12 +3,16 @@ | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
|
|||
import lombok.Getter; | |||
import stelnet.filter.cargostack.CargoStackFilter; | |||
import stelnet.filter.fleetmember.FleetMemberFilter; | |||
|
|||
public class FilterManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I would use class level @Getter
instead
@Getter
public class FilterManager {
|
||
private final Size size; | ||
private final String title; | ||
public class Button extends Renderable implements ButtonHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditch the @Getter @Setter
and use
@Data
public class Button extends Renderable implements ButtonHandler {
If you really really do not want to expose title and handler via setters then you can:
@Setter(value = AccessLevel.NONE)
private int mySecret;
}; | ||
|
||
@Getter | ||
private int horizontalDirection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can add here also @Getter
on top of the enum itself.
@@ -1,8 +1,12 @@ | |||
package stelnet.ui; | |||
|
|||
import lombok.Getter; | |||
|
|||
public class Position { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class level @Getter
public Size getSize() { | ||
if (size == null) { | ||
LogHelper.warn("Null size found"); | ||
} | ||
return size; | ||
} | ||
|
||
public Location getLocation() { | ||
return location; | ||
} | ||
|
||
public Position getOffset() { | ||
return offset; | ||
} | ||
|
||
public void setLocation(Location location) { | ||
this.location = location; | ||
} | ||
|
||
public void setOffset(Position offset) { | ||
this.offset = offset; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could add here class level @Getter
and keep custom implementation of getSize
@@ -3,18 +3,18 @@ | |||
import com.fs.starfarer.api.ui.IntelUIAPI; | |||
import com.fs.starfarer.api.ui.TooltipMakerAPI; | |||
|
|||
public class SimpleCallback implements Callable { | |||
public class SimpleHandler implements ButtonHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SimpleHandler
vs EventHandler
@@ -1,23 +1,19 @@ | |||
package stelnet.ui; | |||
|
|||
import lombok.Getter; | |||
|
|||
public class Size { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class level getter annotation
Happy with @DaTa. I'll change it in another MR as I don't want to hold you up and won't have time today to make the change. |
Closes #22