Skip to content

Commit

Permalink
[NETBEANS-3145] reduce the number of redundant casts
Browse files Browse the repository at this point in the history
Trying to clean up the redundant casts the compiler is rightfully complaining about.
  • Loading branch information
BradWalker authored and matthiasblaesing committed Nov 1, 2019
1 parent c67e1b6 commit f1592df
Show file tree
Hide file tree
Showing 43 changed files with 72 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ public void setSelectedIp(final InetAddress ip) {
for (i = 0; i < count; i++) {
InetAddr element = dataModel.getElementAt(i);
// Passed IP address has highest priority.
if (((InetAddress) ip).equals(
element.getIp())) {
if (ip.equals(element.getIp())) {
super.setSelectedItem(element);
isSelectedSet = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static FileObject selectServerSEPlatform(
Iterator<FileObject> platformIterator
= selectedPlatform.getInstallFolders().iterator();
if (platformIterator.hasNext()) {
selectedJavaHome = (FileObject)platformIterator.next();
selectedJavaHome = platformIterator.next();
}
}
if (selectedJavaHome != null && panel.updateProperties()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static Map<String, String> getChangedData(Map<String, String> remoteData
if (key.indexOf("property.") != -1) { // NOI18N
props.add(key);
}
String localValue = (String) localData.get(key);
String localValue = localData.get(key);
if (localValue != null) {
if (remoteValue == null || !localValue.equals(remoteValue)) {
changedData.put(remoteDataKey, localValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void setProject(final Project project) {
// figure out which ones exist already
//
Lookup lookup = project.getLookup();
J2eeModuleProvider provider = (J2eeModuleProvider) lookup.lookup(J2eeModuleProvider.class);
J2eeModuleProvider provider = lookup.lookup(J2eeModuleProvider.class);
J2eeModule j2eeModule = provider.getJ2eeModule();
sunDDFileName = getConfigFileName(j2eeModule,
org.netbeans.modules.glassfish.eecommon.api.Utils.getInstanceReleaseID(provider));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private J2eeModuleProvider getModuleProvider(FileObject target){
J2eeModuleProvider modProvider = null;
Project holdingProj = FileOwnerQuery.getOwner(target);
if (holdingProj != null){
modProvider = (J2eeModuleProvider) holdingProj.getLookup().lookup(J2eeModuleProvider.class);
modProvider = holdingProj.getLookup().lookup(J2eeModuleProvider.class);
}
return modProvider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ private static Collection<EjbJar> getRelevantEjbModules(FileObject fo) {
J2eeModuleProvider[] j2eeModules = j2eeApp.getChildModuleProviders();

if (j2eeModules != null) {
J2eeModuleProvider affectedPrjProvider =
(J2eeModuleProvider) affectedProject.getLookup().lookup(J2eeModuleProvider.class);
J2eeModuleProvider affectedPrjProvider = affectedProject.getLookup().lookup(J2eeModuleProvider.class);

if (affectedPrjProvider != null) {
if (Arrays.asList(j2eeModules).contains(affectedPrjProvider)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,10 @@ public void connectionsChanged() {
}
};
evaluator.addPropertyChangeListener(pcl);
j2eeModuleProvider.addInstanceListener((InstanceListener)WeakListeners.create(
InstanceListener.class, il, j2eeModuleProvider));
j2eeModuleProvider.addInstanceListener(WeakListeners.create(InstanceListener.class, il, j2eeModuleProvider));
// j2eeModuleProvider.addConfigurationFilesListener((ConfigurationFilesListener)WeakListeners.create(
// ConfigurationFilesListener.class, cfl, j2eeModuleProvider));
ConnectionManager.getDefault().addConnectionListener((ConnectionListener)WeakListeners.create(
ConnectionManager.getDefault().addConnectionListener(WeakListeners.create(
ConnectionListener.class, cl, ConnectionManager.getDefault()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ private J2eePlatformNode(Project project, PropertyEvaluator evaluator, String pl
this.platformPropName = platformPropName;
evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator));

J2eeModuleProvider moduleProvider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class);
moduleProvider.addInstanceListener(
(InstanceListener)WeakListeners.create(InstanceListener.class, this, moduleProvider));
J2eeModuleProvider moduleProvider = project.getLookup().lookup(J2eeModuleProvider.class);
moduleProvider.addInstanceListener(WeakListeners.create(InstanceListener.class, this, moduleProvider));
}

public static J2eePlatformNode create(Project project, PropertyEvaluator evaluator, String platformPropName, ClassPathSupport cs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ private J2eePlatformTestNode(Project project, PropertyEvaluator evaluator, Strin
this.platformPropName = platformPropName;
evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator));

J2eeModuleProvider moduleProvider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class);
moduleProvider.addInstanceListener(
(InstanceListener)WeakListeners.create(InstanceListener.class, this, moduleProvider));
J2eeModuleProvider moduleProvider = project.getLookup().lookup(J2eeModuleProvider.class);
moduleProvider.addInstanceListener(WeakListeners.create(InstanceListener.class, this, moduleProvider));
}

public static J2eePlatformTestNode create(Project project, PropertyEvaluator evaluator, String platformPropName, ClassPathSupport cs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private void jButtonPrjLocationActionPerformed(java.awt.event.ActionEvent evt) {
chooser.setMultiSelectionEnabled(false);
chooser.setAcceptAllFileFilterUsed(false);
chooser.setDialogTitle(NbBundle.getMessage(ProjectImportLocationPanel.class, "LBL_IW_BrowseProjectFolder"));
File lastUsed = (File) UserProjectSettings.getDefault().getLastChooserLocation();
File lastUsed = UserProjectSettings.getDefault().getLastChooserLocation();
if (lastUsed != null) {
chooser.setCurrentDirectory(lastUsed.getParentFile());
} else {
Expand Down Expand Up @@ -456,7 +456,7 @@ private void jButtonSrcLocationActionPerformed(java.awt.event.ActionEvent evt) {
if (currentDirectory != null) {
chooser.setCurrentDirectory(currentDirectory);
} else {
File lastUsedImportLoc = (File) UserProjectSettings.getDefault().getLastUsedImportLocation();
File lastUsedImportLoc = UserProjectSettings.getDefault().getLastUsedImportLocation();
if (lastUsedImportLoc != null)
chooser.setCurrentDirectory(lastUsedImportLoc.getParentFile());
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void readSettings (Object settings) {
public void storeSettings (Object settings) {
WizardDescriptor d = (WizardDescriptor) settings;
panel.store(d);
((WizardDescriptor) d).putProperty ("NewProjectWizard_Title", null); //NOI18N
d.putProperty("NewProjectWizard_Title", null); //NOI18N
}

public String getBuildFile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ public void readSettings(Object settings) {
public void storeSettings(Object settings) {
WizardDescriptor d = (WizardDescriptor) settings;
component.store(d);
((WizardDescriptor) d).putProperty("NewProjectWizard_Title", null); // NOI18N
d.putProperty("NewProjectWizard_Title", null); // NOI18N
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private static String getHtml(String text) {
FontColorSettings settings = lookup.lookup(FontColorSettings.class);
TokenSequence tok = tokenH.tokenSequence();
while (tok.moveNext()) {
Token<GroovyTokenId> token = (Token) tok.token();
Token<GroovyTokenId> token = tok.token();
String category = token.id().primaryCategory();
if (category == null) {
category = "whitespace"; //NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void visitPropertyExpression(PropertyExpression expression) {

@Override
public void visitVariableExpression(VariableExpression expression) {
final VariableExpression variableExpression = ((VariableExpression) expression);
final VariableExpression variableExpression = expression;
final Variable variable = variableExpression.getAccessedVariable();

if (variable != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,14 @@ public boolean contains(String text, boolean removeCompared) {
synchronized (this) {
if(removeCompared) {
while(!statusTextHistory.isEmpty()) {
String status = (String)statusTextHistory.remove(0);
String status = statusTextHistory.remove(0);
if(comparator.equals(status, text)) {
return true;
}
}
} else {
for (int i = 0; i < statusTextHistory.size(); i ++) {
if(comparator.equals((String)statusTextHistory.get(i), text)) {
if(comparator.equals(statusTextHistory.get(i), text)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ public String getDescription() {
public void pushMenuOnTab(String popupPath) {
if (isOpened()) {
this.makeComponentVisible();
TabbedContainer ta = (TabbedContainer) findTabbedAdapter();
TabbedContainer ta = findTabbedAdapter();

int index = ta.indexOf((TopComponent) getSource());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ public boolean cancel() {
public void run() {
handle.start();
try {
openIssue((BugzillaIssue)repository.getIssue(id));
openIssue(repository.getIssue(id));
} finally {
handle.finish();
}
Expand Down Expand Up @@ -828,7 +828,7 @@ private void onMarkSeen() {
public void run() {
Collection<BugzillaIssue> issues = query.getIssues();
for (BugzillaIssue issue : issues) {
((BugzillaIssue) issue).setUpToDate(true);
issue.setUpToDate(true);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ public void run() {
Collection<BugzillaQuery> qs = getQueries();
for (BugzillaQuery q : qs) {
Bugzilla.LOG.log(Level.FINER, "preparing to refresh query {0} - {1}", new Object[] {q.getDisplayName(), getDisplayName()}); // NOI18N
QueryController qc = ((BugzillaQuery) q).getController();
QueryController qc = q.getController();
qc.onRefresh();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class EncodingHelper extends Object {
* @return
*/
public static String getIANA2JavaMapping(String ianaEncoding) {
String java = (String) encodingIANA2JavaMap.get (ianaEncoding.toUpperCase ());
String java = encodingIANA2JavaMap.get (ianaEncoding.toUpperCase ());
return java == null ? ianaEncoding : java;
}

Expand All @@ -59,7 +59,7 @@ public static String getIANA2JavaMapping(String ianaEncoding) {
* @return
*/
public static String getJava2IANAMapping(String javaEncoding) {
String iana = (String) encodingJava2IANAMap.get (javaEncoding);
String iana = encodingJava2IANAMap.get (javaEncoding);
return iana == null ? javaEncoding : iana;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private void fireMatchesHighlighted(Position[] origin, Position[] matches, Brace
if (matchListeners.isEmpty()) {
return;
}
ll = (MatchListener[]) matchListeners.toArray(new MatchListener[matchListeners.size()]);
ll = matchListeners.toArray(new MatchListener[matchListeners.size()]);
}
if (ll.length == 0) {
return;
Expand All @@ -356,7 +356,7 @@ private void fireMatchCleared() {
if (matchListeners.isEmpty()) {
return;
}
ll = (MatchListener[]) matchListeners.toArray(new MatchListener[matchListeners.size()]);
ll = matchListeners.toArray(new MatchListener[matchListeners.size()]);
}
MatchEvent evt = new MatchEvent(component, null, this);
for (int i = 0; i < ll.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private void parseParameterContent(String parametrizedText) {
}

// Determine default parameter's value
String defaultValue = (String)getHints().get(CodeTemplateParameter.DEFAULT_VALUE_HINT_NAME);
String defaultValue = getHints().get(CodeTemplateParameter.DEFAULT_VALUE_HINT_NAME);
if (defaultValue == null) { // implicit value will be name of the parameter
defaultValue = name;
}
Expand Down Expand Up @@ -369,7 +369,7 @@ private void parseParameterContent(String parametrizedText) {
}

private boolean isHintValueFalse(String hintName) {
String hintValue = (String)getHints().get(hintName);
String hintValue = getHints().get(hintName);
return (hintValue != null) && "false".equals(hintValue.toLowerCase()); // NOI18N
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected static RenderedImage transformImage(RenderedImage image,
AffineTransform af = new AffineTransform();
if( pf.getOrientation() == pf.LANDSCAPE ){
}else{
af.translate( (double)pf.getImageableX(), (double)pf.getImageableY() );
af.translate(pf.getImageableX(), pf.getImageableY());
}

/** notify if too big for page **/
Expand Down
8 changes: 4 additions & 4 deletions ide/image/src/org/netbeans/modules/image/ImageViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ private boolean discard () {
}

protected boolean closeLast() {
((ImageOpenSupport)storedObject.getCookie(ImageOpenSupport.class)).lastClosed();
(storedObject.getCookie(ImageOpenSupport.class)).lastClosed();
return true;
}

Expand All @@ -625,7 +625,7 @@ public void readExternal (ObjectInput in)
super.readExternal(in);
storedObject = (ImageDataObject)in.readObject();
// to reset the listener for FileObject changes
((ImageOpenSupport)storedObject.getCookie(ImageOpenSupport.class)).prepareViewer();
(storedObject.getCookie(ImageOpenSupport.class)).prepareViewer();
initialize(storedObject);
}

Expand All @@ -639,7 +639,7 @@ public SystemAction[] getSystemActions() {
SystemAction[] oldValue = super.getSystemActions();
SystemAction fsa = null;
try {
ClassLoader l = (ClassLoader) Lookup.getDefault().lookup(ClassLoader.class);
ClassLoader l = Lookup.getDefault().lookup(ClassLoader.class);
if (l == null) {
l = getClass().getClassLoader();
}
Expand Down Expand Up @@ -772,7 +772,7 @@ private JButton getZoomButton() {
button.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_Zoom_BTN"));
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
CustomZoomAction sa = (CustomZoomAction) SystemAction.get(CustomZoomAction.class);
CustomZoomAction sa = SystemAction.get(CustomZoomAction.class);
sa.performAction ();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void actionPerformed (ActionEvent ev) {
Iterator<Node> it = nodes2open.iterator();
while (it.hasNext ()) {
Node n = (Node) it.next ();
ViewCookie vc = (ViewCookie) n.getLookup ().lookup (ViewCookie.class);
ViewCookie vc = n.getLookup().lookup(ViewCookie.class);
if (vc != null) {
vc.view();
} else {
Expand All @@ -127,7 +127,7 @@ public void propertyChange (java.beans.PropertyChangeEvent evt) {
Node n = nodes [i];
// EditCookie ec = (EditCookie) n.getLookup ().lookup (EditCookie.class);
// OpenCookie oc = (OpenCookie) n.getLookup ().lookup (OpenCookie.class);
ViewCookie vc = (ViewCookie) n.getLookup ().lookup (ViewCookie.class);
ViewCookie vc = n.getLookup().lookup(ViewCookie.class);
res = vc != null; //ec != null || oc != null;

i++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static void mountCatalog(Node[] activatedNodes) {
if (activatedNodes.length == 0) return;
try {
Node current = activatedNodes[0];
CatalogRootNode me = (CatalogRootNode) current.getCookie(CatalogRootNode.class);
CatalogRootNode me = current.getCookie(CatalogRootNode.class);
CatalogMounter newType = me.new CatalogMounter();
newType.create();
} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected void performAction (Node[] nodes) {
for (int i = 0; i<nodes.length; i++) {
String msg = NbBundle.getMessage(RefreshAction.class, "MSG_refreshing", nodes[i].getDisplayName());
StatusDisplayer.getDefault().setStatusText(msg);
Refreshable cake = (Refreshable) nodes[i].getCookie(Refreshable.class);
Refreshable cake = nodes[i].getCookie(Refreshable.class);
cake.refresh();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static String getProjectEncoding(FileObject file) {
* @return
*/
public static String getIANA2JavaMapping(String ianaEncoding) {
String java = (String) encodingIANA2JavaMap.get (ianaEncoding.toUpperCase ());
String java = encodingIANA2JavaMap.get (ianaEncoding.toUpperCase ());
return java == null ? ianaEncoding : java;
}

Expand All @@ -130,7 +130,7 @@ public static String getIANA2JavaMapping(String ianaEncoding) {
* @return
*/
public static String getJava2IANAMapping(String javaEncoding) {
String iana = (String) encodingJava2IANAMap.get (javaEncoding);
String iana = encodingJava2IANAMap.get (javaEncoding);
return iana == null ? javaEncoding : iana;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class EncodingHelper extends Object {
* @return
*/
public static String getIANA2JavaMapping(String ianaEncoding) {
String java = (String) encodingIANA2JavaMap.get (ianaEncoding.toUpperCase ());
String java = encodingIANA2JavaMap.get (ianaEncoding.toUpperCase ());
return java == null ? ianaEncoding : java;
}

Expand All @@ -57,7 +57,7 @@ public static String getIANA2JavaMapping(String ianaEncoding) {
* @return
*/
public static String getJava2IANAMapping(String javaEncoding) {
String iana = (String) encodingJava2IANAMap.get (javaEncoding);
String iana = encodingJava2IANAMap.get (javaEncoding);
return iana == null ? javaEncoding : iana;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected boolean enable( Node[] activatedNodes ) {
return false;

for(int i = 0; i < activatedNodes.length; i++ ) {
BiNode.SubNode bis = ((BiNode.SubNode)activatedNodes[i].getCookie( BiNode.SubNode.class ));
BiNode.SubNode bis = activatedNodes[i].getCookie( BiNode.SubNode.class );
if ( bis == null )
return false;
Node[] nodes = bis.getChildren().getNodes();
Expand Down Expand Up @@ -102,7 +102,7 @@ public void performAction ( Node[] nodes ) {

for(int i = 0; i < nodes.length; i++ ) {
if( nodes[i].getCookie( BiNode.SubNode.class ) != null )
((BiNode.SubNode)nodes[i].getCookie( BiNode.SubNode.class )).includeAll( false );
nodes[i].getCookie( BiNode.SubNode.class ).includeAll( false );
}

}
Expand Down
Loading

0 comments on commit f1592df

Please sign in to comment.