Skip to content

Commit e1c5bf5

Browse files
BananeweizenCalixte
authored andcommitted
Register quickfixes via extension point
* Remove old quickfixprovider extension point. It's entirely useless to register an OSGi plugin as extender of another plugin. OSGi will deal with that kind of class loading anyway. * Instead have a new quickfix extension point, which registers a class implementing the quickfix related interface and the module that can be fixed this way. * Completely avoids loading Checkstyle metadata for looking up quickfixes of existing problem markers. * Fix ExplicitInitializationQuickfix throwing exceptions during the check whether it's applicable. Fixes #315. Fixes #561.
1 parent 4b64836 commit e1c5bf5

File tree

17 files changed

+362
-215
lines changed

17 files changed

+362
-215
lines changed

net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/XMLTags.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ public final class XMLTags {
129129
/** tag to flag if a module is a singleton. */
130130
public static final String IS_SINGLETON_TAG = "singleton"; //$NON-NLS-1$
131131

132-
/** tag for the quickfix element. */
133-
public static final String QUCKFIX_TAG = "quickfix"; //$NON-NLS-1$
134-
135132
/** tag for the message key element. */
136133
public static final String MESSAGEKEY_TAG = "message-key"; //$NON-NLS-1$
137134

net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/meta/MetadataFactory.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -738,13 +738,6 @@ private static void processModules(Element groupElement, RuleGroupMetadata group
738738
module.addAlternativeName(alternativeName);
739739
}
740740

741-
// process quickfixes
742-
for (Element quickfixEl : moduleEl.elements(XMLTags.QUCKFIX_TAG)) {
743-
744-
String quickfixClassName = quickfixEl.attributeValue(XMLTags.CLASSNAME_TAG);
745-
module.addQuickfix(quickfixClassName);
746-
}
747-
748741
// process message keys
749742
for (Element quickfixEl : moduleEl.elements(XMLTags.MESSAGEKEY_TAG)) {
750743

net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/meta/RuleMetadata.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ public class RuleMetadata {
6262
/** Alternative names, including the name of the Checkstyle checker class. */
6363
private final Collection<String> mAlternativeNames;
6464

65-
/** Collection fo quick fixes for this module. */
66-
private final Collection<String> mQuickfixes;
67-
6865
private final Collection<String> mMessageKeys;
6966

7067
/** Determines if the module is a singleton. */
@@ -107,7 +104,6 @@ public RuleMetadata(String ruleName, String internalName, String parent, Severit
107104
mIsDeletable = deletable;
108105
mGroup = group;
109106
mAlternativeNames = new ArrayList<>();
110-
mQuickfixes = new ArrayList<>();
111107
mMessageKeys = new ArrayList<>();
112108
mIsSingleton = isSingleton;
113109
}
@@ -131,25 +127,6 @@ public Collection<String> getAlternativeNames() {
131127
return mAlternativeNames;
132128
}
133129

134-
/**
135-
* Adds a quickfixfor this rule.
136-
*
137-
* @param quickfixClassName
138-
* the fully qualified classname of the quickfix
139-
*/
140-
public void addQuickfix(String quickfixClassName) {
141-
mQuickfixes.add(quickfixClassName);
142-
}
143-
144-
/**
145-
* Returns the list quickfixes for this module.
146-
*
147-
* @return a collection of quickfix class names
148-
*/
149-
public Collection<String> getQuickfixClassNames() {
150-
return mQuickfixes;
151-
}
152-
153130
/**
154131
* Adds a message key to this module metadata.
155132
*

net.sf.eclipsecs.sample/plugin.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
point="net.sf.eclipsecs.core.checkstyleAddonProvider">
88
</extension>
99

10-
<!-- This plugin provides custom quickfixes for Checkstyle problems. -->
11-
<extension
12-
point="net.sf.eclipsecs.ui.checkstyleQuickfixProvider">
13-
</extension>
14-
1510
<!--
1611
Sample builtin check configuration
1712
-->
@@ -39,4 +34,11 @@
3934
description="%filter.description"
4035
class="net.sf.eclipsecs.sample.filter.SampleFilter"/>
4136
</extension>
37+
38+
<extension
39+
point="net.sf.eclipsecs.ui.quickfix">
40+
<quickfix
41+
module="MethodLimit"
42+
class="net.sf.eclipsecs.sample.checks.MethodLimitQuickfix"></quickfix>
43+
</extension>
4244
</plugin>

net.sf.eclipsecs.ui/OSGI-INF/l10n/bundle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ extension-point.quickfix-provider.name = Checkstyle Quickfix provider
5757
extension-point.filter-editor.name = Checkstyle filter editors
5858
extension-point.config-types-ui.name = Checkstyle configuration type editors
5959
addnature.label = Add Checkstyle Nature
60-
removenature.label = Remove Checkstyle Nature
60+
removenature.label = Remove Checkstyle Nature
61+
extension-point.name = checkstyle

net.sf.eclipsecs.ui/plugin.xml

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
<?eclipse version="3.4"?>
33
<plugin>
44

5-
<!-- defines the extension point to contribute custom quickfixes. -->
6-
<extension-point
7-
id="checkstyleQuickfixProvider"
8-
name="%extension-point.quickfix-provider.name"
9-
schema="schema/checkstyleQuickfixProvider.exsd"/>
10-
115
<!-- defines the extension point to contribute custom filter editors for plugin filters -->
126
<extension-point
137
id="filtereditors"
@@ -20,6 +14,12 @@
2014
name="%extension-point.config-types-ui.name"
2115
schema="schema/configtypesui.exsd"/>
2216

17+
<!-- defines the extension point to contribute custom quickfixes. -->
18+
<extension-point
19+
id="quickfix"
20+
name="%extension-point.name"
21+
schema="schema/quickfix.exsd"/>
22+
2323
<!-- Filter editors for filters allowing user input -->
2424
<extension
2525
point="net.sf.eclipsecs.ui.filtereditors">
@@ -542,4 +542,79 @@
542542
icon="platform:/plugin/org.eclipse.ui/icons/full/etool16/clear.png">
543543
</image>
544544
</extension>
545+
<extension
546+
point="net.sf.eclipsecs.ui.quickfix">
547+
<quickfix
548+
module="ArrayTypeStyleCheck"
549+
class="net.sf.eclipsecs.ui.quickfixes.misc.ArrayTypeStyleQuickfix">
550+
</quickfix>
551+
<quickfix
552+
module="AvoidNestedBlocksCheck"
553+
class="net.sf.eclipsecs.ui.quickfixes.blocks.AvoidNestedBlocksQuickfix">
554+
</quickfix>
555+
<quickfix
556+
module="DefaultComesLastCheck"
557+
class="net.sf.eclipsecs.ui.quickfixes.coding.DefaultComesLastQuickfix">
558+
</quickfix>
559+
<quickfix
560+
module="DesignForExtensionCheck"
561+
class="net.sf.eclipsecs.ui.quickfixes.design.DesignForExtensionQuickfix">
562+
</quickfix>
563+
<quickfix
564+
module="EmptyStatementCheck"
565+
class="net.sf.eclipsecs.ui.quickfixes.coding.EmptyStatementQuickfix">
566+
</quickfix>
567+
<quickfix
568+
module="ExplicitInitializationCheck"
569+
class="net.sf.eclipsecs.ui.quickfixes.coding.ExplicitInitializationQuickfix">
570+
</quickfix>
571+
<quickfix
572+
module="FinalClassCheck"
573+
class="net.sf.eclipsecs.ui.quickfixes.design.FinalClassQuickfix">
574+
</quickfix>
575+
<quickfix
576+
module="FinalLocalVariableCheck"
577+
class="net.sf.eclipsecs.ui.quickfixes.coding.FinalLocalVariableQuickfix">
578+
</quickfix>
579+
<quickfix
580+
module="FinalParametersCheck"
581+
class="net.sf.eclipsecs.ui.quickfixes.misc.FinalParametersQuickfix">
582+
</quickfix>
583+
<quickfix
584+
module="MissingSwitchDefaultCheck"
585+
class="net.sf.eclipsecs.ui.quickfixes.coding.MissingSwitchDefaultQuickfix">
586+
</quickfix>
587+
<quickfix
588+
module="ModifierOrderCheck"
589+
class="net.sf.eclipsecs.ui.quickfixes.modifier.ModifierOrderQuickfix">
590+
</quickfix>
591+
<quickfix
592+
module="NeedBracesCheck"
593+
class="net.sf.eclipsecs.ui.quickfixes.blocks.NeedBracesQuickfix">
594+
</quickfix>
595+
<quickfix
596+
module="RedundantModifierCheck"
597+
class="net.sf.eclipsecs.ui.quickfixes.modifier.RedundantModifierQuickfix">
598+
</quickfix>
599+
<quickfix
600+
module="RequireThisCheck"
601+
class="net.sf.eclipsecs.ui.quickfixes.coding.RequireThisQuickfix">
602+
</quickfix>
603+
<quickfix
604+
module="SimplifyBooleanReturnCheck"
605+
class="net.sf.eclipsecs.ui.quickfixes.coding.SimplifyBooleanReturnQuickfix">
606+
</quickfix>
607+
<quickfix
608+
module="StringLiteralEqualityCheck"
609+
class="net.sf.eclipsecs.ui.quickfixes.coding.StringLiteralEqualityQuickfix">
610+
</quickfix>
611+
<quickfix
612+
module="UncommentedMainCheck"
613+
class="net.sf.eclipsecs.ui.quickfixes.misc.UncommentedMainQuickfix">
614+
</quickfix>
615+
<quickfix
616+
module="UpperEllCheck"
617+
class="net.sf.eclipsecs.ui.quickfixes.misc.UpperEllQuickfix">
618+
</quickfix>
619+
</extension>
545620
</plugin>

net.sf.eclipsecs.ui/schema/checkstyleQuickfixProvider.exsd

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!-- Schema file written by PDE -->
3+
<schema targetNamespace="net.sf.eclipsecs.ui" xmlns="http://www.w3.org/2001/XMLSchema">
4+
<annotation>
5+
<appinfo>
6+
<meta.schema plugin="net.sf.eclipsecs.ui" id="quickfix" name="Checkstyle violation quickfix"/>
7+
</appinfo>
8+
<documentation>
9+
Use this extension point to register quickfix classes for specific Checkstyle violations.
10+
</documentation>
11+
</annotation>
12+
13+
<element name="extension">
14+
<annotation>
15+
<appinfo>
16+
<meta.element />
17+
</appinfo>
18+
</annotation>
19+
<complexType>
20+
<sequence minOccurs="1" maxOccurs="unbounded">
21+
<element ref="quickfix"/>
22+
</sequence>
23+
<attribute name="point" type="string" use="required">
24+
<annotation>
25+
<documentation>
26+
27+
</documentation>
28+
</annotation>
29+
</attribute>
30+
<attribute name="id" type="string">
31+
<annotation>
32+
<documentation>
33+
34+
</documentation>
35+
</annotation>
36+
</attribute>
37+
<attribute name="name" type="string">
38+
<annotation>
39+
<documentation>
40+
41+
</documentation>
42+
<appinfo>
43+
<meta.attribute translatable="true"/>
44+
</appinfo>
45+
</annotation>
46+
</attribute>
47+
</complexType>
48+
</element>
49+
50+
<element name="quickfix">
51+
<complexType>
52+
<attribute name="module" type="string" use="required">
53+
<annotation>
54+
<documentation>
55+
fully qualified name of the Checkstyle module that this quickfix can fix
56+
</documentation>
57+
</annotation>
58+
</attribute>
59+
<attribute name="class" type="string" use="required">
60+
<annotation>
61+
<documentation>
62+
Class implementing net.sf.eclipsecs.ui.quickfixes.ICheckstyleMarkerResolution
63+
</documentation>
64+
<appinfo>
65+
<meta.attribute kind="java" basedOn=":net.sf.eclipsecs.ui.quickfixes.ICheckstyleMarkerResolution"/>
66+
</appinfo>
67+
</annotation>
68+
</attribute>
69+
</complexType>
70+
</element>
71+
72+
<annotation>
73+
<appinfo>
74+
<meta.section type="since"/>
75+
</appinfo>
76+
<documentation>
77+
10.9.3
78+
</documentation>
79+
</annotation>
80+
81+
<annotation>
82+
<appinfo>
83+
<meta.section type="examples"/>
84+
</appinfo>
85+
<documentation>
86+
The following is an example for registering a quickfix.
87+
88+
&lt;extension point=&quot;net.sf.eclipsecs.ui.quickfix&quot;&gt;
89+
&lt;quickfix
90+
module=&quot;com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck&quot;
91+
class=&quot;net.sf.eclipsecs.ui.quickfixes.blocks.NeedBracesQuickfix&quot;&gt;&lt;/quickfix&gt;
92+
&lt;/extension&gt;
93+
</documentation>
94+
</annotation>
95+
96+
97+
98+
99+
</schema>

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/CheckstyleUIPlugin.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import net.sf.eclipsecs.core.jobs.AbstractCheckJob;
2929
import net.sf.eclipsecs.core.util.CheckstyleLog;
30-
import net.sf.eclipsecs.core.util.ExtensionClassLoader;
3130
import net.sf.eclipsecs.ui.properties.filter.CheckFileOnOpenPartListener;
3231

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

60-
/** Extension point id for Checkstyle quickfix providers. */
61-
public static final String QUICKFIX_PROVIDER_EXT_PT_ID = PLUGIN_ID
62-
+ ".checkstyleQuickfixProvider"; //$NON-NLS-1$
63-
6459
/** The shared instance. */
6560
private static CheckstyleUIPlugin sPlugin;
6661

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

9287
};
9388

94-
private ClassLoader mQuickfixExtensionClassLoader;
95-
9689
/**
9790
* The constructor.
9891
*/
@@ -104,9 +97,6 @@ public CheckstyleUIPlugin() {
10497
public void start(BundleContext context) throws Exception {
10598
super.start(context);
10699

107-
mQuickfixExtensionClassLoader = new ExtensionClassLoader(context.getBundle(),
108-
QUICKFIX_PROVIDER_EXT_PT_ID);
109-
110100
// add listeners for the Check-On-Open support
111101
final IWorkbench workbench = PlatformUI.getWorkbench();
112102
workbench.getDisplay().asyncExec(new Runnable() {
@@ -280,13 +270,4 @@ public static void warningDialog(Shell shell, String message, Throwable throwabl
280270
ErrorDialog.openError(shell, Messages.CheckstyleLog_titleWarning, message, status);
281271
}
282272

283-
/**
284-
* Returns the classloader containing quickfix extensions.
285-
*
286-
* @return the classloader containing all registered quickfix extensions.
287-
*/
288-
public ClassLoader getQuickfixExtensionClassLoader() {
289-
return mQuickfixExtensionClassLoader;
290-
}
291-
292273
}

0 commit comments

Comments
 (0)