From 36e14f64c3848dd3180e08b35ca8aeb20134da95 Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Sun, 2 May 2010 01:47:28 +0000 Subject: [PATCH] Refactor to move common code to a proper package and externalize strings --- .../META-INF/MANIFEST.MF | 8 +- .../build.properties | 2 +- .../plugin.xml | 6 +- .../codan/internal/checkers/ui/Messages.java | 29 +++++++ .../internal/checkers/ui/messages.properties | 2 + .../ui/quickfix/CatchByReferenceQuickFix.java | 8 +- .../QuickFixAssignmentInCondition.java | 86 +++++-------------- .../META-INF/MANIFEST.MF | 7 +- .../cxx}/AbstractCodanCQuickFixProcessor.java | 2 +- .../META-INF/MANIFEST.MF | 8 +- codan/org.eclipse.cdt.codan.ui/plugin.xml | 1 + .../schema/codanMarkerResolution.exsd | 0 ...CodanProblemMarkerResolutionGenerator.java | 15 ++-- .../ui/AbstarctCodanCMarkerResolution.java | 2 +- 14 files changed, 83 insertions(+), 93 deletions(-) create mode 100644 codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/Messages.java create mode 100644 codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/messages.properties rename codan/{org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui => org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx}/AbstractCodanCQuickFixProcessor.java (98%) rename codan/{org.eclipse.cdt.codan.checkers.ui => org.eclipse.cdt.codan.ui}/schema/codanMarkerResolution.exsd (100%) rename codan/{org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix => org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui}/CodanProblemMarkerResolutionGenerator.java (91%) rename codan/{org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers => org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan}/ui/AbstarctCodanCMarkerResolution.java (98%) diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.checkers.ui/META-INF/MANIFEST.MF index 6517ee023d0..fe0cc57b761 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/META-INF/MANIFEST.MF +++ b/codan/org.eclipse.cdt.codan.checkers.ui/META-INF/MANIFEST.MF @@ -6,14 +6,10 @@ Bundle-Version: 1.0.0.qualifier Bundle-Activator: org.eclipse.cdt.codan.internal.checkers.ui.CheckersUiActivator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, - org.eclipse.ui.ide;bundle-version="3.5.0", org.eclipse.jface.text;bundle-version="3.5.0", - org.eclipse.ui.editors;bundle-version="3.5.0", org.eclipse.core.resources;bundle-version="3.5.0", - org.eclipse.cdt.codan.checkers, - org.eclipse.cdt.ui, - org.eclipse.cdt.core, - org.eclipse.cdt.codan.ui + org.eclipse.cdt.codan.ui, + org.eclipse.ui.ide;bundle-version="3.6.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-Vendor: Eclipse CDT diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/build.properties b/codan/org.eclipse.cdt.codan.checkers.ui/build.properties index 3595411e85a..60150095638 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/build.properties +++ b/codan/org.eclipse.cdt.codan.checkers.ui/build.properties @@ -3,4 +3,4 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ plugin.xml,\ - schema/ + diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml b/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml index 407ee78644a..2eb69dd6d33 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml +++ b/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml @@ -1,17 +1,17 @@ - + + point="org.eclipse.cdt.codan.ui.codanMarkerResolution"> diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/Messages.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/Messages.java new file mode 100644 index 00000000000..e68a5ce2f10 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/Messages.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2009,2010 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.checkers.ui; + +import org.eclipse.osgi.util.NLS; + +/** + * TODO: add description + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.codan.internal.checkers.ui.messages"; //$NON-NLS-1$ + public static String CatchByReferenceQuickFix_Message; + public static String QuickFixAssignmentInCondition_Message; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/messages.properties b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/messages.properties new file mode 100644 index 00000000000..5ce0a9ff7e9 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/messages.properties @@ -0,0 +1,2 @@ +CatchByReferenceQuickFix_Message=Change to use '&' +QuickFixAssignmentInCondition_Message=Change to '==' diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFix.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFix.java index fa9f726ae00..68c38847100 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFix.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFix.java @@ -10,16 +10,20 @@ *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; -import org.eclipse.cdt.codan.checkers.ui.AbstarctCodanCMarkerResolution; import org.eclipse.cdt.codan.internal.checkers.ui.CheckersUiActivator; +import org.eclipse.cdt.codan.internal.checkers.ui.Messages; +import org.eclipse.cdt.codan.ui.AbstarctCodanCMarkerResolution; import org.eclipse.core.resources.IMarker; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.FindReplaceDocumentAdapter; import org.eclipse.jface.text.IDocument; +/** + * quick fix for catch by value + */ public class CatchByReferenceQuickFix extends AbstarctCodanCMarkerResolution { public String getLabel() { - return "Change to use reference"; + return Messages.CatchByReferenceQuickFix_Message; } public void apply(IMarker marker, IDocument document) { diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java index bae8065bdf0..d5d906f2f21 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java @@ -11,79 +11,35 @@ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; import org.eclipse.cdt.codan.internal.checkers.ui.CheckersUiActivator; -import org.eclipse.core.resources.IFile; +import org.eclipse.cdt.codan.internal.checkers.ui.Messages; +import org.eclipse.cdt.codan.ui.AbstarctCodanCMarkerResolution; import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.FindReplaceDocumentAdapter; import org.eclipse.jface.text.IDocument; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.IMarkerResolution; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.part.FileEditorInput; -import org.eclipse.ui.texteditor.ITextEditor; -public class QuickFixAssignmentInCondition implements IMarkerResolution { +/** + * quick fix for assignment in condition + */ +public class QuickFixAssignmentInCondition extends + AbstarctCodanCMarkerResolution { public String getLabel() { - return "Change to '=='"; + return Messages.QuickFixAssignmentInCondition_Message; } - public void run(IMarker marker) { - // See if there is an open editor on the file containing the marker - IWorkbenchWindow w = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow(); - if (w == null) { - return; - } - IWorkbenchPage page = w.getActivePage(); - if (page == null) { - return; - } - IFileEditorInput input = new FileEditorInput((IFile) marker - .getResource()); - IEditorPart editorPart = page.findEditor(input); - if (editorPart == null) { - // open an editor - try { - editorPart = IDE.openEditor(page, (IFile) marker.getResource(), - true); - } catch (PartInitException e) { - e.printStackTrace(); - } - } - if (editorPart == null) { - return; - } - if (editorPart instanceof ITextEditor) { - ITextEditor editor = (ITextEditor) editorPart; - IDocument doc = editor.getDocumentProvider().getDocument( - editor.getEditorInput()); - try { - int charStart = marker.getAttribute(IMarker.CHAR_START, -1); - int position; - if (charStart > 0) { - position = charStart; - } else { - int line = marker.getAttribute(IMarker.LINE_NUMBER, -1) - 1; - position = doc.getLineOffset(line); - } - FindReplaceDocumentAdapter dad = new FindReplaceDocumentAdapter( - doc); - dad.find(position, "=", /* forwardSearch *///$NON-NLS-1$ - true, /* caseSensitive */false, - /* wholeWord */false, /* regExSearch */false); - dad.replace("==", /* regExReplace */false); //$NON-NLS-1$ - marker.delete(); - } catch (CoreException e) { - CheckersUiActivator.log(e); - } catch (BadLocationException e) { - CheckersUiActivator.log(e); - } + + @Override + public void apply(IMarker marker, IDocument document) { + int pos = getOffset(marker, document); + try { + FindReplaceDocumentAdapter dad = new FindReplaceDocumentAdapter( + document); + dad.find(pos, "=", /* forwardSearch *///$NON-NLS-1$ + true, /* caseSensitive */false, + /* wholeWord */false, /* regExSearch */false); + dad.replace("==", /* regExReplace */false); //$NON-NLS-1$ + } catch (BadLocationException e) { + CheckersUiActivator.log(e); } } } diff --git a/codan/org.eclipse.cdt.codan.ui.cxx/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.ui.cxx/META-INF/MANIFEST.MF index 1badca951ad..3eb301b0eae 100644 --- a/codan/org.eclipse.cdt.codan.ui.cxx/META-INF/MANIFEST.MF +++ b/codan/org.eclipse.cdt.codan.ui.cxx/META-INF/MANIFEST.MF @@ -7,12 +7,13 @@ Bundle-Activator: org.eclipse.cdt.codan.internal.ui.cxx.Activator Bundle-Vendor: %Bundle-Vendor Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, - org.eclipse.cdt.codan.core;bundle-version="1.0.0", - org.eclipse.cdt.codan.core.cxx;bundle-version="1.0.0", + org.eclipse.cdt.codan.core, + org.eclipse.cdt.codan.core.cxx, org.eclipse.ui.editors, org.eclipse.cdt.core, org.eclipse.cdt.ui, org.eclipse.core.resources, - org.eclipse.cdt.codan.ui;bundle-version="1.0.0" + org.eclipse.cdt.codan.ui, + org.eclipse.jface.text Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/AbstractCodanCQuickFixProcessor.java b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/AbstractCodanCQuickFixProcessor.java similarity index 98% rename from codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/AbstractCodanCQuickFixProcessor.java rename to codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/AbstractCodanCQuickFixProcessor.java index 1e8cc99febc..29bc3bf8037 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/AbstractCodanCQuickFixProcessor.java +++ b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/AbstractCodanCQuickFixProcessor.java @@ -8,7 +8,7 @@ * Contributors: * Alena Laskavaia - initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.codan.checkers.ui; +package org.eclipse.cdt.codan.internal.ui.cxx; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.core.resources.ResourceLookup; diff --git a/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF index 25999a93377..f754e44147d 100644 --- a/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF +++ b/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF @@ -8,9 +8,11 @@ Bundle-Vendor: %Bundle-Vendor Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.core.resources, - org.eclipse.ui.workbench.texteditor;bundle-version="3.5.0", - org.eclipse.ui.editors;bundle-version="3.5.0", - org.eclipse.cdt.codan.core;bundle-version="1.0.0" + org.eclipse.ui.workbench.texteditor, + org.eclipse.ui.editors, + org.eclipse.cdt.codan.core, + org.eclipse.jface.text, + org.eclipse.ui.ide Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.cdt.codan.internal.ui;x-friends:="org.eclipse.cdt.codan.ui.cxx", diff --git a/codan/org.eclipse.cdt.codan.ui/plugin.xml b/codan/org.eclipse.cdt.codan.ui/plugin.xml index df647fdd3c5..fcb94a4cd05 100644 --- a/codan/org.eclipse.cdt.codan.ui/plugin.xml +++ b/codan/org.eclipse.cdt.codan.ui/plugin.xml @@ -80,6 +80,7 @@ +