mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
- refactored to extract checkers.ui to another plugin
This commit is contained in:
parent
8950983042
commit
c60533c54f
6 changed files with 18 additions and 139 deletions
|
@ -7,10 +7,6 @@ Bundle-Activator: org.eclipse.cdt.codan.checkers.Activator
|
|||
Require-Bundle: org.eclipse.core.runtime,
|
||||
org.eclipse.core.resources;bundle-version="3.5.0",
|
||||
org.eclipse.cdt.core;bundle-version="5.1.0",
|
||||
org.eclipse.cdt.codan.core;bundle-version="1.0.0",
|
||||
org.eclipse.ui.editors;bundle-version="3.5.0",
|
||||
org.eclipse.jface.text;bundle-version="3.5.0",
|
||||
org.eclipse.ui;bundle-version="3.5.0",
|
||||
org.eclipse.ui.ide;bundle-version="3.5.0"
|
||||
org.eclipse.cdt.codan.core;bundle-version="1.0.0"
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
|
|
|
@ -2,24 +2,18 @@
|
|||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
point="org.eclipse.cdt.codan.core.checkers">
|
||||
point="org.eclipse.cdt.codan.core.checkers"
|
||||
id="org.eclipse.cdt.codan.core.checkers.sample">
|
||||
|
||||
<checker
|
||||
class="org.eclipse.cdt.codan.checkers.sample.AssignmentInConditionChecker"
|
||||
id="org.eclipse.cdt.codan.checkers.checker1"
|
||||
id="org.eclipse.cdt.codan.checkers.sample.AssignmentInConditionChecker"
|
||||
name="Assignment in condition">
|
||||
<problem
|
||||
defaultSeverity="Warning"
|
||||
id="org.eclipse.cdt.codan.checkers.sample.assignment_in_condition"
|
||||
id="org.eclipse.cdt.codan.checkers.sample.AssignmentInConditionProblem"
|
||||
name="Assignment in condition">
|
||||
</problem>
|
||||
</checker>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.ide.markerResolution">
|
||||
<markerResolutionGenerator
|
||||
class="org.eclipse.cdt.codan.checkers.sample.MarkerResolutionGenerator"
|
||||
markerType="org.eclipse.cdt.codan.core.codanProblem">
|
||||
</markerResolutionGenerator>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
package org.eclipse.cdt.codan.checkers;
|
||||
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
* The activator class controls the plug-in life cycle
|
||||
*/
|
||||
public class Activator extends AbstractUIPlugin {
|
||||
|
||||
public class Activator extends Plugin {
|
||||
// The plug-in ID
|
||||
public static final String PLUGIN_ID = "org.eclipse.cdt.codan.checkers";
|
||||
|
||||
// The shared instance
|
||||
private static Activator plugin;
|
||||
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
|
@ -22,7 +20,10 @@ public class Activator extends AbstractUIPlugin {
|
|||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
|
||||
* )
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
|
@ -31,7 +32,10 @@ public class Activator extends AbstractUIPlugin {
|
|||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
|
||||
* )
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
plugin = null;
|
||||
|
@ -40,11 +44,10 @@ public class Activator extends AbstractUIPlugin {
|
|||
|
||||
/**
|
||||
* Returns the shared instance
|
||||
*
|
||||
*
|
||||
* @return the shared instance
|
||||
*/
|
||||
public static Activator getDefault() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
|
||||
public class AssignmentInConditionChecker extends AbstractIndexAstChecker {
|
||||
private static final String ER_ID = "org.eclipse.cdt.codan.checkers.sample.assignment_in_condition";
|
||||
private static final String ER_ID = "org.eclipse.cdt.codan.checkers.sample.AssignmentInConditionProblem";
|
||||
|
||||
@Override
|
||||
public void processAst(IASTTranslationUnit ast) {
|
||||
|
|
|
@ -1,24 +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.checkers.sample;
|
||||
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.ui.IMarkerResolution;
|
||||
import org.eclipse.ui.IMarkerResolutionGenerator;
|
||||
|
||||
public class MarkerResolutionGenerator implements IMarkerResolutionGenerator {
|
||||
|
||||
@Override
|
||||
public IMarkerResolution[] getResolutions(IMarker marker) {
|
||||
return new IMarkerResolution[] { new QuickFixAssignmentInCondition() };
|
||||
}
|
||||
|
||||
}
|
|
@ -1,90 +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.checkers.sample;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
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;
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
||||
public class QuickFixAssignmentInCondition implements IMarkerResolution {
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "Change first occurence '=' in the line to condition '=='";
|
||||
}
|
||||
|
||||
@Override
|
||||
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());
|
||||
|
||||
int line = marker.getAttribute(IMarker.LINE_NUMBER, -1)-1;
|
||||
|
||||
FindReplaceDocumentAdapter dad = new FindReplaceDocumentAdapter(doc);
|
||||
try {
|
||||
dad.find(doc.getLineOffset(line), "=", /*forwardSearch*/ true, /*caseSensitive*/ false,
|
||||
/*wholeWord*/ false, /*regExSearch*/ false);
|
||||
dad.replace("==", /*regExReplace*/ false);
|
||||
marker.delete();
|
||||
} catch (BadLocationException e) {
|
||||
// TODO: log the error
|
||||
e.printStackTrace();
|
||||
} catch (CoreException e) {
|
||||
// TODO: log the error
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue