mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
merge misspelled (hashCode, toString, setUp, tearDown, compareTo) inspections
This commit is contained in:
+2
-2
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.deadCode;
|
||||
|
||||
import com.intellij.codeInspection.ex.InspectionElementsMerger;
|
||||
import com.intellij.codeInspection.ex.InspectionElementsMergerBase;
|
||||
import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import org.jdom.Element;
|
||||
|
||||
public class UnusedDeclarationInspectionMerger extends InspectionElementsMerger {
|
||||
public class UnusedDeclarationInspectionMerger extends InspectionElementsMergerBase {
|
||||
private static final String UNUSED_SYMBOL = "UNUSED_SYMBOL";
|
||||
private static final String UNUSED_DECLARATION = "UnusedDeclaration";
|
||||
|
||||
|
||||
@@ -360,6 +360,22 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
"</profile>");
|
||||
}
|
||||
|
||||
public void testMergedMisspelledInspections() throws Exception {
|
||||
checkMergedNoChanges("<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"" + PROFILE + "\" />\n" +
|
||||
" <inspection_tool class=\"MethodNamesDifferOnlyByCase\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\">\n" +
|
||||
" <option name=\"ignoreIfMethodIsOverride\" value=\"false\" />\n" +
|
||||
" </inspection_tool>\n" +
|
||||
"</profile>");
|
||||
checkMergedNoChanges("<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"" + PROFILE + "\" />\n" +
|
||||
" <inspection_tool class=\"MethodNamesDifferOnlyByCase\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\">\n" +
|
||||
" <option name=\"ignoreIfMethodIsOverride\" value=\"false\" />\n" +
|
||||
" </inspection_tool>\n" +
|
||||
" <inspection_tool class=\"MisspelledSetUp\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\" />\n" +
|
||||
"</profile>");
|
||||
}
|
||||
|
||||
public void testDisabledUnusedDeclarationWithChanges() throws Exception {
|
||||
checkMergedNoChanges("<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"" + PROFILE + "\" />\n" +
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInspection.ex.InspectionElementsMerger;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
@@ -81,6 +83,18 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
final InspectionElementsMerger merger = InspectionElementsMerger.getMerger(getShortName());
|
||||
if (merger != null) {
|
||||
for (String sourceToolId : merger.getSourceToolNames()) {
|
||||
for (InspectionSuppressor suppressor : suppressors) {
|
||||
if (isSuppressed(sourceToolId, suppressor, element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Merges multiple inspections settings {@link #getSourceToolNames()} into another one {@link #getMergedToolName()}
|
||||
*
|
||||
* {@see com.intellij.codeInspection.ex.InspectionElementsMergerBase} to provide more fine control over xml
|
||||
*/
|
||||
public abstract class InspectionElementsMerger {
|
||||
public static final ExtensionPointName<InspectionElementsMerger> EP_NAME = ExtensionPointName.create("com.intellij.inspectionElementsMerger");
|
||||
private static Map<String, InspectionElementsMerger> ourMergers;
|
||||
|
||||
@Nullable
|
||||
public synchronized static InspectionElementsMerger getMerger(String shortName) {
|
||||
if (ourMergers == null) {
|
||||
ourMergers = new HashMap<>();
|
||||
for (InspectionElementsMerger merger : Extensions.getExtensions(EP_NAME)) {
|
||||
ourMergers.put(merger.getMergedToolName(), merger);
|
||||
}
|
||||
}
|
||||
return ourMergers.get(shortName);
|
||||
}
|
||||
|
||||
public abstract String getMergedToolName();
|
||||
public abstract String[] getSourceToolNames();
|
||||
}
|
||||
+20
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,21 +16,14 @@
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import org.jdom.Element;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Merges multiple inspections settings {@link #getSourceToolNames()} into another one {@link #getMergedToolName()}
|
||||
*/
|
||||
public abstract class InspectionElementsMerger {
|
||||
public static final ExtensionPointName<InspectionElementsMerger> EP_NAME = ExtensionPointName.create("com.intellij.inspectionElementsMerger");
|
||||
|
||||
protected abstract String getMergedToolName();
|
||||
protected abstract String[] getSourceToolNames();
|
||||
public abstract class InspectionElementsMergerBase extends InspectionElementsMerger {
|
||||
|
||||
/**
|
||||
* serialize old inspection settings as they could appear in old profiles
|
||||
@@ -158,4 +151,22 @@ public abstract class InspectionElementsMerger {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class InspectionElementsMergerDelegate extends InspectionElementsMergerBase {
|
||||
private final InspectionElementsMerger myMerger;
|
||||
|
||||
public InspectionElementsMergerDelegate(InspectionElementsMerger merger) {
|
||||
myMerger = merger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMergedToolName() {
|
||||
return myMerger.getMergedToolName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSourceToolNames() {
|
||||
return myMerger.getSourceToolNames();
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
-17
@@ -71,7 +71,6 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
public static final String DEFAULT_PROFILE_NAME = "Default";
|
||||
@TestOnly
|
||||
public static boolean INIT_INSPECTIONS = false;
|
||||
private static Map<String, InspectionElementsMerger> ourMergers;
|
||||
private final InspectionToolRegistrar myRegistrar;
|
||||
@NotNull
|
||||
private final Map<String, Element> myUninstalledInspectionsSettings;
|
||||
@@ -120,17 +119,6 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
myUninstalledInspectionsSettings = new TreeMap<String, Element>();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static synchronized Map<String, InspectionElementsMerger> getMergers() {
|
||||
if (ourMergers == null) {
|
||||
ourMergers = new LinkedHashMap<String, InspectionElementsMerger>();
|
||||
for (InspectionElementsMerger merger : Extensions.getExtensions(InspectionElementsMerger.EP_NAME)) {
|
||||
ourMergers.put(merger.getMergedToolName(), merger);
|
||||
}
|
||||
}
|
||||
return ourMergers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static InspectionProfileImpl createSimple(@NotNull String name,
|
||||
@NotNull final Project project,
|
||||
@@ -338,9 +326,9 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
|
||||
private void markSettingsMerged(String toolName, Element element) {
|
||||
//add marker if already merged but result is now default (-> empty node)
|
||||
final String mergedName = InspectionElementsMerger.getMergedMarkerName(toolName);
|
||||
final String mergedName = InspectionElementsMergerBase.getMergedMarkerName(toolName);
|
||||
if (!myUninstalledInspectionsSettings.containsKey(mergedName)) {
|
||||
final InspectionElementsMerger merger = getMergers().get(toolName);
|
||||
final InspectionElementsMergerBase merger = getMerger(toolName);
|
||||
if (merger != null && merger.markSettingsMerged(myUninstalledInspectionsSettings)) {
|
||||
element.addContent(new Element(INSPECTION_TOOL_TAG).setAttribute(CLASS_TAG, mergedName));
|
||||
}
|
||||
@@ -349,7 +337,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
|
||||
private boolean areSettingsMerged(String toolName, Element inspectionElement) {
|
||||
//skip merged settings as they could be restored from already provided data
|
||||
final InspectionElementsMerger merger = getMergers().get(toolName);
|
||||
final InspectionElementsMergerBase merger = getMerger(toolName);
|
||||
return merger != null && merger.areSettingsMerged(myUninstalledInspectionsSettings, inspectionElement);
|
||||
}
|
||||
|
||||
@@ -619,8 +607,8 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
if (element != null) {
|
||||
toolsList.readExternal(element, this, dependencies);
|
||||
}
|
||||
else if (!myUninstalledInspectionsSettings.containsKey(InspectionElementsMerger.getMergedMarkerName(shortName))) {
|
||||
final InspectionElementsMerger merger = getMergers().get(shortName);
|
||||
else if (!myUninstalledInspectionsSettings.containsKey(InspectionElementsMergerBase.getMergedMarkerName(shortName))) {
|
||||
final InspectionElementsMergerBase merger = getMerger(shortName);
|
||||
if (merger != null) {
|
||||
final Element merged = merger.merge(myUninstalledInspectionsSettings);
|
||||
if (merged != null) {
|
||||
@@ -635,6 +623,25 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
myTools.put(shortName, toolsList);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static InspectionElementsMergerBase getMerger(String shortName) {
|
||||
final InspectionElementsMerger merger = InspectionElementsMerger.getMerger(shortName);
|
||||
if (merger instanceof InspectionElementsMergerBase) {
|
||||
return (InspectionElementsMergerBase)merger;
|
||||
}
|
||||
return merger != null ? new InspectionElementsMergerBase() {
|
||||
@Override
|
||||
public String getMergedToolName() {
|
||||
return merger.getMergedToolName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSourceToolNames() {
|
||||
return merger.getSourceToolNames();
|
||||
}
|
||||
} : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Transient
|
||||
public String[] getScopesOrder() {
|
||||
|
||||
+3
-17
@@ -3,6 +3,7 @@
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
|
||||
<inspectionElementsMerger implementation="com.siyeh.ig.bugs.ThrowableNeverThrownInspectionMerger"/>
|
||||
<inspectionElementsMerger implementation="com.siyeh.ig.naming.MisspelledMethodNameInspectionMerger"/>
|
||||
|
||||
<!--group.names.abstraction.issues-->
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="BooleanParameter" bundle="com.siyeh.InspectionGadgetsBundle" key="boolean.parameter.display.name"
|
||||
@@ -287,18 +288,9 @@
|
||||
bundle="com.siyeh.InspectionGadgetsBundle" key="mismatched.string.builder.query.update.display.name" runForWholeFile="true"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.probable.bugs" enabledByDefault="true" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.bugs.MismatchedStringBuilderQueryUpdateInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="MisspelledCompareTo" bundle="com.siyeh.InspectionGadgetsBundle" key="misspelled.compareto.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.probable.bugs" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.bugs.MisspelledCompareToInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="MisspelledHashcode" bundle="com.siyeh.InspectionGadgetsBundle" key="misspelled.hashcode.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.probable.bugs" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.bugs.MisspelledHashcodeInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="MisspelledEquals" bundle="com.siyeh.InspectionGadgetsBundle" key="misspelled.equals.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.probable.bugs" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.bugs.MisspelledEqualsInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="MisspelledToString" bundle="com.siyeh.InspectionGadgetsBundle" key="misspelled.tostring.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.probable.bugs" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.bugs.MisspelledToStringInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="NewStringBufferWithCharArgument" bundle="com.siyeh.InspectionGadgetsBundle"
|
||||
key="new.string.buffer.with.char.argument.display.name" groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.probable.bugs" enabledByDefault="true" level="WARNING"
|
||||
@@ -1474,12 +1466,6 @@
|
||||
key="junit.test.class.naming.convention.display.name" groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.junit.JUnitTestClassNamingConventionInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="MisspelledSetUp" bundle="com.siyeh.InspectionGadgetsBundle" key="misspelled.set.up.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.junit.MisspelledSetUpInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="MisspelledTearDown" bundle="com.siyeh.InspectionGadgetsBundle" key="misspelled.tear.down.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.junit.MisspelledTearDownInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" suppressId="MisorderedAssertEqualsArguments" alternativeId="MisorderedAssertEqualsArguments" shortName="MisorderedAssertEqualsParameters"
|
||||
bundle="com.siyeh.InspectionGadgetsBundle" key="misordered.assert.equals.arguments.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
|
||||
@@ -1774,10 +1760,10 @@
|
||||
key="method.name.same.as.parent.name.display.name" groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.naming.conventions" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.naming.MethodNameSameAsParentNameInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" suppressId="MethodNamesDifferingOnlyByCase" shortName="MethodNamesDifferOnlyByCase"
|
||||
<localInspection groupPath="Java" language="JAVA" suppressId="MethodNamesDifferingOnlyByCase" shortName="MisspelledMethodName"
|
||||
bundle="com.siyeh.InspectionGadgetsBundle" key="method.names.differ.only.by.case.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.naming.conventions" enabledByDefault="false"
|
||||
level="WARNING" implementationClass="com.siyeh.ig.naming.MethodNamesDifferOnlyByCaseInspection"/>
|
||||
level="WARNING" implementationClass="com.siyeh.ig.naming.MisspelledMethodNameInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="NativeMethodNamingConvention"
|
||||
bundle="com.siyeh.InspectionGadgetsBundle" key="native.method.naming.convention.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.naming.conventions" enabledByDefault="false"
|
||||
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiParameterList;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MisspelledCompareToInspectionBase extends BaseInspection {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.compareto.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.compareto.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new MisspelledCompareToVisitor();
|
||||
}
|
||||
|
||||
private static class MisspelledCompareToVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitMethod(@NotNull PsiMethod method) {
|
||||
//note: no call to super
|
||||
@NonNls final String methodName = method.getName();
|
||||
if (!"compareto".equals(methodName)) {
|
||||
return;
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
if (parameterList.getParametersCount() != 1) {
|
||||
return;
|
||||
}
|
||||
registerMethodError(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiParameterList;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MisspelledHashcodeInspectionBase extends BaseInspection {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.hashcode.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.hashcode.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new MisspelledHashcodeVisitor();
|
||||
}
|
||||
|
||||
private static class MisspelledHashcodeVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitMethod(@NotNull PsiMethod method) {
|
||||
//note: no call to super
|
||||
@NonNls final String methodName = method.getName();
|
||||
if (!"hashcode".equals(methodName)) {
|
||||
return;
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
if (parameterList.getParametersCount() != 0) {
|
||||
return;
|
||||
}
|
||||
registerMethodError(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiParameterList;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MisspelledToStringInspectionBase extends BaseInspection {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.tostring.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.tostring.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new MisspelledToStringVisitor();
|
||||
}
|
||||
|
||||
private static class MisspelledToStringVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitMethod(@NotNull PsiMethod method) {
|
||||
//note: no call to super
|
||||
@NonNls final String methodName = method.getName();
|
||||
if (!"tostring".equals(methodName)) {
|
||||
return;
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
if (parameterList.getParametersCount() != 0) {
|
||||
return;
|
||||
}
|
||||
registerMethodError(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -23,12 +23,12 @@ import com.intellij.codeInspection.ex.InspectionElementsMerger;
|
||||
public class ThrowableNeverThrownInspectionMerger extends InspectionElementsMerger {
|
||||
|
||||
@Override
|
||||
protected String getMergedToolName() {
|
||||
public String getMergedToolName() {
|
||||
return "ThrowableNeverThrown";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getSourceToolNames() {
|
||||
public String[] getSourceToolNames() {
|
||||
return new String[] {"ThrowableInstanceNeverThrown", "ThrowableResultOfMethodCallIgnored"};
|
||||
}
|
||||
}
|
||||
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MisspelledSetUpInspectionBase extends BaseInspection {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.set.up.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.set.up.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new MisspelledSetUpVisitor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean buildQuickFixesOnlyForOnTheFlyErrors() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static class MisspelledSetUpVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitMethod(@NotNull PsiMethod method) {
|
||||
//note: no call to super
|
||||
final PsiClass aClass = method.getContainingClass();
|
||||
@NonNls final String methodName = method.getName();
|
||||
if (!"setup".equals(methodName)) {
|
||||
return;
|
||||
}
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
registerMethodError(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MisspelledTearDownInspectionBase extends BaseInspection {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.tear.down.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.tear.down.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new MisspelledSetUpVisitor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean buildQuickFixesOnlyForOnTheFlyErrors() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static class MisspelledSetUpVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitMethod(@NotNull PsiMethod method) {
|
||||
// note: no call to super
|
||||
@NonNls final String methodName = method.getName();
|
||||
if (!"teardown".equals(methodName)) {
|
||||
return;
|
||||
}
|
||||
final PsiClass aClass = method.getContainingClass();
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
registerMethodError(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-7
@@ -29,16 +29,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MethodNamesDifferOnlyByCaseInspectionBase extends BaseInspection {
|
||||
public class MisspelledMethodNameInspectionBase extends BaseInspection {
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean ignoreIfMethodIsOverride = true;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
return "MethodNamesDifferingOnlyByCase";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
+12
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,16 +13,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.bugs;
|
||||
package com.siyeh.ig.naming;
|
||||
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
import com.intellij.codeInspection.ex.InspectionElementsMerger;
|
||||
|
||||
public class MisspelledCompareToInspection extends MisspelledCompareToInspectionBase {
|
||||
public class MisspelledMethodNameInspectionMerger extends InspectionElementsMerger {
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new RenameFix(HardcodedMethodConstants.COMPARE_TO);
|
||||
public String getMergedToolName() {
|
||||
return "MisspelledMethodName";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSourceToolNames() {
|
||||
return new String[]{"MethodNamesDifferOnlyByCase", "MisspelledSetUp", "MisspelledTearDown", "MisspelledHashcode", "MisspelledToString", "MisspelledCompareTo"};
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
|
||||
public class MisspelledHashcodeInspection extends MisspelledHashcodeInspectionBase {
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new RenameFix(HardcodedMethodConstants.HASH_CODE);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
|
||||
public class MisspelledToStringInspection extends MisspelledToStringInspectionBase {
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new RenameFix(HardcodedMethodConstants.TO_STRING);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.junit;
|
||||
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
|
||||
public class MisspelledSetUpInspection extends MisspelledSetUpInspectionBase {
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new RenameFix("setUp");
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.junit;
|
||||
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
|
||||
public class MisspelledTearDownInspection extends MisspelledTearDownInspectionBase {
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new RenameFix("tearDown");
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -22,7 +22,7 @@ import com.siyeh.ig.fixes.RenameFix;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class MethodNamesDifferOnlyByCaseInspection extends MethodNamesDifferOnlyByCaseInspectionBase {
|
||||
public class MisspelledMethodNameInspection extends MisspelledMethodNameInspectionBase {
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
@@ -32,6 +32,6 @@ public class MethodNamesDifferOnlyByCaseInspection extends MethodNamesDifferOnly
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new RenameFix();
|
||||
return new RenameFix((String)infos[0]);
|
||||
}
|
||||
}
|
||||
+5
@@ -28,4 +28,9 @@ class X {
|
||||
|
||||
void xx() {}
|
||||
void xX() {}
|
||||
|
||||
@SuppressWarnings("MisspelledToString")
|
||||
public String tostring() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,6 +5,6 @@ import com.siyeh.ig.IGInspectionTestCase;
|
||||
public class MethodNamesDifferOnlyByCaseInspectionTest extends IGInspectionTestCase {
|
||||
|
||||
public void test() throws Exception {
|
||||
doTest("com/siyeh/igtest/naming/method_names_differ_only_by_case", new MethodNamesDifferOnlyByCaseInspection());
|
||||
doTest("com/siyeh/igtest/naming/method_names_differ_only_by_case", new MisspelledMethodNameInspection());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user