Skip to content

Commit

Permalink
fix "The allocated object is never used" warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T authored and jukzi committed Jan 25, 2024
1 parent 8c94f2a commit b3346e8
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ else if (nextWhitespace != -1)
// Set and validate URL string
try {
urlString= line.substring(urlOffsetInLine, urlOffsetInLine + urlLength);
new URL(urlString);
@SuppressWarnings("unused")
URL validated= new URL(urlString);
} catch (MalformedURLException ex) {
urlString= null;
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ protected Control createMessageArea (Composite parent) {
Control result= super.createMessageArea(parent);

// Panic code: use 'parent' instead of 'result' in case super implementation changes in the future
new Label(parent, SWT.NONE); // filler as parent has 2 columns (icon and label)
@SuppressWarnings("unused")
Label filler= new Label(parent, SWT.NONE); // filler as parent has 2 columns (icon and label)
Label label= new Label(parent, SWT.NONE);
label.setText(RefactoringUIMessages.ChangeExceptionHandler_button_explanation);
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ public Menu getMenu(Control parent) {
for (FilterAction fFilterAction : fFilterActions) {
new ActionContributionItem(fFilterAction).fill(fMenu, -1);
}
new MenuItem(fMenu, SWT.SEPARATOR);
@SuppressWarnings("unused")
MenuItem menuItem= new MenuItem(fMenu, SWT.SEPARATOR);
}
new ActionContributionItem(fHideDerivedAction).fill(fMenu, -1);
return fMenu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ public final void widgetSelected(final SelectionEvent event) {
fShareHistoryButton.setLayoutData(data);
fShareHistoryButton.setSelection(hasSharedRefactoringHistory());

new Label(composite, SWT.NONE);
@SuppressWarnings("unused")
Label label= new Label(composite, SWT.NONE);

final IProject project= getCurrentProject();
if (project != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public void selectionChanged(SelectionChangedEvent event) {
* Flag (<code>value 2</code>) denoting tree layout.
*/
public static final int FLAG_LAYOUT_TREE = 2;
private OpenAndLinkWithEditorHelper openAndLinkWithEditorHelper;


/**
Expand Down Expand Up @@ -741,7 +742,7 @@ private void createViewer(Composite parent, int layout) {
fillToolbar(tbm);
tbm.update(false);

new OpenAndLinkWithEditorHelper(fViewer) {
openAndLinkWithEditorHelper = new OpenAndLinkWithEditorHelper(fViewer) {

@Override
protected void activate(ISelection selection) {
Expand Down Expand Up @@ -1135,6 +1136,7 @@ public void dispose() {
AnnotationManagers.removeSearchResult(getSite().getWorkbenchWindow(), oldSearch);
super.dispose();
NewSearchUI.removeQueryListener(fQueryListener);
openAndLinkWithEditorHelper.dispose();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public Menu getMenu(Control parent) {
action.setChecked(searchResult.equals(currentSearch));
addActionToMenu(fMenu, action);
}
new MenuItem(fMenu, SWT.SEPARATOR);
@SuppressWarnings("unused")
MenuItem menuItem = new MenuItem(fMenu, SWT.SEPARATOR);
addActionToMenu(fMenu, new ShowSearchHistoryDialogAction(fSearchView));
addActionToMenu(fMenu, new RemoveAllSearchesAction());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ public void createPartControl(Composite parent) {
}

private void initializePageSwitcher() {
new PageSwitcher(this) {
@SuppressWarnings("unused")
PageSwitcher pageSwitcher = new PageSwitcher(this) {
@Override
public void activatePage(Object page) {
ISearchResult searchResult= ((ISearchQuery) page).getSearchResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ public StyledString getStyledText(Object element) {
return new StyledString();

IResource resource= (IResource) element;
if (!resource.exists())
new StyledString(SearchMessages.FileLabelProvider_removed_resource_label);
if (!resource.exists()) {
StyledString str = new StyledString(SearchMessages.FileLabelProvider_removed_resource_label);
return getColoredLabelWithCounts(resource, str);
}

String name= BasicElementLabels.getResourceName(resource);
if (fOrder == SHOW_LABEL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.search.internal.ui.SearchMessages;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.ISearchResult;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.search.ui.text.FileTextSearchScope;
import org.eclipse.search.ui.text.Match;
Expand Down Expand Up @@ -334,7 +335,9 @@ public boolean canRerun() {
public ISearchResult getSearchResult() {
if (fResult == null) {
fResult= new FileSearchResult(this);
new SearchResultUpdater(fResult);
SearchResultUpdater listener = new SearchResultUpdater(fResult);
NewSearchUI.addQueryListener(listener);
ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
}
return fResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public void createControl(Composite parent) {
new char[0],
true);

new Label(result, SWT.NONE);
@SuppressWarnings("unused")
Label label = new Label(result, SWT.NONE);
fReplaceWithRegex= new Button(result, SWT.CHECK);
fReplaceWithRegex.setText(SearchMessages.ReplaceConfigurationPage_isRegex_label);
fReplaceWithRegex.addSelectionListener(new SelectionAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public class SearchResultUpdater implements IResourceChangeListener, IQueryListe

public SearchResultUpdater(AbstractTextSearchResult result) {
fResult= result;
NewSearchUI.addQueryListener(this);
ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ public void widgetSelected(SelectionEvent e) {
});
setGridData(fSelectAllButton, SWT.FILL, true, SWT.FILL, false);

new Label(panel, SWT.NONE); // filler
@SuppressWarnings("unused")
Label filler = new Label(panel, SWT.NONE); // filler

fReplaceFindButton = makeButton(panel, FindReplaceMessages.FindReplace_ReplaceFindButton_label, 103, false,
new SelectionAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ public void setUp() {

@Test
public void testCreate() {
new LinkedPosition(fDoc, 1, 9);
new LinkedPosition(new Document(), 123, 234);
@SuppressWarnings("unused")
LinkedPosition linkedPosition = new LinkedPosition(fDoc, 1, 9);
@SuppressWarnings("unused")
LinkedPosition linkedPosition2 = new LinkedPosition(new Document(), 123, 234);
}

@Test(expected=Throwable.class)
public void testNullCreate() {
new LinkedPosition(null, 1, 9);
@SuppressWarnings("unused")
LinkedPosition linkedPosition = new LinkedPosition(null, 1, 9);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
*******************************************************************************/
package org.eclipse.ui.workbench.texteditor.tests.revisions;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -68,19 +70,22 @@ public void setUp() throws Exception {
@Test
public void testCreation() throws Exception {
try {
new ChangeRegion(fRevision, null);
@SuppressWarnings("unused")
ChangeRegion changeRegion= new ChangeRegion(fRevision, null);
fail();
} catch (Exception e) {
}

try {
new ChangeRegion(null, new LineRange(12, 3));
@SuppressWarnings("unused")
ChangeRegion changeRegion= new ChangeRegion(null, new LineRange(12, 3));
fail();
} catch (Exception e) {
}

try {
new ChangeRegion(null, null);
@SuppressWarnings("unused")
ChangeRegion changeRegion= new ChangeRegion(null, null);
fail();
} catch (Exception e) {
}
Expand Down

0 comments on commit b3346e8

Please sign in to comment.