Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register quickfixes via extension point #566

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ public final class XMLTags {
/** tag to flag if a module is a singleton. */
public static final String IS_SINGLETON_TAG = "singleton"; //$NON-NLS-1$

/** tag for the quickfix element. */
public static final String QUCKFIX_TAG = "quickfix"; //$NON-NLS-1$

/** tag for the message key element. */
public static final String MESSAGEKEY_TAG = "message-key"; //$NON-NLS-1$

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,13 +738,6 @@ private static void processModules(Element groupElement, RuleGroupMetadata group
module.addAlternativeName(alternativeName);
}

// process quickfixes
for (Element quickfixEl : moduleEl.elements(XMLTags.QUCKFIX_TAG)) {

String quickfixClassName = quickfixEl.attributeValue(XMLTags.CLASSNAME_TAG);
module.addQuickfix(quickfixClassName);
}

// process message keys
for (Element quickfixEl : moduleEl.elements(XMLTags.MESSAGEKEY_TAG)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public class RuleMetadata {
/** Alternative names, including the name of the Checkstyle checker class. */
private final Collection<String> mAlternativeNames;

/** Collection fo quick fixes for this module. */
private final Collection<String> mQuickfixes;

private final Collection<String> mMessageKeys;

/** Determines if the module is a singleton. */
Expand Down Expand Up @@ -107,7 +104,6 @@ public RuleMetadata(String ruleName, String internalName, String parent, Severit
mIsDeletable = deletable;
mGroup = group;
mAlternativeNames = new ArrayList<>();
mQuickfixes = new ArrayList<>();
mMessageKeys = new ArrayList<>();
mIsSingleton = isSingleton;
}
Expand All @@ -131,25 +127,6 @@ public Collection<String> getAlternativeNames() {
return mAlternativeNames;
}

/**
* Adds a quickfixfor this rule.
*
* @param quickfixClassName
* the fully qualified classname of the quickfix
*/
public void addQuickfix(String quickfixClassName) {
mQuickfixes.add(quickfixClassName);
}

/**
* Returns the list quickfixes for this module.
*
* @return a collection of quickfix class names
*/
public Collection<String> getQuickfixClassNames() {
return mQuickfixes;
}

/**
* Adds a message key to this module metadata.
*
Expand Down
12 changes: 7 additions & 5 deletions net.sf.eclipsecs.sample/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
point="net.sf.eclipsecs.core.checkstyleAddonProvider">
</extension>

<!-- This plugin provides custom quickfixes for Checkstyle problems. -->
<extension
point="net.sf.eclipsecs.ui.checkstyleQuickfixProvider">
</extension>

<!--
Sample builtin check configuration
-->
Expand Down Expand Up @@ -39,4 +34,11 @@
description="%filter.description"
class="net.sf.eclipsecs.sample.filter.SampleFilter"/>
</extension>

<extension
point="net.sf.eclipsecs.ui.quickfix">
<quickfix
module="MethodLimit"
class="net.sf.eclipsecs.sample.checks.MethodLimitQuickfix"></quickfix>
</extension>
</plugin>
3 changes: 2 additions & 1 deletion net.sf.eclipsecs.ui/OSGI-INF/l10n/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ extension-point.quickfix-provider.name = Checkstyle Quickfix provider
extension-point.filter-editor.name = Checkstyle filter editors
extension-point.config-types-ui.name = Checkstyle configuration type editors
addnature.label = Add Checkstyle Nature
removenature.label = Remove Checkstyle Nature
removenature.label = Remove Checkstyle Nature
extension-point.name = checkstyle
87 changes: 81 additions & 6 deletions net.sf.eclipsecs.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
<?eclipse version="3.4"?>
<plugin>

<!-- defines the extension point to contribute custom quickfixes. -->
<extension-point
id="checkstyleQuickfixProvider"
name="%extension-point.quickfix-provider.name"
schema="schema/checkstyleQuickfixProvider.exsd"/>

<!-- defines the extension point to contribute custom filter editors for plugin filters -->
<extension-point
id="filtereditors"
Expand All @@ -20,6 +14,12 @@
name="%extension-point.config-types-ui.name"
schema="schema/configtypesui.exsd"/>

<!-- defines the extension point to contribute custom quickfixes. -->
<extension-point
id="quickfix"
name="%extension-point.name"
schema="schema/quickfix.exsd"/>

<!-- Filter editors for filters allowing user input -->
<extension
point="net.sf.eclipsecs.ui.filtereditors">
Expand Down Expand Up @@ -542,4 +542,79 @@
icon="platform:/plugin/org.eclipse.ui/icons/full/etool16/clear.png">
</image>
</extension>
<extension
point="net.sf.eclipsecs.ui.quickfix">
<quickfix
module="ArrayTypeStyleCheck"
class="net.sf.eclipsecs.ui.quickfixes.misc.ArrayTypeStyleQuickfix">
</quickfix>
<quickfix
module="AvoidNestedBlocksCheck"
class="net.sf.eclipsecs.ui.quickfixes.blocks.AvoidNestedBlocksQuickfix">
</quickfix>
<quickfix
module="DefaultComesLastCheck"
class="net.sf.eclipsecs.ui.quickfixes.coding.DefaultComesLastQuickfix">
</quickfix>
<quickfix
module="DesignForExtensionCheck"
class="net.sf.eclipsecs.ui.quickfixes.design.DesignForExtensionQuickfix">
</quickfix>
<quickfix
module="EmptyStatementCheck"
class="net.sf.eclipsecs.ui.quickfixes.coding.EmptyStatementQuickfix">
</quickfix>
<quickfix
module="ExplicitInitializationCheck"
class="net.sf.eclipsecs.ui.quickfixes.coding.ExplicitInitializationQuickfix">
</quickfix>
<quickfix
module="FinalClassCheck"
class="net.sf.eclipsecs.ui.quickfixes.design.FinalClassQuickfix">
</quickfix>
<quickfix
module="FinalLocalVariableCheck"
class="net.sf.eclipsecs.ui.quickfixes.coding.FinalLocalVariableQuickfix">
</quickfix>
<quickfix
module="FinalParametersCheck"
class="net.sf.eclipsecs.ui.quickfixes.misc.FinalParametersQuickfix">
</quickfix>
<quickfix
module="MissingSwitchDefaultCheck"
class="net.sf.eclipsecs.ui.quickfixes.coding.MissingSwitchDefaultQuickfix">
</quickfix>
<quickfix
module="ModifierOrderCheck"
class="net.sf.eclipsecs.ui.quickfixes.modifier.ModifierOrderQuickfix">
</quickfix>
<quickfix
module="NeedBracesCheck"
class="net.sf.eclipsecs.ui.quickfixes.blocks.NeedBracesQuickfix">
</quickfix>
<quickfix
module="RedundantModifierCheck"
class="net.sf.eclipsecs.ui.quickfixes.modifier.RedundantModifierQuickfix">
</quickfix>
<quickfix
module="RequireThisCheck"
class="net.sf.eclipsecs.ui.quickfixes.coding.RequireThisQuickfix">
</quickfix>
<quickfix
module="SimplifyBooleanReturnCheck"
class="net.sf.eclipsecs.ui.quickfixes.coding.SimplifyBooleanReturnQuickfix">
</quickfix>
<quickfix
module="StringLiteralEqualityCheck"
class="net.sf.eclipsecs.ui.quickfixes.coding.StringLiteralEqualityQuickfix">
</quickfix>
<quickfix
module="UncommentedMainCheck"
class="net.sf.eclipsecs.ui.quickfixes.misc.UncommentedMainQuickfix">
</quickfix>
<quickfix
module="UpperEllCheck"
class="net.sf.eclipsecs.ui.quickfixes.misc.UpperEllQuickfix">
</quickfix>
</extension>
</plugin>
26 changes: 0 additions & 26 deletions net.sf.eclipsecs.ui/schema/checkstyleQuickfixProvider.exsd

This file was deleted.

99 changes: 99 additions & 0 deletions net.sf.eclipsecs.ui/schema/quickfix.exsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="net.sf.eclipsecs.ui" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="net.sf.eclipsecs.ui" id="quickfix" name="Checkstyle violation quickfix"/>
</appinfo>
<documentation>
Use this extension point to register quickfix classes for specific Checkstyle violations.
</documentation>
</annotation>

<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<element ref="quickfix"/>
</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="quickfix">
<complexType>
<attribute name="module" type="string" use="required">
<annotation>
<documentation>
fully qualified name of the Checkstyle module that this quickfix can fix
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
Class implementing net.sf.eclipsecs.ui.quickfixes.ICheckstyleMarkerResolution
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":net.sf.eclipsecs.ui.quickfixes.ICheckstyleMarkerResolution"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
10.9.3
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
The following is an example for registering a quickfix.

&lt;extension point=&quot;net.sf.eclipsecs.ui.quickfix&quot;&gt;
&lt;quickfix
module=&quot;com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck&quot;
class=&quot;net.sf.eclipsecs.ui.quickfixes.blocks.NeedBracesQuickfix&quot;&gt;&lt;/quickfix&gt;
&lt;/extension&gt;
</documentation>
</annotation>




</schema>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import net.sf.eclipsecs.core.jobs.AbstractCheckJob;
import net.sf.eclipsecs.core.util.CheckstyleLog;
import net.sf.eclipsecs.core.util.ExtensionClassLoader;
import net.sf.eclipsecs.ui.properties.filter.CheckFileOnOpenPartListener;

import org.eclipse.core.resources.IWorkspace;
Expand Down Expand Up @@ -57,10 +56,6 @@ public class CheckstyleUIPlugin extends AbstractUIPlugin {
/** Identifier of the plug-in. */
public static final String PLUGIN_ID = "net.sf.eclipsecs.ui"; //$NON-NLS-1$

/** Extension point id for Checkstyle quickfix providers. */
public static final String QUICKFIX_PROVIDER_EXT_PT_ID = PLUGIN_ID
+ ".checkstyleQuickfixProvider"; //$NON-NLS-1$

/** The shared instance. */
private static CheckstyleUIPlugin sPlugin;

Expand Down Expand Up @@ -91,8 +86,6 @@ public void windowDeactivated(IWorkbenchWindow window) {

};

private ClassLoader mQuickfixExtensionClassLoader;

/**
* The constructor.
*/
Expand All @@ -104,9 +97,6 @@ public CheckstyleUIPlugin() {
public void start(BundleContext context) throws Exception {
super.start(context);

mQuickfixExtensionClassLoader = new ExtensionClassLoader(context.getBundle(),
QUICKFIX_PROVIDER_EXT_PT_ID);

// add listeners for the Check-On-Open support
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().asyncExec(new Runnable() {
Expand Down Expand Up @@ -280,13 +270,4 @@ public static void warningDialog(Shell shell, String message, Throwable throwabl
ErrorDialog.openError(shell, Messages.CheckstyleLog_titleWarning, message, status);
}

/**
* Returns the classloader containing quickfix extensions.
*
* @return the classloader containing all registered quickfix extensions.
*/
public ClassLoader getQuickfixExtensionClassLoader() {
return mQuickfixExtensionClassLoader;
}

}
Loading