Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlena Laskavaia2010-05-01 21:47:28 -0400
committerAlena Laskavaia2010-05-01 21:47:28 -0400
commit36e14f64c3848dd3180e08b35ca8aeb20134da95 (patch)
tree631ee6cb0c0c365e1f7f4470891d47af51977626 /codan/org.eclipse.cdt.codan.ui.cxx
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.ui.cxx')
-rw-r--r--codan/org.eclipse.cdt.codan.ui.cxx/META-INF/MANIFEST.MF7
-rw-r--r--codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/AbstractCodanCQuickFixProcessor.java97
2 files changed, 101 insertions, 3 deletions
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 1badca951a..3eb301b0ea 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.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/AbstractCodanCQuickFixProcessor.java b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/AbstractCodanCQuickFixProcessor.java
new file mode 100644
index 0000000000..29bc3bf803
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/AbstractCodanCQuickFixProcessor.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * 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.internal.ui.cxx;
+
+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

Back to the top