Skip to content

Commit

Permalink
Removed Unnecessary Casts #155
Browse files Browse the repository at this point in the history
With the improved typing in several places casts could be removed.
Making code better readable and cleaner.

Addresses: #155
  • Loading branch information
azoitl authored and ptziegler committed Sep 30, 2024
1 parent 16561f1 commit 9c5c845
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void layout(IFigure container) {
currentXY.x += shiftRight;
Point correction = transposer.t(new Point(shiftRight, 0));
for (int j = 0; j <= i; j++) {
((IFigure) subtrees.get(j)).translate(correction.x, correction.y);
subtrees.get(j).translate(correction.x, correction.y);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ protected void createEditPolicies() {

@Override
protected IFigure createFigure() {
LabelFigure label = new LabelFigure();
return label;
return new LabelFigure();
}

private LogicLabel getLogicLabel() {
Expand All @@ -78,7 +77,7 @@ public void performRequest(Request request) {
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equalsIgnoreCase("labelContents")) { //$NON-NLS-1$
refreshVisuals();
} else { //$NON-NLS-1$
} else {
super.propertyChange(evt);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.gef.requests.GroupRequest;

import org.eclipse.gef.examples.shapes.model.Connection;
import org.eclipse.gef.examples.shapes.model.ModelElement;
import org.eclipse.gef.examples.shapes.model.commands.ConnectionDeleteCommand;

/**
Expand All @@ -48,7 +47,7 @@ class ConnectionEditPart extends AbstractConnectionEditPart implements PropertyC
public void activate() {
if (!isActive()) {
super.activate();
((ModelElement) getModel()).addPropertyChangeListener(this);
getModel().addPropertyChangeListener(this);
}
}

Expand Down Expand Up @@ -96,7 +95,7 @@ protected IFigure createFigure() {
public void deactivate() {
if (isActive()) {
super.deactivate();
((ModelElement) getModel()).removePropertyChangeListener(this);
getModel().removePropertyChangeListener(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.eclipse.gef.requests.CreateRequest;

import org.eclipse.gef.examples.shapes.model.EllipticalShape;
import org.eclipse.gef.examples.shapes.model.ModelElement;
import org.eclipse.gef.examples.shapes.model.RectangularShape;
import org.eclipse.gef.examples.shapes.model.Shape;
import org.eclipse.gef.examples.shapes.model.ShapesDiagram;
Expand Down Expand Up @@ -67,7 +66,7 @@ class DiagramEditPart extends AbstractGraphicalEditPart implements PropertyChang
public void activate() {
if (!isActive()) {
super.activate();
((ModelElement) getModel()).addPropertyChangeListener(this);
getModel().addPropertyChangeListener(this);
}
}

Expand Down Expand Up @@ -112,7 +111,7 @@ protected IFigure createFigure() {
public void deactivate() {
if (isActive()) {
super.deactivate();
((ModelElement) getModel()).removePropertyChangeListener(this);
getModel().removePropertyChangeListener(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.gef.editparts.AbstractTreeEditPart;
import org.eclipse.gef.editpolicies.RootComponentEditPolicy;

import org.eclipse.gef.examples.shapes.model.ModelElement;
import org.eclipse.gef.examples.shapes.model.Shape;
import org.eclipse.gef.examples.shapes.model.ShapesDiagram;

Expand Down Expand Up @@ -54,7 +53,7 @@ class DiagramTreeEditPart extends AbstractTreeEditPart implements PropertyChange
public void activate() {
if (!isActive()) {
super.activate();
((ModelElement) getModel()).addPropertyChangeListener(this);
getModel().addPropertyChangeListener(this);
}
}

Expand All @@ -81,7 +80,7 @@ protected void createEditPolicies() {
public void deactivate() {
if (isActive()) {
super.deactivate();
((ModelElement) getModel()).removePropertyChangeListener(this);
getModel().removePropertyChangeListener(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import org.eclipse.gef.examples.shapes.model.Connection;
import org.eclipse.gef.examples.shapes.model.EllipticalShape;
import org.eclipse.gef.examples.shapes.model.ModelElement;
import org.eclipse.gef.examples.shapes.model.RectangularShape;
import org.eclipse.gef.examples.shapes.model.Shape;
import org.eclipse.gef.examples.shapes.model.commands.ConnectionCreateCommand;
Expand All @@ -65,7 +64,7 @@ class ShapeEditPart extends AbstractGraphicalEditPart implements PropertyChangeL
public void activate() {
if (!isActive()) {
super.activate();
((ModelElement) getModel()).addPropertyChangeListener(this);
getModel().addPropertyChangeListener(this);
}
}

Expand Down Expand Up @@ -178,7 +177,7 @@ private IFigure createFigureForModel() {
public void deactivate() {
if (isActive()) {
super.deactivate();
((ModelElement) getModel()).removePropertyChangeListener(this);
getModel().removePropertyChangeListener(this);
}
}

Expand Down Expand Up @@ -278,12 +277,19 @@ public ConnectionAnchor getTargetConnectionAnchor(Request request) {
@Override
public void propertyChange(PropertyChangeEvent evt) {
String prop = evt.getPropertyName();
if (Shape.SIZE_PROP.equals(prop) || Shape.LOCATION_PROP.equals(prop)) {
switch (prop) {
case Shape.SIZE_PROP:
case Shape.LOCATION_PROP:
refreshVisuals();
} else if (Shape.SOURCE_CONNECTIONS_PROP.equals(prop)) {
break;
case Shape.SOURCE_CONNECTIONS_PROP:
refreshSourceConnections();
} else if (Shape.TARGET_CONNECTIONS_PROP.equals(prop)) {
break;
case Shape.TARGET_CONNECTIONS_PROP:
refreshTargetConnections();
break;
default:
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

package org.eclipse.gef.examples.text.edit;

import java.util.Iterator;

import org.eclipse.gef.EditPart;

import org.eclipse.gef.examples.text.SelectionRange;
Expand Down Expand Up @@ -65,56 +63,59 @@ public Object getStyleState(String styleID, SelectionRange range) {

@Override
public Object getStyleValue(String styleID, SelectionRange range) {
if (styleID.equals(Style.PROPERTY_BOLD)) {
for (Iterator<EditPart> iter = range.getLeafParts().iterator(); iter.hasNext();) {
TextRun run = (TextRun) ((TextEditPart) iter.next()).getModel();
switch (styleID) {
case Style.PROPERTY_BOLD:
for (EditPart ep : range.getLeafParts()) {
TextRun run = (TextRun) ep.getModel();
if (!run.getContainer().getStyle().isBold()) {
return Boolean.FALSE;
}
}
return Boolean.TRUE;
} else if (styleID.equals(Style.PROPERTY_FONT_SIZE)) {
case Style.PROPERTY_FONT_SIZE: {
int fontHeight = -1;
for (Iterator<EditPart> iter = range.getLeafParts().iterator(); iter.hasNext();) {
TextRun run = (TextRun) ((TextEditPart) iter.next()).getModel();
for (EditPart editPart : range.getLeafParts()) {
TextRun run = (TextRun) editPart.getModel();
if (fontHeight == -1) {
fontHeight = run.getContainer().getStyle().getFontHeight();
} else if (fontHeight != run.getContainer().getStyle().getFontHeight()) {
return StyleService.UNDEFINED;
}
}
return Integer.valueOf(fontHeight);
} else if (styleID.equals(Style.PROPERTY_FONT)) {
}
case Style.PROPERTY_FONT: {
String fontName = null;
for (Iterator<EditPart> iter = range.getLeafParts().iterator(); iter.hasNext();) {
TextRun run = (TextRun) ((TextEditPart) iter.next()).getModel();
for (EditPart editPart : range.getLeafParts()) {
TextRun run = (TextRun) editPart.getModel();
if (fontName == null) {
fontName = run.getContainer().getStyle().getFontFamily();
} else if (!fontName.equals(run.getContainer().getStyle().getFontFamily())) {
return StyleService.UNDEFINED;
}
}
return fontName;
} else if (styleID.equals(Style.PROPERTY_ITALIC)) {
for (Iterator<EditPart> iter = range.getLeafParts().iterator(); iter.hasNext();) {
TextRun run = (TextRun) ((TextEditPart) iter.next()).getModel();
}
case Style.PROPERTY_ITALIC:
for (EditPart editPart : range.getLeafParts()) {
TextRun run = (TextRun) editPart.getModel();
if (!run.getContainer().getStyle().isItalic()) {
return Boolean.FALSE;
}
}
return Boolean.TRUE;
} else if (styleID.equals(Style.PROPERTY_UNDERLINE)) {
for (Iterator<?> iter = range.getLeafParts().iterator(); iter.hasNext();) {
TextRun run = (TextRun) ((TextEditPart) iter.next()).getModel();
case Style.PROPERTY_UNDERLINE:
for (EditPart name : range.getLeafParts()) {
TextRun run = (TextRun) name.getModel();
if (!run.getContainer().getStyle().isUnderline()) {
return Boolean.FALSE;
}
}
return Boolean.TRUE;
} else if (Style.PROPERTY_ALIGNMENT.equals(styleID)) {
case Style.PROPERTY_ALIGNMENT: {
int alignment = 0;
for (Iterator<EditPart> iter = range.getLeafParts().iterator(); iter.hasNext();) {
TextRun run = (TextRun) ((TextEditPart) iter.next()).getModel();
for (EditPart editPart : range.getLeafParts()) {
TextRun run = (TextRun) editPart.getModel();
Style style = run.getBlockContainer().getStyle();
if (alignment == 0) {
alignment = style.getAlignment();
Expand All @@ -124,10 +125,11 @@ public Object getStyleValue(String styleID, SelectionRange range) {
}
}
return Integer.valueOf(alignment);
} else if (Style.PROPERTY_ORIENTATION.equals(styleID)) {
}
case Style.PROPERTY_ORIENTATION: {
int orientation = 0;
for (Iterator<EditPart> iter = range.getLeafParts().iterator(); iter.hasNext();) {
TextRun run = (TextRun) ((TextEditPart) iter.next()).getModel();
for (EditPart editPart : range.getLeafParts()) {
TextRun run = (TextRun) editPart.getModel();
Style style = run.getBlockContainer().getStyle();
if (orientation == 0) {
orientation = style.getOrientation();
Expand All @@ -138,6 +140,9 @@ public Object getStyleValue(String styleID, SelectionRange range) {
}
return Integer.valueOf(orientation);
}
default:
break;
}
return StyleService.UNDEFINED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ protected void refreshTargetConnections() {
for (i = 0; i < modelObjects.size(); i++) {
Object model = modelObjects.get(i);

if (i < targetConns.size() && ((EditPart) targetConns.get(i)).getModel() == model) {
if (i < targetConns.size() && targetConns.get(i).getModel() == model) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public Point computeSize(int wHint, int hHint, boolean changed) {
ToolItem[] items = tbMgr.getControl().getItems();
for (int i = 0; i < items.length; i++) {
ToolItem item = items[i];
item.setText(((IAction) actions.get(i)).getText());
item.setText(actions.get(i).getText());
}

return tbMgr.getControl();
Expand Down

0 comments on commit 9c5c845

Please sign in to comment.