Skip to content

Commit

Permalink
Fix deprecations (#1686)
Browse files Browse the repository at this point in the history
* fix deprecations
  • Loading branch information
carstenartur authored Oct 17, 2024
1 parent 3cea1a7 commit e293b05
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private IfStatement findStart(IfStatement item) {
}
}

private static final class AddBlockOperation extends CompilationUnitRewriteOperation {
private static final class AddBlockOperation extends CompilationUnitRewriteOperationWithSourceRange {

private final ChildPropertyDescriptor fBodyProperty;
private final Statement fBody;
Expand Down Expand Up @@ -266,7 +266,7 @@ public void rewriteASTInternal(CompilationUnitRewrite cuRewrite, LinkedProposalM

}

static class RemoveBlockOperation extends CompilationUnitRewriteOperation {
static class RemoveBlockOperation extends CompilationUnitRewriteOperationWithSourceRange {

private final Statement fStatement;
private final ChildPropertyDescriptor fChild;
Expand Down Expand Up @@ -437,42 +437,42 @@ public static ControlStatementsFix[] createRemoveBlockFix(CompilationUnit compil
RemoveBlockOperation op= new RemoveBlockOperation(item, IfStatement.THEN_STATEMENT_PROPERTY);
removeAllList.add(op);
if (item == statement)
result.add(new ControlStatementsFix(FixMessages.ControlStatementsFix_removeIfBlock_proposalDescription, compilationUnit, new CompilationUnitRewriteOperation[] {op}));
result.add(new ControlStatementsFix(FixMessages.ControlStatementsFix_removeIfBlock_proposalDescription, compilationUnit, new CompilationUnitRewriteOperationWithSourceRange[] {op}));
}
}

if (RemoveBlockOperation.satisfiesQuickAssistPrecondition(item, IfStatement.ELSE_STATEMENT_PROPERTY)) {
RemoveBlockOperation op= new RemoveBlockOperation(item, IfStatement.ELSE_STATEMENT_PROPERTY);
removeAllList.add(op);
if (item == statement)
result.add(new ControlStatementsFix(FixMessages.ControlStatementsFix_removeElseBlock_proposalDescription, compilationUnit, new CompilationUnitRewriteOperation[] {op}));
result.add(new ControlStatementsFix(FixMessages.ControlStatementsFix_removeElseBlock_proposalDescription, compilationUnit, new CompilationUnitRewriteOperationWithSourceRange[] {op}));
}

if (removeAllList.size() > 1) {
CompilationUnitRewriteOperation[] allConvert= removeAllList.toArray(new CompilationUnitRewriteOperation[removeAllList.size()]);
CompilationUnitRewriteOperationWithSourceRange[] allConvert= removeAllList.toArray(new CompilationUnitRewriteOperationWithSourceRange[removeAllList.size()]);
result.add(new ControlStatementsFix(FixMessages.ControlStatementsFix_removeIfElseBlock_proposalDescription, compilationUnit, allConvert));
}

return result.toArray(new ControlStatementsFix[result.size()]);
} else if (statement instanceof WhileStatement) {
if (RemoveBlockOperation.satisfiesQuickAssistPrecondition(statement, WhileStatement.BODY_PROPERTY)) {
RemoveBlockOperation op= new RemoveBlockOperation(statement, WhileStatement.BODY_PROPERTY);
return new ControlStatementsFix[] {new ControlStatementsFix(FixMessages.ControlStatementsFix_removeBrackets_proposalDescription, compilationUnit, new CompilationUnitRewriteOperation[] {op})};
return new ControlStatementsFix[] {new ControlStatementsFix(FixMessages.ControlStatementsFix_removeBrackets_proposalDescription, compilationUnit, new CompilationUnitRewriteOperationWithSourceRange[] {op})};
}
} else if (statement instanceof ForStatement) {
if (RemoveBlockOperation.satisfiesQuickAssistPrecondition(statement, ForStatement.BODY_PROPERTY)) {
RemoveBlockOperation op= new RemoveBlockOperation(statement, ForStatement.BODY_PROPERTY);
return new ControlStatementsFix[] {new ControlStatementsFix(FixMessages.ControlStatementsFix_removeBrackets_proposalDescription, compilationUnit, new CompilationUnitRewriteOperation[] {op})};
return new ControlStatementsFix[] {new ControlStatementsFix(FixMessages.ControlStatementsFix_removeBrackets_proposalDescription, compilationUnit, new CompilationUnitRewriteOperationWithSourceRange[] {op})};
}
} else if (statement instanceof EnhancedForStatement) {
if (RemoveBlockOperation.satisfiesQuickAssistPrecondition(statement, EnhancedForStatement.BODY_PROPERTY)) {
RemoveBlockOperation op= new RemoveBlockOperation(statement, EnhancedForStatement.BODY_PROPERTY);
return new ControlStatementsFix[] {new ControlStatementsFix(FixMessages.ControlStatementsFix_removeBrackets_proposalDescription, compilationUnit, new CompilationUnitRewriteOperation[] {op})};
return new ControlStatementsFix[] {new ControlStatementsFix(FixMessages.ControlStatementsFix_removeBrackets_proposalDescription, compilationUnit, new CompilationUnitRewriteOperationWithSourceRange[] {op})};
}
} else if (statement instanceof DoStatement) {
if (RemoveBlockOperation.satisfiesQuickAssistPrecondition(statement, DoStatement.BODY_PROPERTY)) {
RemoveBlockOperation op= new RemoveBlockOperation(statement, DoStatement.BODY_PROPERTY);
return new ControlStatementsFix[] {new ControlStatementsFix(FixMessages.ControlStatementsFix_removeBrackets_proposalDescription, compilationUnit, new CompilationUnitRewriteOperation[] {op})};
return new ControlStatementsFix[] {new ControlStatementsFix(FixMessages.ControlStatementsFix_removeBrackets_proposalDescription, compilationUnit, new CompilationUnitRewriteOperationWithSourceRange[] {op})};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,11 +655,17 @@ public JavaTextTools getJavaTextTools() {
*
* @return the Java Core plug-in preferences
* @since 3.7
* deprecated use getJavaCorePluginPreferencesNew
*/
public static org.eclipse.core.runtime.Preferences getJavaCorePluginPreferences() {

Check warning on line 660 in org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Deprecation

NORMAL: The type Preferences is deprecated
return JavaCore.getPlugin().getPluginPreferences();

Check warning on line 661 in org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Deprecation

NORMAL: The method getPluginPreferences() from the type Plugin is deprecated
}

public static IEclipsePreferences getJavaCorePluginPreferencesNew() {
return InstanceScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
}


/**
* Returns the AST provider.
*
Expand Down Expand Up @@ -941,11 +947,11 @@ public IPreferenceStore getCombinedPreferenceStore() {
return fCombinedPreferenceStore;
}
}

// Block below may init other bundles and shouldn't be executed with lock held
IPreferenceStore generalTextStore= EditorsUI.getPreferenceStore();
ChainedPreferenceStore store = new ChainedPreferenceStore(new IPreferenceStore[] { getPreferenceStore(), new PreferencesAdapter(getJavaCorePluginPreferences()), generalTextStore });

synchronized (this) {
if (fCombinedPreferenceStore == null) {
fCombinedPreferenceStore = store;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.views.WorkbenchViewerSetup;

import org.eclipse.jdt.core.ElementChangedEvent;
Expand Down Expand Up @@ -568,7 +569,8 @@ public JavaEditorBreadcrumb(JavaEditor javaEditor) {
protected void activateBreadcrumb() {
fEditorSelection= getJavaEditor().getSelectionProvider().getSelection();
IEditorSite editorSite= getJavaEditor().getEditorSite();
editorSite.getKeyBindingService().setScopes(new String[] { "org.eclipse.jdt.ui.breadcrumbEditorScope" }); //$NON-NLS-1$
IContextService contextService = editorSite.getService(IContextService.class);
contextService.activateContext("org.eclipse.jdt.ui.breadcrumbEditorScope"); //$NON-NLS-1$
getJavaEditor().setActionsActivated(false);
fBreadcrumbActionGroup.fillActionBars(editorSite.getActionBars());
}
Expand All @@ -579,7 +581,8 @@ protected void activateBreadcrumb() {
@Override
protected void deactivateBreadcrumb() {
IEditorSite editorSite= getJavaEditor().getEditorSite();
editorSite.getKeyBindingService().setScopes(new String[] { "org.eclipse.jdt.ui.javaEditorScope" }); //$NON-NLS-1$
IContextService contextService = editorSite.getService(IContextService.class);
contextService.activateContext("org.eclipse.jdt.ui.javaEditorScope"); //$NON-NLS-1$
getJavaEditor().getActionGroup().fillActionBars(editorSite.getActionBars());
getJavaEditor().setActionsActivated(true);
fEditorSelection= null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import java.io.IOException;

import org.eclipse.jface.internal.text.html.SingleCharReader;
import org.eclipse.text.readers.SingleCharacterReader;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
Expand All @@ -26,7 +26,7 @@
* Reads from a document either forwards or backwards. May be configured to
* skip comments and strings.
*/
public class JavaCodeReader extends SingleCharReader {
public class JavaCodeReader extends SingleCharacterReader {

/** The EOF character */
public static final int EOF= -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public Image getImage() {
flag= JavaElementImageDescriptor.INFO;
}

ImageDescriptor composite= new JavaElementImageDescriptor(image, flag, new Point(image.getImageData().width, image.getImageData().height));
ImageDescriptor composite= new JavaElementImageDescriptor(image, flag, new Point(image.getImageData(100).width, image.getImageData(100).height));
return composite.createImage();
} else {
return super.getImage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,11 @@ public boolean isVisible() {
public Point computeSizeConstraints(int widthInChars, int heightInChars) {
GC gc= new GC(fText);
gc.setFont(fTextFont);
int width= gc.getFontMetrics().getAverageCharWidth();
double width= gc.getFontMetrics().getAverageCharacterWidth();
int height= fText.getLineHeight(); //https://bugs.eclipse.org/bugs/show_bug.cgi?id=377109
gc.dispose();

return new Point(widthInChars * width, heightInChars * height);
return new Point((int) (widthInChars * width), heightInChars * height);
}

protected void setContentFrom(ISourceViewer other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private static class FilteredTreeWithFilter extends FilteredTree {
private String previousFilterText;

public FilteredTreeWithFilter(Composite parent, int treeStyle, String initialFilter, boolean deepFiltering) {
super(parent, treeStyle, new MultiplePatternFilter(deepFiltering), true);
super(parent, treeStyle, new MultiplePatternFilter(deepFiltering), true, true);
if (initialFilter != null) {
setFilterText(initialFilter);
textChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ private CPListElement[] addProjectDialog() {
Object[] selectArr= getNotYetRequiredProjects();
new JavaElementComparator().sort(null, selectArr);

ListSelectionDialog dialog= new ListSelectionDialog(getShell(), Arrays.asList(selectArr), ArrayContentProvider.getInstance(), new JavaUILabelProvider(), NewWizardMessages.ProjectsWorkbookPage_chooseProjects_message);
ListSelectionDialog dialog= ListSelectionDialog.of(Arrays.asList(selectArr)).contentProvider(ArrayContentProvider.getInstance()).labelProvider(new JavaUILabelProvider()).message(NewWizardMessages.ProjectsWorkbookPage_chooseProjects_message).create(getShell());
dialog.setTitle(NewWizardMessages.ProjectsWorkbookPage_chooseProjects_title);
dialog.setHelpAvailable(false);
if (dialog.open() == Window.OK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void run(IStructuredSelection selection) {
}

private void internalRun(List<?> initialSelection) {
ListSelectionDialog dialog= new ListSelectionDialog(getShell(), getClosedProjectsInWorkspace(), ArrayContentProvider.getInstance(), new JavaElementLabelProvider(), ActionMessages.OpenProjectAction_dialog_message);
ListSelectionDialog dialog= ListSelectionDialog.of(getClosedProjectsInWorkspace()).contentProvider(ArrayContentProvider.getInstance()).labelProvider(new JavaElementLabelProvider()).message(ActionMessages.OpenProjectAction_dialog_message).create(getShell());
dialog.setTitle(ActionMessages.OpenProjectAction_dialog_title);
if (initialSelection != null && !initialSelection.isEmpty()) {
dialog.setInitialElementSelections(initialSelection);
Expand Down

0 comments on commit e293b05

Please sign in to comment.