mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 22:22:11 +02:00
Refactor to move common code to a proper package and externalize strings
This commit is contained in:
parent
bc2f66e8d3
commit
36e14f64c3
14 changed files with 83 additions and 93 deletions
|
@ -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
|
||||
|
|
|
@ -3,4 +3,4 @@ output.. = bin/
|
|||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
plugin.xml,\
|
||||
schema/
|
||||
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
CatchByReferenceQuickFix_Message=Change to use '&'
|
||||
QuickFixAssignmentInCondition_Message=Change to '=='
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
|
@ -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",
|
||||
|
|
|
@ -80,6 +80,7 @@
|
|||
</view>
|
||||
</extension>
|
||||
<extension-point id="codanProblemDetails" name="%extension-point.name" schema="schema/codanProblemDetails.exsd"/>
|
||||
<extension-point id="codanMarkerResolution" name="Codan Marker Resolution" schema="schema/codanMarkerResolution.exsd"/>
|
||||
<!--
|
||||
<extension
|
||||
point="org.eclipse.ui.bindings">
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.internal.checkers.ui.quickfix;
|
||||
package org.eclipse.cdt.codan.internal.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -17,7 +17,6 @@ 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;
|
||||
|
@ -72,7 +71,7 @@ public class CodanProblemMarkerResolutionGenerator implements
|
|||
|
||||
private static synchronized void readExtensions() {
|
||||
IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(
|
||||
CheckersUiActivator.PLUGIN_ID, EXTENSION_POINT_NAME);
|
||||
CodanUIActivator.PLUGIN_ID, EXTENSION_POINT_NAME);
|
||||
if (ep == null)
|
||||
return;
|
||||
try {
|
||||
|
@ -95,8 +94,8 @@ public class CodanProblemMarkerResolutionGenerator implements
|
|||
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");
|
||||
CodanUIActivator.log("Extension for " + EXTENSION_POINT_NAME //$NON-NLS-1$
|
||||
+ " problemId is not defined"); //$NON-NLS-1$
|
||||
return;
|
||||
}
|
||||
IMarkerResolution res;
|
||||
|
@ -104,7 +103,7 @@ public class CodanProblemMarkerResolutionGenerator implements
|
|||
res = (IMarkerResolution) configurationElement
|
||||
.createExecutableExtension("class");//$NON-NLS-1$
|
||||
} catch (CoreException e) {
|
||||
CheckersUiActivator.log(e);
|
||||
CodanUIActivator.log(e);
|
||||
return;
|
||||
}
|
||||
String messagePattern = configurationElement
|
||||
|
@ -114,9 +113,9 @@ public class CodanProblemMarkerResolutionGenerator implements
|
|||
Pattern.compile(messagePattern);
|
||||
} catch (Exception e) {
|
||||
// bad pattern log and ignore
|
||||
CheckersUiActivator.log("Extension for "
|
||||
CodanUIActivator.log("Extension for " //$NON-NLS-1$
|
||||
+ EXTENSION_POINT_NAME
|
||||
+ " messagePattern is invalid: " + e.getMessage());
|
||||
+ " messagePattern is invalid: " + e.getMessage()); //$NON-NLS-1$
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.checkers.ui;
|
||||
package org.eclipse.cdt.codan.ui;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IMarker;
|
Loading…
Add table
Reference in a new issue