aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-02-14 16:58:08 -0800
committerTor Norbye <tnorbye@google.com>2012-02-15 09:57:33 -0800
commitd91de0dae79d468a9a7b11b2e19721f12fedd861 (patch)
treeacfb49a41d1c940f8070808cdefdc07ec8f89c9e /eclipse
parentfaf7b68609a860c9f818bc7c8c01c14a3d969e18 (diff)
downloadsdk-d91de0dae79d468a9a7b11b2e19721f12fedd861.zip
sdk-d91de0dae79d468a9a7b11b2e19721f12fedd861.tar.gz
sdk-d91de0dae79d468a9a7b11b2e19721f12fedd861.tar.bz2
Add suppress-this to Lint View, and preserve tree expansion state
This changeset adds a new toolbar button to the Lint View: "Suppress this error with an annotation/attribute". This is enabled when the selected warning is for a Java or XML file, and it adds the annotation or suppress attribute in the relevant source file for the warning. It also adds some handling to preserve the expanded tree state in the Lint View when the view is refreshed, which happens automatically whenever a fix is applied or a file is saved and the marker set changes. Change-Id: I393ee5f6e062a0e08a7e9457a03f37d8899a4df8
Diffstat (limited to 'eclipse')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-all-disabled.pngbin332 -> 392 bytes
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-all.pngbin509 -> 635 bytes
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-this-disabled.pngbin0 -> 332 bytes
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-this.pngbin0 -> 509 bytes
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java9
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddSuppressAttribute.java37
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java73
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintList.java66
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintViewPart.java57
9 files changed, 204 insertions, 38 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-all-disabled.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-all-disabled.png
index 0576450..56f0098 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-all-disabled.png
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-all-disabled.png
Binary files differ
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-all.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-all.png
index 3e66d82..581e323 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-all.png
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-all.png
Binary files differ
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-this-disabled.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-this-disabled.png
new file mode 100644
index 0000000..0576450
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-this-disabled.png
Binary files differ
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-this.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-this.png
new file mode 100644
index 0000000..3e66d82
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/icons/ignore-this.png
Binary files differ
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java
index b20d190..9883ff5 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java
@@ -382,9 +382,12 @@ public class LayoutEditorDelegate extends CommonXmlDelegate
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
- LayoutActionBar bar = getGraphicalEditor().getLayoutActionBar();
- if (!bar.isDisposed()) {
- bar.updateErrorIndicator();
+ GraphicalEditorPart graphicalEditor = getGraphicalEditor();
+ if (graphicalEditor != null) {
+ LayoutActionBar bar = graphicalEditor.getLayoutActionBar();
+ if (!bar.isDisposed()) {
+ bar.updateErrorIndicator();
+ }
}
}
});
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddSuppressAttribute.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddSuppressAttribute.java
index b3174d3..8a54986 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddSuppressAttribute.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddSuppressAttribute.java
@@ -43,6 +43,9 @@ import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -122,9 +125,28 @@ class AddSuppressAttribute implements ICompletionProposal {
UiElementNode rootUiNode = mEditor.getUiRootNode();
if (rootUiNode != null) {
- UiElementNode uiNode = rootUiNode.findXmlNode(mElement);
+ final UiElementNode uiNode = rootUiNode.findXmlNode(mElement);
if (uiNode != null) {
mEditor.scheduleNodeReformat(uiNode, true /*attributesOnly*/);
+
+ // Update editor selection after format
+ Display display = AdtPlugin.getDisplay();
+ if (display != null) {
+ display.asyncExec(new Runnable() {
+ @SuppressWarnings("restriction") // DOM model
+ @Override
+ public void run() {
+ Node xmlNode = uiNode.getXmlNode();
+ Attr attribute = ((Element) xmlNode).getAttributeNodeNS(
+ TOOLS_URI, ATTR_IGNORE);
+ if (attribute instanceof IndexedRegion) {
+ IndexedRegion region = (IndexedRegion) attribute;
+ mEditor.getStructuredTextEditor().selectAndReveal(
+ region.getStartOffset(), region.getLength());
+ }
+ }
+ });
+ }
}
}
}
@@ -159,7 +181,15 @@ class AddSuppressAttribute implements ICompletionProposal {
}
int offset = marker.getAttribute(IMarker.CHAR_START, -1);
- Node node = DomUtilities.getNode(editor.getStructuredDocument(), offset);
+ Node node;
+ if (offset == -1) {
+ node = DomUtilities.getNode(editor.getStructuredDocument(), 0);
+ if (node != null) {
+ node = node.getOwnerDocument().getDocumentElement();
+ }
+ } else {
+ node = DomUtilities.getNode(editor.getStructuredDocument(), offset);
+ }
if (node == null) {
return null;
}
@@ -167,6 +197,9 @@ class AddSuppressAttribute implements ICompletionProposal {
while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
node = node.getParentNode();
}
+ if (node == null) {
+ return null;
+ }
// Some issues cannot find a specific node scope associated with the error
// (for example because it involves cross-file analysis and at the end of
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java
index ef2a265..7669ae4 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java
@@ -16,6 +16,7 @@
package com.android.ide.eclipse.adt.internal.lint;
import static com.android.ide.eclipse.adt.AdtConstants.DOT_JAVA;
+import static com.android.ide.eclipse.adt.AdtConstants.DOT_XML;
import com.android.ide.eclipse.adt.AdtConstants;
import com.android.ide.eclipse.adt.AdtPlugin;
@@ -36,6 +37,8 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
@@ -44,11 +47,16 @@ import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolution2;
import org.eclipse.ui.IMarkerResolutionGenerator2;
import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import java.io.File;
import java.util.ArrayList;
@@ -229,6 +237,71 @@ public class LintFixGenerator implements IMarkerResolutionGenerator2, IQuickAssi
}
}
+ /**
+ * Adds a suppress lint annotation or attribute depending on whether the
+ * error is in a Java or XML file.
+ *
+ * @param marker the marker pointing to the error to be suppressed
+ */
+ @SuppressWarnings("restriction") // XML model
+ public static void addSuppressAnnotation(IMarker marker) {
+ String id = EclipseLintClient.getId(marker);
+ if (id != null) {
+ IResource resource = marker.getResource();
+ if (!(resource instanceof IFile)) {
+ return;
+ }
+ IFile file = (IFile) resource;
+ boolean isJava = file.getName().endsWith(DOT_JAVA);
+ boolean isXml = AdtUtils.endsWith(file.getName(), DOT_XML);
+ if (!isJava && !isXml) {
+ return;
+ }
+
+ try {
+ IEditorPart activeEditor = AdtUtils.getActiveEditor();
+ IEditorPart part = null;
+ if (activeEditor != null) {
+ IEditorInput input = activeEditor.getEditorInput();
+ if (input instanceof FileEditorInput
+ && ((FileEditorInput)input).getFile().equals(file)) {
+ part = activeEditor;
+ }
+ }
+ if (part == null) {
+ IRegion region = null;
+ int start = marker.getAttribute(IMarker.CHAR_START, -1);
+ int end = marker.getAttribute(IMarker.CHAR_END, -1);
+ if (start != -1 && end != -1) {
+ region = new Region(start, end - start);
+ }
+ part = AdtPlugin.openFile(file, region, true /* showEditor */);
+ }
+
+ if (isJava) {
+ List<IMarkerResolution> resolutions = new ArrayList<IMarkerResolution>();
+ AddSuppressAnnotation.createFixes(marker, id, resolutions);
+ if (resolutions.size() > 0) {
+ resolutions.get(0).run(marker);
+ }
+ } else {
+ assert isXml;
+ if (part instanceof AndroidXmlEditor) {
+ AndroidXmlEditor editor = (AndroidXmlEditor) part;
+ AddSuppressAttribute fix = AddSuppressAttribute.createFix(editor,
+ marker, id);
+ if (fix != null) {
+ IStructuredDocument document = editor.getStructuredDocument();
+ fix.apply(document);
+ }
+ }
+ }
+ } catch (PartInitException pie) {
+ AdtPlugin.log(pie, null);
+ }
+ }
+ }
+
private static class SuppressProposal implements ICompletionProposal, IMarkerResolution2 {
private final String mId;
private final boolean mGlobal;
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintList.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintList.java
index 7c8d6f5..c40f3b7 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintList.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintList.java
@@ -43,10 +43,12 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ColumnPixelData;
import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TreeNodeContentProvider;
+import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
@@ -78,9 +80,9 @@ import org.eclipse.ui.progress.WorkbenchJob;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -102,7 +104,7 @@ class LintList extends Composite implements IResourceChangeListener, ControlList
private final TreeViewer mTreeViewer;
private final Tree mTree;
private ContentProvider mContentProvider;
-
+ private String mSelectedId;
private List<? extends IResource> mResources;
private Configuration mConfiguration;
private final boolean mSingleFile;
@@ -165,6 +167,18 @@ class LintList extends Composite implements IResourceChangeListener, ControlList
mTreeViewer.getTree().removePaintListener(this);
}
});
+
+ // Remember the most recently selected id category such that we can
+ // attempt to reselect it after a refresh
+ mTree.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ List<IMarker> markers = getSelectedMarkers();
+ if (markers.size() > 0) {
+ mSelectedId = EclipseLintClient.getId(markers.get(0));
+ }
+ }
+ });
}
private boolean treePainted;
@@ -282,6 +296,7 @@ class LintList extends Composite implements IResourceChangeListener, ControlList
private class ContentProvider extends TreeNodeContentProvider {
private Map<Object, Object[]> mChildren;
private Map<IMarker, Integer> mTypeCount;
+ private IMarker[] mTopLevels;
@Override
public Object[] getElements(Object inputElement) {
@@ -311,28 +326,24 @@ class LintList extends Composite implements IResourceChangeListener, ControlList
List<IMarker> topLevel = new ArrayList<IMarker>(ids.size());
for (String id : ids) {
Collection<IMarker> markers = types.get(id);
-
- Iterator<IMarker> iterator = markers.iterator();
- assert iterator.hasNext() : id;
-
int childCount = markers.size();
- IMarker topMarker = iterator.next();
- mTypeCount.put(topMarker, childCount);
- childCount--;
- IMarker[] children = new IMarker[childCount];
- for (int i = 0; i < childCount; i++) {
- children[i] = iterator.next();
- }
+ // Must sort the list items in order to have a stable first item
+ // (otherwise preserving expanded paths etc won't work)
+ TableComparator sorter = getTableSorter();
+ IMarker[] array = markers.toArray(new IMarker[markers.size()]);
+ sorter.sort(mTreeViewer, array);
+ IMarker topMarker = array[0];
+ mTypeCount.put(topMarker, childCount);
topLevel.add(topMarker);
+
+ IMarker[] children = Arrays.copyOfRange(array, 1, array.length);
mChildren.put(topMarker, children);
}
- // Sort top level: Sort by severity, then priority, then category:
-
- IMarker[] array = topLevel.toArray(new IMarker[topLevel.size()]);
- return array;
+ mTopLevels = topLevel.toArray(new IMarker[topLevel.size()]);
+ return mTopLevels;
}
@Override
@@ -366,6 +377,10 @@ class LintList extends Composite implements IResourceChangeListener, ControlList
return -1;
}
+
+ IMarker[] getTopMarkers() {
+ return mTopLevels;
+ }
}
private class LintColumnLabelProvider extends StyledCellLabelProvider {
@@ -463,6 +478,10 @@ class LintList extends Composite implements IResourceChangeListener, ControlList
if (mTree.isDisposed()) {
return Status.CANCEL_STATUS;
}
+
+ Object[] expandedElements = mTreeViewer.getExpandedElements();
+ TreePath[] expandedTreePaths = mTreeViewer.getExpandedTreePaths();
+
mTreeViewer.setInput(null);
List<IMarker> markerList = getMarkers();
if (markerList.size() == 0) {
@@ -485,6 +504,19 @@ class LintList extends Composite implements IResourceChangeListener, ControlList
mTreeViewer.setInput(markerList);
mTreeViewer.refresh();
+ mTreeViewer.setExpandedElements(expandedElements);
+ mTreeViewer.setExpandedTreePaths(expandedTreePaths);
+
+ if (mSelectedId != null) {
+ IMarker[] topMarkers = mContentProvider.getTopMarkers();
+ for (IMarker marker : topMarkers) {
+ if (mSelectedId.equals(EclipseLintClient.getId(marker))) {
+ mTreeViewer.setSelection(new StructuredSelection(marker), true /*reveal*/);
+ break;
+ }
+ }
+ }
+
return Status.OK_STATUS;
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintViewPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintViewPart.java
index 431b213..956ee9d 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintViewPart.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintViewPart.java
@@ -15,10 +15,14 @@
*/
package com.android.ide.eclipse.adt.internal.lint;
+import static com.android.ide.eclipse.adt.AdtConstants.DOT_JAVA;
+import static com.android.ide.eclipse.adt.AdtConstants.DOT_XML;
+
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.ide.eclipse.adt.internal.preferences.LintPreferencePage;
import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
+import com.android.tools.lint.detector.api.LintUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -86,8 +90,10 @@ public class LintViewPart extends ViewPart implements SelectionListener, IJobCha
private static final String EXPAND_ICON = "expandall"; //$NON-NLS-1$
private static final String COLUMNS_ICON = "columns"; //$NON-NLS-1$
private static final String OPTIONS_ICON = "options"; //$NON-NLS-1$
- private static final String IGNORE_THIS_ICON = "ignore-file"; //$NON-NLS-1$
- private static final String IGNORE_THIS_DISABLED_ICON = "ignore-file-disabled"; //$NON-NLS-1$
+ private static final String IGNORE_THIS_ICON = "ignore-this"; //$NON-NLS-1$
+ private static final String IGNORE_THIS_DISABLED_ICON = "ignore-this-disabled"; //$NON-NLS-1$
+ private static final String IGNORE_FILE_ICON = "ignore-file"; //$NON-NLS-1$
+ private static final String IGNORE_FILE_DISABLED_ICON = "ignore-file-disabled"; //$NON-NLS-1$
private static final String IGNORE_PRJ_ICON = "ignore-project"; //$NON-NLS-1$
private static final String IGNORE_PRJ_DISABLED_ICON = "ignore-project-disabled"; //$NON-NLS-1$
private static final String IGNORE_ALL_ICON = "ignore-all"; //$NON-NLS-1$
@@ -100,6 +106,7 @@ public class LintViewPart extends ViewPart implements SelectionListener, IJobCha
private Action mFixAction;
private Action mRemoveAction;
private Action mIgnoreAction;
+ private Action mAlwaysIgnoreAction;
private Action mIgnoreFileAction;
private Action mIgnoreProjectAction;
private Action mRemoveAllAction;
@@ -202,13 +209,17 @@ public class LintViewPart extends ViewPart implements SelectionListener, IJobCha
iconFactory.getImageDescriptor(QUICKFIX_ICON),
iconFactory.getImageDescriptor(QUICKFIX_DISABLED_ICON));
- mIgnoreFileAction = new LintViewAction("Ignore in this file", ACTION_IGNORE_THIS,
+ mIgnoreAction = new LintViewAction("Suppress this error with an annotation/attribute",
+ ACTION_IGNORE_THIS,
iconFactory.getImageDescriptor(IGNORE_THIS_ICON),
iconFactory.getImageDescriptor(IGNORE_THIS_DISABLED_ICON));
+ mIgnoreFileAction = new LintViewAction("Ignore in this file", ACTION_IGNORE_FILE,
+ iconFactory.getImageDescriptor(IGNORE_FILE_ICON),
+ iconFactory.getImageDescriptor(IGNORE_FILE_DISABLED_ICON));
mIgnoreProjectAction = new LintViewAction("Ignore in this project", ACTION_IGNORE_TYPE,
iconFactory.getImageDescriptor(IGNORE_PRJ_ICON),
iconFactory.getImageDescriptor(IGNORE_PRJ_DISABLED_ICON));
- mIgnoreAction = new LintViewAction("Always Ignore", ACTION_IGNORE_ALL,
+ mAlwaysIgnoreAction = new LintViewAction("Always Ignore", ACTION_IGNORE_ALL,
iconFactory.getImageDescriptor(IGNORE_ALL_ICON),
iconFactory.getImageDescriptor(IGNORE_ALL_DISABLED_ICON));
@@ -248,9 +259,10 @@ public class LintViewPart extends ViewPart implements SelectionListener, IJobCha
IToolBarManager toolbarManager = getViewSite().getActionBars().getToolBarManager();
toolbarManager.add(mRefreshAction);
toolbarManager.add(mFixAction);
+ toolbarManager.add(mIgnoreAction);
toolbarManager.add(mIgnoreFileAction);
toolbarManager.add(mIgnoreProjectAction);
- toolbarManager.add(mIgnoreAction);
+ toolbarManager.add(mAlwaysIgnoreAction);
toolbarManager.add(new Separator());
toolbarManager.add(mRemoveAction);
toolbarManager.add(mRemoveAllAction);
@@ -334,18 +346,24 @@ public class LintViewPart extends ViewPart implements SelectionListener, IJobCha
}
boolean haveFile = false;
+ boolean isJavaOrXml = true;
for (IMarker marker : markers) {
IResource resource = marker.getResource();
if (resource instanceof IFile || resource instanceof IFolder) {
haveFile = true;
+ String name = resource.getName();
+ if (!LintUtils.endsWith(name, DOT_XML) && !LintUtils.endsWith(name, DOT_JAVA)) {
+ isJavaOrXml = false;
+ }
break;
}
}
mFixAction.setEnabled(canFix);
+ mIgnoreAction.setEnabled(hasSelection && haveFile && isJavaOrXml);
mIgnoreFileAction.setEnabled(hasSelection && haveFile);
mIgnoreProjectAction.setEnabled(hasSelection);
- mIgnoreAction.setEnabled(hasSelection);
+ mAlwaysIgnoreAction.setEnabled(hasSelection);
mRemoveAction.setEnabled(hasSelection);
if (updateWidgets) {
@@ -415,14 +433,15 @@ public class LintViewPart extends ViewPart implements SelectionListener, IJobCha
private static final int ACTION_REFRESH = 1;
private static final int ACTION_FIX = 2;
private static final int ACTION_IGNORE_THIS = 3;
- private static final int ACTION_IGNORE_TYPE = 4;
- private static final int ACTION_IGNORE_ALL = 5;
- private static final int ACTION_REMOVE = 6;
- private static final int ACTION_REMOVE_ALL = 7;
- private static final int ACTION_COLLAPSE = 8;
- private static final int ACTION_EXPAND = 9;
- private static final int ACTION_COLUMNS = 10;
- private static final int ACTION_OPTIONS = 11;
+ private static final int ACTION_IGNORE_FILE = 4;
+ private static final int ACTION_IGNORE_TYPE = 5;
+ private static final int ACTION_IGNORE_ALL = 6;
+ private static final int ACTION_REMOVE = 7;
+ private static final int ACTION_REMOVE_ALL = 8;
+ private static final int ACTION_COLLAPSE = 9;
+ private static final int ACTION_EXPAND = 10;
+ private static final int ACTION_COLUMNS = 11;
+ private static final int ACTION_OPTIONS = 12;
private class LintViewAction extends Action {
@@ -523,8 +542,8 @@ public class LintViewPart extends ViewPart implements SelectionListener, IJobCha
assert false;
break;
case ACTION_IGNORE_TYPE:
- case ACTION_IGNORE_THIS: {
- boolean ignoreInFile = mAction == ACTION_IGNORE_THIS;
+ case ACTION_IGNORE_FILE: {
+ boolean ignoreInFile = mAction == ACTION_IGNORE_FILE;
for (IMarker marker : mLintView.getSelectedMarkers()) {
String id = EclipseLintClient.getId(marker);
if (id != null) {
@@ -536,6 +555,12 @@ public class LintViewPart extends ViewPart implements SelectionListener, IJobCha
}
break;
}
+ case ACTION_IGNORE_THIS: {
+ for (IMarker marker : mLintView.getSelectedMarkers()) {
+ LintFixGenerator.addSuppressAnnotation(marker);
+ }
+ break;
+ }
case ACTION_COLLAPSE: {
mLintView.collapseAll();
break;