Skip to content

Commit

Permalink
Marked all Potential Static Warnings in Draw2d and GEF Plugins (#614)
Browse files Browse the repository at this point in the history
All remaining potential static warnings in GEF related plugins where
reviewed and either resolved or flagged with a suppress warning
annotation.

Several smaller issues reported by sonar have been fixed in the touched
files as well.

Co-authored-by: Patrick Ziegler <[email protected]>
  • Loading branch information
azoitl and ptziegler authored Nov 11, 2024
1 parent 98cd019 commit 8081afe
Show file tree
Hide file tree
Showing 34 changed files with 128 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2023 Google, Inc.
* Copyright (c) 2011, 2024 Google, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -55,6 +55,7 @@ public void testState() throws Exception {
assertFalse(transposer.isEnabled());
}

@SuppressWarnings("static-method")
@Test
public void testTDimension() throws Exception {
Dimension dimension = new Dimension(100, 200);
Expand All @@ -75,6 +76,7 @@ public void testTDimension() throws Exception {
assertEquals(100, 200, dimension);
}

@SuppressWarnings("static-method")
@Test
public void testTInsets() throws Exception {
Insets insets = new Insets(1, 2, 3, 4);
Expand All @@ -95,6 +97,7 @@ public void testTInsets() throws Exception {
assertEquals(1, 2, 3, 4, insets);
}

@SuppressWarnings("static-method")
@Test
public void testTPoint() throws Exception {
Point point = new Point(100, 200);
Expand All @@ -115,6 +118,7 @@ public void testTPoint() throws Exception {
assertEquals(100, 200, point);
}

@SuppressWarnings("static-method")
@Test
public void testTRectangle() throws Exception {
Rectangle rectangle = new Rectangle(1, 2, 3, 4);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -107,17 +107,15 @@ public List<Point> getTargetAnchorLocations() {
return super.getAdapter(key);
}

protected Image getBackgroundImage(int state) {
private static Image getBackgroundImage(int state) {
if (state == SELECTED_PRIMARY) {
if (LED_SEL_PRIM_BG == null)
{
if (LED_SEL_PRIM_BG == null) {
LED_SEL_PRIM_BG = createImage("icons/ledbgprim.gif"); //$NON-NLS-1$
}
return LED_SEL_PRIM_BG;
}
if (state == SELECTED) {
if (LED_SEL_SECD_BG == null)
{
if (LED_SEL_SECD_BG == null) {
LED_SEL_SECD_BG = createImage("icons/ledbgsel.gif"); //$NON-NLS-1$
}
return LED_SEL_SECD_BG;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -137,7 +137,7 @@ public <T> T getAdapter(final Class<T> adapter) {

@Override
public DragTracker getDragTracker(Request req) {
if (req instanceof SelectionRequest && ((SelectionRequest) req).getLastButtonPressed() == 3) {
if (req instanceof SelectionRequest selReq && selReq.getLastButtonPressed() == 3) {
return new DeselectAllTracker(this);
}
return new MarqueeDragTracker();
Expand All @@ -158,6 +158,7 @@ public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart editPart) {
*
* @return ConnectionAnchor
*/
@SuppressWarnings("static-method")
public ConnectionAnchor getSourceConnectionAnchor(int x, int y) {
return null;
}
Expand All @@ -177,6 +178,7 @@ public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart editPart) {
*
* @return ConnectionAnchor
*/
@SuppressWarnings("static-method")
public ConnectionAnchor getTargetConnectionAnchor(int x, int y) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -84,7 +84,7 @@ protected IFigure createFigure(GraphicalEditPart part, IFigure parent) {
return child;
}

protected IFigure getCustomFeedbackFigure(Object modelPart) {
private static IFigure getCustomFeedbackFigure(Object modelPart) {
IFigure figure;

if (modelPart instanceof Circuit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2001, 2022 IBM Corporation and others.
* Copyright (c) 2001, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -75,6 +75,7 @@ protected Command chainGuideAttachmentCommand(Request request, LogicSubpart part
return result;
}

@SuppressWarnings("static-method")
protected Command chainGuideDetachmentCommand(Request request, LogicSubpart part, Command cmd, boolean horizontal) {
Command result = cmd;

Expand Down Expand Up @@ -189,11 +190,12 @@ protected EditPolicy createChildEditPolicy(EditPart child) {
return editPolicy;
}

@SuppressWarnings("static-method")
protected int getResizeDirections(EditPart child) {
return getResizeDirections(child.getModel().getClass());
}

private static int getResizeDirections(Class modelClass) {
private static int getResizeDirections(Class<?> modelClass) {
if (LED.class.equals(modelClass) || SimpleOutput.class.isAssignableFrom(modelClass)) {
return PositionConstants.NONE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -94,6 +94,7 @@ public boolean isPropertySet(Object propName) {
return true;
}

@SuppressWarnings("static-method")
public boolean isPropertySet(String propName) {
return (ID_HEIGHT.equals(propName) || ID_WIDTH.equals(propName));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -27,7 +27,7 @@ public abstract class LogicElement implements IPropertySource, Cloneable, Serial
public static final String INPUTS = "inputs"; //$NON-NLS-1$
public static final String OUTPUTS = "outputs"; //$NON-NLS-1$

transient protected PropertyChangeSupport listeners = new PropertyChangeSupport(this);
protected transient PropertyChangeSupport listeners = new PropertyChangeSupport(this);
static final long serialVersionUID = 1;

public void addPropertyChangeListener(PropertyChangeListener l) {
Expand Down Expand Up @@ -65,6 +65,7 @@ public Object getPropertyValue(Object propName) {
return null;
}

@SuppressWarnings("static-method")
final Object getPropertyValue(String propName) {
return null;
}
Expand All @@ -74,6 +75,7 @@ public boolean isPropertySet(Object propName) {
return isPropertySet((String) propName);
}

@SuppressWarnings("static-method")
final boolean isPropertySet(String propName) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -12,8 +12,6 @@
*******************************************************************************/
package org.eclipse.gef.examples.logicdesigner.model;

import java.io.IOException;

import org.eclipse.swt.graphics.Image;

import org.eclipse.draw2d.geometry.Dimension;
Expand All @@ -33,7 +31,6 @@ public class LogicLabel extends LogicSubpart {
private static int count;

public LogicLabel() {
super();
size.width = DEFAULT_WIDTH;
}

Expand All @@ -56,10 +53,6 @@ public Dimension getSize() {
return new Dimension(size.width, -1);
}

private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException {
s.defaultReadObject();
}

@Override
public void setSize(Dimension d) {
d.height = -1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2022 IBM Corporation and others.
* Copyright (c) 2003, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -32,8 +32,8 @@ public class LogicRuler implements Serializable {

protected PropertyChangeSupport listeners = new PropertyChangeSupport(this);
private int unit;
private boolean horizontal;
private List<LogicGuide> guides = new ArrayList<>();
private final boolean horizontal;
private final List<LogicGuide> guides = new ArrayList<>();

public LogicRuler(boolean isHorizontal) {
this(isHorizontal, RulerProvider.UNIT_PIXELS);
Expand Down Expand Up @@ -65,6 +65,7 @@ public int getUnit() {
return unit;
}

@SuppressWarnings("static-method")
public boolean isHidden() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public LogicGuide getVerticalGuide() {
/**
*
*/
@SuppressWarnings("static-method")
public boolean isPropertySet() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2023 IBM Corporation and others.
* Copyright (c) 2004, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -24,6 +24,7 @@ public class TestModelUtil extends TestCase {

static List<ModelElement> result;

@SuppressWarnings("static-method")
public void testNestedBegin() {
Container doc = new Block(Container.TYPE_ROOT);
Container branch1 = new Block(0);
Expand Down Expand Up @@ -61,6 +62,7 @@ public void testNestedBegin() {

}

@SuppressWarnings("static-method")
public void testNestedEnd() {
Container doc = new Block(Container.TYPE_ROOT);
Container branch1 = new Block(0);
Expand Down
3 changes: 2 additions & 1 deletion org.eclipse.gef/src/org/eclipse/gef/SnapToGeometry.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2023 IBM Corporation and others.
* Copyright (c) 2003, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -302,6 +302,7 @@ protected double getCorrectionFor(Entry[] entries, Map extendedData, boolean ver
* @param part the child
* @return the rectangular guide for that part
*/
@SuppressWarnings("static-method")
protected Rectangle getFigureBounds(GraphicalEditPart part) {
IFigure fig = part.getFigure();
return (fig instanceof HandleBounds hb) ? hb.getHandleBounds() : fig.getBounds();
Expand Down
8 changes: 5 additions & 3 deletions org.eclipse.gef/src/org/eclipse/gef/SnapToHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2010 IBM Corporation and others.
* Copyright (c) 2003, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -40,6 +40,7 @@ public abstract class SnapToHelper implements PositionConstants {
* @param figure the reference figure
* @param t the object to translate
*/
@SuppressWarnings("static-method")
protected void makeAbsolute(IFigure figure, Translatable t) {
figure.translateToAbsolute(t);
}
Expand All @@ -50,6 +51,7 @@ protected void makeAbsolute(IFigure figure, Translatable t) {
* @param figure the reference figure
* @param t the object to translate
*/
@SuppressWarnings("static-method")
protected void makeRelative(IFigure figure, Translatable t) {
figure.translateToRelative(t);
}
Expand Down Expand Up @@ -109,7 +111,7 @@ public int snapPoint(Request request, int snapDirections, PrecisionPoint where,
* @param result the correction will be applied to this point
* @return the remaining snap locations
*/
public int snapPoint(Request request, int snapLocations, PrecisionRectangle rects[], PrecisionPoint result) {
public int snapPoint(Request request, int snapLocations, PrecisionRectangle[] rects, PrecisionPoint result) {
PrecisionRectangle resultRect = new PrecisionRectangle();
snapLocations = snapRectangle(request, snapLocations, rects, resultRect);
result.setPreciseX(result.preciseX() + resultRect.preciseX());
Expand All @@ -132,7 +134,7 @@ public int snapPoint(Request request, int snapLocations, PrecisionRectangle rect
* @param snapOrientation the input snap locations
* @return the remaining snap locations
*/
public int snapRectangle(Request request, int snapOrientation, PrecisionRectangle baseRects[],
public int snapRectangle(Request request, int snapOrientation, PrecisionRectangle[] baseRects,
PrecisionRectangle result) {

for (int i = 0; i < baseRects.length && snapOrientation != 0; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -99,6 +99,7 @@ private EditPart calculateTargetEditPart() {
*
* @return the <code>Request</code> to be used with the <i>target</i> EditPart
*/
@SuppressWarnings("static-method")
protected Request createTargetRequest() {
return new Request();
}
Expand Down Expand Up @@ -237,8 +238,8 @@ public DropTargetEvent getCurrentEvent() {
protected Point getDropLocation() {
org.eclipse.swt.graphics.Point swt;
swt = new org.eclipse.swt.graphics.Point(getCurrentEvent().x, getCurrentEvent().y);
DropTarget target = (DropTarget) getCurrentEvent().widget;
swt = target.getControl().toControl(swt);
DropTarget curTarget = (DropTarget) getCurrentEvent().widget;
swt = curTarget.getControl().toControl(swt);
return new Point(swt.x, swt.y);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ protected IFigure getLayer(Object layer) {
*
* @return the List of model source connections
*/
@SuppressWarnings("static-method")
protected List getModelSourceConnections() {
return Collections.EMPTY_LIST;
}
Expand All @@ -512,6 +513,7 @@ protected List getModelSourceConnections() {
*
* @return the List of model target connections
*/
@SuppressWarnings("static-method")
protected List getModelTargetConnections() {
return Collections.EMPTY_LIST;
}
Expand Down
Loading

0 comments on commit 8081afe

Please sign in to comment.