diff options
author | Alexander Kurtakov | 2013-09-12 07:21:00 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2013-09-12 11:27:51 +0000 |
commit | 081044f8a1379b4640e7ba240044d780ad0ddd91 (patch) | |
tree | ed8e88985cacc8baf8d7da5995371743681d795d | |
parent | b7c245b78a50ceafa4517dae44f57acf08499e63 (diff) | |
download | org.eclipse.linuxtools-081044f8a1379b4640e7ba240044d780ad0ddd91.tar.gz org.eclipse.linuxtools-081044f8a1379b4640e7ba240044d780ad0ddd91.tar.xz org.eclipse.linuxtools-081044f8a1379b4640e7ba240044d780ad0ddd91.zip |
valgrind.ui: Another try to fix tests.
Simplify the implementation and let it not hide members/fields.
Also:
* Bump BREE to 1.6.
* Enable project specific warnings and save actions.
* Fix the warnings.
* Drop unused methods/fields.
* Fix formatting.
Change-Id: I10166df6b03990eb949c5e135016d1d488b5ea7a
Reviewed-on: https://git.eclipse.org/r/16350
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
IP-Clean: Alexander Kurtakov <akurtako@redhat.com>
Tested-by: Alexander Kurtakov <akurtako@redhat.com>
11 files changed, 129 insertions, 76 deletions
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.ui.tests/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/tests/WrongDeallocationResolutionTest.java b/valgrind/org.eclipse.linuxtools.valgrind.ui.tests/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/tests/WrongDeallocationResolutionTest.java index 4901ad8427..5b06b45596 100644 --- a/valgrind/org.eclipse.linuxtools.valgrind.ui.tests/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/tests/WrongDeallocationResolutionTest.java +++ b/valgrind/org.eclipse.linuxtools.valgrind.ui.tests/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/tests/WrongDeallocationResolutionTest.java @@ -21,7 +21,6 @@ import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; -import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; @@ -37,8 +36,7 @@ public class WrongDeallocationResolutionTest extends AbstractValgrindTest { private final String EMPTY_STRING = ""; //$NON-NLS-1$ private final String VALGRIND_MARKER_TYPE = "org.eclipse.linuxtools.valgrind.launch.marker"; //$NON-NLS-1$ - private static Document document; - private static ICProject proj; + private Document document; private IMarker[] markers; @Override @@ -141,8 +139,7 @@ public class WrongDeallocationResolutionTest extends AbstractValgrindTest { } private void createResolutionAndApply(IMarker marker) throws CoreException { - WrongDeallocationResolution resolution = new WrongDeallocationResolution( - marker); + WrongDeallocationResolution resolution = new WrongDeallocationResolution(); assertNotNull(resolution); int numMarkersBefore = proj.getProject().findMarkers( diff --git a/valgrind/org.eclipse.linuxtools.valgrind.ui/.classpath b/valgrind/org.eclipse.linuxtools.valgrind.ui/.classpath index 64c5e31b7a..ad32c83a78 100644 --- a/valgrind/org.eclipse.linuxtools.valgrind.ui/.classpath +++ b/valgrind/org.eclipse.linuxtools.valgrind.ui/.classpath @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> <classpathentry kind="output" path="bin"/> diff --git a/valgrind/org.eclipse.linuxtools.valgrind.ui/.settings/org.eclipse.jdt.core.prefs b/valgrind/org.eclipse.linuxtools.valgrind.ui/.settings/org.eclipse.jdt.core.prefs index 355f1d6a0a..459217a36c 100644 --- a/valgrind/org.eclipse.linuxtools.valgrind.ui/.settings/org.eclipse.jdt.core.prefs +++ b/valgrind/org.eclipse.linuxtools.valgrind.ui/.settings/org.eclipse.jdt.core.prefs @@ -1,11 +1,17 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore @@ -31,7 +37,9 @@ org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning +org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled @@ -39,7 +47,8 @@ org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning +org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error org.eclipse.jdt.core.compiler.problem.nullReference=warning org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error @@ -60,6 +69,7 @@ org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled @@ -83,6 +93,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference= org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/valgrind/org.eclipse.linuxtools.valgrind.ui/.settings/org.eclipse.jdt.ui.prefs b/valgrind/org.eclipse.linuxtools.valgrind.ui/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000000..9795a6f906 --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.ui/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,54 @@ +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=false +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/valgrind/org.eclipse.linuxtools.valgrind.ui/META-INF/MANIFEST.MF b/valgrind/org.eclipse.linuxtools.valgrind.ui/META-INF/MANIFEST.MF index b370dce81b..167e6f79a1 100644 --- a/valgrind/org.eclipse.linuxtools.valgrind.ui/META-INF/MANIFEST.MF +++ b/valgrind/org.eclipse.linuxtools.valgrind.ui/META-INF/MANIFEST.MF @@ -9,7 +9,7 @@ Require-Bundle: org.eclipse.ui, org.eclipse.ui.ide, org.eclipse.core.runtime, org.eclipse.cdt.codan.ui.cxx -Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.linuxtools.internal.valgrind.ui, org.eclipse.linuxtools.valgrind.ui diff --git a/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/CoreMessagesViewer.java b/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/CoreMessagesViewer.java index 1d9c396e6d..0afea23b36 100644 --- a/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/CoreMessagesViewer.java +++ b/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/CoreMessagesViewer.java @@ -88,6 +88,7 @@ public class CoreMessagesViewer { } contentProvider = new ITreeContentProvider() { + @Override public Object[] getChildren(Object parentElement) { if (parentElement instanceof Object[]) { return (Object[]) parentElement; @@ -95,20 +96,25 @@ public class CoreMessagesViewer { return ((IValgrindMessage) parentElement).getChildren(); } + @Override public Object getParent(Object element) { return ((IValgrindMessage) element).getParent(); } + @Override public boolean hasChildren(Object element) { return getChildren(element).length > 0; } + @Override public Object[] getElements(Object inputElement) { return getChildren(inputElement); } + @Override public void dispose() {} + @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} @@ -140,6 +146,7 @@ public class CoreMessagesViewer { doubleClickListener = new IDoubleClickListener() { + @Override public void doubleClick(DoubleClickEvent event) { Object element = ((TreeSelection) event.getSelection()).getFirstElement(); if (element instanceof ValgrindStackFrame) { @@ -205,6 +212,7 @@ public class CoreMessagesViewer { MenuManager manager = new MenuManager(); manager.addMenuListener(new IMenuListener() { + @Override public void menuAboutToShow(IMenuManager manager) { ITreeSelection selection = (ITreeSelection) viewer.getSelection(); Object element = selection.getFirstElement(); diff --git a/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/ValgrindUIPlugin.java b/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/ValgrindUIPlugin.java index 028d6a4657..6886408db6 100644 --- a/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/ValgrindUIPlugin.java +++ b/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/ValgrindUIPlugin.java @@ -30,7 +30,7 @@ import org.osgi.framework.BundleContext; public class ValgrindUIPlugin extends AbstractUIPlugin { // The plug-in ID - public static final String PLUGIN_ID = "org.eclipse.linuxtools.valgrind.ui"; + public static final String PLUGIN_ID = "org.eclipse.linuxtools.valgrind.ui"; //$NON-NLS-1$ public static final String TOOLBAR_LOC_GROUP_ID = "toolbarLocal"; //$NON-NLS-1$ public static final String TOOLBAR_EXT_GROUP_ID = "toolbarExtensions"; //$NON-NLS-1$ @@ -80,6 +80,7 @@ public class ValgrindUIPlugin extends AbstractUIPlugin { public void createView(final String contentDescription, final String toolID) { Display.getDefault().syncExec(new Runnable() { + @Override public void run() { try { activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); @@ -105,6 +106,7 @@ public class ValgrindUIPlugin extends AbstractUIPlugin { */ public void showView() { Display.getDefault().syncExec(new Runnable() { + @Override public void run() { try { activePage.showView(ValgrindUIConstants.VIEW_ID); @@ -121,6 +123,7 @@ public class ValgrindUIPlugin extends AbstractUIPlugin { public void refreshView() { if (view != null) { Display.getDefault().syncExec(new Runnable() { + @Override public void run() { view.refreshView(); } @@ -134,6 +137,7 @@ public class ValgrindUIPlugin extends AbstractUIPlugin { public void resetView() { if (view != null) { Display.getDefault().syncExec(new Runnable() { + @Override public void run() { try { view.createDynamicContent(Messages.getString("ValgrindViewPart.No_Valgrind_output"), null); //$NON-NLS-1$ diff --git a/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/ValgrindViewPart.java b/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/ValgrindViewPart.java index b9c1d61a3f..b7f824351f 100644 --- a/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/ValgrindViewPart.java +++ b/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/ValgrindViewPart.java @@ -7,7 +7,7 @@ * * Contributors: * Elliott Baron <ebaron@redhat.com> - initial API and implementation - *******************************************************************************/ + *******************************************************************************/ package org.eclipse.linuxtools.internal.valgrind.ui; import org.eclipse.core.runtime.CoreException; @@ -49,15 +49,15 @@ public class ValgrindViewPart extends ViewPart { pageBook = new PageBook(parent, SWT.NONE); pageBook.setLayoutData(new GridData(GridData.FILL_BOTH)); - + messagesViewer = new CoreMessagesViewer(pageBook, SWT.NONE); - + dynamicViewHolder = new Composite(pageBook, SWT.NONE); GridLayout dynamicViewLayout = new GridLayout(); dynamicViewLayout.marginWidth = dynamicViewLayout.marginHeight = 0; dynamicViewHolder.setLayout(dynamicViewLayout); dynamicViewHolder.setLayoutData(new GridData(GridData.FILL_BOTH)); - + showCoreAction = new Action(Messages.getString("ValgrindViewPart.Show_Core_Action"), IAction.AS_RADIO_BUTTON) { //$NON-NLS-1$ @Override public void run() { @@ -70,7 +70,7 @@ public class ValgrindViewPart extends ViewPart { showToolPage(); } }; - + ValgrindUIPlugin.getDefault().setView(this); } @@ -81,26 +81,26 @@ public class ValgrindViewPart extends ViewPart { IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager(); ToolBar tb = ((ToolBarManager) toolbar).getControl(); if (tb == null || tb.isDisposed()) { - throw new CoreException(new Status(IStatus.ERROR, ValgrindUIPlugin.PLUGIN_ID, "Toolbar is disposed")); + throw new CoreException(new Status(IStatus.ERROR, ValgrindUIPlugin.PLUGIN_ID, "Toolbar is disposed")); //$NON-NLS-1$ } - + if (dynamicActions != null) { for (ActionContributionItem item : dynamicActions) { toolbar.remove(item); } } - + // remove old view controls if (dynamicView != null) { dynamicView.dispose(); } - + // remove old messages if (messages != null){ messagesViewer.getTreeViewer().setInput(null); messages = null; } - + for (Control child : dynamicViewHolder.getChildren()) { if (!child.isDisposed()) { child.dispose(); @@ -132,10 +132,10 @@ public class ValgrindViewPart extends ViewPart { hasDynamicContent = dynamicViewHolder.getChildren().length > 0; if (hasDynamicContent) { menu.add(showCoreAction); - menu.add(showToolAction); - } - - menu.update(true); + menu.add(showToolAction); + } + + menu.update(true); toolbar.update(true); // Update to notify the workbench items have been changed getViewSite().getActionBars().updateActionBars(); @@ -147,11 +147,11 @@ public class ValgrindViewPart extends ViewPart { public void setMessages(IValgrindMessage[] messages) { this.messages = messages; } - + public IValgrindMessage[] getMessages() { return messages; } - + @Override public void setFocus() { if (dynamicView != null) { @@ -162,7 +162,7 @@ public class ValgrindViewPart extends ViewPart { public void refreshView() { if (messages != null && messages.length > 0) { messagesViewer.getTreeViewer().setInput(messages); - + // decide which page to show if (hasDynamicContent && messages[0] instanceof ValgrindInfo) { // no valgrind messages to show @@ -184,10 +184,10 @@ public class ValgrindViewPart extends ViewPart { if (dynamicView != null) { dynamicView.dispose(); } - + // Unset this view in the UI plugin ValgrindUIPlugin.getDefault().setView(null); - + super.dispose(); } @@ -198,13 +198,13 @@ public class ValgrindViewPart extends ViewPart { public CoreMessagesViewer getMessagesViewer() { return messagesViewer; } - + private void showCorePage() { pageBook.showPage(messagesViewer.getTreeViewer().getControl()); showCoreAction.setChecked(true); showToolAction.setChecked(false); } - + private void showToolPage() { pageBook.showPage(dynamicViewHolder); showToolAction.setChecked(true); diff --git a/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/AbstractValgrindMarkerResolution.java b/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/AbstractValgrindMarkerResolution.java index 4d6ab046d1..dbc1bdc24b 100644 --- a/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/AbstractValgrindMarkerResolution.java +++ b/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/AbstractValgrindMarkerResolution.java @@ -29,28 +29,14 @@ import org.eclipse.jface.text.IDocument; */ public abstract class AbstractValgrindMarkerResolution extends AbstractCodanCMarkerResolution { - protected IMarker marker; - protected IDocument document; - protected IASTTranslationUnit ast; - protected IASTNode node; - - public AbstractValgrindMarkerResolution(IMarker marker) { - super(); - this.marker = marker; - this.ast = getASTTranslationUnit(marker); - this.document = openDocument(marker); - } - - public abstract String getLabel(); - /** * Returns the enclosed AST node in the given marker. * @param marker The {@link IMarker} containing the {@link IASTNode} * @return the enclosed {@link IASTNode} */ - protected IASTNode getIASTNode(IMarker marker){ + protected IASTNode getIASTNode(IMarker marker, IDocument document){ int offset = this.getOffset(marker, document); - int length = this.getLength(marker); + int length = this.getLength(marker, document); IASTNode node = null; IASTTranslationUnit ast = getASTTranslationUnit(marker); @@ -82,11 +68,12 @@ public abstract class AbstractValgrindMarkerResolution extends AbstractCodanCMar * @param marker {@link IMarker} from which the length will be obtained * @return length of the code enclosed in the {@link IMarker} */ - protected int getLength(IMarker marker) { + protected int getLength(IMarker marker, IDocument document) { int charStart = marker.getAttribute(IMarker.CHAR_START, -1); int charEnd = marker.getAttribute(IMarker.CHAR_END, -1); - if (charEnd != -1 && charStart != -1) + if (charEnd != -1 && charStart != -1) { return charEnd - charStart; + } int line = marker.getAttribute(IMarker.LINE_NUMBER, -1) -1; try { return document.getLineLength(line); diff --git a/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/ValgrindResolutionGenerator.java b/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/ValgrindResolutionGenerator.java index c656fb4b64..27ab5a6aca 100644 --- a/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/ValgrindResolutionGenerator.java +++ b/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/ValgrindResolutionGenerator.java @@ -22,23 +22,20 @@ import org.eclipse.ui.IMarkerResolutionGenerator2; * @author rafaelmt */ public class ValgrindResolutionGenerator implements IMarkerResolutionGenerator2 { - private static final String EMPTY_STRING = ""; //$NON-NLS-1$ + @Override public IMarkerResolution[] getResolutions(IMarker marker) { - String message = marker.getAttribute(IMarker.MESSAGE, EMPTY_STRING ); + String message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$ if(message.contains(Messages.getString("ValgrindMemcheckQuickFixes.Wrong_dealloc_message"))){ //$NON-NLS-1$ - return new IMarkerResolution[]{new WrongDeallocationResolution(marker)}; + return new IMarkerResolution[]{new WrongDeallocationResolution()}; } else { return new IMarkerResolution[0]; } } + @Override public boolean hasResolutions(IMarker marker) { - String message = marker.getAttribute(IMarker.MESSAGE, EMPTY_STRING ); - if(message.contains(Messages.getString("ValgrindMemcheckQuickFixes.Wrong_dealloc_message"))){ //$NON-NLS-1$ - return true; - } else { - return false; - } + String message = marker.getAttribute(IMarker.MESSAGE, "" ); //$NON-NLS-1$ + return message.contains(Messages.getString("ValgrindMemcheckQuickFixes.Wrong_dealloc_message")) ? true: false; //$NON-NLS-1$ } } diff --git a/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/WrongDeallocationResolution.java b/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/WrongDeallocationResolution.java index 043cfb643f..184987e30d 100644 --- a/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/WrongDeallocationResolution.java +++ b/valgrind/org.eclipse.linuxtools.valgrind.ui/src/org/eclipse/linuxtools/internal/valgrind/ui/quickfixes/WrongDeallocationResolution.java @@ -46,34 +46,29 @@ public class WrongDeallocationResolution extends AbstractValgrindMarkerResolutio private int allocOffset; private int allocLength; - public WrongDeallocationResolution(IMarker marker) { - super(marker); - } - @Override public void apply(IMarker marker, IDocument document) { - this.document = document; try { - IASTNode astNode = getIASTNode(marker); + IASTNode astNode = getIASTNode(marker, document); if(astNode != null) { int nodeLength = astNode.getFileLocation().getNodeLength(); int nodeOffset = astNode.getFileLocation().getNodeOffset(); String content = document.get(nodeOffset, nodeLength); if(content.contains(DELETE)){ - String allocFunction = getAllocFunction(marker); + String allocFunction = getAllocFunction(marker, document); if(allocFunction.contains(NEW)){ content = document.get(nodeOffset, nodeLength).replace(DELETE, DELETE + "[]"); //$NON-NLS-1$ document.replace(nodeOffset, nodeLength, content); } else { - addParentheses(astNode); + addParentheses(astNode, document); if(content.contains("[")){ //$NON-NLS-1$ - removeBrackets(astNode); + removeBrackets(astNode, document); } content = document.get(nodeOffset, nodeLength).replace(DELETE, FREE); document.replace(nodeOffset, nodeLength, content); } } else if(content.contains(FREE)){ - if(getAllocFunction(marker).contains("[")){ //$NON-NLS-1$ + if(getAllocFunction(marker, document).contains("[")){ //$NON-NLS-1$ content = content.concat("[]"); //$NON-NLS-1$ } content = content.replace(FREE, DELETE); @@ -127,14 +122,14 @@ public class WrongDeallocationResolution extends AbstractValgrindMarkerResolutio * @param node {@link IASTNode} containing the function call * @throws BadLocationException */ - private void addParentheses(IASTNode node) throws BadLocationException{ + private void addParentheses(IASTNode node, IDocument document) throws BadLocationException{ IASTNode[] children = node.getChildren(); if(children.length > 0 && !children[0].getRawSignature().contains("(")) { //$NON-NLS-1$ IASTNode childNode = children[0]; int childNodeLength = childNode.getFileLocation().getNodeLength(); int childNodeOffset = childNode.getFileLocation().getNodeOffset(); String childContent = document.get(childNodeOffset, childNodeLength); - String newChild = "(".concat(childContent).concat(")"); //$NON-NLS-2$ + String newChild = "(".concat(childContent).concat(")"); //$NON-NLS-1$//$NON-NLS-2$ // Skewed 1 char to left to remove space before parentheses document.replace(childNodeOffset - 1, childNodeLength + 1, newChild); } @@ -147,7 +142,7 @@ public class WrongDeallocationResolution extends AbstractValgrindMarkerResolutio * @throws BadLocationException * @throws ValgrindMessagesException */ - private String getAllocFunction(IMarker marker) throws BadLocationException, ValgrindMessagesException { + private String getAllocFunction(IMarker marker, IDocument document) throws BadLocationException, ValgrindMessagesException { IValgrindMessage allocMessage = null; String file = marker.getResource().getName(); int line = marker.getAttribute(IMarker.LINE_NUMBER, 0); @@ -161,7 +156,7 @@ public class WrongDeallocationResolution extends AbstractValgrindMarkerResolutio allocMessage = getStackBottom(getNestedStack(wrongDeallocMessage)); } } - if(allocMessage != null && allocMessage instanceof ValgrindStackFrame){ + if(allocMessage instanceof ValgrindStackFrame){ allocLine = ((ValgrindStackFrame)allocMessage).getLine() - 1; allocOffset = document.getLineOffset(allocLine); allocLength = document.getLineLength(allocLine); @@ -175,11 +170,11 @@ public class WrongDeallocationResolution extends AbstractValgrindMarkerResolutio * @param node {@link IASTNode} from which the brackets will be removed * @throws BadLocationException */ - private void removeBrackets(IASTNode node) throws BadLocationException{ + private void removeBrackets(IASTNode node, IDocument document) throws BadLocationException{ int nodeLength = node.getFileLocation().getNodeLength(); int nodeOffset = node.getFileLocation().getNodeOffset(); String content = document.get(nodeOffset, nodeLength); - String newContent = content.replace("[","").replace("]",""); //$NON-NLS-4$ + String newContent = content.replace("[","").replace("]",""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$ document.replace(nodeOffset, nodeLength, newContent); } |