1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

@Override annotations

This commit is contained in:
Andrew Gvozdev 2011-12-30 15:51:00 -05:00
parent 032d94ff51
commit c099f67da4
23 changed files with 361 additions and 283 deletions

View file

@ -52,7 +52,7 @@ import org.eclipse.cdt.ui.CDTUITools;
import org.eclipse.cdt.ui.CElementGrouping; import org.eclipse.cdt.ui.CElementGrouping;
import org.eclipse.cdt.ui.IncludesGrouping; import org.eclipse.cdt.ui.IncludesGrouping;
import org.eclipse.cdt.ui.NamespacesGrouping; import org.eclipse.cdt.ui.NamespacesGrouping;
/** /**
* A base content provider for C elements. It provides access to the * A base content provider for C elements. It provides access to the
* C element hierarchy without listening to changes in the C model. * C element hierarchy without listening to changes in the C model.
@ -83,11 +83,11 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
protected boolean fNamespacesGrouping= false; protected boolean fNamespacesGrouping= false;
protected boolean fMemberGrouping= false; protected boolean fMemberGrouping= false;
protected boolean fMacroGrouping= false; protected boolean fMacroGrouping= false;
public BaseCElementContentProvider() { public BaseCElementContentProvider() {
this(false, false); this(false, false);
} }
public BaseCElementContentProvider(boolean provideMembers, boolean provideWorkingCopy) { public BaseCElementContentProvider(boolean provideMembers, boolean provideWorkingCopy) {
fProvideMembers= provideMembers; fProvideMembers= provideMembers;
fProvideWorkingCopy= provideWorkingCopy; fProvideWorkingCopy= provideWorkingCopy;
@ -161,7 +161,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
public boolean isMemberGroupingEnabled() { public boolean isMemberGroupingEnabled() {
return fMemberGrouping; return fMemberGrouping;
} }
/** /**
* Enable/disable member grouping by common namespace. * Enable/disable member grouping by common namespace.
* @param enable * @param enable
@ -169,14 +169,14 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
public void setMemberGrouping(boolean enable) { public void setMemberGrouping(boolean enable) {
fMemberGrouping = enable; fMemberGrouping = enable;
} }
/** /**
* @return whether grouping of macros is enabled * @return whether grouping of macros is enabled
*/ */
public boolean isMacroGroupingEnabled() { public boolean isMacroGroupingEnabled() {
return fMacroGrouping; return fMacroGrouping;
} }
/** /**
* Enable/disable marco grouping * Enable/disable marco grouping
* @param enable * @param enable
@ -188,25 +188,29 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
/* (non-Cdoc) /* (non-Cdoc)
* Method declared on IContentProvider. * Method declared on IContentProvider.
*/ */
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
} }
/* (non-Cdoc) /* (non-Cdoc)
* Method declared on IContentProvider. * Method declared on IContentProvider.
*/ */
@Override
public void dispose() { public void dispose() {
} }
/* (non-Cdoc) /* (non-Cdoc)
* Method declared on IStructuredContentProvider. * Method declared on IStructuredContentProvider.
*/ */
@Override
public Object[] getElements(Object parent) { public Object[] getElements(Object parent) {
return getChildren(parent); return getChildren(parent);
} }
/* (non-Cdoc) /* (non-Cdoc)
* Method declared on ITreeContentProvider. * Method declared on ITreeContentProvider.
*/ */
@Override
public Object[] getChildren(Object element) { public Object[] getChildren(Object element) {
if (!exists(element)) if (!exists(element))
return NO_CHILDREN; return NO_CHILDREN;
@ -263,6 +267,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
* *
* @see ITreeContentProvider * @see ITreeContentProvider
*/ */
@Override
public boolean hasChildren(Object element) { public boolean hasChildren(Object element) {
if (fProvideMembers) { if (fProvideMembers) {
// assume TUs and binary files are never empty // assume TUs and binary files are never empty
@ -303,7 +308,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
return true; return true;
} }
} }
if (element instanceof CElementGrouping) { if (element instanceof CElementGrouping) {
return true; return true;
} }
@ -311,10 +316,11 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
Object[] children= getChildren(element); Object[] children= getChildren(element);
return (children != null) && children.length > 0; return (children != null) && children.length > 0;
} }
/* (non-Cdoc) /* (non-Cdoc)
* Method declared on ITreeContentProvider. * Method declared on ITreeContentProvider.
*/ */
@Override
public Object getParent(Object element) { public Object getParent(Object element) {
if (!exists(element)) { if (!exists(element)) {
return null; return null;
@ -398,7 +404,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
} }
return parent; return parent;
} }
protected Object[] getCProjects(ICModel cModel) throws CModelException { protected Object[] getCProjects(ICModel cModel) throws CModelException {
Object[] objects = cModel.getCProjects(); Object[] objects = cModel.getCProjects();
try { try {
@ -415,7 +421,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
protected Object[] getSourceRoots(ICProject cproject) throws CModelException { protected Object[] getSourceRoots(ICProject cproject) throws CModelException {
if (!cproject.getProject().isOpen()) if (!cproject.getProject().isOpen())
return NO_CHILDREN; return NO_CHILDREN;
List<ICElement> list= new ArrayList<ICElement>(); List<ICElement> list= new ArrayList<ICElement>();
ICElement[] children = cproject.getChildren(); ICElement[] children = cproject.getChildren();
for (ICElement child : children) { for (ICElement child : children) {
@ -426,8 +432,8 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
list.add(c2[k]); list.add(c2[k]);
} else if (CCorePlugin.showSourceRootsAtTopOfProject()) { } else if (CCorePlugin.showSourceRootsAtTopOfProject()) {
list.add(child); list.add(child);
} else if (child instanceof ISourceRoot && } else if (child instanceof ISourceRoot &&
child.getResource().getParent().equals(cproject.getProject())) { child.getResource().getParent().equals(cproject.getProject())) {
list.add(child); list.add(child);
} }
} }
@ -579,7 +585,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
} }
} catch (CModelException e) { } catch (CModelException e) {
} }
Object[] result = children; Object[] result = children;
if (missingElements.size() > 0) { if (missingElements.size() > 0) {
result = concatenate(result, missingElements.toArray()); result = concatenate(result, missingElements.toArray());
@ -593,7 +599,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
} }
private List<ICElement> getMissingElements(ICContainer container, ICElement[] elements) { private List<ICElement> getMissingElements(ICContainer container, ICElement[] elements) {
// nested source roots may be filtered out below the project root, // nested source roots may be filtered out below the project root,
// we need to find them to add them back in // we need to find them to add them back in
List<ICElement> missingElements = new ArrayList<ICElement>(); List<ICElement> missingElements = new ArrayList<ICElement>();
try { try {
@ -643,7 +649,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
} }
return filterNonCResources(members, cproject); return filterNonCResources(members, cproject);
} }
private Object[] filterNonCResources(Object[] objects, ICProject cproject) throws CModelException { private Object[] filterNonCResources(Object[] objects, ICProject cproject) throws CModelException {
ICElement[] binaries = null; ICElement[] binaries = null;
ICElement[] archives = null; ICElement[] archives = null;

View file

@ -25,6 +25,7 @@ public class CActionFilter implements IActionFilter {
public CActionFilter() { public CActionFilter() {
} }
@Override
public boolean testAttribute(Object target, String name, String value) { public boolean testAttribute(Object target, String name, String value) {
ICElement element = (ICElement) target; ICElement element = (ICElement) target;
IResource resource = element.getResource(); IResource resource = element.getResource();

View file

@ -31,33 +31,35 @@ import org.eclipse.cdt.core.model.ICElement;
* Implements basic UI support for C elements. * Implements basic UI support for C elements.
*/ */
public class CElementAdapterFactory implements IAdapterFactory { public class CElementAdapterFactory implements IAdapterFactory {
private static Class<?>[] PROPERTIES= new Class[] { private static Class<?>[] PROPERTIES= new Class[] {
IPropertySource.class, IPropertySource.class,
IResource.class, IResource.class,
IWorkbenchAdapter.class, IWorkbenchAdapter.class,
IPersistableElement.class, IPersistableElement.class,
IDeferredWorkbenchAdapter.class, IDeferredWorkbenchAdapter.class,
IActionFilter.class IActionFilter.class
}; };
private static CWorkbenchAdapter fgCWorkbenchAdapter; private static CWorkbenchAdapter fgCWorkbenchAdapter;
private static CActionFilter fgCActionFilter; private static CActionFilter fgCActionFilter;
/** /**
* @see CElementAdapterFactory#getAdapterList * @see CElementAdapterFactory#getAdapterList
*/ */
@Override
public Class<?>[] getAdapterList() { public Class<?>[] getAdapterList() {
return PROPERTIES; return PROPERTIES;
} }
/** /**
* @see CElementAdapterFactory#getAdapter * @see CElementAdapterFactory#getAdapter
*/ */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
public Object getAdapter(Object element, Class key) { public Object getAdapter(Object element, Class key) {
ICElement celem = (ICElement) element; ICElement celem = (ICElement) element;
if (IPropertySource.class.equals(key)) { if (IPropertySource.class.equals(key)) {
return getPropertySource(celem); return getPropertySource(celem);
} else if (IResource.class.isAssignableFrom(key)) { } else if (IResource.class.isAssignableFrom(key)) {
@ -74,12 +76,12 @@ public class CElementAdapterFactory implements IAdapterFactory {
} else if (IActionFilter.class.equals(key)) { } else if (IActionFilter.class.equals(key)) {
return getActionFilter(celem); return getActionFilter(celem);
} }
return null; return null;
} }
private IPropertySource getPropertySource(ICElement celement) { private IPropertySource getPropertySource(ICElement celement) {
if (celement instanceof IBinary) { if (celement instanceof IBinary) {
return new BinaryPropertySource((IBinary)celement); return new BinaryPropertySource((IBinary)celement);
} }
IResource res = celement.getResource(); IResource res = celement.getResource();
if (res != null) { if (res != null) {
@ -88,7 +90,7 @@ public class CElementAdapterFactory implements IAdapterFactory {
} }
return new ResourcePropertySource(res); return new ResourcePropertySource(res);
} }
return new CElementPropertySource(celement); return new CElementPropertySource(celement);
} }
private IResource getResource(ICElement celement) { private IResource getResource(ICElement celement) {
@ -105,7 +107,7 @@ public class CElementAdapterFactory implements IAdapterFactory {
} }
return fgCWorkbenchAdapter; return fgCWorkbenchAdapter;
} }
private IActionFilter getActionFilter(ICElement celement) { private IActionFilter getActionFilter(ICElement celement) {
if (fgCActionFilter == null) { if (fgCActionFilter == null) {
fgCActionFilter = new CActionFilter(); fgCActionFilter = new CActionFilter();

View file

@ -11,31 +11,32 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui; package org.eclipse.cdt.internal.ui;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.jface.viewers.IBasicPropertyConstants; import org.eclipse.jface.viewers.IBasicPropertyConstants;
import org.eclipse.ui.views.properties.IPropertyDescriptor; import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource; import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor; import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CUIPlugin;
public class CElementPropertySource implements IPropertySource { public class CElementPropertySource implements IPropertySource {
private final static String LABEL= "CElementProperties.name"; //$NON-NLS-1$ private final static String LABEL= "CElementProperties.name"; //$NON-NLS-1$
private ICElement fCElement; private ICElement fCElement;
// Property Descriptors // Property Descriptors
static private IPropertyDescriptor[] fgPropertyDescriptors; static private IPropertyDescriptor[] fgPropertyDescriptors;
static { static {
// resource name // resource name
String displayName= CUIPlugin.getResourceString(LABEL); String displayName= CUIPlugin.getResourceString(LABEL);
PropertyDescriptor descriptor= new PropertyDescriptor(IBasicPropertyConstants.P_TEXT, displayName); PropertyDescriptor descriptor= new PropertyDescriptor(IBasicPropertyConstants.P_TEXT, displayName);
descriptor.setAlwaysIncompatible(true); descriptor.setAlwaysIncompatible(true);
fgPropertyDescriptors= new IPropertyDescriptor[] { descriptor }; fgPropertyDescriptors= new IPropertyDescriptor[] { descriptor };
} }
public CElementPropertySource(ICElement elem) { public CElementPropertySource(ICElement elem) {
fCElement= elem; fCElement= elem;
} }
@ -43,13 +44,15 @@ public class CElementPropertySource implements IPropertySource {
/** /**
* @see IPropertySource#getPropertyDescriptors * @see IPropertySource#getPropertyDescriptors
*/ */
@Override
public IPropertyDescriptor[] getPropertyDescriptors() { public IPropertyDescriptor[] getPropertyDescriptors() {
return fgPropertyDescriptors; return fgPropertyDescriptors;
} }
/** /**
* @see IPropertySource#getPropertyValue * @see IPropertySource#getPropertyValue
*/ */
@Override
public Object getPropertyValue(Object name) { public Object getPropertyValue(Object name) {
if (name.equals(IBasicPropertyConstants.P_TEXT)) { if (name.equals(IBasicPropertyConstants.P_TEXT)) {
return fCElement.getElementName(); return fCElement.getElementName();
@ -59,27 +62,31 @@ public class CElementPropertySource implements IPropertySource {
/** /**
* @see IPropertySource#setPropertyValue * @see IPropertySource#setPropertyValue
*/ */
@Override
public void setPropertyValue(Object name, Object value) { public void setPropertyValue(Object name, Object value) {
} }
/** /**
* @see IPropertySource#getEditableValue * @see IPropertySource#getEditableValue
*/ */
@Override
public Object getEditableValue() { public Object getEditableValue() {
return null; return null;
} }
/** /**
* @see IPropertySource#isPropertySet * @see IPropertySource#isPropertySet
*/ */
@Override
public boolean isPropertySet(Object property) { public boolean isPropertySet(Object property) {
return false; return false;
} }
/** /**
* @see IPropertySource#resetPropertyValue * @see IPropertySource#resetPropertyValue
*/ */
@Override
public void resetPropertyValue(Object property) { public void resetPropertyValue(Object property) {
} }
} }

View file

@ -12,8 +12,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui; package org.eclipse.cdt.internal.ui;
import org.eclipse.cdt.internal.ui.wizards.CWizardRegistry;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.search.ui.NewSearchUI; import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.ui.IFolderLayout; import org.eclipse.ui.IFolderLayout;
import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPageLayout;
@ -21,8 +19,12 @@ import org.eclipse.ui.IPerspectiveFactory;
import org.eclipse.ui.console.IConsoleConstants; import org.eclipse.ui.console.IConsoleConstants;
import org.eclipse.ui.navigator.resources.ProjectExplorer; import org.eclipse.ui.navigator.resources.ProjectExplorer;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.wizards.CWizardRegistry;
public class CPerspectiveFactory implements IPerspectiveFactory { public class CPerspectiveFactory implements IPerspectiveFactory {
/** /**
* Constructs a new Default layout engine. * Constructs a new Default layout engine.
*/ */
@ -33,34 +35,35 @@ public class CPerspectiveFactory implements IPerspectiveFactory {
/** /**
* @see IPerspectiveFactory#createInitialLayout * @see IPerspectiveFactory#createInitialLayout
*/ */
@Override
public void createInitialLayout(IPageLayout layout) { public void createInitialLayout(IPageLayout layout) {
String editorArea = layout.getEditorArea(); String editorArea = layout.getEditorArea();
IFolderLayout folder1= layout.createFolder("topLeft", IPageLayout.LEFT, (float)0.25, editorArea); //$NON-NLS-1$ IFolderLayout folder1= layout.createFolder("topLeft", IPageLayout.LEFT, (float)0.25, editorArea); //$NON-NLS-1$
folder1.addView(ProjectExplorer.VIEW_ID); folder1.addView(ProjectExplorer.VIEW_ID);
folder1.addPlaceholder(CUIPlugin.CVIEW_ID); folder1.addPlaceholder(CUIPlugin.CVIEW_ID);
folder1.addPlaceholder(IPageLayout.ID_RES_NAV); folder1.addPlaceholder(IPageLayout.ID_RES_NAV);
folder1.addPlaceholder(IPageLayout.ID_BOOKMARKS); folder1.addPlaceholder(IPageLayout.ID_BOOKMARKS);
IFolderLayout folder2= layout.createFolder("bottom", IPageLayout.BOTTOM, (float)0.75, editorArea); //$NON-NLS-1$ IFolderLayout folder2= layout.createFolder("bottom", IPageLayout.BOTTOM, (float)0.75, editorArea); //$NON-NLS-1$
folder2.addView(IPageLayout.ID_PROBLEM_VIEW); folder2.addView(IPageLayout.ID_PROBLEM_VIEW);
folder2.addView(IPageLayout.ID_TASK_LIST); folder2.addView(IPageLayout.ID_TASK_LIST);
folder2.addView(IConsoleConstants.ID_CONSOLE_VIEW); folder2.addView(IConsoleConstants.ID_CONSOLE_VIEW);
folder2.addView(IPageLayout.ID_PROP_SHEET); folder2.addView(IPageLayout.ID_PROP_SHEET);
IFolderLayout folder3= layout.createFolder("topRight", IPageLayout.RIGHT,(float)0.75, editorArea); //$NON-NLS-1$ IFolderLayout folder3= layout.createFolder("topRight", IPageLayout.RIGHT,(float)0.75, editorArea); //$NON-NLS-1$
folder3.addView(IPageLayout.ID_OUTLINE); folder3.addView(IPageLayout.ID_OUTLINE);
layout.addActionSet(CUIPlugin.SEARCH_ACTION_SET_ID); layout.addActionSet(CUIPlugin.SEARCH_ACTION_SET_ID);
layout.addActionSet(CUIPlugin.ID_CELEMENT_CREATION_ACTION_SET); layout.addActionSet(CUIPlugin.ID_CELEMENT_CREATION_ACTION_SET);
layout.addActionSet(IPageLayout.ID_NAVIGATE_ACTION_SET); layout.addActionSet(IPageLayout.ID_NAVIGATE_ACTION_SET);
// views - build console // views - build console
layout.addShowViewShortcut(IConsoleConstants.ID_CONSOLE_VIEW); layout.addShowViewShortcut(IConsoleConstants.ID_CONSOLE_VIEW);
// views - searching // views - searching
layout.addShowViewShortcut(NewSearchUI.SEARCH_VIEW_ID); layout.addShowViewShortcut(NewSearchUI.SEARCH_VIEW_ID);
// views - standard workbench // views - standard workbench
layout.addShowViewShortcut(IPageLayout.ID_OUTLINE); layout.addShowViewShortcut(IPageLayout.ID_OUTLINE);
layout.addShowViewShortcut(IPageLayout.ID_PROBLEM_VIEW); layout.addShowViewShortcut(IPageLayout.ID_PROBLEM_VIEW);
@ -71,7 +74,7 @@ public class CPerspectiveFactory implements IPerspectiveFactory {
addCWizardShortcuts(layout); addCWizardShortcuts(layout);
} }
private void addCWizardShortcuts(IPageLayout layout) { private void addCWizardShortcuts(IPageLayout layout) {
// new actions - C project creation wizard // new actions - C project creation wizard
String[] wizIDs = CWizardRegistry.getProjectWizardIDs(); String[] wizIDs = CWizardRegistry.getProjectWizardIDs();
@ -93,6 +96,6 @@ public class CPerspectiveFactory implements IPerspectiveFactory {
for (int i = 0; i < wizIDs.length; ++i) { for (int i = 0; i < wizIDs.length; ++i) {
layout.addNewWizardShortcut(wizIDs[i]); layout.addNewWizardShortcut(wizIDs[i]);
} }
} }
} }

View file

@ -28,6 +28,7 @@ public class CProjectAdapterFactory implements IAdapterFactory {
/* /*
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
*/ */
@Override
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public Object getAdapter(Object adaptableObject, Class adapterType) { public Object getAdapter(Object adaptableObject, Class adapterType) {
if (IProject.class.equals(adapterType)) { if (IProject.class.equals(adapterType)) {
@ -39,6 +40,7 @@ public class CProjectAdapterFactory implements IAdapterFactory {
/* /*
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
*/ */
@Override
public Class<?>[] getAdapterList() { public Class<?>[] getAdapterList() {
return ADAPTERS; return ADAPTERS;
} }

View file

@ -12,14 +12,16 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui; package org.eclipse.cdt.internal.ui;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
import org.eclipse.cdt.ui.CElementLabelProvider; import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.model.IWorkbenchAdapter; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
/** /**
* An implementation of the IWorkbenchAdapter for CElements. * An implementation of the IWorkbenchAdapter for CElements.
@ -38,6 +40,7 @@ public class CWorkbenchAdapter implements IWorkbenchAdapter {
/** /**
* @see IWorkbenchAdapter#getChildren * @see IWorkbenchAdapter#getChildren
*/ */
@Override
public Object[] getChildren(Object o) { public Object[] getChildren(Object o) {
if (o instanceof IParent) { if (o instanceof IParent) {
try { try {
@ -55,6 +58,7 @@ public class CWorkbenchAdapter implements IWorkbenchAdapter {
/** /**
* @see IWorkbenchAdapter#getImageDescriptor * @see IWorkbenchAdapter#getImageDescriptor
*/ */
@Override
public ImageDescriptor getImageDescriptor(Object element) { public ImageDescriptor getImageDescriptor(Object element) {
if (element instanceof ICElement) { if (element instanceof ICElement) {
return fImageProvider.getCImageDescriptor( return fImageProvider.getCImageDescriptor(
@ -67,6 +71,7 @@ public class CWorkbenchAdapter implements IWorkbenchAdapter {
/** /**
* @see IWorkbenchAdapter#getLabel * @see IWorkbenchAdapter#getLabel
*/ */
@Override
public String getLabel(Object o) { public String getLabel(Object o) {
if (o instanceof ICElement) { if (o instanceof ICElement) {
return fLabelProvider.getText(o); return fLabelProvider.getText(o);
@ -77,6 +82,7 @@ public class CWorkbenchAdapter implements IWorkbenchAdapter {
/** /**
* @see IWorkbenchAdapter#getParent * @see IWorkbenchAdapter#getParent
*/ */
@Override
public Object getParent(Object o) { public Object getParent(Object o) {
if (o instanceof ICElement) { if (o instanceof ICElement) {
return ((ICElement) o).getParent(); return ((ICElement) o).getParent();

View file

@ -10,13 +10,14 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui; package org.eclipse.cdt.internal.ui;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IParent;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
import org.eclipse.ui.progress.IElementCollector; import org.eclipse.ui.progress.IElementCollector;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IParent;
public class DeferredCWorkbenchAdapter extends CWorkbenchAdapter implements IDeferredWorkbenchAdapter { public class DeferredCWorkbenchAdapter extends CWorkbenchAdapter implements IDeferredWorkbenchAdapter {
private ICElement fCElement; private ICElement fCElement;
@ -28,11 +29,12 @@ public class DeferredCWorkbenchAdapter extends CWorkbenchAdapter implements IDef
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#fetchDeferredChildren(java.lang.Object, * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#fetchDeferredChildren(java.lang.Object,
* org.eclipse.jface.progress.IElementCollector, * org.eclipse.jface.progress.IElementCollector,
* org.eclipse.core.runtime.IProgressMonitor) * org.eclipse.core.runtime.IProgressMonitor)
*/ */
@Override
public void fetchDeferredChildren(Object object, IElementCollector collector, IProgressMonitor monitor) { public void fetchDeferredChildren(Object object, IElementCollector collector, IProgressMonitor monitor) {
Object[] children = getChildren(object); Object[] children = getChildren(object);
if (monitor.isCanceled()) { if (monitor.isCanceled()) {
@ -44,18 +46,20 @@ public class DeferredCWorkbenchAdapter extends CWorkbenchAdapter implements IDef
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#isContainer() * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#isContainer()
*/ */
@Override
public boolean isContainer() { public boolean isContainer() {
return fCElement instanceof IParent; return fCElement instanceof IParent;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#getRule(java.lang.Object) * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#getRule(java.lang.Object)
*/ */
@Override
public ISchedulingRule getRule(final Object object) { public ISchedulingRule getRule(final Object object) {
return fCElement.getResource(); return fCElement.getResource();
} }

View file

@ -34,13 +34,13 @@ import org.eclipse.swt.graphics.Rectangle;
/** /**
* A painter for configurable background painting a range of text lines. * A painter for configurable background painting a range of text lines.
* Replicates also the functionality of the * Replicates also the functionality of the
* {@link org.eclipse.jface.text.CursorLinePainter} * {@link org.eclipse.jface.text.CursorLinePainter}
* because only one {@link LineBackgroundListener} is allowed * because only one {@link LineBackgroundListener} is allowed
* per {@link StyledText} widget. * per {@link StyledText} widget.
* *
* @author anton.leherbauer@windriver.com * @author anton.leherbauer@windriver.com
* *
* @since 4.0 * @since 4.0
*/ */
public class LineBackgroundPainter implements IPainter, LineBackgroundListener { public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
@ -89,7 +89,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/** /**
* Sets the color in which to draw the background of the given position type. * Sets the color in which to draw the background of the given position type.
* *
* @param positionType the position type for which to specify the background color * @param positionType the position type for which to specify the background color
* @param color the color in which to draw the background of the given position type * @param color the color in which to draw the background of the given position type
*/ */
@ -99,7 +99,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/** /**
* Sets the color in which to draw the background of the cursor line. * Sets the color in which to draw the background of the cursor line.
* *
* @param cursorLineColor the color in which to draw the background of the cursor line * @param cursorLineColor the color in which to draw the background of the cursor line
*/ */
public void setCursorLineColor(Color cursorLineColor) { public void setCursorLineColor(Color cursorLineColor) {
@ -108,7 +108,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/** /**
* Sets the color in which to draw the background of untyped positions. * Sets the color in which to draw the background of untyped positions.
* *
* @param color the color in which to draw the background of untyped positions * @param color the color in which to draw the background of untyped positions
*/ */
public void setDefaultColor(Color color) { public void setDefaultColor(Color color) {
@ -117,7 +117,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/** /**
* Enable/disable cursor line highlighting. * Enable/disable cursor line highlighting.
* *
* @param enable * @param enable
*/ */
public void enableCursorLine(boolean enable) { public void enableCursorLine(boolean enable) {
@ -131,7 +131,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/** /**
* Set highlight positions. It is assumed that all positions * Set highlight positions. It is assumed that all positions
* are up-to-date with respect to the text viewer document. * are up-to-date with respect to the text viewer document.
* *
* @param positions a list of <code>Position</code>s * @param positions a list of <code>Position</code>s
*/ */
public void setHighlightPositions(List<Position> positions) { public void setHighlightPositions(List<Position> positions) {
@ -148,7 +148,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/** /**
* Add highlight positions. It is assumed that all positions * Add highlight positions. It is assumed that all positions
* are up-to-date with respect to the text viewer document. * are up-to-date with respect to the text viewer document.
* *
* @param positions a list of <code>Position</code>s * @param positions a list of <code>Position</code>s
*/ */
public void addHighlightPositions(List<Position> positions) { public void addHighlightPositions(List<Position> positions) {
@ -162,7 +162,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/** /**
* Remove highlight positions by identity. * Remove highlight positions by identity.
* *
* @param positions a list of <code>Position</code>s * @param positions a list of <code>Position</code>s
*/ */
public void removeHighlightPositions(List<Position> positions) { public void removeHighlightPositions(List<Position> positions) {
@ -176,7 +176,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/** /**
* Replace given highlight positions in one step. * Replace given highlight positions in one step.
* *
* @param removePositions a list of <code>Position</code>s to remove * @param removePositions a list of <code>Position</code>s to remove
* @param addPositions a list of <code>Position</code>s to add * @param addPositions a list of <code>Position</code>s to add
*/ */
@ -232,6 +232,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/* /*
* @see org.eclipse.jface.text.IPainter#dispose() * @see org.eclipse.jface.text.IPainter#dispose()
*/ */
@Override
public void dispose() { public void dispose() {
// no deactivate! // no deactivate!
fIsActive= false; fIsActive= false;
@ -252,10 +253,11 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
public boolean isDisposed() { public boolean isDisposed() {
return fTextViewer == null; return fTextViewer == null;
} }
/* /*
* @see org.eclipse.jface.text.IPainter#paint(int) * @see org.eclipse.jface.text.IPainter#paint(int)
*/ */
@Override
public void paint(int reason) { public void paint(int reason) {
IDocument document= fTextViewer.getDocument(); IDocument document= fTextViewer.getDocument();
if (document == null) { if (document == null) {
@ -365,7 +367,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/** /**
* Trigger redraw of given text positions. * Trigger redraw of given text positions.
* *
* @param positions * @param positions
*/ */
private void redrawPositions(List<Position> positions) { private void redrawPositions(List<Position> positions) {
@ -429,6 +431,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/* /*
* @see org.eclipse.jface.text.IPainter#deactivate(boolean) * @see org.eclipse.jface.text.IPainter#deactivate(boolean)
*/ */
@Override
public void deactivate(boolean redraw) { public void deactivate(boolean redraw) {
if (fIsActive) { if (fIsActive) {
fIsActive= false; fIsActive= false;
@ -443,6 +446,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/* /*
* @see org.eclipse.jface.text.IPainter#setPositionManager(org.eclipse.jface.text.IPaintPositionManager) * @see org.eclipse.jface.text.IPainter#setPositionManager(org.eclipse.jface.text.IPaintPositionManager)
*/ */
@Override
public void setPositionManager(IPaintPositionManager manager) { public void setPositionManager(IPaintPositionManager manager) {
fPositionManager= manager; fPositionManager= manager;
} }
@ -485,6 +489,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
/* /*
* @see org.eclipse.swt.custom.LineBackgroundListener#lineGetBackground(org.eclipse.swt.custom.LineBackgroundEvent) * @see org.eclipse.swt.custom.LineBackgroundListener#lineGetBackground(org.eclipse.swt.custom.LineBackgroundEvent)
*/ */
@Override
public void lineGetBackground(LineBackgroundEvent event) { public void lineGetBackground(LineBackgroundEvent event) {
if (fTextWidget != null) { if (fTextWidget != null) {
Position match= findIncludingPosition(getDocumentOffset(event.lineOffset)); Position match= findIncludingPosition(getDocumentOffset(event.lineOffset));
@ -541,7 +546,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
IDocument document= fTextViewer.getDocument(); IDocument document= fTextViewer.getDocument();
if (document != null) { if (document != null) {
int lineNumber= document.getLineOfOffset(getDocumentOffset(fTextWidget.getCaretOffset())); int lineNumber= document.getLineOfOffset(getDocumentOffset(fTextWidget.getCaretOffset()));
fCursorLine.isDeleted= false; fCursorLine.isDeleted= false;
fCursorLine.offset= document.getLineOffset(lineNumber); fCursorLine.offset= document.getLineOffset(lineNumber);
fCursorLine.length= 0; fCursorLine.length= 0;

View file

@ -27,7 +27,7 @@ import org.eclipse.ui.IPersistableElement;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
/** /**
* The PersistableCElementFactory is used to save and recreate an ICElement object. * The PersistableCElementFactory is used to save and recreate an ICElement object.
* As such, it implements the IPersistableElement interface for storage * As such, it implements the IPersistableElement interface for storage
* and the IElementFactory interface for recreation. * and the IElementFactory interface for recreation.
@ -66,7 +66,8 @@ public class PersistableCElementFactory implements IElementFactory, IPersistable
/** /**
* @see IElementFactory * @see IElementFactory
*/ */
public IAdaptable createElement(IMemento memento) { @Override
public IAdaptable createElement(IMemento memento) {
// Get the file name. // Get the file name.
String fileName = memento.getString(TAG_PATH); String fileName = memento.getString(TAG_PATH);
if (fileName == null) { if (fileName == null) {
@ -84,7 +85,7 @@ public class PersistableCElementFactory implements IElementFactory, IPersistable
if (fCElement != null) { if (fCElement != null) {
return fCElement; return fCElement;
} }
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
Integer elementType= memento.getInteger(TAG_TYPE); Integer elementType= memento.getInteger(TAG_TYPE);
if (elementType == null) { if (elementType == null) {
@ -114,14 +115,16 @@ public class PersistableCElementFactory implements IElementFactory, IPersistable
/** /**
* @see IPersistableElement * @see IPersistableElement
*/ */
public String getFactoryId() { @Override
public String getFactoryId() {
return FACTORY_ID; return FACTORY_ID;
} }
/** /**
* @see IPersistableElement * @see IPersistableElement
*/ */
public void saveState(IMemento memento) { @Override
public void saveState(IMemento memento) {
if (fCElement.getResource() != null) { if (fCElement.getResource() != null) {
memento.putString(TAG_PATH, fCElement.getResource().getFullPath().toString()); memento.putString(TAG_PATH, fCElement.getResource().getFullPath().toString());
memento.putInteger(TAG_TYPE, fCElement.getResource().getType()); memento.putInteger(TAG_TYPE, fCElement.getResource().getType());

View file

@ -26,20 +26,22 @@ public class ResourceAdapterFactory implements IAdapterFactory {
private static Class<?>[] PROPERTIES= new Class[] { private static Class<?>[] PROPERTIES= new Class[] {
ICElement.class ICElement.class
}; };
//private static CElementFactory celementFactory= new CElementFactory(); //private static CElementFactory celementFactory= new CElementFactory();
private static CoreModel celementFactory= CoreModel.getDefault(); private static CoreModel celementFactory= CoreModel.getDefault();
/** /**
* @see IAdapterFactory#getAdapterList * @see IAdapterFactory#getAdapterList
*/ */
@Override
public Class<?>[] getAdapterList() { public Class<?>[] getAdapterList() {
return PROPERTIES; return PROPERTIES;
} }
/** /**
* @see IAdapterFactory#getAdapter * @see IAdapterFactory#getAdapter
*/ */
@Override
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public Object getAdapter(Object element, Class key) { public Object getAdapter(Object element, Class key) {
if (ICElement.class.equals(key)) { if (ICElement.class.equals(key)) {
@ -60,5 +62,5 @@ public class ResourceAdapterFactory implements IAdapterFactory {
//} //}
} }
return null; return null;
} }
} }

View file

@ -8,7 +8,7 @@
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.actions; package org.eclipse.cdt.internal.ui.actions;
@ -34,14 +34,16 @@ import org.eclipse.cdt.ui.CUIPlugin;
public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate { public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate {
private ISelection fSelection; private ISelection fSelection;
@Override
public void setActivePart(IAction action, IWorkbenchPart targetPart) { public void setActivePart(IAction action, IWorkbenchPart targetPart) {
} }
@Override
public void run(IAction action) { public void run(IAction action) {
if (!(fSelection instanceof IStructuredSelection)) if (!(fSelection instanceof IStructuredSelection))
return; return;
IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection); IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
Iterator<?> i= cElements.iterator(); Iterator<?> i= cElements.iterator();
ArrayList<ICElement> tuSelection= new ArrayList<ICElement>(); ArrayList<ICElement> tuSelection= new ArrayList<ICElement>();
@ -52,7 +54,7 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate
} }
} }
ICElement[] tuArray= tuSelection.toArray(new ICElement[tuSelection.size()]); ICElement[] tuArray= tuSelection.toArray(new ICElement[tuSelection.size()]);
try { try {
CCorePlugin.getIndexManager().update(tuArray, getUpdateOptions()); CCorePlugin.getIndexManager().update(tuArray, getUpdateOptions());
} }
@ -71,6 +73,7 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate
/** /**
* @see IActionDelegate#selectionChanged(IAction, ISelection) * @see IActionDelegate#selectionChanged(IAction, ISelection)
*/ */
@Override
public void selectionChanged(IAction action, ISelection selection) { public void selectionChanged(IAction action, ISelection selection) {
fSelection = selection; fSelection = selection;
} }

View file

@ -11,20 +11,17 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.actions; package org.eclipse.cdt.internal.ui.actions;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Point;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler; import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.ITextViewerExtension5; import org.eclipse.jface.text.ITextViewerExtension5;
import org.eclipse.jface.text.Region; import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.actions.QuickMenuCreator; import org.eclipse.ui.actions.QuickMenuCreator;
import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -33,7 +30,7 @@ import org.eclipse.cdt.internal.ui.text.CWordFinder;
/** /**
* C/C++ editor aware quick menu creator. In the given editor, the menu will be aligned with the word * C/C++ editor aware quick menu creator. In the given editor, the menu will be aligned with the word
* at the current offset. * at the current offset.
* *
* @since 5.2 * @since 5.2
*/ */
public abstract class CDTQuickMenuCreator extends QuickMenuCreator { public abstract class CDTQuickMenuCreator extends QuickMenuCreator {
@ -94,11 +91,12 @@ public abstract class CDTQuickMenuCreator extends QuickMenuCreator {
/** /**
* Returns a handler that can create and open the quick menu. * Returns a handler that can create and open the quick menu.
* *
* @return a handler that can create and open the quick menu * @return a handler that can create and open the quick menu
*/ */
public IHandler createHandler() { public IHandler createHandler() {
return new AbstractHandler() { return new AbstractHandler() {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
createMenu(); createMenu();
return null; return null;

View file

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.actions; package org.eclipse.cdt.internal.ui.actions;
import java.io.File; import java.io.File;
@ -98,7 +98,7 @@ public class CreateParserLogAction implements IObjectActionDelegate {
fProblems.add(problem); fProblems.add(problem);
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@Override @Override
public int visit(IASTName name) { public int visit(IASTName name) {
if (name instanceof ICPPASTQualifiedName) { if (name instanceof ICPPASTQualifiedName) {
@ -117,6 +117,7 @@ public class CreateParserLogAction implements IObjectActionDelegate {
} }
private static final Comparator<String> COMP_INSENSITIVE= new Comparator<String> () { private static final Comparator<String> COMP_INSENSITIVE= new Comparator<String> () {
@Override
public int compare(String o1, String o2) { public int compare(String o1, String o2) {
return o1.toUpperCase().compareTo(o2.toUpperCase()); return o1.toUpperCase().compareTo(o2.toUpperCase());
} }
@ -126,20 +127,23 @@ public class CreateParserLogAction implements IObjectActionDelegate {
private IWorkbenchPartSite fSite; private IWorkbenchPartSite fSite;
private boolean fWroteUnresolvedTitle; private boolean fWroteUnresolvedTitle;
@Override
public void setActivePart(IAction action, IWorkbenchPart targetPart) { public void setActivePart(IAction action, IWorkbenchPart targetPart) {
fSite= targetPart.getSite(); fSite= targetPart.getSite();
} }
@Override
public void selectionChanged(IAction action, ISelection selection) { public void selectionChanged(IAction action, ISelection selection) {
fSelection = selection; fSelection = selection;
} }
@Override
public void run(IAction action) { public void run(IAction action) {
if (!(fSelection instanceof IStructuredSelection)) if (!(fSelection instanceof IStructuredSelection))
return; return;
final String title= action.getText().replace("&", ""); final String title= action.getText().replace("&", "");
IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection); IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
Iterator<?> i= cElements.iterator(); Iterator<?> i= cElements.iterator();
ArrayList<ITranslationUnit> tuSelection= new ArrayList<ITranslationUnit>(); ArrayList<ITranslationUnit> tuSelection= new ArrayList<ITranslationUnit>();
@ -155,36 +159,36 @@ public class CreateParserLogAction implements IObjectActionDelegate {
} }
FileDialog dlg= new FileDialog(fSite.getShell(), SWT.SAVE); FileDialog dlg= new FileDialog(fSite.getShell(), SWT.SAVE);
dlg.setText(title); dlg.setText(title);
dlg.setFilterExtensions(new String[]{"*.log"}); dlg.setFilterExtensions(new String[]{"*.log"});
String path= null; String path= null;
while(path == null) { while(path == null) {
path= dlg.open(); path= dlg.open();
if (path == null) if (path == null)
return; return;
File file= new File(path); File file= new File(path);
if (file.exists()) { if (file.exists()) {
if (!file.canWrite()) { if (!file.canWrite()) {
final String msg= NLS.bind(ActionMessages.CreateParserLogAction_readOnlyFile, path); final String msg= NLS.bind(ActionMessages.CreateParserLogAction_readOnlyFile, path);
MessageDialog.openError(fSite.getShell(), title, msg); MessageDialog.openError(fSite.getShell(), title, msg);
path= null; path= null;
} }
else { else {
final String msg = NLS.bind(ActionMessages.CreateParserLogAction_existingFile, path); final String msg = NLS.bind(ActionMessages.CreateParserLogAction_existingFile, path);
if (!MessageDialog.openQuestion(fSite.getShell(), title, msg)) { if (!MessageDialog.openQuestion(fSite.getShell(), title, msg)) {
path= null; path= null;
} }
} }
} }
} }
try { try {
PrintStream out= new PrintStream(path); PrintStream out= new PrintStream(path);
try { try {
boolean needsep= false; boolean needsep= false;
for (ITranslationUnit tu : tuArray) { for (ITranslationUnit tu : tuArray) {
if (needsep) { if (needsep) {
out.println(); out.println(); out.println(); out.println();
} }
createLog(out, tu, new NullProgressMonitor()); createLog(out, tu, new NullProgressMonitor());
needsep= true; needsep= true;
@ -205,6 +209,7 @@ public class CreateParserLogAction implements IObjectActionDelegate {
CUIPlugin.log(e); CUIPlugin.log(e);
} }
ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_IF_OPEN, pm, new ASTCache.ASTRunnable() { ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_IF_OPEN, pm, new ASTCache.ASTRunnable() {
@Override
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException { public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
if (ast != null) if (ast != null)
return createLog(out, tu, lang, ast); return createLog(out, tu, lang, ast);
@ -243,11 +248,11 @@ public class CreateParserLogAction implements IObjectActionDelegate {
final ExtendedScannerInfo scfg= new ExtendedScannerInfo(configureWith.getScannerInfo(true)); final ExtendedScannerInfo scfg= new ExtendedScannerInfo(configureWith.getScannerInfo(true));
final MyVisitor visitor= new MyVisitor(); final MyVisitor visitor= new MyVisitor();
ast.accept(visitor); ast.accept(visitor);
out.println("Project: " + projectName); out.println("Project: " + projectName);
out.println("File: " + tu.getLocationURI()); out.println("File: " + tu.getLocationURI());
out.println("Language: " + lang.getName()); out.println("Language: " + lang.getName());
out.println("Index Version: " + PDOM.versionString(PDOM.getDefaultVersion())); out.println("Index Version: " + PDOM.versionString(PDOM.getDefaultVersion()));
out.println("Build Configuration: " + getBuildConfig(cproject)); out.println("Build Configuration: " + getBuildConfig(cproject));
if (configureWith == tu) { if (configureWith == tu) {
out.println("Context: none"); out.println("Context: none");
@ -255,7 +260,7 @@ public class CreateParserLogAction implements IObjectActionDelegate {
out.println("Context: " + configureWith.getLocationURI()); out.println("Context: " + configureWith.getLocationURI());
out.println(INDENT + getLinkageName(ctxLinkage) + ", " + ctxSigMacros); out.println(INDENT + getLinkageName(ctxLinkage) + ", " + ctxSigMacros);
} }
try { try {
IIndexFile[] versions= index.getFiles(IndexLocationFactory.getIFL(tu)); IIndexFile[] versions= index.getFiles(IndexLocationFactory.getIFL(tu));
out.println("Versions in Index: " + versions.length); out.println("Versions in Index: " + versions.length);
@ -271,7 +276,7 @@ public class CreateParserLogAction implements IObjectActionDelegate {
output(out, "Local Include Search Path (option -iquote):", scfg.getLocalIncludePath()); output(out, "Local Include Search Path (option -iquote):", scfg.getLocalIncludePath());
output(out, "Preincluded files (option -include):", scfg.getIncludeFiles()); output(out, "Preincluded files (option -include):", scfg.getIncludeFiles());
output(out, "Preincluded macro files (option -imacros):", scfg.getMacroFiles()); output(out, "Preincluded macro files (option -imacros):", scfg.getMacroFiles());
HashSet<String> reported= new HashSet<String>(); HashSet<String> reported= new HashSet<String>();
output(out, "Macro definitions (option -D):", scfg.getDefinedSymbols(), reported); output(out, "Macro definitions (option -D):", scfg.getDefinedSymbols(), reported);
output(out, "Macro definitions (from language + headers in index):", ast.getBuiltinMacroDefinitions(), reported); output(out, "Macro definitions (from language + headers in index):", ast.getBuiltinMacroDefinitions(), reported);
@ -306,13 +311,13 @@ public class CreateParserLogAction implements IObjectActionDelegate {
ICProjectDescription prefs= prjDescMgr.getProjectDescription(cproject.getProject(), false); ICProjectDescription prefs= prjDescMgr.getProjectDescription(cproject.getProject(), false);
if (prefs != null) { if (prefs != null) {
ICConfigurationDescription cfg= prefs.getDefaultSettingConfiguration(); ICConfigurationDescription cfg= prefs.getDefaultSettingConfiguration();
if (cfg != null) if (cfg != null)
return cfg.getName(); return cfg.getName();
} }
return "unknown"; return "unknown";
} }
private void outputUnresolvedIncludes(ICProject prj, IIndex index, PrintStream out, private void outputUnresolvedIncludes(ICProject prj, IIndex index, PrintStream out,
IASTPreprocessorIncludeStatement[] includeDirectives, int linkageID) throws CoreException { IASTPreprocessorIncludeStatement[] includeDirectives, int linkageID) throws CoreException {
fWroteUnresolvedTitle= false; fWroteUnresolvedTitle= false;
ASTFilePathResolver resolver= new ProjectIndexerInputAdapter(prj); ASTFilePathResolver resolver= new ProjectIndexerInputAdapter(prj);
@ -328,11 +333,11 @@ public class CreateParserLogAction implements IObjectActionDelegate {
out.println(); out.println();
} }
private void outputUnresolvedIncludes(IIndex index, PrintStream out, private void outputUnresolvedIncludes(IIndex index, PrintStream out,
IIndexFileLocation ifl, IIndexFile ifile, Set<IIndexFile> handled) throws CoreException { IIndexFileLocation ifl, IIndexFile ifile, Set<IIndexFile> handled) throws CoreException {
if (ifile == null) { if (ifile == null) {
writeUnresolvedTitle(out); writeUnresolvedTitle(out);
out.println(INDENT + ifl.getURI() + " is not indexed"); out.println(INDENT + ifl.getURI() + " is not indexed");
} else if (handled.add(ifile)) { } else if (handled.add(ifile)) {
IIndexInclude[] includes = ifile.getIncludes(); IIndexInclude[] includes = ifile.getIncludes();
for (IIndexInclude inc : includes) { for (IIndexInclude inc : includes) {
@ -342,7 +347,7 @@ public class CreateParserLogAction implements IObjectActionDelegate {
outputUnresolvedIncludes(index, out, inc.getIncludesLocation(), next, handled); outputUnresolvedIncludes(index, out, inc.getIncludesLocation(), next, handled);
} else { } else {
writeUnresolvedTitle(out); writeUnresolvedTitle(out);
out.println(INDENT + "Unresolved inclusion: " + inc.getFullName() + " in file " + out.println(INDENT + "Unresolved inclusion: " + inc.getFullName() + " in file " +
inc.getIncludedByLocation().getURI()); inc.getIncludedByLocation().getURI());
} }
} }
@ -382,7 +387,7 @@ public class CreateParserLogAction implements IObjectActionDelegate {
out.println(); out.println();
} }
} }
private void output(PrintStream out, String label, IASTPreprocessorMacroDefinition[] defs, HashSet<String> reported) { private void output(PrintStream out, String label, IASTPreprocessorMacroDefinition[] defs, HashSet<String> reported) {
if (defs.length > 0) { if (defs.length > 0) {
out.println(label); out.println(label);
@ -399,7 +404,7 @@ public class CreateParserLogAction implements IObjectActionDelegate {
out.println(); out.println();
} }
} }
private void output(PrintStream out, String label, IASTProblem[] preprocessorProblems) { private void output(PrintStream out, String label, IASTProblem[] preprocessorProblems) {
if (preprocessorProblems.length > 0) { if (preprocessorProblems.length > 0) {
out.println(label); out.println(label);
@ -409,14 +414,14 @@ public class CreateParserLogAction implements IObjectActionDelegate {
out.println(); out.println();
} }
} }
private void output(PrintStream out, String label, IProblemBinding[] list) { private void output(PrintStream out, String label, IProblemBinding[] list) {
if (list.length > 0) { if (list.length > 0) {
out.println(label); out.println(label);
for (IProblemBinding problem : list) { for (IProblemBinding problem : list) {
String file= problem.getFileName(); String file= problem.getFileName();
int line = problem.getLineNumber(); int line = problem.getLineNumber();
out.println(INDENT + problem.getMessage() + " in file " + file + ':' + line); out.println(INDENT + problem.getMessage() + " in file " + file + ':' + line);
} }
out.println(); out.println();
} }

View file

@ -58,14 +58,14 @@ import org.eclipse.cdt.ui.newui.AbstractPage;
public class DeleteResConfigsHandler extends AbstractHandler { public class DeleteResConfigsHandler extends AbstractHandler {
protected ArrayList<IResource> objects; protected ArrayList<IResource> objects;
private ArrayList<ResCfgData> outData; private ArrayList<ResCfgData> outData;
@Override @Override
public void setEnabled(Object context) { public void setEnabled(Object context) {
ISelection selection = getSelection(context); ISelection selection = getSelection(context);
setEnabledFromSelection(selection); setEnabledFromSelection(selection);
} }
protected ISelection getSelection(Object context) { protected ISelection getSelection(Object context) {
Object s = HandlerUtil.getVariable(context, ISources.ACTIVE_MENU_SELECTION_NAME); Object s = HandlerUtil.getVariable(context, ISources.ACTIVE_MENU_SELECTION_NAME);
if (s instanceof ISelection) { if (s instanceof ISelection) {
@ -76,7 +76,7 @@ public class DeleteResConfigsHandler extends AbstractHandler {
public void setEnabledFromSelection(ISelection selection) { public void setEnabledFromSelection(ISelection selection) {
objects = null; objects = null;
if ((selection != null) && !selection.isEmpty()) { if ((selection != null) && !selection.isEmpty()) {
// case for context menu // case for context menu
Object[] obs = null; Object[] obs = null;
@ -100,10 +100,10 @@ public class DeleteResConfigsHandler extends AbstractHandler {
if (res != null) { if (res != null) {
IProject p = res.getProject(); IProject p = res.getProject();
if (!p.isOpen()) continue; if (!p.isOpen()) continue;
if (!CoreModel.getDefault().isNewStyleProject(p)) if (!CoreModel.getDefault().isNewStyleProject(p))
continue; continue;
IPath path = res.getProjectRelativePath(); IPath path = res.getProjectRelativePath();
// getting description in read-only mode // getting description in read-only mode
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(p, false); ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(p, false);
@ -121,7 +121,7 @@ public class DeleteResConfigsHandler extends AbstractHandler {
} }
} }
} }
} }
setBaseEnabled(objects != null); setBaseEnabled(objects != null);
} }
@ -141,19 +141,20 @@ public class DeleteResConfigsHandler extends AbstractHandler {
return null; return null;
} }
@Override
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
openDialog(); openDialog();
return null; return null;
} }
private void openDialog() { private void openDialog() {
if (objects == null || objects.size() == 0) return; if (objects == null || objects.size() == 0) return;
// create list of configurations to delete // create list of configurations to delete
ListSelectionDialog dialog = new ListSelectionDialog( ListSelectionDialog dialog = new ListSelectionDialog(
CUIPlugin.getActiveWorkbenchShell(), CUIPlugin.getActiveWorkbenchShell(),
objects, objects,
createSelectionDialogContentProvider(), createSelectionDialogContentProvider(),
new LabelProvider() {}, ActionMessages.DeleteResConfigsAction_0); new LabelProvider() {}, ActionMessages.DeleteResConfigsAction_0);
dialog.setTitle(ActionMessages.DeleteResConfigsAction_1); dialog.setTitle(ActionMessages.DeleteResConfigsAction_1);
if (dialog.open() == Window.OK) { if (dialog.open() == Window.OK) {
@ -173,12 +174,12 @@ public class DeleteResConfigsHandler extends AbstractHandler {
ICProjectDescription prjd; ICProjectDescription prjd;
ICConfigurationDescription cfgd; ICConfigurationDescription cfgd;
ICResourceDescription rdesc; ICResourceDescription rdesc;
public ResCfgData(IResource res2, ICProjectDescription prjd2, public ResCfgData(IResource res2, ICProjectDescription prjd2,
ICConfigurationDescription cfgd2, ICResourceDescription rdesc2) { ICConfigurationDescription cfgd2, ICResourceDescription rdesc2) {
res = res2; prjd = prjd2; cfgd = cfgd2; rdesc = rdesc2; res = res2; prjd = prjd2; cfgd = cfgd2; rdesc = rdesc2;
} }
// performs deletion // performs deletion
public void delete() { public void delete() {
try { try {
@ -191,16 +192,17 @@ public class DeleteResConfigsHandler extends AbstractHandler {
return "[" + cfgd.getName() + "] for " + res.getName(); //$NON-NLS-1$ //$NON-NLS-2$ return "[" + cfgd.getName() + "] for " + res.getName(); //$NON-NLS-1$ //$NON-NLS-2$
} }
} }
private IStructuredContentProvider createSelectionDialogContentProvider() { private IStructuredContentProvider createSelectionDialogContentProvider() {
outData = null; outData = null;
return new IStructuredContentProvider() { return new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) { public Object[] getElements(Object inputElement) {
if (outData != null) return outData.toArray(); if (outData != null) return outData.toArray();
outData = new ArrayList<ResCfgData>(); outData = new ArrayList<ResCfgData>();
List<?> ls = (List<?>)inputElement; List<?> ls = (List<?>)inputElement;
Iterator<?> it = ls.iterator(); Iterator<?> it = ls.iterator();
@ -220,16 +222,18 @@ public class DeleteResConfigsHandler extends AbstractHandler {
if (cfgds != null) { if (cfgds != null) {
for (ICConfigurationDescription cfgd : cfgds) { for (ICConfigurationDescription cfgd : cfgds) {
ICResourceDescription rd = cfgd.getResourceDescription(path, true); ICResourceDescription rd = cfgd.getResourceDescription(path, true);
if (rd != null) if (rd != null)
outData.add(new ResCfgData(res, prjd, cfgd, rd)); outData.add(new ResCfgData(res, prjd, cfgd, rd));
} }
} }
} }
return outData.toArray(); return outData.toArray();
} }
@Override
public void dispose() {} public void dispose() {}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
}; };
} }
} }

View file

@ -68,7 +68,7 @@ public class ExcludeFromBuildHandler extends AbstractHandler {
ISelection selection = getSelection(context); ISelection selection = getSelection(context);
setEnabledFromSelection(selection); setEnabledFromSelection(selection);
} }
protected ISelection getSelection(Object context) { protected ISelection getSelection(Object context) {
Object s = HandlerUtil.getVariable(context, ISources.ACTIVE_MENU_SELECTION_NAME); Object s = HandlerUtil.getVariable(context, ISources.ACTIVE_MENU_SELECTION_NAME);
if (s instanceof ISelection) { if (s instanceof ISelection) {
@ -81,7 +81,7 @@ public class ExcludeFromBuildHandler extends AbstractHandler {
objects = null; objects = null;
cfgNames = null; cfgNames = null;
boolean cfgsOK = true; boolean cfgsOK = true;
if ((selection != null) && !selection.isEmpty()) { if ((selection != null) && !selection.isEmpty()) {
// case for context menu // case for context menu
Object[] obs = null; Object[] obs = null;
@ -97,7 +97,7 @@ public class ExcludeFromBuildHandler extends AbstractHandler {
for (int i=0; i<obs.length && cfgsOK; i++) { for (int i=0; i<obs.length && cfgsOK; i++) {
// if project selected, don't do anything // if project selected, don't do anything
if ((obs[i] instanceof IProject) || (obs[i] instanceof ICProject)) { if ((obs[i] instanceof IProject) || (obs[i] instanceof ICProject)) {
cfgsOK=false; cfgsOK=false;
break; break;
} }
IResource res = null; IResource res = null;
@ -111,12 +111,12 @@ public class ExcludeFromBuildHandler extends AbstractHandler {
if (res != null) { if (res != null) {
ICConfigurationDescription[] cfgds = getCfgsRead(res); ICConfigurationDescription[] cfgds = getCfgsRead(res);
if (cfgds == null || cfgds.length == 0) continue; if (cfgds == null || cfgds.length == 0) continue;
if (objects == null) objects = new ArrayList<IResource>(); if (objects == null) objects = new ArrayList<IResource>();
objects.add(res); objects.add(res);
if (cfgNames == null) { if (cfgNames == null) {
cfgNames = new ArrayList<String>(cfgds.length); cfgNames = new ArrayList<String>(cfgds.length);
for (int j=0; j<cfgds.length; j++) { for (int j=0; j<cfgds.length; j++) {
if (!canExclude(res, cfgds[j])) { if (!canExclude(res, cfgds[j])) {
cfgNames = null; cfgNames = null;
cfgsOK = false; cfgsOK = false;
@ -140,7 +140,7 @@ public class ExcludeFromBuildHandler extends AbstractHandler {
} }
} }
} }
} }
setBaseEnabled(cfgsOK && (objects != null)); setBaseEnabled(cfgsOK && (objects != null));
} }
@ -173,14 +173,15 @@ public class ExcludeFromBuildHandler extends AbstractHandler {
cfg.setSourceEntries(newEntries); cfg.setSourceEntries(newEntries);
} catch (CoreException e) { } catch (CoreException e) {
CUIPlugin.log(e); CUIPlugin.log(e);
} }
} }
@Override
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
openDialog(); openDialog();
return null; return null;
} }
private ICConfigurationDescription[] getCfgsRead(IResource res) { private ICConfigurationDescription[] getCfgsRead(IResource res) {
IProject p = res.getProject(); IProject p = res.getProject();
if (!p.isOpen()) return null; if (!p.isOpen()) return null;
@ -189,19 +190,19 @@ public class ExcludeFromBuildHandler extends AbstractHandler {
if (prjd == null) return null; if (prjd == null) return null;
return prjd.getConfigurations(); return prjd.getConfigurations();
} }
private void openDialog() { private void openDialog() {
if (objects == null || objects.size() == 0) return; if (objects == null || objects.size() == 0) return;
// create list of configurations to delete // create list of configurations to delete
ListSelectionDialog dialog = new ListSelectionDialog( ListSelectionDialog dialog = new ListSelectionDialog(
CUIPlugin.getActiveWorkbenchShell(), CUIPlugin.getActiveWorkbenchShell(),
cfgNames, cfgNames,
createSelectionDialogContentProvider(), createSelectionDialogContentProvider(),
new LabelProvider() {}, new LabelProvider() {},
ActionMessages.ExcludeFromBuildAction_0); ActionMessages.ExcludeFromBuildAction_0);
dialog.setTitle(ActionMessages.ExcludeFromBuildAction_1); dialog.setTitle(ActionMessages.ExcludeFromBuildAction_1);
boolean[] status = new boolean[cfgNames.size()]; boolean[] status = new boolean[cfgNames.size()];
Iterator<IResource> it = objects.iterator(); Iterator<IResource> it = objects.iterator();
while (it.hasNext()) { while (it.hasNext()) {
@ -214,11 +215,11 @@ public class ExcludeFromBuildHandler extends AbstractHandler {
} }
} }
ArrayList<String> lst = new ArrayList<String>(); ArrayList<String> lst = new ArrayList<String>();
for (int i=0; i<status.length; i++) for (int i=0; i<status.length; i++)
if (status[i]) lst.add(cfgNames.get(i)); if (status[i]) lst.add(cfgNames.get(i));
if (lst.size() > 0) if (lst.size() > 0)
dialog.setInitialElementSelections(lst); dialog.setInitialElementSelections(lst);
if (dialog.open() == Window.OK) { if (dialog.open() == Window.OK) {
Object[] selected = dialog.getResult(); // may be empty Object[] selected = dialog.getResult(); // may be empty
Iterator<IResource> it2 = objects.iterator(); Iterator<IResource> it2 = objects.iterator();
@ -243,7 +244,7 @@ public class ExcludeFromBuildHandler extends AbstractHandler {
try { try {
CoreModel.getDefault().setProjectDescription(p, prjd); CoreModel.getDefault().setProjectDescription(p, prjd);
} catch (CoreException e) { } catch (CoreException e) {
CUIPlugin.logError(Messages.AbstractPage_11 + e.getLocalizedMessage()); CUIPlugin.logError(Messages.AbstractPage_11 + e.getLocalizedMessage());
} }
AbstractPage.updateViews(res); AbstractPage.updateViews(res);
} }
@ -252,10 +253,13 @@ public class ExcludeFromBuildHandler extends AbstractHandler {
private IStructuredContentProvider createSelectionDialogContentProvider() { private IStructuredContentProvider createSelectionDialogContentProvider() {
return new IStructuredContentProvider() { return new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) { return cfgNames.toArray(); } public Object[] getElements(Object inputElement) { return cfgNames.toArray(); }
@Override
public void dispose() {} public void dispose() {}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
}; };
} }
} }

View file

@ -30,7 +30,7 @@ import org.eclipse.cdt.internal.ui.editor.CEditor;
/** /**
* Groups the CDT folding actions. * Groups the CDT folding actions.
* *
* @since 3.0 * @since 3.0
*/ */
public class FoldingActionGroup extends ActionGroup { public class FoldingActionGroup extends ActionGroup {
@ -41,38 +41,39 @@ public class FoldingActionGroup extends ActionGroup {
update(); update();
} }
} }
private class FoldingAction extends PreferenceAction { private class FoldingAction extends PreferenceAction {
FoldingAction(ResourceBundle bundle, String prefix) { FoldingAction(ResourceBundle bundle, String prefix) {
super(bundle, prefix, IAction.AS_PUSH_BUTTON); super(bundle, prefix, IAction.AS_PUSH_BUTTON);
} }
@Override
public void update() { public void update() {
setEnabled(FoldingActionGroup.this.isEnabled() && fViewer.isProjectionMode()); setEnabled(FoldingActionGroup.this.isEnabled() && fViewer.isProjectionMode());
} }
} }
private ProjectionViewer fViewer; private ProjectionViewer fViewer;
private IProjectionListener fProjectionListener; private IProjectionListener fProjectionListener;
private TextOperationAction fToggle; private TextOperationAction fToggle;
private TextOperationAction fExpand; private TextOperationAction fExpand;
private TextOperationAction fCollapse; private TextOperationAction fCollapse;
private TextOperationAction fExpandAll; private TextOperationAction fExpandAll;
// since 4.0 // since 4.0
private TextOperationAction fCollapseAll; private TextOperationAction fCollapseAll;
private PreferenceAction fRestoreDefaults; private PreferenceAction fRestoreDefaults;
/** /**
* Creates a new projection action group for <code>editor</code>. If the * Creates a new projection action group for <code>editor</code>. If the
* supplied viewer is not an instance of <code>ProjectionViewer</code>, the * supplied viewer is not an instance of <code>ProjectionViewer</code>, the
* action group is disabled. * action group is disabled.
* *
* @param editor the text editor to operate on * @param editor the text editor to operate on
* @param viewer the viewer of the editor * @param viewer the viewer of the editor
*/ */
@ -87,28 +88,30 @@ public class FoldingActionGroup extends ActionGroup {
fProjectionListener= null; fProjectionListener= null;
return; return;
} }
fViewer= (ProjectionViewer) viewer; fViewer= (ProjectionViewer) viewer;
fProjectionListener= new IProjectionListener() { fProjectionListener= new IProjectionListener() {
@Override
public void projectionEnabled() { public void projectionEnabled() {
update(); update();
} }
@Override
public void projectionDisabled() { public void projectionDisabled() {
update(); update();
} }
}; };
fViewer.addProjectionListener(fProjectionListener); fViewer.addProjectionListener(fProjectionListener);
fToggle= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$ fToggle= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$
fToggle.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE); fToggle.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE);
editor.setAction("FoldingToggle", fToggle); //$NON-NLS-1$ editor.setAction("FoldingToggle", fToggle); //$NON-NLS-1$
fExpandAll= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.ExpandAll.", editor, ProjectionViewer.EXPAND_ALL, true); //$NON-NLS-1$ fExpandAll= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.ExpandAll.", editor, ProjectionViewer.EXPAND_ALL, true); //$NON-NLS-1$
fExpandAll.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND_ALL); fExpandAll.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND_ALL);
editor.setAction("FoldingExpandAll", fExpandAll); //$NON-NLS-1$ editor.setAction("FoldingExpandAll", fExpandAll); //$NON-NLS-1$
fCollapseAll= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.CollapseAll.", editor, ProjectionViewer.COLLAPSE_ALL, true); //$NON-NLS-1$ fCollapseAll= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.CollapseAll.", editor, ProjectionViewer.COLLAPSE_ALL, true); //$NON-NLS-1$
fCollapseAll.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE_ALL); fCollapseAll.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE_ALL);
editor.setAction("FoldingCollapseAll", fCollapseAll); //$NON-NLS-1$ editor.setAction("FoldingCollapseAll", fCollapseAll); //$NON-NLS-1$
@ -116,7 +119,7 @@ public class FoldingActionGroup extends ActionGroup {
fExpand= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Expand.", editor, ProjectionViewer.EXPAND, true); //$NON-NLS-1$ fExpand= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Expand.", editor, ProjectionViewer.EXPAND, true); //$NON-NLS-1$
fExpand.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND); fExpand.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND);
editor.setAction("FoldingExpand", fExpand); //$NON-NLS-1$ editor.setAction("FoldingExpand", fExpand); //$NON-NLS-1$
fCollapse= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Collapse.", editor, ProjectionViewer.COLLAPSE, true); //$NON-NLS-1$ fCollapse= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Collapse.", editor, ProjectionViewer.COLLAPSE, true); //$NON-NLS-1$
fCollapse.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE); fCollapse.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE);
editor.setAction("FoldingCollapse", fCollapse); //$NON-NLS-1$ editor.setAction("FoldingCollapse", fCollapse); //$NON-NLS-1$
@ -133,19 +136,19 @@ public class FoldingActionGroup extends ActionGroup {
fRestoreDefaults.setActionDefinitionId(IFoldingCommandIds.FOLDING_RESTORE); fRestoreDefaults.setActionDefinitionId(IFoldingCommandIds.FOLDING_RESTORE);
editor.setAction("FoldingRestore", fRestoreDefaults); //$NON-NLS-1$ editor.setAction("FoldingRestore", fRestoreDefaults); //$NON-NLS-1$
} }
/** /**
* Returns <code>true</code> if the group is enabled. * Returns <code>true</code> if the group is enabled.
* <pre> * <pre>
* Invariant: isEnabled() <=> fViewer and all actions are != null. * Invariant: isEnabled() <=> fViewer and all actions are != null.
* </pre> * </pre>
* *
* @return <code>true</code> if the group is enabled * @return <code>true</code> if the group is enabled
*/ */
protected boolean isEnabled() { protected boolean isEnabled() {
return fViewer != null; return fViewer != null;
} }
/* /*
* @see org.eclipse.ui.actions.ActionGroup#dispose() * @see org.eclipse.ui.actions.ActionGroup#dispose()
*/ */
@ -157,7 +160,7 @@ public class FoldingActionGroup extends ActionGroup {
} }
super.dispose(); super.dispose();
} }
/** /**
* Updates the actions. * Updates the actions.
*/ */
@ -172,10 +175,10 @@ public class FoldingActionGroup extends ActionGroup {
fRestoreDefaults.update(); fRestoreDefaults.update();
} }
} }
/** /**
* Fills the menu with all folding actions. * Fills the menu with all folding actions.
* *
* @param manager the menu manager for the folding submenu * @param manager the menu manager for the folding submenu
*/ */
public void fillMenu(IMenuManager manager) { public void fillMenu(IMenuManager manager) {
@ -189,7 +192,7 @@ public class FoldingActionGroup extends ActionGroup {
manager.add(fRestoreDefaults); manager.add(fRestoreDefaults);
} }
} }
/* /*
* @see org.eclipse.ui.actions.ActionGroup#updateActionBars() * @see org.eclipse.ui.actions.ActionGroup#updateActionBars()
*/ */

View file

@ -38,6 +38,7 @@ public class GotoNextBookmarkAction extends TextEditorAction {
* Private class to handle comparison of markers using their line numbers. * Private class to handle comparison of markers using their line numbers.
*/ */
private class CompareMarker implements Comparator<IMarker> { private class CompareMarker implements Comparator<IMarker> {
@Override
public int compare(IMarker m1, IMarker m2) { public int compare(IMarker m1, IMarker m2) {
int l1 = MarkerUtilities.getLineNumber(m1); int l1 = MarkerUtilities.getLineNumber(m1);
int l2 = MarkerUtilities.getLineNumber(m2); int l2 = MarkerUtilities.getLineNumber(m2);

View file

@ -57,24 +57,24 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility;
* AST must be present, the indentation is computed using heuristics. The algorithm used is fast for * AST must be present, the indentation is computed using heuristics. The algorithm used is fast for
* single lines, but does not store any information and therefore not so efficient for large line * single lines, but does not store any information and therefore not so efficient for large line
* ranges. * ranges.
* *
* @see org.eclipse.cdt.internal.ui.text.CHeuristicScanner * @see org.eclipse.cdt.internal.ui.text.CHeuristicScanner
* @see org.eclipse.cdt.internal.ui.text.CIndenter * @see org.eclipse.cdt.internal.ui.text.CIndenter
*/ */
public class IndentAction extends TextEditorAction { public class IndentAction extends TextEditorAction {
/** The caret offset after an indent operation. */ /** The caret offset after an indent operation. */
private int fCaretOffset; private int fCaretOffset;
/** /**
* Whether this is the action invoked by TAB. When <code>true</code>, indentation behaves * Whether this is the action invoked by TAB. When <code>true</code>, indentation behaves
* differently to accommodate normal TAB operation. * differently to accommodate normal TAB operation.
*/ */
private final boolean fIsTabAction; private final boolean fIsTabAction;
/** /**
* Creates a new instance. * Creates a new instance.
* *
* @param bundle the resource bundle * @param bundle the resource bundle
* @param prefix the prefix to use for keys in <code>bundle</code> * @param prefix the prefix to use for keys in <code>bundle</code>
* @param editor the text editor * @param editor the text editor
@ -84,7 +84,7 @@ public class IndentAction extends TextEditorAction {
super(bundle, prefix, editor); super(bundle, prefix, editor);
fIsTabAction= isTabAction; fIsTabAction= isTabAction;
} }
/* /*
* @see org.eclipse.jface.action.Action#run() * @see org.eclipse.jface.action.Action#run()
*/ */
@ -93,17 +93,17 @@ public class IndentAction extends TextEditorAction {
// update has been called by the framework // update has been called by the framework
if (!isEnabled() || !validateEditorInputState()) if (!isEnabled() || !validateEditorInputState())
return; return;
ITextSelection selection= getSelection(); ITextSelection selection= getSelection();
final IDocument document= getDocument(); final IDocument document= getDocument();
if (document != null) { if (document != null) {
final int offset= selection.getOffset(); final int offset= selection.getOffset();
final int length= selection.getLength(); final int length= selection.getLength();
final Position end= new Position(offset + length); final Position end= new Position(offset + length);
final int firstLine, nLines; final int firstLine, nLines;
fCaretOffset= -1; fCaretOffset= -1;
try { try {
firstLine= document.getLineOfOffset(offset); firstLine= document.getLineOfOffset(offset);
// check for marginal (zero-length) lines // check for marginal (zero-length) lines
@ -115,13 +115,14 @@ public class IndentAction extends TextEditorAction {
CUIPlugin.log(new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.OK, "", e)); //$NON-NLS-1$ CUIPlugin.log(new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.OK, "", e)); //$NON-NLS-1$
return; return;
} }
Runnable runnable= new Runnable() { Runnable runnable= new Runnable() {
@Override
public void run() { public void run() {
IRewriteTarget target= (IRewriteTarget)getTextEditor().getAdapter(IRewriteTarget.class); IRewriteTarget target= (IRewriteTarget)getTextEditor().getAdapter(IRewriteTarget.class);
if (target != null) if (target != null)
target.beginCompoundChange(); target.beginCompoundChange();
try { try {
CHeuristicScanner scanner= new CHeuristicScanner(document); CHeuristicScanner scanner= new CHeuristicScanner(document);
CIndenter indenter= new CIndenter(document, scanner, getCProject()); CIndenter indenter= new CIndenter(document, scanner, getCProject());
@ -130,7 +131,7 @@ public class IndentAction extends TextEditorAction {
for (int i= 0; i < nLines; i++) { for (int i= 0; i < nLines; i++) {
hasChanged |= indentLine(document, firstLine + i, offset, indenter, scanner, multiLine); hasChanged |= indentLine(document, firstLine + i, offset, indenter, scanner, multiLine);
} }
// update caret position: move to new position when indenting just one line // update caret position: move to new position when indenting just one line
// keep selection when indenting multiple // keep selection when indenting multiple
int newOffset, newLength; int newOffset, newLength;
@ -141,12 +142,12 @@ public class IndentAction extends TextEditorAction {
newOffset= fCaretOffset; newOffset= fCaretOffset;
newLength= 0; newLength= 0;
} }
// always reset the selection if anything was replaced // always reset the selection if anything was replaced
// but not when we had a single line non-tab invocation // but not when we had a single line non-tab invocation
if (newOffset != -1 && (hasChanged || newOffset != offset || newLength != length)) if (newOffset != -1 && (hasChanged || newOffset != offset || newLength != length))
selectAndReveal(newOffset, newLength); selectAndReveal(newOffset, newLength);
} catch (BadLocationException e) { } catch (BadLocationException e) {
// will only happen on concurrent modification // will only happen on concurrent modification
CUIPlugin.log(new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.OK, "ConcurrentModification in IndentAction", e)); //$NON-NLS-1$ CUIPlugin.log(new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.OK, "ConcurrentModification in IndentAction", e)); //$NON-NLS-1$
@ -157,7 +158,7 @@ public class IndentAction extends TextEditorAction {
} }
} }
}; };
if (nLines > 50) { if (nLines > 50) {
Display display= getTextEditor().getEditorSite().getWorkbenchWindow().getShell().getDisplay(); Display display= getTextEditor().getEditorSite().getWorkbenchWindow().getShell().getDisplay();
BusyIndicator.showWhile(display, runnable); BusyIndicator.showWhile(display, runnable);
@ -166,10 +167,10 @@ public class IndentAction extends TextEditorAction {
} }
} }
} }
/** /**
* Selects the given range on the editor. * Selects the given range on the editor.
* *
* @param newOffset the selection offset * @param newOffset the selection offset
* @param newLength the selection range * @param newLength the selection range
*/ */
@ -190,7 +191,7 @@ public class IndentAction extends TextEditorAction {
/** /**
* Indents a single line using the heuristic scanner. Multiline comments are * Indents a single line using the heuristic scanner. Multiline comments are
* indented as specified by the <code>CCommentAutoIndentStrategy</code>. * indented as specified by the <code>CCommentAutoIndentStrategy</code>.
* *
* @param document the document * @param document the document
* @param line the line to be indented * @param line the line to be indented
* @param caret the caret position * @param caret the caret position
@ -204,7 +205,7 @@ public class IndentAction extends TextEditorAction {
IRegion currentLine= document.getLineInformation(line); IRegion currentLine= document.getLineInformation(line);
int offset= currentLine.getOffset(); int offset= currentLine.getOffset();
int wsStart= offset; // where we start searching for non-WS; after the "//" in single line comments int wsStart= offset; // where we start searching for non-WS; after the "//" in single line comments
String indent= null; String indent= null;
if (offset < document.getLength()) { if (offset < document.getLength()) {
ITypedRegion partition= TextUtilities.getPartition(document, ICPartitions.C_PARTITIONING, offset, true); ITypedRegion partition= TextUtilities.getPartition(document, ICPartitions.C_PARTITIONING, offset, true);
@ -224,9 +225,9 @@ public class IndentAction extends TextEditorAction {
int slashes= 2; int slashes= 2;
while (slashes < max - 1 && document.get(offset + slashes, 2).equals("//")) //$NON-NLS-1$ while (slashes < max - 1 && document.get(offset + slashes, 2).equals("//")) //$NON-NLS-1$
slashes+= 2; slashes+= 2;
wsStart= offset + slashes; wsStart= offset + slashes;
StringBuilder computed= indenter.computeIndentation(offset); StringBuilder computed= indenter.computeIndentation(offset);
if (computed == null) if (computed == null)
computed= new StringBuilder(0); computed= new StringBuilder(0);
@ -243,15 +244,15 @@ public class IndentAction extends TextEditorAction {
} else { } else {
break; break;
} }
computed.deleteCharAt(0); computed.deleteCharAt(0);
} }
indent= document.get(offset, wsStart - offset) + computed; indent= document.get(offset, wsStart - offset) + computed;
} }
} }
} }
// standard C code indentation // standard C code indentation
if (indent == null) { if (indent == null) {
StringBuilder computed= indenter.computeIndentation(offset); StringBuilder computed= indenter.computeIndentation(offset);
@ -260,7 +261,7 @@ public class IndentAction extends TextEditorAction {
else else
indent= ""; //$NON-NLS-1$ indent= ""; //$NON-NLS-1$
} }
// change document: // change document:
// get current white space // get current white space
int lineLength= currentLine.getLength(); int lineLength= currentLine.getLength();
@ -273,7 +274,7 @@ public class IndentAction extends TextEditorAction {
} }
int length= end - offset; int length= end - offset;
String currentIndent= document.get(offset, length); String currentIndent= document.get(offset, length);
// if we are right before the text start / line end, and already after the insertion point // if we are right before the text start / line end, and already after the insertion point
// then just shift to the right // then just shift to the right
if (fIsTabAction && caret == end && whiteSpaceLength(currentIndent) >= whiteSpaceLength(indent)) { if (fIsTabAction && caret == end && whiteSpaceLength(currentIndent) >= whiteSpaceLength(indent)) {
@ -286,13 +287,13 @@ public class IndentAction extends TextEditorAction {
fCaretOffset= offset + replacement.length(); fCaretOffset= offset + replacement.length();
return true; return true;
} }
// set the caret offset so it can be used when setting the selection // set the caret offset so it can be used when setting the selection
if (caret >= offset && caret <= end) if (caret >= offset && caret <= end)
fCaretOffset= offset + indent.length(); fCaretOffset= offset + indent.length();
else else
fCaretOffset= -1; fCaretOffset= -1;
// only change the document if it is a real change // only change the document if it is a real change
if (!indent.equals(currentIndent)) { if (!indent.equals(currentIndent)) {
document.replace(offset, length, indent); document.replace(offset, length, indent);
@ -303,7 +304,7 @@ public class IndentAction extends TextEditorAction {
/** /**
* Strip trailing space characters. * Strip trailing space characters.
* *
* @param indent * @param indent
* @return string with trailing spaces removed * @return string with trailing spaces removed
*/ */
@ -317,7 +318,7 @@ public class IndentAction extends TextEditorAction {
/** /**
* Computes and returns the indentation for a block comment line. * Computes and returns the indentation for a block comment line.
* *
* @param document the document * @param document the document
* @param line the line in document * @param line the line in document
* @param scanner the scanner * @param scanner the scanner
@ -328,10 +329,10 @@ public class IndentAction extends TextEditorAction {
private String computeCommentIndent(IDocument document, int line, CHeuristicScanner scanner, ITypedRegion partition) throws BadLocationException { private String computeCommentIndent(IDocument document, int line, CHeuristicScanner scanner, ITypedRegion partition) throws BadLocationException {
return IndentUtil.computeCommentIndent(document, line, scanner, partition); return IndentUtil.computeCommentIndent(document, line, scanner, partition);
} }
/** /**
* Computes and returns the indentation for a preprocessor line. * Computes and returns the indentation for a preprocessor line.
* *
* @param document the document * @param document the document
* @param line the line in document * @param line the line in document
* @param partition the comment partition * @param partition the comment partition
@ -341,11 +342,11 @@ public class IndentAction extends TextEditorAction {
private String computePreprocessorIndent(IDocument document, int line, ITypedRegion partition) throws BadLocationException { private String computePreprocessorIndent(IDocument document, int line, ITypedRegion partition) throws BadLocationException {
return IndentUtil.computePreprocessorIndent(document, line, partition); return IndentUtil.computePreprocessorIndent(document, line, partition);
} }
/** /**
* Returns the size in characters of a string. All characters count one, tabs count the editor's * Returns the size in characters of a string. All characters count one, tabs count the editor's
* preference for the tab display * preference for the tab display
* *
* @param indent the string to be measured. * @param indent the string to be measured.
* @return the size in characters of a string * @return the size in characters of a string
*/ */
@ -358,27 +359,27 @@ public class IndentAction extends TextEditorAction {
/** /**
* Returns whether spaces should be used exclusively for indentation, depending on the editor and * Returns whether spaces should be used exclusively for indentation, depending on the editor and
* formatter preferences. * formatter preferences.
* *
* @return <code>true</code> if only spaces should be used * @return <code>true</code> if only spaces should be used
*/ */
private boolean useSpaces() { private boolean useSpaces() {
return CCorePlugin.SPACE.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR)); return CCorePlugin.SPACE.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR));
} }
/** /**
* Returns whether mixed tabs/spaces should be used for indentation, depending on the editor and * Returns whether mixed tabs/spaces should be used for indentation, depending on the editor and
* formatter preferences. * formatter preferences.
* *
* @return <code>true</code> if tabs and spaces should be used * @return <code>true</code> if tabs and spaces should be used
*/ */
private boolean useTabsAndSpaces() { private boolean useTabsAndSpaces() {
return DefaultCodeFormatterConstants.MIXED.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR)); return DefaultCodeFormatterConstants.MIXED.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR));
} }
/** /**
* Returns the tab size used by the editor, which is deduced from the * Returns the tab size used by the editor, which is deduced from the
* formatter preferences. * formatter preferences.
* *
* @return the tab size as defined in the current formatter preferences * @return the tab size as defined in the current formatter preferences
*/ */
private int getTabSize() { private int getTabSize() {
@ -388,7 +389,7 @@ public class IndentAction extends TextEditorAction {
/** /**
* Returns the indent size used by the editor, which is deduced from the * Returns the indent size used by the editor, which is deduced from the
* formatter preferences. * formatter preferences.
* *
* @return the indent size as defined in the current formatter preferences * @return the indent size as defined in the current formatter preferences
*/ */
private int getIndentSize() { private int getIndentSize() {
@ -397,25 +398,25 @@ public class IndentAction extends TextEditorAction {
/** /**
* Returns <code>true</code> if empty lines should be indented, <code>false</code> otherwise. * Returns <code>true</code> if empty lines should be indented, <code>false</code> otherwise.
* *
* @return <code>true</code> if empty lines should be indented, <code>false</code> otherwise * @return <code>true</code> if empty lines should be indented, <code>false</code> otherwise
*/ */
private boolean indentEmptyLines() { private boolean indentEmptyLines() {
return DefaultCodeFormatterConstants.TRUE.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES)); return DefaultCodeFormatterConstants.TRUE.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES));
} }
/** /**
* Returns <code>true</code> if line comments at column 0 should be indented inside, <code>false</code> otherwise. * Returns <code>true</code> if line comments at column 0 should be indented inside, <code>false</code> otherwise.
* *
* @return <code>true</code> if line comments at column 0 should be indented inside, <code>false</code> otherwise. * @return <code>true</code> if line comments at column 0 should be indented inside, <code>false</code> otherwise.
*/ */
private boolean indentInsideLineComments() { private boolean indentInsideLineComments() {
return DefaultCodeFormatterConstants.TRUE.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_INDENT_INSIDE_LINE_COMMENTS)); return DefaultCodeFormatterConstants.TRUE.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_INDENT_INSIDE_LINE_COMMENTS));
} }
/** /**
* Returns the possibly project-specific core preference defined under <code>key</code>. * Returns the possibly project-specific core preference defined under <code>key</code>.
* *
* @param key the key of the preference * @param key the key of the preference
* @return the value of the preference * @return the value of the preference
*/ */
@ -429,7 +430,7 @@ public class IndentAction extends TextEditorAction {
/** /**
* Returns the possibly project-specific core preference defined under <code>key</code>, or * Returns the possibly project-specific core preference defined under <code>key</code>, or
* <code>def</code> if the value is not a integer. * <code>def</code> if the value is not a integer.
* *
* @param key the key of the preference * @param key the key of the preference
* @param def the default value * @param def the default value
* @return the value of the preference * @return the value of the preference
@ -445,7 +446,7 @@ public class IndentAction extends TextEditorAction {
/** /**
* Returns the <code>ICProject</code> of the current editor input, or * Returns the <code>ICProject</code> of the current editor input, or
* <code>null</code> if it cannot be found. * <code>null</code> if it cannot be found.
* *
* @return the <code>ICProject</code> of the current editor input, or * @return the <code>ICProject</code> of the current editor input, or
* <code>null</code> if it cannot be found * <code>null</code> if it cannot be found
*/ */
@ -453,13 +454,13 @@ public class IndentAction extends TextEditorAction {
ITextEditor editor= getTextEditor(); ITextEditor editor= getTextEditor();
if (editor == null) if (editor == null)
return null; return null;
return EditorUtility.getCProject(editor.getEditorInput()); return EditorUtility.getCProject(editor.getEditorInput());
} }
/** /**
* Returns the editor's selection provider. * Returns the editor's selection provider.
* *
* @return the editor's selection provider or <code>null</code> * @return the editor's selection provider or <code>null</code>
*/ */
private ISelectionProvider getSelectionProvider() { private ISelectionProvider getSelectionProvider() {
@ -469,14 +470,14 @@ public class IndentAction extends TextEditorAction {
} }
return null; return null;
} }
/* /*
* @see org.eclipse.ui.texteditor.IUpdate#update() * @see org.eclipse.ui.texteditor.IUpdate#update()
*/ */
@Override @Override
public void update() { public void update() {
super.update(); super.update();
if (isEnabled()) { if (isEnabled()) {
if (fIsTabAction) if (fIsTabAction)
setEnabled(canModifyEditor() && isSmartMode() && isValidSelection()); setEnabled(canModifyEditor() && isSmartMode() && isValidSelection());
@ -484,29 +485,29 @@ public class IndentAction extends TextEditorAction {
setEnabled(canModifyEditor() && !getSelection().isEmpty()); setEnabled(canModifyEditor() && !getSelection().isEmpty());
} }
} }
/** /**
* Returns if the current selection is valid, i.e. whether it is empty and the caret in the * Returns if the current selection is valid, i.e. whether it is empty and the caret in the
* whitespace at the start of a line, or covers multiple lines. * whitespace at the start of a line, or covers multiple lines.
* *
* @return <code>true</code> if the selection is valid for an indent operation * @return <code>true</code> if the selection is valid for an indent operation
*/ */
private boolean isValidSelection() { private boolean isValidSelection() {
ITextSelection selection= getSelection(); ITextSelection selection= getSelection();
if (selection.isEmpty()) if (selection.isEmpty())
return false; return false;
int offset= selection.getOffset(); int offset= selection.getOffset();
int length= selection.getLength(); int length= selection.getLength();
IDocument document= getDocument(); IDocument document= getDocument();
if (document == null) if (document == null)
return false; return false;
try { try {
IRegion firstLine= document.getLineInformationOfOffset(offset); IRegion firstLine= document.getLineInformationOfOffset(offset);
int lineOffset= firstLine.getOffset(); int lineOffset= firstLine.getOffset();
// either the selection has to be empty and the caret in the WS at the line start // either the selection has to be empty and the caret in the WS at the line start
// or the selection has to extend over multiple lines // or the selection has to extend over multiple lines
if (length == 0) { if (length == 0) {
@ -516,28 +517,28 @@ public class IndentAction extends TextEditorAction {
return false; // only enable for empty selections for now return false; // only enable for empty selections for now
} catch (BadLocationException e) { } catch (BadLocationException e) {
} }
return false; return false;
} }
/** /**
* Returns the smart preference state. * Returns the smart preference state.
* *
* @return <code>true</code> if smart mode is on, <code>false</code> otherwise * @return <code>true</code> if smart mode is on, <code>false</code> otherwise
*/ */
private boolean isSmartMode() { private boolean isSmartMode() {
ITextEditor editor= getTextEditor(); ITextEditor editor= getTextEditor();
if (editor instanceof ITextEditorExtension3) if (editor instanceof ITextEditorExtension3)
return ((ITextEditorExtension3) editor).getInsertMode() == ITextEditorExtension3.SMART_INSERT; return ((ITextEditorExtension3) editor).getInsertMode() == ITextEditorExtension3.SMART_INSERT;
return false; return false;
} }
/** /**
* Returns the document currently displayed in the editor, or <code>null</code> if none can be * Returns the document currently displayed in the editor, or <code>null</code> if none can be
* obtained. * obtained.
* *
* @return the current document or <code>null</code> * @return the current document or <code>null</code>
*/ */
private IDocument getDocument() { private IDocument getDocument() {
@ -547,15 +548,15 @@ public class IndentAction extends TextEditorAction {
IEditorInput input= editor.getEditorInput(); IEditorInput input= editor.getEditorInput();
if (provider != null && input != null) if (provider != null && input != null)
return provider.getDocument(input); return provider.getDocument(input);
} }
return null; return null;
} }
/** /**
* Returns the selection on the editor or an invalid selection if none can be obtained. Returns * Returns the selection on the editor or an invalid selection if none can be obtained. Returns
* never <code>null</code>. * never <code>null</code>.
* *
* @return the current selection, never <code>null</code> * @return the current selection, never <code>null</code>
*/ */
private ITextSelection getSelection() { private ITextSelection getSelection() {
@ -565,7 +566,7 @@ public class IndentAction extends TextEditorAction {
if (selection instanceof ITextSelection) if (selection instanceof ITextSelection)
return (ITextSelection) selection; return (ITextSelection) selection;
} }
// null object // null object
return TextSelection.emptySelection(); return TextSelection.emptySelection();
} }

View file

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.actions; package org.eclipse.cdt.internal.ui.actions;
@ -27,9 +27,11 @@ public class RebuildIndexAction implements IObjectActionDelegate {
private ISelection fSelection; private ISelection fSelection;
@Override
public void setActivePart(IAction action, IWorkbenchPart targetPart) { public void setActivePart(IAction action, IWorkbenchPart targetPart) {
} }
@Override
public void run(IAction action) { public void run(IAction action) {
IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection); IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
for (Iterator<?> i = cElements.iterator(); i.hasNext();) { for (Iterator<?> i = cElements.iterator(); i.hasNext();) {
@ -39,10 +41,11 @@ public class RebuildIndexAction implements IObjectActionDelegate {
} }
} }
} }
/** /**
* @see IActionDelegate#selectionChanged(IAction, ISelection) * @see IActionDelegate#selectionChanged(IAction, ISelection)
*/ */
@Override
public void selectionChanged(IAction action, ISelection selection) { public void selectionChanged(IAction action, ISelection selection) {
fSelection= selection; fSelection= selection;
} }

View file

@ -15,10 +15,11 @@ import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditor;
public class SurroundWithActionGroup extends ActionGroup { public class SurroundWithActionGroup extends ActionGroup {
@ -56,6 +57,7 @@ public class SurroundWithActionGroup extends ActionGroup {
menu.appendToGroup(fGroup, subMenu); menu.appendToGroup(fGroup, subMenu);
subMenu.add(new Action() {}); subMenu.add(new Action() {});
subMenu.addMenuListener(new IMenuListener() { subMenu.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) { public void menuAboutToShow(IMenuManager manager) {
manager.removeAll(); manager.removeAll();
SurroundWithTemplateMenuAction.fillMenu(manager, fEditor); SurroundWithTemplateMenuAction.fillMenu(manager, fEditor);

View file

@ -15,24 +15,12 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.swt.events.MenuAdapter;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.action.Action; import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator; import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IEditingSupport; import org.eclipse.jface.text.IEditingSupport;
@ -44,7 +32,15 @@ import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerExtension; import org.eclipse.jface.text.ITextViewerExtension;
import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2; import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.swt.events.MenuAdapter;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IPartListener; import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPartService; import org.eclipse.ui.IPartService;
import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPart;
@ -55,6 +51,7 @@ import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistInvocationContext; import org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistInvocationContext;
import org.eclipse.cdt.internal.ui.text.contentassist.TemplateCompletionProposalComputer; import org.eclipse.cdt.internal.ui.text.contentassist.TemplateCompletionProposalComputer;
@ -68,7 +65,7 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD
private static final String TEMPLATE_GROUP= "templateGroup"; //$NON-NLS-1$ private static final String TEMPLATE_GROUP= "templateGroup"; //$NON-NLS-1$
private static final String CONFIG_GROUP= "configGroup"; //$NON-NLS-1$ private static final String CONFIG_GROUP= "configGroup"; //$NON-NLS-1$
private static class ConfigureTemplatesAction extends Action { private static class ConfigureTemplatesAction extends Action {
public ConfigureTemplatesAction() { public ConfigureTemplatesAction() {
@ -103,19 +100,24 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD
private IPartService fPartService; private IPartService fPartService;
private IPartListener fPartListener= new IPartListener() { private IPartListener fPartListener= new IPartListener() {
@Override
public void partActivated(IWorkbenchPart part) { public void partActivated(IWorkbenchPart part) {
} }
@Override
public void partBroughtToTop(IWorkbenchPart part) { public void partBroughtToTop(IWorkbenchPart part) {
} }
@Override
public void partClosed(IWorkbenchPart part) { public void partClosed(IWorkbenchPart part) {
} }
@Override
public void partDeactivated(IWorkbenchPart part) { public void partDeactivated(IWorkbenchPart part) {
disposeMenuItems(); disposeMenuItems();
} }
@Override
public void partOpened(IWorkbenchPart part) { public void partOpened(IWorkbenchPart part) {
} }
}; };
@ -136,6 +138,7 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public Menu getMenu(Menu parent) { public Menu getMenu(Menu parent) {
setMenu(new Menu(parent)); setMenu(new Menu(parent));
fillMenu(fMenu); fillMenu(fMenu);
@ -146,6 +149,7 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public Menu getMenu(Control parent) { public Menu getMenu(Control parent) {
setMenu(new Menu(parent)); setMenu(new Menu(parent));
fillMenu(fMenu); fillMenu(fMenu);
@ -170,6 +174,7 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public void dispose() { public void dispose() {
if (fPartService != null) { if (fPartService != null) {
fPartService.removePartListener(fPartListener); fPartService.removePartListener(fPartListener);
@ -181,6 +186,7 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public void init(IWorkbenchWindow window) { public void init(IWorkbenchWindow window) {
if (fPartService != null) { if (fPartService != null) {
fPartService.removePartListener(fPartListener); fPartService.removePartListener(fPartListener);
@ -199,6 +205,7 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public void run(IAction action) { public void run(IAction action) {
IWorkbenchPart activePart= CUIPlugin.getActivePage().getActivePart(); IWorkbenchPart activePart= CUIPlugin.getActivePage().getActivePart();
if (!(activePart instanceof CEditor)) if (!(activePart instanceof CEditor))
@ -217,6 +224,7 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public void selectionChanged(IAction action, ISelection selection) { public void selectionChanged(IAction action, ISelection selection) {
// Default do nothing // Default do nothing
} }
@ -280,18 +288,18 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD
ITextSelection textSelection= getTextSelection(editor); ITextSelection textSelection= getTextSelection(editor);
if (textSelection == null || textSelection.getLength() == 0) if (textSelection == null || textSelection.getLength() == 0)
return null; return null;
ITranslationUnit tu= CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput()); ITranslationUnit tu= CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
if (tu == null) if (tu == null)
return null; return null;
TemplateCompletionProposalComputer templateComputer = new TemplateCompletionProposalComputer(); TemplateCompletionProposalComputer templateComputer = new TemplateCompletionProposalComputer();
CContentAssistInvocationContext context = new CContentAssistInvocationContext( editor.getViewer(), textSelection.getOffset(), editor, true, false ); CContentAssistInvocationContext context = new CContentAssistInvocationContext( editor.getViewer(), textSelection.getOffset(), editor, true, false );
List<ICompletionProposal> proposals= templateComputer.computeCompletionProposals(context, null); List<ICompletionProposal> proposals= templateComputer.computeCompletionProposals(context, null);
if (proposals == null || proposals.isEmpty()) if (proposals == null || proposals.isEmpty())
return null; return null;
return getActionsFromProposals(proposals, context.getInvocationOffset(), editor.getViewer()); return getActionsFromProposals(proposals, context.getInvocationOffset(), editor.getViewer());
} }
@ -344,10 +352,12 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD
IEditingSupportRegistry registry= null; IEditingSupportRegistry registry= null;
IEditingSupport helper= new IEditingSupport() { IEditingSupport helper= new IEditingSupport() {
@Override
public boolean isOriginator(DocumentEvent event, IRegion focus) { public boolean isOriginator(DocumentEvent event, IRegion focus) {
return focus.getOffset() <= offset && focus.getOffset() + focus.getLength() >= offset; return focus.getOffset() <= offset && focus.getOffset() + focus.getLength() >= offset;
} }
@Override
public boolean ownsFocusShell() { public boolean ownsFocusShell() {
return false; return false;
} }

View file

@ -12,8 +12,6 @@ package org.eclipse.cdt.internal.ui.actions;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.internal.ui.CUIStatus;
import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -23,27 +21,30 @@ import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.operation.IThreadListener; import org.eclipse.jface.operation.IThreadListener;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.internal.ui.CUIStatus;
/** /**
* An <code>IRunnableWithProgress</code> that adapts and <code>IWorkspaceRunnable</code> * An <code>IRunnableWithProgress</code> that adapts and <code>IWorkspaceRunnable</code>
* so that is can be executed inside <code>IRunnableContext</code>. <code>OperationCanceledException</code> * so that is can be executed inside <code>IRunnableContext</code>. <code>OperationCanceledException</code>
* thrown by the adapted runnable are caught and re-thrown as a <code>InterruptedException</code>. * thrown by the adapted runnable are caught and re-thrown as a <code>InterruptedException</code>.
*/ */
public class WorkbenchRunnableAdapter implements IRunnableWithProgress, IThreadListener { public class WorkbenchRunnableAdapter implements IRunnableWithProgress, IThreadListener {
private IWorkspaceRunnable fWorkspaceRunnable; private IWorkspaceRunnable fWorkspaceRunnable;
private ISchedulingRule fRule; private ISchedulingRule fRule;
private boolean fTransfer; private boolean fTransfer;
/** /**
* Runs a workspace runnable with the workspace lock. * Runs a workspace runnable with the workspace lock.
*/ */
public WorkbenchRunnableAdapter(IWorkspaceRunnable runnable) { public WorkbenchRunnableAdapter(IWorkspaceRunnable runnable) {
this(runnable, ResourcesPlugin.getWorkspace().getRoot()); this(runnable, ResourcesPlugin.getWorkspace().getRoot());
} }
/** /**
* Runs a workspace runnable with the given lock or <code>null</code> to run with no lock at all. * Runs a workspace runnable with the given lock or <code>null</code> to run with no lock at all.
*/ */
@ -51,11 +52,11 @@ public class WorkbenchRunnableAdapter implements IRunnableWithProgress, IThreadL
fWorkspaceRunnable= runnable; fWorkspaceRunnable= runnable;
fRule= rule; fRule= rule;
} }
/** /**
* Runs a workspace runnable with the given lock or <code>null</code> to run with no lock at * Runs a workspace runnable with the given lock or <code>null</code> to run with no lock at
* all. * all.
* *
* @param runnable the runnable * @param runnable the runnable
* @param rule the scheduling rule, or <code>null</code> * @param rule the scheduling rule, or <code>null</code>
* @param transfer <code>true</code> iff the rule is to be transfered to the modal context * @param transfer <code>true</code> iff the rule is to be transfered to the modal context
@ -71,6 +72,7 @@ public class WorkbenchRunnableAdapter implements IRunnableWithProgress, IThreadL
return fRule; return fRule;
} }
@Override
public void threadChange(Thread thread) { public void threadChange(Thread thread) {
if (fTransfer) if (fTransfer)
Job.getJobManager().transferRule(fRule, thread); Job.getJobManager().transferRule(fRule, thread);
@ -79,6 +81,7 @@ public class WorkbenchRunnableAdapter implements IRunnableWithProgress, IThreadL
/* /*
* @see IRunnableWithProgress#run(IProgressMonitor) * @see IRunnableWithProgress#run(IProgressMonitor)
*/ */
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try { try {
CoreModel.run(fWorkspaceRunnable, fRule, monitor); CoreModel.run(fWorkspaceRunnable, fRule, monitor);
@ -88,9 +91,9 @@ public class WorkbenchRunnableAdapter implements IRunnableWithProgress, IThreadL
throw new InvocationTargetException(e); throw new InvocationTargetException(e);
} }
} }
public void runAsUserJob(String name, final Object jobFamiliy) { public void runAsUserJob(String name, final Object jobFamiliy) {
Job buildJob = new Job(name){ Job buildJob = new Job(name){
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/ */
@ -117,9 +120,9 @@ public class WorkbenchRunnableAdapter implements IRunnableWithProgress, IThreadL
} }
}; };
buildJob.setRule(fRule); buildJob.setRule(fRule);
buildJob.setUser(true); buildJob.setUser(true);
buildJob.schedule(); buildJob.schedule();
// TODO: should block until user pressed 'to background' // TODO: should block until user pressed 'to background'
} }
} }