Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlena Laskavaia2010-05-02 01:47:28 +0000
committerAlena Laskavaia2010-05-02 01:47:28 +0000
commit36e14f64c3848dd3180e08b35ca8aeb20134da95 (patch)
tree631ee6cb0c0c365e1f7f4470891d47af51977626 /codan/org.eclipse.cdt.codan.checkers.ui
parentbc2f66e8d357bfa5adc4b20ee72e3ef184c564cb (diff)
downloadorg.eclipse.cdt-36e14f64c3848dd3180e08b35ca8aeb20134da95.tar.gz
org.eclipse.cdt-36e14f64c3848dd3180e08b35ca8aeb20134da95.tar.xz
org.eclipse.cdt-36e14f64c3848dd3180e08b35ca8aeb20134da95.zip
Refactor to move common code to a proper package and externalize strings
Diffstat (limited to 'codan/org.eclipse.cdt.codan.checkers.ui')
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/META-INF/MANIFEST.MF8
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/build.properties2
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml6
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/schema/codanMarkerResolution.exsd132
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/AbstarctCodanCMarkerResolution.java106
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/AbstractCodanCQuickFixProcessor.java97
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/Messages.java29
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/messages.properties2
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFix.java8
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CodanProblemMarkerResolutionGenerator.java142
-rw-r--r--codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java86
11 files changed, 64 insertions, 554 deletions
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 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
- <extension-point id="codanMarkerResolution" name="Codan Marker Resolution" schema="schema/codanMarkerResolution.exsd"/>
+
<extension
point="org.eclipse.ui.ide.markerResolution">
<markerResolutionGenerator
- class="org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CodanProblemMarkerResolutionGenerator"
+ class="org.eclipse.cdt.codan.internal.ui.CodanProblemMarkerResolutionGenerator"
markerType="org.eclipse.cdt.codan.core.codanProblem">
</markerResolutionGenerator>
</extension>
<extension
- point="org.eclipse.cdt.codan.checkers.ui.codanMarkerResolution">
+ point="org.eclipse.cdt.codan.ui.codanMarkerResolution">
<resolution
class="org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CatchByReferenceQuickFix"
problemId="org.eclipse.cdt.codan.internal.checkers.CatchByReference">
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/schema/codanMarkerResolution.exsd b/codan/org.eclipse.cdt.codan.checkers.ui/schema/codanMarkerResolution.exsd
deleted file mode 100644
index 4cdbf233f09..00000000000
--- a/codan/org.eclipse.cdt.codan.checkers.ui/schema/codanMarkerResolution.exsd
+++ /dev/null
@@ -1,132 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- Schema file written by PDE -->
-<schema targetNamespace="org.eclipse.cdt.codan.checkers.ui" xmlns="http://www.w3.org/2001/XMLSchema">
-<annotation>
- <appinfo>
- <meta.schema plugin="org.eclipse.cdt.codan.checkers.ui" id="codanMarkerResolution" name="Codan Marker Resolution"/>
- </appinfo>
- <documentation>
- Extension point to plugin quick fix for codan markers
-
- </documentation>
- </annotation>
-
- <element name="extension">
- <annotation>
- <appinfo>
- <meta.element />
- </appinfo>
- </annotation>
- <complexType>
- <sequence minOccurs="1" maxOccurs="unbounded">
- <element ref="resolution"/>
- </sequence>
- <attribute name="point" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="id" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="name" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- <appinfo>
- <meta.attribute translatable="true"/>
- </appinfo>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <element name="resolution">
- <annotation>
- <documentation>
- Contribute codan marker resolution
- </documentation>
- </annotation>
- <complexType>
- <attribute name="class" type="string" use="required">
- <annotation>
- <documentation>
- Class that implement IMarkerResolution that provides a fix for the given problem
- </documentation>
- <appinfo>
- <meta.attribute kind="java" basedOn=":org.eclipse.ui.IMarkerResolution"/>
- </appinfo>
- </annotation>
- </attribute>
- <attribute name="problemId" type="string" use="required">
- <annotation>
- <documentation>
- Problem id of the problem for which quick fix is defined
- </documentation>
- <appinfo>
- <meta.attribute kind="identifier" basedOn="org.eclipse.cdt.codan.core.checkers/checker/problem/@id"/>
- </appinfo>
- </annotation>
- </attribute>
- <attribute name="messagePattern" type="string">
- <annotation>
- <documentation>
- If problem id is not enought to identity the fix messagePattern can be used to apply fix for given message
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <annotation>
- <appinfo>
- <meta.section type="since"/>
- </appinfo>
- <documentation>
- since 1.0
- </documentation>
- </annotation>
-
- <annotation>
- <appinfo>
- <meta.section type="examples"/>
- </appinfo>
- <documentation>
- &lt;extension
- point=&quot;org.eclipse.cdt.codan.checkers.ui.codanMarkerResolution&quot;&gt;
- &lt;resolution
- class=&quot;org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CatchByReferenceQuickFix&quot;
- problemId=&quot;org.eclipse.cdt.codan.internal.checkers.CatchByReference&quot;&gt;
- &lt;/resolution&gt;
- &lt;/extension&gt;
- </documentation>
- </annotation>
-
- <annotation>
- <appinfo>
- <meta.section type="apiinfo"/>
- </appinfo>
- <documentation>
- Programmatically resolution can be added using CatchByReferenceQuickFix.addResolution method.
-It is not API yet.
- </documentation>
- </annotation>
-
- <annotation>
- <appinfo>
- <meta.section type="implementation"/>
- </appinfo>
- <documentation>
- see CatchByReferenceQuickFix
- </documentation>
- </annotation>
-
-
-</schema>
diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/AbstarctCodanCMarkerResolution.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/AbstarctCodanCMarkerResolution.java
deleted file mode 100644
index 879eb8e3131..00000000000
--- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/AbstarctCodanCMarkerResolution.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 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.checkers.ui;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.jface.text.BadLocationException;
-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.IMarkerResolution2;
-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;
-
-/**
- * Generic class for codan marker resolution (for quick fix).
- * Use as a base class for codanMarkerResolution extension.
- * To add specific icon and description client class should additionally
- * implement {@link IMarkerResolution2}
- */
-public abstract class AbstarctCodanCMarkerResolution implements
- IMarkerResolution {
- /**
- * Get position offset from marker. If CHAR_START attribute is not set
- * for marker, line and document would be used.
- * @param marker
- * @param doc
- * @return
- */
- public int getOffset(IMarker marker, IDocument doc) {
- 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;
- try {
- position = doc.getLineOffset(line);
- } catch (BadLocationException e) {
- return -1;
- }
- }
- return position;
- }
- /**
- * Runs this resolution.
- *
- * @param marker the marker to resolve
- */
- 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());
- apply(marker, doc);
- }
- }
-
- /**
- * Apply marker resolution for given marker in given open document.
- * @param marker
- * @param document
- */
- public abstract void apply(IMarker marker, IDocument document);
-
-
-}
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.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/AbstractCodanCQuickFixProcessor.java
deleted file mode 100644
index 1e8cc99febc..00000000000
--- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/AbstractCodanCQuickFixProcessor.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 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.checkers.ui;
-
-import org.eclipse.cdt.core.model.ITranslationUnit;
-import org.eclipse.cdt.internal.core.resources.ResourceLookup;
-import org.eclipse.cdt.ui.text.ICCompletionProposal;
-import org.eclipse.cdt.ui.text.IInvocationContext;
-import org.eclipse.cdt.ui.text.IProblemLocation;
-import org.eclipse.cdt.ui.text.IQuickFixProcessor;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-
-/**
- * Abstract class IQuickFixProcessor - not used right now because it does not work
- * properly for non hardcoded errors
- * <p>
- * <strong>EXPERIMENTAL</strong>. This class or interface has been added as part
- * of a work in progress. There is no guarantee that this API will work or that
- * it will remain the same.
- * </p>
- */
-public abstract class AbstractCodanCQuickFixProcessor implements IQuickFixProcessor {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.cdt.ui.text.IQuickFixProcessor#hasCorrections(org.eclipse
- * .cdt.ui.text.ITranslationUnit, int)
- */
- public boolean hasCorrections(ITranslationUnit unit, int problemId) {
- return problemId == 42;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.cdt.ui.text.IQuickFixProcessor#getCorrections(org.eclipse
- * .cdt.ui.text.IInvocationContext,
- * org.eclipse.cdt.ui.text.IProblemLocation[])
- */
- public ICCompletionProposal[] getCorrections(IInvocationContext context,
- IProblemLocation[] locations) throws CoreException {
- if (locations==null || locations.length==0) return null;
- IProblemLocation loc = locations[0];
- IPath location= context.getTranslationUnit().getLocation();
- IFile astFile = ResourceLookup.selectFileForLocation(location, context.getTranslationUnit().getCProject().getProject());
- IMarker[] markers = astFile.findMarkers(loc.getMarkerType(), false, 1);
- for (int i = 0; i < markers.length; i++) {
- IMarker m = markers[i];
- int start = m.getAttribute(IMarker.CHAR_START, -1);
- if (start==loc.getOffset()) {
- String id = m.getAttribute(IMarker.PROBLEM,"");
- return getCorrections(context, id, m);
- }
- }
-
- return null;
- }
-
- public int getOffset(IMarker marker, IDocument doc) {
- 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;
- try {
- position = doc.getLineOffset(line);
- } catch (BadLocationException e) {
- return -1;
- }
- }
- return position;
- }
- /**
- * @param context
- * @param loc
- * @param marker
- * @return
- */
- public abstract ICCompletionProposal[] getCorrections(IInvocationContext context,
- String problemId, IMarker marker);
-} \ No newline at end of file
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/CodanProblemMarkerResolutionGenerator.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CodanProblemMarkerResolutionGenerator.java
deleted file mode 100644
index 90350190e04..00000000000
--- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CodanProblemMarkerResolutionGenerator.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Andrew Gvozdev
- * 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:
- * Andrew Gvozdev - initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.codan.internal.checkers.ui.quickfix;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import org.eclipse.cdt.codan.internal.checkers.ui.CheckersUiActivator;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.ui.IMarkerResolution;
-import org.eclipse.ui.IMarkerResolutionGenerator;
-
-public class CodanProblemMarkerResolutionGenerator implements
- IMarkerResolutionGenerator {
- private static final String EXTENSION_POINT_NAME = "codanMarkerResolution"; //$NON-NLS-1$
- private static Map<String, Collection<ConditionalResolution>> resolutions = new HashMap<String, Collection<ConditionalResolution>>();
- private static boolean resolutionsLoaded = false;
-
- static class ConditionalResolution {
- IMarkerResolution res;
- String messagePattern;
-
- public ConditionalResolution(IMarkerResolution res2,
- String messagePattern2) {
- res = res2;
- messagePattern = messagePattern2;
- }
- }
-
- public IMarkerResolution[] getResolutions(IMarker marker) {
- if (resolutionsLoaded == false) {
- readExtensions();
- }
- String id = marker.getAttribute(IMarker.PROBLEM, null);
- if (id == null)
- return new IMarkerResolution[0];
- String message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
- Collection<ConditionalResolution> collection = resolutions.get(id);
- if (collection != null) {
- ArrayList<IMarkerResolution> list = new ArrayList<IMarkerResolution>();
- for (Iterator<ConditionalResolution> iterator = collection
- .iterator(); iterator.hasNext();) {
- ConditionalResolution res = iterator.next();
- if (res.messagePattern != null) {
- if (message.matches(res.messagePattern))
- list.add(res.res);
- } else {
- list.add(res.res);
- }
- }
- if (list.size() > 0)
- return list.toArray(new IMarkerResolution[list.size()]);
- }
- return new IMarkerResolution[0];
- }
-
- private static synchronized void readExtensions() {
- IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(
- CheckersUiActivator.PLUGIN_ID, EXTENSION_POINT_NAME);
- if (ep == null)
- return;
- try {
- IConfigurationElement[] elements = ep.getConfigurationElements();
- // process categories
- for (int i = 0; i < elements.length; i++) {
- IConfigurationElement configurationElement = elements[i];
- processResolution(configurationElement);
- }
- } finally {
- resolutionsLoaded = true;
- }
- }
-
- /**
- * @param configurationElement
- */
- private static void processResolution(
- IConfigurationElement configurationElement) {
- if (configurationElement.getName().equals("resolution")) { //$NON-NLS-1$
- String id = configurationElement.getAttribute("problemId"); //$NON-NLS-1$
- if (id == null) {
- CheckersUiActivator.log("Extension for " + EXTENSION_POINT_NAME
- + " problemId is not defined");
- return;
- }
- IMarkerResolution res;
- try {
- res = (IMarkerResolution) configurationElement
- .createExecutableExtension("class");//$NON-NLS-1$
- } catch (CoreException e) {
- CheckersUiActivator.log(e);
- return;
- }
- String messagePattern = configurationElement
- .getAttribute("messagePattern"); //$NON-NLS-1$
- if (messagePattern != null) {
- try {
- Pattern.compile(messagePattern);
- } catch (Exception e) {
- // bad pattern log and ignore
- CheckersUiActivator.log("Extension for "
- + EXTENSION_POINT_NAME
- + " messagePattern is invalid: " + e.getMessage());
- return;
- }
- }
- ConditionalResolution co = new ConditionalResolution(res,
- messagePattern);
- addResolution(id, co);
- }
- }
-
- public static void addResolution(String id, IMarkerResolution res,
- String messagePattern) {
- addResolution(id, new ConditionalResolution(res, messagePattern));
- }
-
- private static void addResolution(String id, ConditionalResolution res) {
- Collection<ConditionalResolution> collection = resolutions.get(id);
- if (collection == null) {
- collection = new ArrayList<ConditionalResolution>();
- resolutions.put(id, collection);
- }
- collection.add(res);
- }
-} \ No newline at end of file
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);
}
}
}

Back to the top