Skip to content

Commit

Permalink
Fixed all potential static method warnings in draw2d
Browse files Browse the repository at this point in the history
  • Loading branch information
azoitl authored and ptziegler committed Jan 20, 2024
1 parent 2ca0069 commit 6e92f48
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
public abstract class AbstractHintLayout extends AbstractLayout {

private Dimension minimumSize = null;
private Dimension cachedPreferredHint = new Dimension(-1, -1);
private Dimension cachedMinimumHint = new Dimension(-1, -1);
private final Dimension cachedPreferredHint = new Dimension(-1, -1);
private final Dimension cachedMinimumHint = new Dimension(-1, -1);

/**
* Calculates the minimum size using the given width and height hints. This
Expand Down Expand Up @@ -106,6 +106,7 @@ public void invalidate() {
* @return <code>true</code> if this layout is sensite to horizontal hint
* changes
*/
@SuppressWarnings("static-method")
protected boolean isSensitiveHorizontally(IFigure container) {
return true;
}
Expand All @@ -117,6 +118,7 @@ protected boolean isSensitiveHorizontally(IFigure container) {
* @param container the layout's container
* @return <code>true</code> if this layout is sensite to vertical hint changes
*/
@SuppressWarnings("static-method")
protected boolean isSensitiveVertically(IFigure container) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected final void calculatePreferredSize(IFigure container) {
* @param container The figure that the border is on
* @return The border's preferred size
*/
@SuppressWarnings("static-method")
protected Dimension getBorderPreferredSize(IFigure container) {
if (container.getBorder() == null) {
return new Dimension();
Expand Down
2 changes: 2 additions & 0 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/AbstractRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public Object getConstraint(Connection connection) {
* @return The endpoint
* @since 2.0
*/
@SuppressWarnings("static-method")
protected Point getEndPoint(Connection connection) {
Point ref = connection.getSourceAnchor().getReferencePoint();
return END.setLocation(connection.getTargetAnchor().getLocation(ref));
Expand All @@ -64,6 +65,7 @@ protected Point getEndPoint(Connection connection) {
* @return The start point
* @since 2.0
*/
@SuppressWarnings("static-method")
protected Point getStartPoint(Connection conn) {
Point ref = conn.getTargetAnchor().getReferencePoint();
return START.setLocation(conn.getSourceAnchor().getLocation(ref));
Expand Down
1 change: 1 addition & 0 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/Animator.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void capture(IFigure figure) {
* @return <code>true</code> if playback was successful
* @since 3.2
*/
@SuppressWarnings("static-method")
protected boolean playback(IFigure figure) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/Clickable.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ public void addChangeListener(ChangeListener listener) {
protected ButtonModel createDefaultModel() {
if (isStyle(STYLE_TOGGLE)) {
return new ToggleModel();
} else {
return new ButtonModel();
}
return new ButtonModel();
}

/**
Expand All @@ -151,6 +150,7 @@ protected ButtonModel createDefaultModel() {
* @return The event handler
* @since 2.0
*/
@SuppressWarnings("static-method")
protected ClickableEventHandler createEventHandler() {
return new ClickableEventHandler();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public void setViewport(Viewport vp) {
hookViewport();
}

private int verifyScrollBarOffset(RangeModel model, int value) {
private static int verifyScrollBarOffset(RangeModel model, int value) {
value = Math.max(model.getMinimum(), value);
return Math.min(model.getMaximum() - model.getExtent(), value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private static IFigure findDeepestRightmostChildOf(IFigure fig) {
* @param prevFocus the IFigure who currently owns focus
* @return the next focusable figure
*/
@SuppressWarnings("static-method")
public IFigure getNextFocusableFigure(IFigure root, IFigure prevFocus) {
boolean found = false;
IFigure nextFocus = prevFocus;
Expand Down Expand Up @@ -90,7 +91,7 @@ public IFigure getNextFocusableFigure(IFigure root, IFigure prevFocus) {
}
} else if (siblingPos < siblings.size() - 1) {
siblingPos++;
nextFocus = ((siblings.get(siblingPos)));
nextFocus = siblings.get(siblingPos);
if (isFocusEligible(nextFocus)) {
found = true;
}
Expand Down Expand Up @@ -133,6 +134,7 @@ public IFigure getNextFocusableFigure(IFigure root, IFigure prevFocus) {
* @param prevFocus The IFigure who currently owns focus
* @return the previous focusable figure
*/
@SuppressWarnings("static-method")
public IFigure getPreviousFocusableFigure(IFigure root, IFigure prevFocus) {
if (prevFocus == null) {
return null;
Expand Down
22 changes: 11 additions & 11 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/GridLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public GridLayout(int numColumns, boolean makeColumnsEqualWidth) {
* @param hHint
* @return the child size.
*/
@SuppressWarnings("static-method")
protected Dimension getChildSize(IFigure child, int wHint, int hHint) {
return child.getPreferredSize(wHint, hHint);
}
Expand Down Expand Up @@ -683,7 +684,8 @@ Dimension layout(IFigure container, boolean move, int x, int y, int width, int h
if (data != null) {
int hSpan = Math.max(1, Math.min(data.horizontalSpan, columnCount));
int vSpan = Math.max(1, data.verticalSpan);
int cellWidth = 0, cellHeight = 0;
int cellWidth = 0;
int cellHeight = 0;
for (int k = 0; k < hSpan; k++) {
cellWidth += widths[j + k];
}
Expand All @@ -694,36 +696,34 @@ Dimension layout(IFigure container, boolean move, int x, int y, int width, int h
int childX = gridX + data.horizontalIndent;
int childWidth = Math.min(data.cacheWidth, cellWidth);
switch (data.horizontalAlignment) {
case SWT.CENTER:
case GridData.CENTER:
case SWT.CENTER, GridData.CENTER:
childX = gridX + Math.max(0, (cellWidth - childWidth) / 2);
break;
case SWT.RIGHT:
case SWT.END:
case GridData.END:
case SWT.RIGHT, SWT.END, GridData.END:
childX = gridX + Math.max(0, cellWidth - childWidth);
break;
case SWT.FILL:
childWidth = cellWidth - data.horizontalIndent;
break;
default:
break;
}
cellHeight += verticalSpacing * (vSpan - 1);
int childY = gridY; // + data.verticalIndent;
int childHeight = Math.min(data.cacheHeight, cellHeight);
switch (data.verticalAlignment) {
case SWT.CENTER:
case GridData.CENTER:
case SWT.CENTER, GridData.CENTER:
childY = gridY + Math.max(0, (cellHeight - childHeight) / 2);
break;
case SWT.BOTTOM:
case SWT.END:
case GridData.END:
case SWT.BOTTOM, SWT.END, GridData.END:
childY = gridY + Math.max(0, cellHeight - childHeight);
break;
case SWT.FILL:
childHeight = cellHeight; // -
// data.verticalIndent;
break;
default:
break;
}
IFigure child = grid[i][j];
if (child != null) {
Expand Down
2 changes: 2 additions & 0 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ public void setTextPlacement(int where) {
* @return a <code>TextUtilities</code> instance
* @since 3.4
*/
@SuppressWarnings("static-method")
public TextUtilities getTextUtilities() {
return TextUtilities.INSTANCE;
}
Expand All @@ -700,6 +701,7 @@ public TextUtilities getTextUtilities() {
* @return the string to append to the text when truncated
* @since 3.4
*/
@SuppressWarnings("static-method")
protected String getTruncationString() {
return ELLIPSIS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private int getColumnNear(Connection connection, int r, int n, int x) {
* @param p the point
* @return the direction from <i>r</i> to <i>p</i>
*/
@SuppressWarnings("static-method")
protected Ray getDirection(Rectangle r, Point p) {
int distance = Math.abs(r.x - p.x);
Ray direction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ protected PrinterGraphics getFreshPrinterGraphics() {
* @since 3.1
* @TODO Make protected post-3.1
*/
@SuppressWarnings("static-method")
int getGraphicsOrientation() {
return SWT.LEFT_TO_RIGHT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public void clipRect(Rectangle r) {
graphics.clipRect(zoomClipRect(r));
}

@SuppressWarnings("static-method")
Font createFont(FontData data) {
return new Font(Display.getCurrent(), data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public void paint(IFigure figure, Graphics g, Insets insets) {
* @param tl the highlight (top/left) colors
* @param br the shadow (bottom/right) colors
*/
@SuppressWarnings("static-method")
protected void paint(Graphics graphics, IFigure fig, Insets insets, Color[] tl, Color[] br) {
graphics.setLineWidth(1);
graphics.setLineStyle(Graphics.LINE_SOLID);
Expand Down
8 changes: 6 additions & 2 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/ScrollBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public ScrollBar() {
* @return the up button
* @since 2.0
*/
@SuppressWarnings("static-method")
protected Clickable createDefaultUpButton() {
Button buttonUp = new ArrowButton();
buttonUp.setBorder(new ButtonBorder(ButtonBorder.SCHEMES.BUTTON_SCROLLBAR));
Expand All @@ -90,6 +91,7 @@ protected Clickable createDefaultUpButton() {
* @return the down button
* @since 2.0
*/
@SuppressWarnings("static-method")
protected Clickable createDefaultDownButton() {
Button buttonDown = new ArrowButton();
buttonDown.setBorder(new ButtonBorder(ButtonBorder.SCHEMES.BUTTON_SCROLLBAR));
Expand All @@ -112,6 +114,7 @@ protected Clickable createPageDown() {
* @return the page up figure
* @since 2.0
*/
@SuppressWarnings("static-method")
protected Clickable createPageUp() {
final Clickable clickable = new Clickable();
clickable.setOpaque(true);
Expand All @@ -135,6 +138,7 @@ protected Clickable createPageUp() {
* @return the thumb figure
* @since 2.0
*/
@SuppressWarnings("static-method")
protected IFigure createDefaultThumb() {
Panel thumb = new Panel();
thumb.setMinimumSize(new Dimension(6, 6));
Expand Down Expand Up @@ -379,7 +383,7 @@ public void setDownClickable(Clickable down) {
buttonDown = down;
if (buttonDown != null) {
if (buttonDown instanceof Orientable orientable) {
orientable.setDirection(isHorizontal() ? Orientable.EAST : Orientable.SOUTH);
orientable.setDirection(isHorizontal() ? PositionConstants.EAST : PositionConstants.SOUTH);
}
buttonDown.setFiringMethod(Clickable.REPEAT_FIRING);
buttonDown.addActionListener(e -> stepDown());
Expand All @@ -401,7 +405,7 @@ public void setUpClickable(Clickable up) {
buttonUp = up;
if (up != null) {
if (up instanceof Orientable orientable) {
orientable.setDirection(isHorizontal() ? Orientable.WEST : Orientable.NORTH);
orientable.setDirection(isHorizontal() ? PositionConstants.WEST : PositionConstants.NORTH);
}
buttonUp.setFiringMethod(Clickable.REPEAT_FIRING);
buttonUp.addActionListener(e -> stepUp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ protected Viewport getRootViewport() {
/**
* Returns the connection's points in absolute coordinates.
*/
@SuppressWarnings("static-method")
protected PointList getAbsolutePointsAsCopy(Connection connection) {
PointList points = connection.getPoints().getCopy();
connection.translateToAbsolute(points);
Expand All @@ -194,6 +195,7 @@ protected Rectangle getAbsoluteViewportAreaAsCopy(Viewport viewport) {
/**
* Returns the viewport's client area in absolute coordinates.
*/
@SuppressWarnings("static-method")
protected Rectangle getAbsoluteClientAreaAsCopy(IFigure figure) {
Rectangle absoluteClientArea = figure.getClientArea();
figure.translateToParent(absoluteClientArea);
Expand All @@ -204,6 +206,7 @@ protected Rectangle getAbsoluteClientAreaAsCopy(IFigure figure) {
/**
* Returns the figure's bounds in absolute coordinates.
*/
@SuppressWarnings("static-method")
protected Rectangle getAbsoluteBoundsAsCopy(IFigure figure) {
Rectangle absoluteFigureBounds = figure.getBounds().getCopy();
figure.translateToAbsolute(absoluteFigureBounds);
Expand Down
1 change: 1 addition & 0 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/XYLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public Object getConstraint(IFigure figure) {
* @param parent the figure whose origin is requested
* @return the origin
*/
@SuppressWarnings("static-method")
public Point getOrigin(IFigure parent) {
return parent.getClientArea().getLocation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
class LocalOptimizer extends GraphVisitor {

@SuppressWarnings("static-method")
boolean shouldSwap(Node current, Node next) {
if (GraphUtilities.isConstrained(current, next)) {
return false;
Expand Down
12 changes: 8 additions & 4 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/graph/Obstacle.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
class Obstacle extends Rectangle {

boolean exclude;
Vertex topLeft, topRight, bottomLeft, bottomRight, center;
private ShortestPathRouter router;
Vertex topLeft;
Vertex topRight;
Vertex bottomLeft;
Vertex bottomRight;
Vertex center;
private final ShortestPathRouter router;

/**
* Creates a new obstacle from the given rectangle bounds.
Expand All @@ -56,7 +60,7 @@ public int getSpacing() {
return router.getSpacing();
}

private void growVertex(Vertex vertex) {
private static void growVertex(Vertex vertex) {
if (vertex.totalCount > 0) {
vertex.grow();
}
Expand Down Expand Up @@ -106,7 +110,7 @@ void reset() {
topRight.fullReset();
}

private void shrinkVertex(Vertex vertex) {
private static void shrinkVertex(Vertex vertex) {
if (vertex.totalCount > 0) {
vertex.shrink();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ Edge enter(Node branch) {
return result;
}

@SuppressWarnings("static-method")
int getTreeMax(Node n) {
return n.workingInts[1];
}

@SuppressWarnings("static-method")
int getTreeMin(Node n) {
return n.workingInts[0];
}
Expand Down Expand Up @@ -142,7 +144,7 @@ Edge leave() {
}

void networkSimplexLoop() {
Edge leave, enter;
Edge leave;
int count = 0;
while ((leave = leave()) != null && count < 900) {

Expand All @@ -151,7 +153,7 @@ void networkSimplexLoop() {
Node leaveTail = getTreeTail(leave);
Node leaveHead = getTreeHead(leave);

enter = enter(leaveTail);
Edge enter = enter(leaveTail);
if (enter == null) {
break;
}
Expand Down Expand Up @@ -221,14 +223,17 @@ void repairCutValues(Edge edge) {
}
}

@SuppressWarnings("static-method")
void setTreeMax(Node n, int value) {
n.workingInts[1] = value;
}

@SuppressWarnings("static-method")
void setTreeMin(Node n, int value) {
n.workingInts[0] = value;
}

@SuppressWarnings("static-method")
boolean subtreeContains(Node parent, Node child) {
return parent.workingInts[0] <= child.workingInts[1] && child.workingInts[1] <= parent.workingInts[1];
}
Expand Down

0 comments on commit 6e92f48

Please sign in to comment.