1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 01:36:01 +02:00

Fixed deprecation warnings.

This commit is contained in:
Sergey Prigogin 2016-04-08 11:57:01 -07:00
parent 9804e683e6
commit e7d8109e95
3 changed files with 29 additions and 48 deletions

View file

@ -27,9 +27,8 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException;
@ -664,10 +663,10 @@ public class CDocumentProvider extends TextFileDocumentProvider {
}
protected static class GlobalAnnotationModelListener implements IAnnotationModelListener, IAnnotationModelListenerExtension {
private ListenerList fListenerList;
private ListenerList<IAnnotationModelListener> fListenerList;
public GlobalAnnotationModelListener() {
fListenerList= new ListenerList(ListenerList.IDENTITY);
fListenerList= new ListenerList<IAnnotationModelListener>(ListenerList.IDENTITY);
}
@Override
@ -872,27 +871,9 @@ public class CDocumentProvider extends TextFileDocumentProvider {
super.disposeFileInfo(element, info);
}
/**
* Creates and returns a new sub-progress monitor for the
* given parent monitor.
*
* @param monitor the parent progress monitor
* @param ticks the number of work ticks allocated from the parent monitor
* @return the new sub-progress monitor
*/
private IProgressMonitor getSubProgressMonitor(IProgressMonitor monitor, int ticks) {
if (monitor != null)
return new SubProgressMonitor(monitor, ticks, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
return new NullProgressMonitor();
}
protected void commitWorkingCopy(IProgressMonitor monitor, Object element, TranslationUnitInfo info,
boolean overwrite) throws CoreException {
if (monitor == null)
monitor= new NullProgressMonitor();
monitor.beginTask("", 100); //$NON-NLS-1$
SubMonitor progress = SubMonitor.convert(monitor, 100);
try {
IDocument document= info.fTextFileBuffer.getDocument();
@ -900,7 +881,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
if (resource instanceof IFile && !resource.exists()) {
// The underlying resource has been deleted, just recreate the file, ignore the rest
createFileFromDocument(getSubProgressMonitor(monitor, 20), (IFile) resource, document);
createFileFromDocument(progress.split(20), (IFile) resource, document);
return;
}
@ -912,12 +893,12 @@ public class CDocumentProvider extends TextFileDocumentProvider {
if (resource != null) {
cproject = CoreModel.getDefault().create(resource.getProject());
}
performSaveActions(cproject, info.fTextFileBuffer, getSubProgressMonitor(monitor, 20));
performSaveActions(cproject, info.fTextFileBuffer, progress.split(20));
} catch (CoreException e) {
saveActionException = e;
}
commitFileBuffer(getSubProgressMonitor(monitor, 20), info, overwrite);
commitFileBuffer(progress.split(20), info, overwrite);
if (saveActionException != null) {
CUIPlugin.log(saveActionException);
@ -1003,10 +984,11 @@ public class CDocumentProvider extends TextFileDocumentProvider {
* if the last line of the file was changed.
* @throws BadLocationException
*/
private void performSaveActions(ICProject project, ITextFileBuffer buffer, IProgressMonitor monitor) throws CoreException {
private void performSaveActions(ICProject project, ITextFileBuffer buffer, IProgressMonitor monitor)
throws CoreException {
if (shouldRemoveTrailingWhitespace() || shouldAddNewlineAtEof() || shouldStyleFormatCode()) {
IRegion[] changedRegions= needsChangedRegions() ?
EditorUtility.calculateChangedLineRegions(buffer, getSubProgressMonitor(monitor, 20)) :
EditorUtility.calculateChangedLineRegions(buffer, monitor) :
null;
IDocument document = buffer.getDocument();
formatCode(project, document);

View file

@ -1319,7 +1319,8 @@ public class CEditor extends TextEditor implements ICEditor, ISelectionChangedLi
* AST reconciling listeners.
* @since 4.0
*/
private final ListenerList fReconcilingListeners= new ListenerList(ListenerList.IDENTITY);
private final ListenerList<ICReconcilingListener> fReconcilingListeners=
new ListenerList<ICReconcilingListener>(ListenerList.IDENTITY);
/**
* Semantic highlighting manager
@ -1342,7 +1343,7 @@ public class CEditor extends TextEditor implements ICEditor, ISelectionChangedLi
private final IndexUpdateRequestor fIndexUpdateRequestor = new IndexUpdateRequestor();
private final ListenerList fPostSaveListeners;
private final ListenerList<IPostSaveListener> fPostSaveListeners;
private static final Set<String> angularIntroducers = new HashSet<>();
static {
@ -1379,7 +1380,7 @@ public class CEditor extends TextEditor implements ICEditor, ISelectionChangedLi
setOutlinerContextMenuId("#CEditorOutlinerContext"); //$NON-NLS-1$
fCEditorErrorTickUpdater = new CEditorErrorTickUpdater(this);
fPostSaveListeners = new ListenerList();
fPostSaveListeners = new ListenerList<IPostSaveListener>();
}
@Override
@ -1545,12 +1546,12 @@ public class CEditor extends TextEditor implements ICEditor, ISelectionChangedLi
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object getAdapter(Class adapterClass) {
@SuppressWarnings("unchecked")
public <T> T getAdapter(Class<T> adapterClass) {
if (adapterClass.isAssignableFrom(IContentOutlinePage.class)) {
return getOutlinePage();
return (T) getOutlinePage();
} else if (adapterClass.isAssignableFrom(IShowInTargetList.class)) {
return new IShowInTargetList() {
return (T) new IShowInTargetList() {
@Override
@SuppressWarnings("deprecation")
public String[] getShowInTargetIds() {
@ -1563,7 +1564,7 @@ public class CEditor extends TextEditor implements ICEditor, ISelectionChangedLi
ce = null;
}
final ISelection selection= ce != null ? new StructuredSelection(ce) : null;
return new IShowInSource() {
return (T) new IShowInSource() {
@Override
public ShowInContext getShowInContext() {
return new ShowInContext(getEditorInput(), selection);
@ -1571,21 +1572,21 @@ public class CEditor extends TextEditor implements ICEditor, ISelectionChangedLi
};
} else if (adapterClass.isAssignableFrom(ProjectionAnnotationModel.class)) {
if (fProjectionSupport != null) {
Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), adapterClass);
T adapter = fProjectionSupport.getAdapter(getSourceViewer(), adapterClass);
if (adapter != null)
return adapter;
}
} else if (adapterClass.isAssignableFrom(IContextProvider.class)) {
return new CUIHelp.CUIHelpContextProvider(this);
return (T) new CUIHelp.CUIHelpContextProvider(this);
} else if (adapterClass.isAssignableFrom(IGotoMarker.class)) {
return new GotoMarkerAdapter();
return (T) new GotoMarkerAdapter();
} else if (adapterClass.isAssignableFrom(ITemplatesPage.class)) {
if (fTemplatesPage == null) {
fTemplatesPage = new CTemplatesPage(this);
}
return fTemplatesPage;
return (T) fTemplatesPage;
} else if (adapterClass.isAssignableFrom(ITranslationUnitHolder.class))
return this;
return (T) this;
return super.getAdapter(adapterClass);
}
@ -2485,7 +2486,7 @@ public class CEditor extends TextEditor implements ICEditor, ISelectionChangedLi
parent.addHelpListener(new HelpListener() {
@Override
public void helpRequested(HelpEvent e) {
IContextProvider provider = (IContextProvider) CEditor.this.getAdapter(IContextProvider.class);
IContextProvider provider = CEditor.this.getAdapter(IContextProvider.class);
if (provider != null) {
IContext context = provider.getContext(CEditor.this);
if (context != null) {
@ -2657,15 +2658,13 @@ public class CEditor extends TextEditor implements ICEditor, ISelectionChangedLi
if (model == null)
return null;
@SuppressWarnings("rawtypes")
Iterator parent;
Iterator<Annotation> parent;
if (model instanceof IAnnotationModelExtension2) {
parent= ((IAnnotationModelExtension2) model).getAnnotationIterator(offset, length, true, true);
} else {
parent= model.getAnnotationIterator();
}
@SuppressWarnings("unchecked")
Iterator<Annotation> e= new CAnnotationIterator(parent, false);
Annotation annotation = null;
while (e.hasNext()) {

View file

@ -54,7 +54,7 @@ class EclipsePreferencesAdapter implements IPreferenceStore {
}
/** Listeners on on this adapter */
private ListenerList fListeners= new ListenerList(ListenerList.IDENTITY);
private ListenerList<IPropertyChangeListener> fListeners= new ListenerList<IPropertyChangeListener>(ListenerList.IDENTITY);
/** Listener on the node */
private IEclipsePreferences.IPreferenceChangeListener fListener= new PreferenceChangeListener();
@ -83,7 +83,7 @@ class EclipsePreferencesAdapter implements IPreferenceStore {
*/
@Override
public void addPropertyChangeListener(IPropertyChangeListener listener) {
if (fListeners.size() == 0)
if (fListeners.isEmpty())
getNode().addPreferenceChangeListener(fListener);
fListeners.add(listener);
}
@ -94,7 +94,7 @@ class EclipsePreferencesAdapter implements IPreferenceStore {
@Override
public void removePropertyChangeListener(IPropertyChangeListener listener) {
fListeners.remove(listener);
if (fListeners.size() == 0) {
if (fListeners.isEmpty()) {
getNode().removePreferenceChangeListener(fListener);
}
}