Skip to content

Commit

Permalink
Cleanup redundant cast warnings..
Browse files Browse the repository at this point in the history
As a result of much of the warning cleanup work I've done over the past couple of years, the redundant cast warnings start happening more fequently.

   [repeat] /home/bwalker/src/netbeans/platform/core.multitabs/src/org/netbeans/core/multitabs/impl/ButtonPopupSwitcher.java:344: warning: [cast] redundant cast to Item
   [repeat]                 final Item item = ( Item ) pTable.getSelectedItem();
   [repeat]                                   ^

This works reduces those warnings. This will need to be an ongoing process.
  • Loading branch information
BradWalker authored May 27, 2023
1 parent b75d913 commit 711207c
Show file tree
Hide file tree
Showing 67 changed files with 133 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected final void scanJarForPublicClassNames(Set<String> result, File jar) th
try {
Enumeration<JarEntry> entries = jf.entries();
ENTRY: while (entries.hasMoreElements()) {
JarEntry entry = (JarEntry) entries.nextElement();
JarEntry entry = entries.nextElement();
String path = entry.getName();
if (!path.endsWith(".class")) { // NOI18N
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public HashMap<String,Map> getSunDatasourcesFromXml(){

private Map<String,String> getPoolValues(Map<String, Node> cpMap, String poolName) {
Map<String,String> pValues = new HashMap<>();
Node cpNode = (Node) cpMap.get(poolName);
Node cpNode = cpMap.get(poolName);
NamedNodeMap cpAttrMap = cpNode.getAttributes();
Node dsClassName = cpAttrMap.getNamedItem(CONST_DS_CLASS);
Node resType = cpAttrMap.getNamedItem(CONST_RES_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ public Enumeration enabled(GrammarEnvironment ctx) {
if (ctx.getFileObject() == null) return null;
Enumeration<Node> en = ctx.getDocumentChildren();
while (en.hasMoreElements()) {
Node next = (Node) en.nextElement();
Node next = en.nextElement();
if (next.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
return null; // null for web.xml specified by DTD
} else if (next.getNodeType() == Node.ELEMENT_NODE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static <T> T containsClass(@NonNull Collection<File> classpath, @NonNull
try {
Enumeration<JarEntry> entries = jf.entries();
while (entries.hasMoreElements()) {
JarEntry entry = (JarEntry) entries.nextElement();
JarEntry entry = entries.nextElement();
if (classFilePathFirst.equals(entry.getName())) {
return tokenFirst;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private WebAppProxy getFromCache(FileObject fo) throws IOException {
if (wr == null) {
return null;
}
WebAppProxy webApp = (WebAppProxy) wr.get();
WebAppProxy webApp = wr.get();
if (webApp == null) {
ddMap.remove(fo.toURL());
}
Expand All @@ -205,7 +205,7 @@ private WebApp getOriginalFromCache(FileObject fo) throws IOException {
if (wr == null) {
return null;
}
WebApp webApp = (WebApp) wr.get();
WebApp webApp = wr.get();
if (webApp == null) {
baseBeanMap.remove(fo.toURL());
errorMap.remove(fo.toURL());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public void actionPerformed (ActionEvent e) {
else if (options[1].equals (e.getSource ())) {
Enumeration<DDChangeEvent> en = connectionPanel.listModel.elements ();
while (en.hasMoreElements ()) {
processDDChangeEvent ((DDChangeEvent)en.nextElement ());
processDDChangeEvent(en.nextElement());
}
confirmChangesDialog[0].setVisible (false);
connectionPanel.setChanges (null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public void actionPerformed(ActionEvent e) {
} else if (options[1].equals(e.getSource())) {
Enumeration<DDChangeEvent> en = connectionPanel.listModel.elements();
while (en.hasMoreElements()) {
processDDChangeEvent((DDChangeEvent)en.nextElement());
processDDChangeEvent(en.nextElement());
}
confirmChangesDialog[0].setVisible(false);
connectionPanel.setChanges(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ private boolean fireEvent(String oldResourceName, String resourceName, int event
}

public EntityHelper getEntityHelper(Entity entity) {
EntityHelper entityHelper = (EntityHelper) entityHelperMap.get(entity);
EntityHelper entityHelper = entityHelperMap.get(entity);
if (entityHelper == null) {
entityHelper = new EntityHelper(this, entity);
entityHelperMap.put(entity, entityHelper);
Expand All @@ -770,7 +770,7 @@ public EntityHelper getEntityHelper(Entity entity) {
}

public SessionHelper getSessionHelper(Session session) {
SessionHelper sessionHelper = (SessionHelper) sessionHelperMap.get(session);
SessionHelper sessionHelper = sessionHelperMap.get(session);
if (sessionHelper == null) {
sessionHelper = new SessionHelper(this, session);
sessionHelperMap.put(session, sessionHelper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ public int getCmpFieldCount() {

public CmpFieldHelper getCmpFieldHelper(int row) {
CmpField field = getCmpField(row);
CmpFieldHelper cmpFieldHelper = (CmpFieldHelper) cmpFieldHelperMap.get(field);
CmpFieldHelper cmpFieldHelper = cmpFieldHelperMap.get(field);
if (cmpFieldHelper == null) {
cmpFieldHelper = createCmpFieldHelper(field);
}
return cmpFieldHelper;
}

private CmpFieldHelper getCmpFieldHelper(String fieldName) {
CmpFieldHelper cmpFieldHelper = (CmpFieldHelper) cmpFieldHelperMap.get(fieldName);
CmpFieldHelper cmpFieldHelper = cmpFieldHelperMap.get(fieldName);
if (cmpFieldHelper == null) {
CmpField[] cmpFields = entity.getCmpField();
for (int i = 0; i < cmpFields.length; i++) {
Expand Down Expand Up @@ -197,7 +197,7 @@ public void change(Object source, String propertyName, Object oldValue, Object n

protected void firePropertyChange(PropertyChangeEvent evt) {
for (Iterator<PropertyChangeListener> iterator = listeners.iterator(); iterator.hasNext();) {
((PropertyChangeListener) iterator.next()).propertyChange(evt);
iterator.next().propertyChange(evt);
}
}

Expand Down Expand Up @@ -258,13 +258,13 @@ private Query[] getQueries(String s) {
Query query = queries[i];
if (query.getQueryMethod().getMethodName().startsWith(s)) {
list.add(query);
final QueryMethodHelper helper = (QueryMethodHelper) queryMethodHelperMap.get(query);
final QueryMethodHelper helper = queryMethodHelperMap.get(query);
if (helper != null) {
helper.init();
}
}
}
return (Query[]) list.toArray(new Query[0]);
return list.toArray(new Query[0]);
}

public int getFinderMethodCount() {
Expand Down Expand Up @@ -303,7 +303,7 @@ public void removePropertyChangeListener(PropertyChangeListener listener) {

protected void firePropertyChange(PropertyChangeEvent evt) {
for (Iterator<PropertyChangeListener> iterator = listeners.iterator(); iterator.hasNext();) {
((PropertyChangeListener) iterator.next()).propertyChange(evt);
iterator.next().propertyChange(evt);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static final SourceFileMap findSourceMap(FileObject source) {
Project owner = FileOwnerQuery.getOwner(source);
if (owner != null) {
Lookup l = owner.getLookup();
J2eeModuleProvider projectModule = (J2eeModuleProvider) l.lookup(J2eeModuleProvider.class);
J2eeModuleProvider projectModule = l.lookup(J2eeModuleProvider.class);
if (projectModule != null) {
return projectModule.getSourceFileMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class Server implements Node.Cookie {
return;
}
DataObject dobj = DataObject.find(factoryinstance);
InstanceCookie cookie = (InstanceCookie) dobj.getCookie(InstanceCookie.class);
InstanceCookie cookie = dobj.getCookie(InstanceCookie.class);
if (cookie == null) {
String msg = NbBundle.getMessage(Server.class, "MSG_FactoryFailed", name);
LOGGER.log(Level.SEVERE, msg);
Expand Down Expand Up @@ -206,7 +206,7 @@ public synchronized RegistryNodeProvider getNodeProvider() {
return nodeProvider;
}

RegistryNodeFactory nodeFact = (RegistryNodeFactory) lkp.lookup(RegistryNodeFactory.class);
RegistryNodeFactory nodeFact = lkp.lookup(RegistryNodeFactory.class);
if (nodeFact == null) {
String msg = NbBundle.getMessage(Server.class, "MSG_NoInstance", name, RegistryNodeFactory.class);
LOGGER.log(Level.INFO, msg);
Expand All @@ -216,19 +216,18 @@ public synchronized RegistryNodeProvider getNodeProvider() {
}

public RegistryNodeFactory getRegistryNodeFactory() {
return (RegistryNodeFactory) lkp.lookup(RegistryNodeFactory.class);
return lkp.lookup(RegistryNodeFactory.class);
}

/** returns OptionalDeploymentManagerFactory or null it is not provided by the plugin */
public OptionalDeploymentManagerFactory getOptionalFactory () {
OptionalDeploymentManagerFactory o = (OptionalDeploymentManagerFactory)
lkp.lookup(OptionalDeploymentManagerFactory.class);
OptionalDeploymentManagerFactory o = lkp.lookup(OptionalDeploymentManagerFactory.class);
return o;
}

/** returns J2eePlatformFactory or null if it is not provided by the plugin */
public J2eePlatformFactory getJ2eePlatformFactory () {
J2eePlatformFactory o = (J2eePlatformFactory) lkp.lookup(J2eePlatformFactory.class);
J2eePlatformFactory o = lkp.lookup(J2eePlatformFactory.class);
return o;
}

Expand All @@ -237,7 +236,7 @@ public ModuleConfigurationFactory getModuleConfigurationFactory() {
}

public VerifierSupport getVerifierSupport() {
VerifierSupport vs = (VerifierSupport) lkp.lookup(VerifierSupport.class);
VerifierSupport vs = lkp.lookup(VerifierSupport.class);
return vs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public JavaPlatform getJavaPlatform() {
JavaPlatformManager jpm = JavaPlatformManager.getDefault();
JavaPlatform[] installedPlatforms = jpm.getPlatforms(null, new Specification("J2SE", null)); // NOI18N
for (int i = 0; i < installedPlatforms.length; i++) {
String platformName = (String)installedPlatforms[i].getProperties().get(PLAT_PROP_ANT_NAME);
String platformName = installedPlatforms[i].getProperties().get(PLAT_PROP_ANT_NAME);
if (platformName != null && platformName.equals(currentJvm)) {
return installedPlatforms[i];
}
Expand All @@ -404,7 +404,7 @@ public JavaPlatform getJavaPlatform() {
}

public void setJavaPlatform(JavaPlatform javaPlatform) {
ip.setProperty(PROP_JAVA_PLATFORM, (String)javaPlatform.getProperties().get(PLAT_PROP_ANT_NAME));
ip.setProperty(PROP_JAVA_PLATFORM, javaPlatform.getProperties().get(PLAT_PROP_ANT_NAME));
}

public String getJavaOpts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected void drawStringToGraphics(Graphics g, String s, Font font, boolean str
}

protected int getWidth(String s) {
Integer i = (Integer)widths.get(s);
Integer i = widths.get(s);
if (i != null) {
return i;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static void putFolder(String folderType, AntProjectHelper helper, List<S
} else {
List<Element> l = XMLUtil.findSubElements(foldersEl);
for (int i = 0; i < l.size(); i++) {
Element e = (Element) l.get(i);
Element e = l.get(i);
Element te = XMLUtil.findElement(e, "type", Util.NAMESPACE);
if (te != null && XMLUtil.findText(te).equals(folderType)) {
foldersEl.removeChild(e);
Expand All @@ -108,7 +108,7 @@ private static void putFolder(String folderType, AntProjectHelper helper, List<S
} else {
List<Element> l = XMLUtil.findSubElements(itemsEl);
for (int i = 0; i < l.size(); i++) {
Element e = (Element) l.get(i);
Element e = l.get(i);
if (e.hasAttribute("style")) {
if (e.getAttribute("style").equals("tree")) {
// #110173
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public File getPersistenceXmlDirAsFile() {
}

public ClassPathProvider getClassPathProvider () {
return (ClassPathProvider) project.getLookup ().lookup (ClassPathProvider.class);
return project.getLookup().lookup(ClassPathProvider.class);
}

public FileObject getArchive () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void saveUpdate(EditableProperties props) throws IOException {
ReferenceHelper refHelper = new ReferenceHelper(helper, cfg, helper.getStandardPropertyEvaluator());
ClassPathSupport cs = new ClassPathSupport(helper.getStandardPropertyEvaluator(), refHelper, helper,
updateHelper, new ClassPathSupportCallbackImpl(helper));
Iterator<ClassPathSupport.Item> items = cs.itemsIterator((String)props.get( ProjectProperties.JAVAC_CLASSPATH ), ClassPathSupportCallbackImpl.TAG_WEB_MODULE_LIBRARIES);
Iterator<ClassPathSupport.Item> items = cs.itemsIterator(props.get( ProjectProperties.JAVAC_CLASSPATH ), ClassPathSupportCallbackImpl.TAG_WEB_MODULE_LIBRARIES);
ArrayList<ClassPathSupport.Item> cpItems = new ArrayList<ClassPathSupport.Item>();
while(items.hasNext()) {
ClassPathSupport.Item cpti = items.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private static JavaPlatform findJavaPlatform(String platformName, String specFil
JavaPlatform[] platforms = JavaPlatformManager.getDefault().getInstalledPlatforms();
for(int i = 0; i < platforms.length; i++) {
JavaPlatform platform = platforms[i];
String antName = (String)platform.getProperties().get(PLATFORM_ANT_NAME);
String antName = platform.getProperties().get(PLATFORM_ANT_NAME);
if (antName != null && antName.equals(platformName)) {
if(specFilter == null || specFilter.equalsIgnoreCase(platform.getSpecification().getName())) {
return platform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public FileObject createLocation() throws IOException {
public PersistenceScope findPersistenceScope(FileObject fo) {
Project proj = FileOwnerQuery.getOwner(fo);
if (proj != null) {
WebPersistenceProvider provider = (WebPersistenceProvider) proj.getLookup().lookup(WebPersistenceProvider.class);
WebPersistenceProvider provider = proj.getLookup().lookup(WebPersistenceProvider.class);
return provider.getPersistenceScope();
}
return null;
Expand All @@ -138,7 +138,7 @@ public PersistenceScope findPersistenceScope(FileObject fo) {
public EntityClassScope findEntityClassScope(FileObject fo) {
Project proj = FileOwnerQuery.getOwner(fo);
if (proj != null) {
WebPersistenceProvider provider = (WebPersistenceProvider) proj.getLookup().lookup(WebPersistenceProvider.class);
WebPersistenceProvider provider = proj.getLookup().lookup(WebPersistenceProvider.class);
return provider.getEntityClassScope();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ final class ProjectOpenedHookImpl extends ProjectOpenedHook {
protected void projectOpened() {
evaluator().addPropertyChangeListener(WebProject.this.webModule);

WebLogicalViewProvider logicalViewProvider = (WebLogicalViewProvider) WebProject.this.getLookup().lookup (WebLogicalViewProvider.class);
WebLogicalViewProvider logicalViewProvider = WebProject.this.getLookup().lookup(WebLogicalViewProvider.class);
if (logicalViewProvider != null) {
logicalViewProvider.initialize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ public void run() {
AntProjectHelper helper = project.getAntProjectHelper();
EditableProperties projectProps = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);

String warName = (String) projectProps.get(WebProjectProperties.WAR_NAME);
String warEarName = (String) projectProps.get(WebProjectProperties.WAR_EAR_NAME);
String warName = projectProps.get(WebProjectProperties.WAR_NAME);
String warEarName = projectProps.get(WebProjectProperties.WAR_EAR_NAME);
String oldName = warName.substring(0, warName.length() - 4);
if (warName.endsWith(".war") && oldName.equals(oldProjectName)) //NOI18N
projectProps.put(WebProjectProperties.WAR_NAME, PropertyUtils.getUsablePropertyName(newName) + ".war"); //NOI18N
if (warEarName.endsWith(".war") && oldName.equals(oldProjectName)) //NOI18N
projectProps.put(WebProjectProperties.WAR_EAR_NAME, PropertyUtils.getUsablePropertyName(newName) + ".war"); //NOI18N

ProjectWebModule wm = (ProjectWebModule) project.getLookup ().lookup(ProjectWebModule.class);
ProjectWebModule wm = project.getLookup().lookup(ProjectWebModule.class);
if (wm != null) //should not be null
wm.setContextPath("/" + newName);

Expand Down Expand Up @@ -228,15 +228,15 @@ public void run() {
EditableProperties projectProps = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
EditableProperties privateProps = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);

String warName = (String) projectProps.get(WebProjectProperties.WAR_NAME);
String warEarName = (String) projectProps.get(WebProjectProperties.WAR_EAR_NAME);
String warName = projectProps.get(WebProjectProperties.WAR_NAME);
String warEarName = projectProps.get(WebProjectProperties.WAR_EAR_NAME);
String oldName = warName.substring(0, warName.length() - 4);
if (warName.endsWith(".war") && oldName.equals(oldProjectName)) //NOI18N
projectProps.put(WebProjectProperties.WAR_NAME, PropertyUtils.getUsablePropertyName(newName) + ".war"); //NOI18N
if (warEarName != null && warEarName.endsWith(".war") && oldName.equals(oldProjectName)) //NOI18N
projectProps.put(WebProjectProperties.WAR_EAR_NAME, PropertyUtils.getUsablePropertyName(newName) + ".war"); //NOI18N

ProjectWebModule wm = (ProjectWebModule) project.getLookup().lookup(ProjectWebModule.class);
ProjectWebModule wm = project.getLookup().lookup(ProjectWebModule.class);
String serverId = privateProps.getProperty(WebProjectProperties.J2EE_SERVER_INSTANCE);
String oldCP = wm.getContextPath(serverId);
if (oldCP != null && oldName.equals(oldCP.substring(1)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private static AntProjectHelper createProjectImpl(final WebProjectCreateData cre
false);

WebProject p = (WebProject)ProjectManager.getDefault().findProject(h.getProjectDirectory());
UpdateHelper updateHelper = ((WebProject) p).getUpdateHelper();
UpdateHelper updateHelper = p.getUpdateHelper();

// #119052
if (sourceLevel == null) {
Expand All @@ -315,7 +315,7 @@ public Void run() throws Exception {
Exceptions.printStackTrace(ex.getException());
}

ProjectWebModule pwm = (ProjectWebModule) p.getLookup().lookup(ProjectWebModule.class);
ProjectWebModule pwm = p.getLookup().lookup(ProjectWebModule.class);
if (pwm != null) { //should not be null
pwm.setContextPath(contextPath);
}
Expand Down
Loading

0 comments on commit 711207c

Please sign in to comment.