From e1c5bf54fc18fb380e5c780afa8b09a08cb2e810 Mon Sep 17 00:00:00 2001 From: Michael Keppler Date: Sun, 17 Sep 2023 19:15:28 +0200 Subject: [PATCH] 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. --- .../net/sf/eclipsecs/core/config/XMLTags.java | 3 - .../core/config/meta/MetadataFactory.java | 7 -- .../core/config/meta/RuleMetadata.java | 23 ---- net.sf.eclipsecs.sample/plugin.xml | 12 +- .../OSGI-INF/l10n/bundle.properties | 3 +- net.sf.eclipsecs.ui/plugin.xml | 87 +++++++++++++- .../schema/checkstyleQuickfixProvider.exsd | 26 ---- net.sf.eclipsecs.ui/schema/quickfix.exsd | 99 +++++++++++++++ .../sf/eclipsecs/ui/CheckstyleUIPlugin.java | 19 --- .../ui/quickfixes/AbstractASTResolution.java | 63 ++++------ .../CheckstyleMarkerResolutionGenerator.java | 86 ++++--------- .../ui/quickfixes/CheckstyleQuickfixes.java | 113 ++++++++++++++++++ .../ICheckstyleMarkerResolution.java | 19 +-- .../sf/eclipsecs/ui/quickfixes/Messages.java | 4 +- .../blocks/AvoidNestedBlocksQuickfix.java | 4 +- .../ExplicitInitializationQuickfix.java | 5 +- .../ui/quickfixes/messages.properties | 4 +- 17 files changed, 362 insertions(+), 215 deletions(-) delete mode 100644 net.sf.eclipsecs.ui/schema/checkstyleQuickfixProvider.exsd create mode 100644 net.sf.eclipsecs.ui/schema/quickfix.exsd create mode 100644 net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/CheckstyleQuickfixes.java diff --git a/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/XMLTags.java b/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/XMLTags.java index 326c47945..4031dee21 100644 --- a/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/XMLTags.java +++ b/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/XMLTags.java @@ -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$ diff --git a/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/meta/MetadataFactory.java b/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/meta/MetadataFactory.java index 9d5005dd5..2514ed5e6 100644 --- a/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/meta/MetadataFactory.java +++ b/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/meta/MetadataFactory.java @@ -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)) { diff --git a/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/meta/RuleMetadata.java b/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/meta/RuleMetadata.java index 993ffb3cb..ecd064b89 100644 --- a/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/meta/RuleMetadata.java +++ b/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/meta/RuleMetadata.java @@ -62,9 +62,6 @@ public class RuleMetadata { /** Alternative names, including the name of the Checkstyle checker class. */ private final Collection mAlternativeNames; - /** Collection fo quick fixes for this module. */ - private final Collection mQuickfixes; - private final Collection mMessageKeys; /** Determines if the module is a singleton. */ @@ -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; } @@ -131,25 +127,6 @@ public Collection 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 getQuickfixClassNames() { - return mQuickfixes; - } - /** * Adds a message key to this module metadata. * diff --git a/net.sf.eclipsecs.sample/plugin.xml b/net.sf.eclipsecs.sample/plugin.xml index 8316d0dd8..b5eea4e79 100644 --- a/net.sf.eclipsecs.sample/plugin.xml +++ b/net.sf.eclipsecs.sample/plugin.xml @@ -7,11 +7,6 @@ point="net.sf.eclipsecs.core.checkstyleAddonProvider"> - - - - @@ -39,4 +34,11 @@ description="%filter.description" class="net.sf.eclipsecs.sample.filter.SampleFilter"/> + + + + diff --git a/net.sf.eclipsecs.ui/OSGI-INF/l10n/bundle.properties b/net.sf.eclipsecs.ui/OSGI-INF/l10n/bundle.properties index 668c8db32..d76d8ee10 100644 --- a/net.sf.eclipsecs.ui/OSGI-INF/l10n/bundle.properties +++ b/net.sf.eclipsecs.ui/OSGI-INF/l10n/bundle.properties @@ -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 \ No newline at end of file +removenature.label = Remove Checkstyle Nature +extension-point.name = checkstyle diff --git a/net.sf.eclipsecs.ui/plugin.xml b/net.sf.eclipsecs.ui/plugin.xml index c7ad888a2..9f1186ffe 100644 --- a/net.sf.eclipsecs.ui/plugin.xml +++ b/net.sf.eclipsecs.ui/plugin.xml @@ -2,12 +2,6 @@ - - - + + + @@ -542,4 +542,79 @@ icon="platform:/plugin/org.eclipse.ui/icons/full/etool16/clear.png"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/net.sf.eclipsecs.ui/schema/checkstyleQuickfixProvider.exsd b/net.sf.eclipsecs.ui/schema/checkstyleQuickfixProvider.exsd deleted file mode 100644 index 9b80e387d..000000000 --- a/net.sf.eclipsecs.ui/schema/checkstyleQuickfixProvider.exsd +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - Use this extension point to declare a plugin providing custom quickfixes for Checkstyle problems. - - - - - - - - - 5.6.0 - - - - - - - - diff --git a/net.sf.eclipsecs.ui/schema/quickfix.exsd b/net.sf.eclipsecs.ui/schema/quickfix.exsd new file mode 100644 index 000000000..f749cd945 --- /dev/null +++ b/net.sf.eclipsecs.ui/schema/quickfix.exsd @@ -0,0 +1,99 @@ + + + + + + + + + Use this extension point to register quickfix classes for specific Checkstyle violations. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fully qualified name of the Checkstyle module that this quickfix can fix + + + + + + + Class implementing net.sf.eclipsecs.ui.quickfixes.ICheckstyleMarkerResolution + + + + + + + + + + + + + + + 10.9.3 + + + + + + + + + The following is an example for registering a quickfix. + + <extension point="net.sf.eclipsecs.ui.quickfix"> + <quickfix + module="com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck" + class="net.sf.eclipsecs.ui.quickfixes.blocks.NeedBracesQuickfix"></quickfix> + </extension> + + + + + + + diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/CheckstyleUIPlugin.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/CheckstyleUIPlugin.java index 8eca0e8f5..d6d5acfe7 100644 --- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/CheckstyleUIPlugin.java +++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/CheckstyleUIPlugin.java @@ -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; @@ -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; @@ -91,8 +86,6 @@ public void windowDeactivated(IWorkbenchWindow window) { }; - private ClassLoader mQuickfixExtensionClassLoader; - /** * The constructor. */ @@ -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() { @@ -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; - } - } diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/AbstractASTResolution.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/AbstractASTResolution.java index 5ebdc84eb..714b09e4f 100644 --- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/AbstractASTResolution.java +++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/AbstractASTResolution.java @@ -20,16 +20,14 @@ package net.sf.eclipsecs.ui.quickfixes; -import java.util.HashSet; +import java.util.Arrays; import java.util.Iterator; import java.util.List; -import java.util.Set; - import net.sf.eclipsecs.core.builder.CheckstyleMarker; -import net.sf.eclipsecs.core.config.meta.RuleMetadata; import net.sf.eclipsecs.core.util.CheckstyleLog; import net.sf.eclipsecs.ui.Messages; +import org.apache.commons.lang3.StringUtils; import org.eclipse.core.filebuffers.FileBuffers; import org.eclipse.core.filebuffers.ITextFileBuffer; import org.eclipse.core.filebuffers.ITextFileBufferManager; @@ -71,14 +69,12 @@ public abstract class AbstractASTResolution extends WorkbenchMarkerResolution implements ICheckstyleMarkerResolution { - private boolean mAutoCommit; - - private RuleMetadata mMetaData; + private String module; /** * Template method to be implemented by concrete quickfix implementations. These must provide - * their fixing modification through an AST visitor, more specifically by doing the neccessary - * modifications directly on the visited AST nodes. The AST itself will recored modification. + * their fixing modification through an AST visitor, more specifically by doing the necessary + * modifications directly on the visited AST nodes. The AST itself will record modification. * * @param lineInfo * the IRegion for the line containing the marker to fix @@ -89,27 +85,22 @@ public abstract class AbstractASTResolution extends WorkbenchMarkerResolution protected abstract ASTVisitor handleGetCorrectingASTVisitor(IRegion lineInfo, int markerStartOffset); - @Override - public void setRuleMetaData(RuleMetadata metadata) { - this.mMetaData = metadata; - } - @Override public boolean canFix(IMarker marker) { - - String moduleName = marker.getAttribute(CheckstyleMarker.MODULE_NAME, null); try { - return CheckstyleMarker.MARKER_ID.equals(marker.getType()) - && (mMetaData.getInternalName().equals(moduleName) - || mMetaData.getAlternativeNames().contains(moduleName)); + if (!CheckstyleMarker.MARKER_ID.equals(marker.getType())) { + return false; + } + String markerModule = marker.getAttribute(CheckstyleMarker.MODULE_NAME, StringUtils.EMPTY); + if (module.equals(markerModule)) { + return true; + } + var shortName = StringUtils.substringAfterLast(markerModule, '.'); + return module.equals(shortName); } catch (CoreException ex) { - throw new IllegalStateException(ex); + // ignore } - } - - @Override - public void setAutoCommitChanges(boolean autoCommit) { - mAutoCommit = autoCommit; + return false; } @Override @@ -120,17 +111,9 @@ public Image getImage() { @Override public IMarker[] findOtherMarkers(IMarker[] markers) { - - Set candidates = new HashSet<>(); - - for (IMarker m : markers) { - - if (canFix(m)) { - candidates.add(m); - } - } - - return candidates.toArray(new IMarker[candidates.size()]); + return Arrays.stream(markers) + .filter(this::canFix) + .toArray(IMarker[]::new); } @Override @@ -192,11 +175,12 @@ public void run(IMarker marker) { ast.accept(handleGetCorrectingASTVisitor(lineInfo, markerStart)); // rewrite all recorded changes to the document + var wasDirtyBefore = textFileBuffer.isDirty(); TextEdit edit = ast.rewrite(document, compilationUnit.getJavaProject().getOptions(true)); edit.apply(document); // commit changes to underlying file - if (mAutoCommit) { + if (!wasDirtyBefore) { textFileBuffer.commit(monitor, false); } } catch (CoreException | MalformedTreeException | BadLocationException ex) { @@ -213,6 +197,11 @@ public void run(IMarker marker) { } } + @Override + public void setModule(String module) { + this.module = module; + } + /** * Determines if the given position lies within the boundaries of the ASTNode. * diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/CheckstyleMarkerResolutionGenerator.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/CheckstyleMarkerResolutionGenerator.java index 759f24b31..4d292bbe7 100644 --- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/CheckstyleMarkerResolutionGenerator.java +++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/CheckstyleMarkerResolutionGenerator.java @@ -20,22 +20,15 @@ package net.sf.eclipsecs.ui.quickfixes; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import net.sf.eclipsecs.core.builder.CheckstyleMarker; -import net.sf.eclipsecs.core.config.meta.MetadataFactory; -import net.sf.eclipsecs.core.config.meta.RuleMetadata; -import net.sf.eclipsecs.core.util.CheckstyleLog; -import net.sf.eclipsecs.ui.CheckstyleUIPlugin; - import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; import org.eclipse.ui.IMarkerResolution; import org.eclipse.ui.IMarkerResolutionGenerator2; +import net.sf.eclipsecs.core.builder.CheckstyleMarker; + /** - * Profides marker resolutions (quickfixes) for Checkstyle markers. + * Provides marker resolutions (quickfixes) for Checkstyle markers. * * @author Lars Ködderitzsch */ @@ -43,68 +36,31 @@ public class CheckstyleMarkerResolutionGenerator implements IMarkerResolutionGen @Override public IMarkerResolution[] getResolutions(IMarker marker) { - - Collection fixes = new ArrayList<>(); - - // get all fixes that apply to this marker instance - String moduleName = marker.getAttribute(CheckstyleMarker.MODULE_NAME, null); - - RuleMetadata metadata = MetadataFactory.getRuleMetadata(moduleName); - List potentialFixes = getInstantiatedQuickfixes(metadata); - - for (ICheckstyleMarkerResolution fix : potentialFixes) { - - if (fix.canFix(marker)) { - fixes.add(fix); - } - } - - return fixes.toArray(new ICheckstyleMarkerResolution[fixes.size()]); + return CheckstyleQuickfixes.getInstance().getQuickfixes().stream() + .filter(fix -> fix.canFix(marker)) + .toArray(IMarkerResolution[]::new); } @Override public boolean hasResolutions(IMarker marker) { - - boolean hasAtLeastOneFix = false; - - // check if there is at least one fix that really applies to the module - String moduleName = marker.getAttribute(CheckstyleMarker.MODULE_NAME, null); - - RuleMetadata metadata = MetadataFactory.getRuleMetadata(moduleName); - - if (metadata != null) { - - List fixes = getInstantiatedQuickfixes(metadata); - - for (ICheckstyleMarkerResolution fix : fixes) { - - if (fix.canFix(marker)) { - hasAtLeastOneFix = true; - break; - } - } + if (!isCheckstyleMarker(marker)) { + return false; } - return hasAtLeastOneFix; + return CheckstyleQuickfixes.getInstance().getQuickfixes().stream() + .anyMatch(fix -> fix.canFix(marker)); } - private List getInstantiatedQuickfixes(RuleMetadata ruleMetadata) { - - List fixes = new ArrayList<>(); - + /** + * @param marker + * @return {@code true} if this is a checkstyle marker + */ + private boolean isCheckstyleMarker(IMarker marker) { try { - - for (String quickfixClassName : ruleMetadata.getQuickfixClassNames()) { - - Class quickfixClass = CheckstyleUIPlugin.getDefault().getQuickfixExtensionClassLoader() - .loadClass(quickfixClassName); - - ICheckstyleMarkerResolution fix = (ICheckstyleMarkerResolution) quickfixClass.getDeclaredConstructor().newInstance(); - fix.setRuleMetaData(ruleMetadata); - fixes.add(fix); - } - } catch (ReflectiveOperationException | IllegalArgumentException | SecurityException ex) { - CheckstyleLog.log(ex); + return CheckstyleMarker.MARKER_ID.equals(marker.getType()); + } catch (CoreException ex) { + return false; } - return fixes; } + + } diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/CheckstyleQuickfixes.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/CheckstyleQuickfixes.java new file mode 100644 index 000000000..dbee24528 --- /dev/null +++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/CheckstyleQuickfixes.java @@ -0,0 +1,113 @@ +//============================================================================ +// +// Copyright (C) 2003-2023 the original author or authors. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// +//============================================================================ + +package net.sf.eclipsecs.ui.quickfixes; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; + +import net.sf.eclipsecs.core.util.CheckstyleLog; + +/** + * List of all registered quickfixes. + * + * @implNote Cached over the runtime of the application. Will not react to plugins loaded + * dynamically. + */ +public class CheckstyleQuickfixes { + + /** + * ID of the quickfix extension point + */ + private static final String QUICKFIX_EXTENSION_POINT = "net.sf.eclipsecs.ui.quickfix"; + /** + * attribute under which the fully qualified class name of the quick fix is registered + */ + private static final String EXTENSION_CLASS_ATTRIBUTE = "class"; + /** + * attribute under which the module id is registered + */ + private static final String EXTENSION_MODULE_ATTRIBUTE = "module"; + + private final Collection quickfixes; + + private CheckstyleQuickfixes() { + quickfixes = readRegistry(); + } + + public static CheckstyleQuickfixes getInstance() { + return LazyHolder.INSTANCE; + } + + /** + * @return the quickfixes + */ + public Collection getQuickfixes() { + return quickfixes; + } + + /** + * @return all registered quickfixes + */ + private Collection readRegistry() { + List result = new ArrayList<>(); + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] elements = registry.getConfigurationElementsFor(QUICKFIX_EXTENSION_POINT); + for (IConfigurationElement element : elements) { + var module = element.getAttribute(EXTENSION_MODULE_ATTRIBUTE); + if (StringUtils.isNotBlank(module)) { + var resolution = toClass(element); + if (resolution != null) { + resolution.setModule(module); + result.add(resolution); + } + } + } + + return result; + } + + private ICheckstyleMarkerResolution toClass(IConfigurationElement element) { + try { + var resolution = element.createExecutableExtension(EXTENSION_CLASS_ATTRIBUTE); + if (resolution instanceof ICheckstyleMarkerResolution) { + return (ICheckstyleMarkerResolution) resolution; + } + } catch (CoreException ex) { + CheckstyleLog.log(ex, "cannot create quickfix for " + element.getAttribute(EXTENSION_CLASS_ATTRIBUTE)); + } + return null; + } + + /** + * initialization-on-demand-holder + */ + private static class LazyHolder { + static final CheckstyleQuickfixes INSTANCE = new CheckstyleQuickfixes(); + } + +} diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/ICheckstyleMarkerResolution.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/ICheckstyleMarkerResolution.java index fc260ceb5..8b9497e9d 100644 --- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/ICheckstyleMarkerResolution.java +++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/ICheckstyleMarkerResolution.java @@ -20,8 +20,6 @@ package net.sf.eclipsecs.ui.quickfixes; -import net.sf.eclipsecs.core.config.meta.RuleMetadata; - import org.eclipse.core.resources.IMarker; import org.eclipse.ui.IMarkerResolution2; @@ -33,7 +31,7 @@ public interface ICheckstyleMarkerResolution extends IMarkerResolution2 { /** - * Checks if this quickfix can actually fix the marker occurrance. + * Checks if this quickfix can actually fix the marker occurrence. * * @param marker * the marker to potentially be fixed. @@ -43,19 +41,8 @@ public interface ICheckstyleMarkerResolution extends IMarkerResolution2 { boolean canFix(IMarker marker); /** - * Sets if the quickfix automatically commits the changes (saves the file). - * - * @param autoCommit - * true if changes are automatically committed + * @param module id of the checkstyle module */ - void setAutoCommitChanges(boolean autoCommit); + void setModule(String module); - /** - * Sets the metadata for the checkstyle rule to which this quickfix - * implementation applies. - * - * @param metadata - * the checkstyle rule metadata - */ - void setRuleMetaData(RuleMetadata metadata); } diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/Messages.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/Messages.java index 1a96ff56e..3ebafec2e 100644 --- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/Messages.java +++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/Messages.java @@ -104,9 +104,9 @@ private Messages() { public static String StringLiteralEqualityQuickfix_label; - public static String AvoidNextedBlocksQuickfix_description; + public static String AvoidNestedBlocksQuickfix_description; - public static String AvoidNextedBlocksQuickfix_label; + public static String AvoidNestedBlocksQuickfix_label; public static String NeedBracesQuickfix_description; diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/blocks/AvoidNestedBlocksQuickfix.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/blocks/AvoidNestedBlocksQuickfix.java index 43b854544..5d8342d0d 100644 --- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/blocks/AvoidNestedBlocksQuickfix.java +++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/blocks/AvoidNestedBlocksQuickfix.java @@ -76,12 +76,12 @@ public boolean visit(Block node) { @Override public String getDescription() { - return Messages.AvoidNextedBlocksQuickfix_description; + return Messages.AvoidNestedBlocksQuickfix_description; } @Override public String getLabel() { - return Messages.AvoidNextedBlocksQuickfix_label; + return Messages.AvoidNestedBlocksQuickfix_label; } @Override diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/coding/ExplicitInitializationQuickfix.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/coding/ExplicitInitializationQuickfix.java index 6c152253f..b81b5e2bc 100644 --- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/coding/ExplicitInitializationQuickfix.java +++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/coding/ExplicitInitializationQuickfix.java @@ -50,8 +50,11 @@ public class ExplicitInitializationQuickfix extends AbstractASTResolution { @Override public boolean canFix(final IMarker marker) { + if (!super.canFix(marker)) { + return false; + } retrieveFieldName(marker); - return super.canFix(marker); + return true; } private void retrieveFieldName(final IMarker marker) { diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/messages.properties b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/messages.properties index 83f9903b3..d78453c25 100644 --- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/messages.properties +++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/messages.properties @@ -1,7 +1,7 @@ ArrayTypeStyleQuickfix_description=Moves array declaration to the opposite style (Java style vs. C style) ArrayTypeStyleQuickfix_label=Move array declaration -AvoidNextedBlocksQuickfix_description=Removes the nested block -AvoidNextedBlocksQuickfix_label=Remove nested block +AvoidNestedBlocksQuickfix_description=Removes the nested block +AvoidNestedBlocksQuickfix_label=Remove nested block DefaultComesLastQuickfix_description=Moves the default case to the end of the switch statement DefaultComesLastQuickfix_label=Move default case to end DesignForExtensionQuickfix_description=Adds the final modifier to the method declaration.