summaryrefslogtreecommitdiff
path: root/plugins/InspectionGadgets
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/InspectionGadgets')
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml4
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties6
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspectionVisitor.java13
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java6
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MismatchedArrayReadWriteInspection.java84
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javabeans/PropertyValueSetToItselfInspection.java102
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java5
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ImportUtils.java2
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/InstanceOfUtils.java4
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java37
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SimplifiableAnnotationInspection.java93
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java6
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryEnumModifierInspection.java7
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java5
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessarySemicolonInspection.java15
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/HighlightUtils.java9
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/ui/TextField.java28
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/AmbiguousFieldAccess.html4
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/PropertyValueSetToItself.html10
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ReturnNull.html8
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/style/replace_with_string/MethodCallOnString.after.java5
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/style/replace_with_string/MethodCallOnString.java6
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/DeclareCollectionAsInterface.java10
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/AutoClosableTest.java4
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/NumberAdderDemo.java4
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java22
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/sub/NumberAdder.java9
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/sub/NumberAdderExtension.java12
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/sub/NumberAdderImpl.java13
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/orInstanceofOrInstanceof/OrInstanceofOrInstanceof.java30
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/orInstanceofOrInstanceof/expected.xml4
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_array_read_write/MismatchedArrayReadWrite.java13
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/style/simplifiable_annotation/SimplifiableAnnotation.java10
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspectionTest.java56
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java4
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/style/StringBufferReplaceableByStringFixTest.java1
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ExtendsConcreteCollectionInspectionTest.java2
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/javabeans/PropertyValueSetToItselfInspectionTest.java56
38 files changed, 477 insertions, 232 deletions
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml
index 164c690d4da3..5581810b3f2c 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml
@@ -1209,6 +1209,10 @@
key="field.has.setter.but.no.getter.display.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.javabeans.issues" enabledByDefault="false" level="WARNING"
implementationClass="com.siyeh.ig.javabeans.FieldHasSetterButNoGetterInspection"/>
+ <localInspection language="JAVA" shortName="PropertyValueSetToItself" bundle="com.siyeh.InspectionGadgetsBundle"
+ key="property.value.set.to.itself.display.name" groupBundle="messages.InspectionsBundle"
+ groupKey="group.names.javabeans.issues" enabledByDefault="false" level="WARNING"
+ implementationClass="com.siyeh.ig.javabeans.PropertyValueSetToItselfInspection"/>
<!--group.names.javadoc.issues-->
<localInspection language="JAVA" shortName="HtmlTagCanBeJavadocTag" bundle="com.siyeh.InspectionGadgetsBundle"
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
index f92925b33bc0..715bf898c50a 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
@@ -1841,8 +1841,9 @@ double.literal.may.be.float.literal.problem.descriptor=<code>#ref</code> could b
double.literal.may.be.float.literal.quickfix=Replace with ''{0}''
multiple.declaration.option=Ignore 'for' loop declarations
simplifiable.annotation.display.name=Simplifiable annotation
-simplifiable.annotation.problem.descriptor=Annotation <code>#ref</code> can be simplified #loc
-simplifiable.annotation.quickfix=Replace with ''{0}''
+simplifiable.annotation.problem.descriptor=Unnecessary <code>#ref</code> in annotation #loc
+simplifiable.annotation.whitespace.problem.descriptor=Unnecessary whitespace in annotation #loc
+simplifiable.annotation.quickfix=Simplify annotation
overloaded.methods.with.same.number.parameters.option=<html>Ignore overloaded methods whose parameter types are definitely incompatible</html>
string.concatenation.in.format.call.display.name=String concatenation as argument to 'format()' call
string.concatenation.in.format.call.problem.descriptor=<code>#ref()</code> call has a String concatenation argument #loc
@@ -2098,3 +2099,4 @@ assignment.to.lambda.parameter.display.name=Assignment to lambda parameter
assignment.to.lambda.parameter.problem.descriptor=Assignment to lambda parameter <code>#ref</code> #loc
class.with.only.private.constructors.display.name=Class with only 'private' constructors should be declared 'final'
class.with.only.private.constructors.problem.descriptor=Class <code>#ref</code> with only 'private' constructors should be declared 'final'
+property.value.set.to.itself.display.name=Property value set to itself
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspectionVisitor.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspectionVisitor.java
index 1ba34a6235d8..d792a1ae1101 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspectionVisitor.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspectionVisitor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2014 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.
@@ -191,8 +191,13 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor {
holder.registerProblem(location, description, highlightType, fixes);
}
- protected final void registerErrorAtOffset(@NotNull PsiElement location,
- int offset, int length, Object... infos) {
+ protected final void registerErrorAtOffset(@NotNull PsiElement location, int offset, int length, Object... infos) {
+ registerErrorAtOffset(location, offset, length, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, infos);
+ }
+
+ protected final void registerErrorAtOffset(@NotNull PsiElement location, int offset, int length,
+ ProblemHighlightType highlightType,
+ Object... infos) {
if (location.getTextLength() == 0 || length == 0) {
return;
}
@@ -202,7 +207,7 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor {
}
final String description = inspection.buildErrorString(infos);
final TextRange range = new TextRange(offset, offset + length);
- holder.registerProblem(location, range, description, fixes);
+ holder.registerProblem(location, description, highlightType, range, fixes);
}
@NotNull
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java
index 8db2598dc39f..7f5012f2be76 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java
@@ -284,8 +284,10 @@ public class DeclareCollectionAsInterfaceInspection extends BaseInspection {
weaklingList.remove(objectClass);
if (weaklingList.isEmpty()) {
final String typeText = type.getCanonicalText();
- final String interfaceText =
- CollectionUtils.getInterfaceForClass(typeText);
+ final String interfaceText = CollectionUtils.getInterfaceForClass(typeText);
+ if (interfaceText == null) {
+ return;
+ }
registerError(nameElement, interfaceText);
}
else {
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MismatchedArrayReadWriteInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MismatchedArrayReadWriteInspection.java
index 41b391183395..17f7a83316ef 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MismatchedArrayReadWriteInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MismatchedArrayReadWriteInspection.java
@@ -72,8 +72,7 @@ public class MismatchedArrayReadWriteInspection extends BaseInspection {
return new MismatchedArrayReadWriteVisitor();
}
- private static class MismatchedArrayReadWriteVisitor
- extends BaseInspectionVisitor {
+ private static class MismatchedArrayReadWriteVisitor extends BaseInspectionVisitor {
@Override
public void visitField(@NotNull PsiField field) {
@@ -88,8 +87,7 @@ public class MismatchedArrayReadWriteInspection extends BaseInspection {
if (!checkVariable(field, containingClass)) {
return;
}
- final boolean written =
- arrayContentsAreWritten(field, containingClass);
+ final boolean written = arrayContentsAreWritten(field, containingClass);
final boolean read = arrayContentsAreRead(field, containingClass);
if (written == read) {
return;
@@ -98,16 +96,13 @@ public class MismatchedArrayReadWriteInspection extends BaseInspection {
}
@Override
- public void visitLocalVariable(
- @NotNull PsiLocalVariable variable) {
+ public void visitLocalVariable(@NotNull PsiLocalVariable variable) {
super.visitLocalVariable(variable);
- final PsiCodeBlock codeBlock =
- PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class);
+ final PsiCodeBlock codeBlock = PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class);
if (!checkVariable(variable, codeBlock)) {
return;
}
- final boolean written =
- arrayContentsAreWritten(variable, codeBlock);
+ final boolean written = arrayContentsAreWritten(variable, codeBlock);
final boolean read = arrayContentsAreRead(variable, codeBlock);
if (written == read) {
return;
@@ -133,8 +128,7 @@ public class MismatchedArrayReadWriteInspection extends BaseInspection {
if (VariableAccessUtils.variableIsReturned(variable, context)) {
return false;
}
- return !VariableAccessUtils.variableIsUsedInArrayInitializer(
- variable, context);
+ return !VariableAccessUtils.variableIsUsedInArrayInitializer(variable, context);
}
private static boolean arrayContentsAreWritten(PsiVariable variable,
@@ -187,26 +181,20 @@ public class MismatchedArrayReadWriteInspection extends BaseInspection {
return true;
}
if (initializer instanceof PsiNewExpression) {
- final PsiNewExpression newExpression =
- (PsiNewExpression)initializer;
- final PsiArrayInitializerExpression arrayInitializer =
- newExpression.getArrayInitializer();
- return arrayInitializer == null ||
- isDefaultArrayInitializer(arrayInitializer);
+ final PsiNewExpression newExpression = (PsiNewExpression)initializer;
+ final PsiArrayInitializerExpression arrayInitializer = newExpression.getArrayInitializer();
+ return arrayInitializer == null || isDefaultArrayInitializer(arrayInitializer);
}
else if (initializer instanceof PsiArrayInitializerExpression) {
- final PsiArrayInitializerExpression arrayInitializerExpression =
- (PsiArrayInitializerExpression)initializer;
- final PsiExpression[] initializers =
- arrayInitializerExpression.getInitializers();
+ final PsiArrayInitializerExpression arrayInitializerExpression = (PsiArrayInitializerExpression)initializer;
+ final PsiExpression[] initializers = arrayInitializerExpression.getInitializers();
return initializers.length == 0;
}
return false;
}
public static boolean variableIsWritten(@NotNull PsiVariable variable, @NotNull PsiElement context) {
- final VariableReadWriteVisitor visitor =
- new VariableReadWriteVisitor(variable, true);
+ final VariableReadWriteVisitor visitor = new VariableReadWriteVisitor(variable, true);
context.accept(visitor);
return visitor.isPassed();
}
@@ -272,8 +260,7 @@ public class MismatchedArrayReadWriteInspection extends BaseInspection {
final PsiExpression[] arguments = argumentList.getExpressions();
for (int i = 0; i < arguments.length; i++) {
final PsiExpression argument = arguments[i];
- if (VariableAccessUtils.mayEvaluateToVariable(argument,
- variable)) {
+ if (VariableAccessUtils.mayEvaluateToVariable(argument, variable)) {
if (write && i == 0 && isCallToSystemArraycopy(call)) {
return;
}
@@ -285,49 +272,50 @@ public class MismatchedArrayReadWriteInspection extends BaseInspection {
}
}
- private static boolean isCallToSystemArraycopy(
- PsiMethodCallExpression call) {
- final PsiReferenceExpression methodExpression =
- call.getMethodExpression();
- @NonNls final String name =
- methodExpression.getReferenceName();
+ private static boolean isCallToSystemArraycopy(PsiMethodCallExpression call) {
+ final PsiReferenceExpression methodExpression = call.getMethodExpression();
+ @NonNls final String name = methodExpression.getReferenceName();
if (!"arraycopy".equals(name)) {
return false;
}
- final PsiExpression qualifier =
- methodExpression.getQualifierExpression();
+ final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (!(qualifier instanceof PsiReferenceExpression)) {
return false;
}
- final PsiReferenceExpression referenceExpression =
- (PsiReferenceExpression)qualifier;
- final PsiElement element =
- referenceExpression.resolve();
+ final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)qualifier;
+ final PsiElement element = referenceExpression.resolve();
if (!(element instanceof PsiClass)) {
return false;
}
- final PsiClass aClass = (PsiClass)element;
- final String qualifiedName =
- aClass.getQualifiedName();
- return "java.lang.System".equals(qualifiedName);
+ return "java.lang.System".equals(((PsiClass)element).getQualifiedName());
}
@Override
- public void visitNewExpression(
- @NotNull PsiNewExpression newExpression) {
+ public void visitNewExpression(@NotNull PsiNewExpression newExpression) {
if (passed) {
return;
}
super.visitNewExpression(newExpression);
- final PsiExpressionList argumentList =
- newExpression.getArgumentList();
+ visitPsiCall(newExpression);
+ }
+
+ @Override
+ public void visitEnumConstant(PsiEnumConstant enumConstant) {
+ if (passed) {
+ return;
+ }
+ super.visitEnumConstant(enumConstant);
+ visitPsiCall(enumConstant);
+ }
+
+ private void visitPsiCall(PsiCall newExpression) {
+ final PsiExpressionList argumentList = newExpression.getArgumentList();
if (argumentList == null) {
return;
}
final PsiExpression[] arguments = argumentList.getExpressions();
for (final PsiExpression argument : arguments) {
- if (VariableAccessUtils.mayEvaluateToVariable(argument,
- variable)) {
+ if (VariableAccessUtils.mayEvaluateToVariable(argument, variable)) {
passed = true;
}
}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javabeans/PropertyValueSetToItselfInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javabeans/PropertyValueSetToItselfInspection.java
new file mode 100644
index 000000000000..e4ee7c5956bc
--- /dev/null
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javabeans/PropertyValueSetToItselfInspection.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2000-2014 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.javabeans;
+
+import com.intellij.psi.*;
+import com.intellij.psi.util.PropertyUtil;
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.BaseInspection;
+import com.siyeh.ig.BaseInspectionVisitor;
+import com.siyeh.ig.psiutils.EquivalenceChecker;
+import com.siyeh.ig.psiutils.ParenthesesUtils;
+import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class PropertyValueSetToItselfInspection extends BaseInspection {
+
+ @Nls
+ @NotNull
+ @Override
+ public String getDisplayName() {
+ return InspectionGadgetsBundle.message("property.value.set.to.itself.display.name");
+ }
+
+ @NotNull
+ @Override
+ protected String buildErrorString(Object... infos) {
+ return InspectionGadgetsBundle.message("property.value.set.to.itself.display.name");
+ }
+
+ @Override
+ public BaseInspectionVisitor buildVisitor() {
+ return new PropertyValueSetToItselfVisitor();
+ }
+
+ private static class PropertyValueSetToItselfVisitor extends BaseInspectionVisitor {
+
+ @Override
+ public void visitMethodCallExpression(PsiMethodCallExpression expression) {
+ super.visitMethodCallExpression(expression);
+ final PsiExpressionList argumentList1 = expression.getArgumentList();
+ final PsiExpression[] arguments1 = argumentList1.getExpressions();
+ if (arguments1.length != 1) {
+ return;
+ }
+ final PsiExpression argument = arguments1[0];
+ if (!(argument instanceof PsiMethodCallExpression)) {
+ return;
+ }
+ final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)argument;
+ final PsiExpressionList argumentList2 = methodCallExpression.getArgumentList();
+ final PsiExpression[] arguments2 = argumentList2.getExpressions();
+ if (arguments2.length != 0) {
+ return;
+ }
+ final PsiReferenceExpression methodExpression1 = expression.getMethodExpression();
+ final PsiExpression qualifierExpression1 = ParenthesesUtils.stripParentheses(methodExpression1.getQualifierExpression());
+ final PsiReferenceExpression methodExpression2 = methodCallExpression.getMethodExpression();
+ final PsiExpression qualifierExpression2 = ParenthesesUtils.stripParentheses(methodExpression2.getQualifierExpression());
+ if (qualifierExpression1 instanceof PsiReferenceExpression && qualifierExpression2 instanceof PsiReferenceExpression) {
+ if (!EquivalenceChecker.expressionsAreEquivalent(qualifierExpression1, qualifierExpression2)) {
+ return;
+ }
+ }
+ else if((qualifierExpression1 != null &&
+ !(qualifierExpression1 instanceof PsiThisExpression) &&
+ !(qualifierExpression1 instanceof PsiSuperExpression))
+ ||
+ qualifierExpression2 != null &&
+ !(qualifierExpression2 instanceof PsiThisExpression) &&
+ !(qualifierExpression2 instanceof PsiSuperExpression)) {
+ return;
+ }
+ final PsiMethod method1 = expression.resolveMethod();
+ final PsiField fieldOfSetter = PropertyUtil.getFieldOfSetter(method1);
+ if (fieldOfSetter == null) {
+ return;
+ }
+ final PsiMethod method2 = methodCallExpression.resolveMethod();
+ final PsiField fieldOfGetter = PropertyUtil.getFieldOfGetter(method2);
+ if (!fieldOfSetter.equals(fieldOfGetter)) {
+ return;
+ }
+ registerMethodCallError(expression);
+ }
+ }
+}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java
index 5b4c0c9c8305..adfff487443e 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java
@@ -515,7 +515,10 @@ public class IfCanBeSwitchInspection extends BaseInspection {
super.readSettings(node);
for (Element child : node.getChildren("option")) {
if (Comparing.strEqual(child.getAttributeValue("name"), ONLY_SAFE)) {
- onlySuggestNullSafe = Boolean.parseBoolean(child.getAttributeValue("value"));
+ final String value = child.getAttributeValue("value");
+ if (value != null) {
+ onlySuggestNullSafe = Boolean.parseBoolean(value);
+ }
break;
}
}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ImportUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ImportUtils.java
index 375e0f6a8017..9b4a3a832913 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ImportUtils.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ImportUtils.java
@@ -416,7 +416,7 @@ public class ImportUtils {
final List<PsiImportStaticStatement> imports = getMatchingImports(importList, qualifiedName);
final int onDemandCount = JavaCodeStyleSettingsFacade.getInstance(project).getNamesCountToUseImportOnDemand();
final PsiElementFactory elementFactory = psiFacade.getElementFactory();
- if (imports.size() < onDemandCount) {
+ if (imports.size() + 1 < onDemandCount) {
importList.add(elementFactory.createImportStaticStatement(aClass, memberName));
}
else {
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/InstanceOfUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/InstanceOfUtils.java
index 702d84d522ac..fdbc531406de 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/InstanceOfUtils.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/InstanceOfUtils.java
@@ -117,6 +117,9 @@ public class InstanceOfUtils {
inElse = true;
}
checkExpression(operand);
+ if (agreeingInstanceof) {
+ return;
+ }
}
if (inElse && conflictingInstanceof != null) {
agreeingInstanceof = false;
@@ -215,6 +218,7 @@ public class InstanceOfUtils {
(PsiInstanceOfExpression)expression;
if (isAgreeing(instanceOfExpression)) {
agreeingInstanceof = true;
+ conflictingInstanceof = null;
}
else if (isConflicting(instanceOfExpression)) {
conflictingInstanceof = instanceOfExpression;
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java
index 1440c58e5113..aade5a56361f 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java
@@ -132,7 +132,7 @@ public class WeakestTypeFinder {
else if (referenceParent instanceof PsiVariable) {
final PsiVariable variable = (PsiVariable)referenceParent;
final PsiType type = variable.getType();
- if (!checkType(type, weakestTypeClasses)) {
+ if (!type.isAssignableFrom(variableOrMethodType) || !checkType(type, weakestTypeClasses)) {
return Collections.emptyList();
}
}
@@ -251,7 +251,7 @@ public class WeakestTypeFinder {
if (!hasUsages) {
return Collections.emptyList();
}
- weakestTypeClasses = filterAccessibleClasses(weakestTypeClasses, variableOrMethod);
+ weakestTypeClasses = filterAccessibleClasses(weakestTypeClasses, variableOrMethodClass, variableOrMethod);
return weakestTypeClasses;
}
@@ -442,22 +442,23 @@ public class WeakestTypeFinder {
}
final PsiExpression lhs = assignmentExpression.getLExpression();
final PsiExpression rhs = assignmentExpression.getRExpression();
+ if (rhs == null) {
+ return false;
+ }
final PsiType lhsType = lhs.getType();
+ final PsiType rhsType = rhs.getType();
+ if (lhsType == null || rhsType == null || !lhsType.isAssignableFrom(rhsType)) {
+ return false;
+ }
if (referenceElement.equals(rhs)) {
if (!checkType(lhsType, weakestTypeClasses)) {
return false;
}
}
- else if (useRighthandTypeAsWeakestTypeInAssignments) {
- if (rhs == null) {
- return false;
- }
- if (!(rhs instanceof PsiNewExpression) || !(rhs instanceof PsiTypeCastExpression)) {
- final PsiType rhsType = rhs.getType();
- if (lhsType == null || lhsType.equals(rhsType)) {
- return false;
- }
- }
+ else if (useRighthandTypeAsWeakestTypeInAssignments &&
+ (!(rhs instanceof PsiNewExpression) || !(rhs instanceof PsiTypeCastExpression)) &&
+ lhsType.equals(rhsType)) {
+ return false;
}
return true;
}
@@ -546,14 +547,14 @@ public class WeakestTypeFinder {
return true;
}
- public static Set<PsiClass> filterAccessibleClasses(Set<PsiClass> weakestTypeClasses, PsiElement context) {
+ public static Set<PsiClass> filterAccessibleClasses(Set<PsiClass> weakestTypeClasses, PsiClass upperBound, PsiElement context) {
final Set<PsiClass> result = new HashSet<PsiClass>();
for (PsiClass weakestTypeClass : weakestTypeClasses) {
- if (PsiUtil.isAccessible(weakestTypeClass, context, null)) {
+ if (PsiUtil.isAccessible(weakestTypeClass, context, null) && !weakestTypeClass.isDeprecated()) {
result.add(weakestTypeClass);
continue;
}
- final PsiClass visibleInheritor = getVisibleInheritor(weakestTypeClass, context);
+ final PsiClass visibleInheritor = getVisibleInheritor(weakestTypeClass, upperBound, context);
if (visibleInheritor != null) {
result.add(visibleInheritor);
}
@@ -562,16 +563,16 @@ public class WeakestTypeFinder {
}
@Nullable
- private static PsiClass getVisibleInheritor(@NotNull PsiClass superClass, PsiElement context) {
+ private static PsiClass getVisibleInheritor(@NotNull PsiClass superClass, PsiClass upperBound, PsiElement context) {
final Query<PsiClass> search = DirectClassInheritorsSearch.search(superClass, context.getResolveScope());
final Project project = superClass.getProject();
for (PsiClass aClass : search) {
- if (superClass.isInheritor(aClass, true)) {
+ if (aClass.isInheritor(superClass, true) && upperBound.isInheritor(aClass, true)) {
if (PsiUtil.isAccessible(project, aClass, context, null)) {
return aClass;
}
else {
- return getVisibleInheritor(aClass, context);
+ return getVisibleInheritor(aClass, upperBound, context);
}
}
}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SimplifiableAnnotationInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SimplifiableAnnotationInspection.java
index 794716ba0412..e45f06cac284 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SimplifiableAnnotationInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SimplifiableAnnotationInspection.java
@@ -16,9 +16,10 @@
package com.siyeh.ig.style;
import com.intellij.codeInspection.ProblemDescriptor;
+import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
+import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.IncorrectOperationException;
@@ -46,30 +47,30 @@ public class SimplifiableAnnotationInspection extends BaseInspection {
@NotNull
@Override
protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message("simplifiable.annotation.problem.descriptor");
+ if (((Boolean)infos[0]).booleanValue()) {
+ return InspectionGadgetsBundle.message("simplifiable.annotation.whitespace.problem.descriptor");
+ }
+ else {
+ return InspectionGadgetsBundle.message("simplifiable.annotation.problem.descriptor");
+ }
}
@Override
protected InspectionGadgetsFix buildFix(Object... infos) {
- final PsiAnnotation annotation = (PsiAnnotation)infos[0];
- return new SimplifiableAnnotationFix(annotation);
+ return new SimplifiableAnnotationFix();
}
private static class SimplifiableAnnotationFix extends InspectionGadgetsFix {
- private final String replacement;
-
- public SimplifiableAnnotationFix(PsiAnnotation annotation) {
- this.replacement = buildAnnotationText(annotation, new StringBuilder()).toString();
- }
+ public SimplifiableAnnotationFix() {}
@Override
@NotNull
public String getName() {
- return InspectionGadgetsBundle.message("simplifiable.annotation.quickfix",
- StringUtil.shortenTextWithEllipsis(replacement, 50, 0, true));
+ return InspectionGadgetsBundle.message("simplifiable.annotation.quickfix");
}
- @Override
+
+ @Override
@NotNull
public String getFamilyName() {
return getName();
@@ -78,23 +79,25 @@ public class SimplifiableAnnotationInspection extends BaseInspection {
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiElement element = descriptor.getPsiElement();
- if (!(element instanceof PsiAnnotation)) {
+ final PsiAnnotation annotation = PsiTreeUtil.getParentOfType(element, PsiAnnotation.class);
+ if (annotation == null) {
return;
}
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
- final PsiAnnotation annotation = factory.createAnnotationFromText(replacement, element);
- element.replace(annotation);
+ final String annotationText = buildAnnotationText(annotation);
+ final PsiAnnotation newAnnotation = factory.createAnnotationFromText(annotationText, element);
+ annotation.replace(newAnnotation);
}
- private static StringBuilder buildAnnotationText(PsiAnnotation annotation, StringBuilder out) {
- out.append('@');
+ private static String buildAnnotationText(PsiAnnotation annotation) {
+ final StringBuilder out = new StringBuilder("@");
final PsiJavaCodeReferenceElement nameReferenceElement = annotation.getNameReferenceElement();
assert nameReferenceElement != null;
out.append(nameReferenceElement.getText());
final PsiAnnotationParameterList parameterList = annotation.getParameterList();
final PsiNameValuePair[] attributes = parameterList.getAttributes();
if (attributes.length == 0) {
- return out;
+ return out.toString();
}
out.append('(');
if (attributes.length == 1) {
@@ -116,7 +119,7 @@ public class SimplifiableAnnotationInspection extends BaseInspection {
}
}
out.append(')');
- return out;
+ return out.toString();
}
private static StringBuilder buildAttributeValueText(PsiAnnotationMemberValue value, StringBuilder out) {
@@ -128,7 +131,7 @@ public class SimplifiableAnnotationInspection extends BaseInspection {
}
}
else if (value instanceof PsiAnnotation) {
- return buildAnnotationText((PsiAnnotation)value, out);
+ return out.append(buildAnnotationText((PsiAnnotation)value));
}
return out.append(value.getText());
}
@@ -151,36 +154,36 @@ public class SimplifiableAnnotationInspection extends BaseInspection {
}
final PsiNameValuePair[] attributes = parameterList.getAttributes();
final PsiElement[] annotationChildren = annotation.getChildren();
- if (annotationChildren.length >= 2 && annotationChildren[1] instanceof PsiWhiteSpace) {
- if (!containsError(annotation)) {
- registerError(annotation, annotation);
- }
+ if (annotationChildren.length >= 2 && annotationChildren[1] instanceof PsiWhiteSpace && !containsError(annotation)) {
+ registerError(annotationChildren[1], Boolean.TRUE);
}
- else if (attributes.length == 0) {
- final PsiElement[] children = parameterList.getChildren();
- if (children.length <= 0) {
- return;
- }
- if (!containsError(annotation)) {
- registerError(annotation, annotation);
+ if (attributes.length == 0) {
+ if (parameterList.getChildren().length > 0 && !containsError(annotation)) {
+ registerError(parameterList, ProblemHighlightType.LIKE_UNUSED_SYMBOL, Boolean.FALSE);
}
}
else if (attributes.length == 1) {
final PsiNameValuePair attribute = attributes[0];
- @NonNls final String name = attribute.getName();
+ final PsiIdentifier identifier = attribute.getNameIdentifier();
final PsiAnnotationMemberValue attributeValue = attribute.getValue();
- if (!PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.equals(name)) {
- if (!(attributeValue instanceof PsiArrayInitializerMemberValue)) {
- return;
- }
- final PsiArrayInitializerMemberValue arrayValue = (PsiArrayInitializerMemberValue)attributeValue;
- final PsiAnnotationMemberValue[] initializers = arrayValue.getInitializers();
- if (initializers.length != 1) {
- return;
+ if (identifier != null && attributeValue != null) {
+ @NonNls final String name = attribute.getName();
+ if (PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.equals(name) && !containsError(annotation)) {
+ registerErrorAtOffset(attribute, 0, attributeValue.getStartOffsetInParent(), ProblemHighlightType.LIKE_UNUSED_SYMBOL,
+ Boolean.FALSE);
}
}
+ if (!(attributeValue instanceof PsiArrayInitializerMemberValue)) {
+ return;
+ }
+ final PsiArrayInitializerMemberValue arrayValue = (PsiArrayInitializerMemberValue)attributeValue;
+ final PsiAnnotationMemberValue[] initializers = arrayValue.getInitializers();
+ if (initializers.length != 1) {
+ return;
+ }
if (!containsError(annotation)) {
- registerError(annotation, annotation);
+ registerError(arrayValue.getFirstChild(), ProblemHighlightType.LIKE_UNUSED_SYMBOL, Boolean.FALSE);
+ registerError(arrayValue.getLastChild(), ProblemHighlightType.LIKE_UNUSED_SYMBOL, Boolean.FALSE);
}
}
else if (attributes.length > 1) {
@@ -189,15 +192,15 @@ public class SimplifiableAnnotationInspection extends BaseInspection {
if (!(value instanceof PsiArrayInitializerMemberValue)) {
continue;
}
- final PsiArrayInitializerMemberValue arrayInitializerMemberValue = (PsiArrayInitializerMemberValue)value;
- final PsiAnnotationMemberValue[] initializers = arrayInitializerMemberValue.getInitializers();
+ final PsiArrayInitializerMemberValue arrayValue = (PsiArrayInitializerMemberValue)value;
+ final PsiAnnotationMemberValue[] initializers = arrayValue.getInitializers();
if (initializers.length != 1) {
continue;
}
if (!containsError(annotation)) {
- registerError(annotation, annotation);
+ registerError(arrayValue.getFirstChild(), ProblemHighlightType.LIKE_UNUSED_SYMBOL, Boolean.FALSE);
+ registerError(arrayValue.getLastChild(), ProblemHighlightType.LIKE_UNUSED_SYMBOL, Boolean.FALSE);
}
- return;
}
}
}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java
index 4747e7426fd7..70b620f9434c 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java
@@ -20,7 +20,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -86,7 +85,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
}
@Override
- protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
+ protected void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
final PsiElement parent = element.getParent();
if (!(parent instanceof PsiVariable)) {
@@ -290,6 +289,9 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
methodCallExpression = (PsiMethodCallExpression)grandParent;
parent = methodCallExpression.getParent();
grandParent = parent.getParent();
+ if ("toString".equals(methodCallExpression.getMethodExpression().getReferenceName())) {
+ break;
+ }
}
if (buildStringExpression(methodCallExpression, myBuilder) == null) {
myProblem = true;
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryEnumModifierInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryEnumModifierInspection.java
index 2aa72fae7bbe..7d8d9558ef53 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryEnumModifierInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryEnumModifierInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2014 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.
@@ -17,6 +17,7 @@ package com.siyeh.ig.style;
import com.intellij.codeInspection.CleanupLocalInspectionTool;
import com.intellij.codeInspection.ProblemDescriptor;
+import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.util.IncorrectOperationException;
@@ -112,7 +113,7 @@ public class UnnecessaryEnumModifierInspection extends BaseInspection implements
for (final PsiElement child : children) {
final String text = child.getText();
if (PsiModifier.STATIC.equals(text)) {
- registerError(child, child, aClass);
+ registerError(child, ProblemHighlightType.LIKE_UNUSED_SYMBOL, child, aClass);
}
}
}
@@ -131,7 +132,7 @@ public class UnnecessaryEnumModifierInspection extends BaseInspection implements
for (final PsiElement child : children) {
final String text = child.getText();
if (PsiModifier.PRIVATE.equals(text)) {
- registerError(child, child, method);
+ registerError(child, ProblemHighlightType.LIKE_UNUSED_SYMBOL, child, method);
}
}
}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java
index 310cc20c30b6..a0718c07fa8f 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2014 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.
@@ -17,6 +17,7 @@ package com.siyeh.ig.style;
import com.intellij.codeInspection.CleanupLocalInspectionTool;
import com.intellij.codeInspection.ProblemDescriptor;
+import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
@@ -214,7 +215,7 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection imple
}
for (PsiElement child : children) {
if (modifiers.contains(child.getText())) {
- registerError(child, redundantModifiers.toString(), list);
+ registerError(child, ProblemHighlightType.LIKE_UNUSED_SYMBOL, redundantModifiers.toString(), list);
}
}
}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessarySemicolonInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessarySemicolonInspection.java
index c1a75887c6aa..36f5af9408df 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessarySemicolonInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessarySemicolonInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2014 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.
@@ -17,6 +17,7 @@ package com.siyeh.ig.style;
import com.intellij.codeInspection.CleanupLocalInspectionTool;
import com.intellij.codeInspection.ProblemDescriptor;
+import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
@@ -111,7 +112,7 @@ public class UnnecessarySemicolonInspection extends BaseInspection implements Cl
private void findTopLevelSemicolons(PsiElement element) {
for (PsiElement sibling = element.getFirstChild(); sibling != null; sibling = skipForwardWhiteSpacesAndComments(sibling)) {
if (PsiUtil.isJavaToken(sibling, JavaTokenType.SEMICOLON)) {
- registerError(sibling);
+ registerError(sibling, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
}
}
@@ -149,7 +150,7 @@ public class UnnecessarySemicolonInspection extends BaseInspection implements Cl
if (next == null || !next.equals(aClass.getRBrace())) {
return;
}
- registerError(element);
+ registerError(element, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
private void findUnnecessarySemicolonsAfterEnumConstants(
@@ -171,11 +172,11 @@ public class UnnecessarySemicolonInspection extends BaseInspection implements Cl
if (!JavaTokenType.COMMA.equals(prevTokenType)
&& !JavaTokenType.LBRACE.equals(
prevTokenType)) {
- registerError(child);
+ registerError(child, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
}
else {
- registerError(child);
+ registerError(child, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
}
}
@@ -207,7 +208,7 @@ public class UnnecessarySemicolonInspection extends BaseInspection implements Cl
if (semicolon == null) {
return;
}
- registerError(semicolon);
+ registerError(semicolon, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
}
@@ -218,7 +219,7 @@ public class UnnecessarySemicolonInspection extends BaseInspection implements Cl
if (last instanceof PsiJavaToken && ((PsiJavaToken)last).getTokenType() == JavaTokenType.RPARENTH) {
final PsiElement prev = skipBackwardWhiteSpacesAndComments(last);
if (prev instanceof PsiJavaToken && ((PsiJavaToken)prev).getTokenType() == JavaTokenType.SEMICOLON) {
- registerError(prev);
+ registerError(prev, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/HighlightUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/HighlightUtils.java
index 1894986e9a5b..6444ff8b0660 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/HighlightUtils.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/HighlightUtils.java
@@ -34,6 +34,7 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.WindowManager;
@@ -41,6 +42,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNameIdentifierOwner;
import com.intellij.psi.PsiReference;
import com.intellij.psi.util.PsiUtilCore;
+import com.intellij.util.containers.ContainerUtil;
import com.siyeh.InspectionGadgetsBundle;
import org.jetbrains.annotations.NotNull;
@@ -68,7 +70,12 @@ public class HighlightUtils {
final PsiElement[] elements =
PsiUtilCore.toPsiElementArray(elementCollection);
final PsiElement firstElement = elements[0];
- if (!firstElement.isValid()) {
+ if (ContainerUtil.exists(elements, new Condition<PsiElement>() {
+ @Override
+ public boolean value(PsiElement element) {
+ return !element.isValid();
+ }
+ })) {
return;
}
final Project project = firstElement.getProject();
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/ui/TextField.java b/plugins/InspectionGadgets/src/com/siyeh/ig/ui/TextField.java
index 47344f5cc861..28c947e24ac0 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/ui/TextField.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/ui/TextField.java
@@ -16,13 +16,13 @@
package com.siyeh.ig.ui;
import com.intellij.codeInspection.InspectionProfileEntry;
+import com.intellij.util.ReflectionUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
-import java.lang.reflect.Field;
public class TextField extends JTextField {
@@ -36,35 +36,13 @@ public class TextField extends JTextField {
private static String getPropertyValue(InspectionProfileEntry owner,
String property) {
- try {
- final Class<? extends InspectionProfileEntry> aClass =
- owner.getClass();
- final Field field = aClass.getField(property);
- return (String)field.get(owner);
- }
- catch (IllegalAccessException ignore) {
- return null;
- }
- catch (NoSuchFieldException ignore) {
- return null;
- }
+ return ReflectionUtil.getField(owner.getClass(), owner, String.class, property);
}
private static void setPropertyValue(InspectionProfileEntry owner,
String property,
String value) {
- try {
- final Class<? extends InspectionProfileEntry> aClass =
- owner.getClass();
- final Field field = aClass.getField(property);
- field.set(owner, value);
- }
- catch (IllegalAccessException ignore) {
- // do nothing
- }
- catch (NoSuchFieldException ignore) {
- // do nothing
- }
+ ReflectionUtil.setField(owner.getClass(), owner, String.class, property, value);
}
private class TextFieldDocumentListener implements DocumentListener {
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/AmbiguousFieldAccess.html b/plugins/InspectionGadgets/src/inspectionDescriptions/AmbiguousFieldAccess.html
index b22ad3712458..b0f698b74e7e 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/AmbiguousFieldAccess.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/AmbiguousFieldAccess.html
@@ -12,8 +12,8 @@ accessed, when in fact a field from the super class is accessed. To make the int
<b>class</b> Y {
<b>void</b> foo(String s) {
<b>new</b> X() {{
- System.out.println(s); // problem indicated here
- }}
+ System.out.println(s); // here the field is accessed not the parameter
+ }};
}
}
</code></pre>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/PropertyValueSetToItself.html b/plugins/InspectionGadgets/src/inspectionDescriptions/PropertyValueSetToItself.html
new file mode 100644
index 000000000000..c72e160a9b8c
--- /dev/null
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/PropertyValueSetToItself.html
@@ -0,0 +1,10 @@
+<html>
+<body>
+Reports calls on a setter with the value of same objects getter.
+For example: <code>bean.setPayerId(bean.getPayerId());</code>
+In regular circumstances this code is a no-op and probably not what was intented..
+<!-- tooltip end -->
+<p>
+ <small>New in 14</small>
+</body>
+</html> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ReturnNull.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ReturnNull.html
index 70255c1e9440..c36afbcd8886 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ReturnNull.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ReturnNull.html
@@ -3,14 +3,14 @@
Reports return statements with <b>null</b> values.
While occasionally useful, this construct may make the code more prone
to failing with a <b>NullPointerException</b>, and often indicates that the
-developer doesn't really understand the classes intended semantics.
+developer doesn't really understand the class's intended semantics.
<!-- tooltip end -->
<p>
-Use the first control below to let this inspection ignore private methods.
+Use the first checkbox below to let this inspection ignore private methods.
<p>
-Use bottom three controls to specify whether this inspection should report
+Use the bottom three checkboxes to specify whether
<b>null</b> values on array returns, collection
-object returns, plain object returns, or a combination of the three.
+object returns, plain object returns, or a combination of the three should be reported.
<p>
</body>
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/style/replace_with_string/MethodCallOnString.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/style/replace_with_string/MethodCallOnString.after.java
new file mode 100644
index 000000000000..4ced8b802fc5
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/style/replace_with_string/MethodCallOnString.after.java
@@ -0,0 +1,5 @@
+public class MethodCallOnString {
+ public static void main(String... args) {
+ int length = "ABC".length();
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/style/replace_with_string/MethodCallOnString.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/style/replace_with_string/MethodCallOnString.java
new file mode 100644
index 000000000000..2ff02036eced
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/style/replace_with_string/MethodCallOnString.java
@@ -0,0 +1,6 @@
+public class MethodCallOnString {
+ public static void main(String... args) {
+ StringBuilder theBuilder<caret> = new StringBuilder("ABC");
+ int length = theBuilder.toString().length();
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/DeclareCollectionAsInterface.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/DeclareCollectionAsInterface.java
index e5c11992d86c..f21cc080de25 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/DeclareCollectionAsInterface.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/DeclareCollectionAsInterface.java
@@ -60,4 +60,14 @@ public class DeclareCollectionAsInterface
<warning descr="Declaration of 'HashSet' should probably be weakened to 'java.util.Set'">HashSet</warning><String> set = new HashSet<>();
set.add("foo");
}
+
+ public static Properties stringToProperties(String propertiesAsString) { return null; }
+ public static Properties stringToProperties2(String propertiesAsString) { return null; }
+ public static Properties stringToProperties3(String propertiesAsString) { return null; }
+
+ void m() {
+ stringToProperties("");
+ <error descr="Incompatible types. Found: 'java.util.Properties', required: 'java.lang.String'">String s = stringToProperties2("");</error>
+ <error descr="Incompatible types. Found: 'java.util.Properties', required: 'java.lang.String'">s = stringToProperties3("")</error>;
+ }
}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/AutoClosableTest.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/AutoClosableTest.java
index 3d9b0a2fd811..7c96abd2260c 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/AutoClosableTest.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/AutoClosableTest.java
@@ -31,13 +31,13 @@ class AutoClosableTest2
public static class Bar extends Foo {}
public static void test() {
- try (Bar bar = new Bar()) {
+ try (Bar <warning descr="Type of variable 'bar' may be weakened to 'com.siyeh.igtest.abstraction.weaken_type.AutoClosableTest2.Foo'">bar</warning> = new Bar()) {
bar.go();
}
}
void dodo() throws java.io.IOException {
- try (java.io.Reader reader = new java.io.FileReader("/home/steve/foo.txt")) {
+ try (java.io.Reader <warning descr="Type of variable 'reader' may be weakened to 'java.io.Closeable'">reader</warning> = new java.io.FileReader("/home/steve/foo.txt")) {
System.out.println(reader);
}
}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/NumberAdderDemo.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/NumberAdderDemo.java
index 0a009777a810..4b3547198e83 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/NumberAdderDemo.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/NumberAdderDemo.java
@@ -1,6 +1,6 @@
-package com.siyeh.igtest.abstraction.weaken_type;
+package weaken_type;
-import com.siyeh.igtest.abstraction.weaken_type.sub.NumberAdderExtension;
+import weaken_type.sub.NumberAdderExtension;
public class NumberAdderDemo {
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java
index aeb2e1a5f811..370aba53a19c 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java
@@ -52,7 +52,7 @@ public class TypeMayBeWeakened {
foo(new WeakBoolean());
}
- void foo(WeakBoolean b) {
+ void foo(WeakBoolean <warning descr="Type of parameter 'b' may be weakened to 'java.lang.Object'">b</warning>) {
System.out.println("b: " + b);
}
@@ -65,7 +65,7 @@ public class TypeMayBeWeakened {
FileInputStream fis=new FileInputStream("/etc/modules");
}
catch(FileNotFoundException fnfex) {
- IllegalArgumentException iaex=new IllegalArgumentException("Exception Message");
+ IllegalArgumentException <warning descr="Type of variable 'iaex' may be weakened to 'java.lang.RuntimeException'">iaex</warning>=new IllegalArgumentException("Exception Message");
iaex.initCause(fnfex);
throw iaex;
}
@@ -82,7 +82,7 @@ public class TypeMayBeWeakened {
void foo() { Test f = new Test(); f.x++; }
}
- void listy(ArrayList list) {
+ void listy(ArrayList <warning descr="Type of parameter 'list' may be weakened to 'java.lang.Iterable'">list</warning>) {
for (Object o : list) {
}
@@ -130,7 +130,7 @@ class MyClass {
public MyClass(java.util.Date date, String[] classNames) {}
- static MyClass readMyClass(final ObjectInputStream objectInput) {
+ static MyClass readMyClass(final ObjectInputStream <warning descr="Type of parameter 'objectInput' may be weakened to 'com.siyeh.igtest.abstraction.weaken_type.DataInput'">objectInput</warning>) {
final long time = objectInput.readLong();
final int size = objectInput.readInt();
final String[] classNames = new String[size];
@@ -150,4 +150,16 @@ abstract class ObjectInputStream implements DataInput {
public String readUTF() {
return null;
}
-} \ No newline at end of file
+}
+class Test implements Foo2 {
+ void test(Test <warning descr="Type of parameter 't' may be weakened to 'com.siyeh.igtest.abstraction.weaken_type.Foo2'">t</warning>) {
+ t.bar();
+ }
+ public void bar() {
+ }
+}
+@Deprecated
+interface Foo {
+ void bar();
+}
+interface Foo2 extends Foo {} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/sub/NumberAdder.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/sub/NumberAdder.java
deleted file mode 100644
index 8f15c784c12a..000000000000
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/sub/NumberAdder.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.siyeh.igtest.abstraction.weaken_type.sub;
-
-/**
- * Created by IntelliJ IDEA. User: HONOURK Date: 21-Aug-2008 Time: 12:15:41 To change this template
- * use File | Settings | File Templates.
- */
-public interface NumberAdder {
- int doSomething();
-}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/sub/NumberAdderExtension.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/sub/NumberAdderExtension.java
deleted file mode 100644
index 21bdf2988a11..000000000000
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/sub/NumberAdderExtension.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.siyeh.igtest.abstraction.weaken_type.sub;
-
-/**
- * Created by IntelliJ IDEA. User: HONOURK Date: 21-Aug-2008 Time: 12:15:41 To change this template
- * use File | Settings | File Templates.
- */
-public class NumberAdderExtension extends NumberAdderImpl {
- @Override
- public int getNumberOne() {
- return super.getNumberOne();
- }
-}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/sub/NumberAdderImpl.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/sub/NumberAdderImpl.java
deleted file mode 100644
index 669373d0342f..000000000000
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/sub/NumberAdderImpl.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.siyeh.igtest.abstraction.weaken_type.sub;
-
-public class NumberAdderImpl implements NumberAdder {
-
- public int doSomething() {
- return getNumberOne() + 1;
- }
-
- protected int getNumberOne() {
- return 1;
- }
-}
-
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/orInstanceofOrInstanceof/OrInstanceofOrInstanceof.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/orInstanceofOrInstanceof/OrInstanceofOrInstanceof.java
new file mode 100644
index 000000000000..228fe5c10117
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/orInstanceofOrInstanceof/OrInstanceofOrInstanceof.java
@@ -0,0 +1,30 @@
+package com.siyeh.igtest.bugs.castConflictingInstanceof.andAnd;
+
+class Test {
+
+ public void test(Object o)
+ {
+
+ if (!(o instanceof Number) ||
+ ((Number)o).intValue() == 0 ||
+ !(o instanceof Integer) ||
+ ((Integer) o).byteValue() == 9) {
+ System.out.println();
+ }
+
+ if (!(o instanceof Number) ||
+ ((Number)o).intValue() == 0 ||
+ !(o instanceof Integer) ||
+ !(o instanceof Number) ||
+ ((Integer) o).byteValue() == 9) {
+ System.out.println();
+ }
+
+ if (!(o instanceof Integer) ||
+ ((Number)o).intValue() == 0 ||
+ !(o instanceof Number) ||
+ ((Integer) o).byteValue() == 9) {
+ System.out.println();
+ }
+ }
+}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/orInstanceofOrInstanceof/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/orInstanceofOrInstanceof/expected.xml
new file mode 100644
index 000000000000..e8f00e82629f
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/orInstanceofOrInstanceof/expected.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<problems>
+
+</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_array_read_write/MismatchedArrayReadWrite.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_array_read_write/MismatchedArrayReadWrite.java
index beed034bc1ba..33683aaa4d1f 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_array_read_write/MismatchedArrayReadWrite.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_array_read_write/MismatchedArrayReadWrite.java
@@ -183,4 +183,17 @@ class Ferrari458Spider implements java.io.Serializable {
private static final java.io.ObjectStreamField[] serialPersistentFields = {
new java.io.ObjectStreamField("b", String.class)
};
+}
+
+class TestIDEA128098 {
+ private static final String[] CONSTANT_ARRAY = new String[]{""}; // warning is on this constant
+
+
+ enum SomeEnum {
+ ITEM( CONSTANT_ARRAY);
+ private final String[] myPatterns;
+ SomeEnum(String... patterns) {
+ myPatterns = patterns;
+ }
+ }
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/simplifiable_annotation/SimplifiableAnnotation.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/simplifiable_annotation/SimplifiableAnnotation.java
index b40289507a08..1fe15e0f3eeb 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/simplifiable_annotation/SimplifiableAnnotation.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/simplifiable_annotation/SimplifiableAnnotation.java
@@ -2,8 +2,8 @@ package com.siyeh.igtest.style.simplifiable_annotation;
public class SimplifiableAnnotation {
- <warning descr="Annotation '@ SuppressWarnings(value = \\"blabla\\")' can be simplified">@ SuppressWarnings(value = "blabla")</warning>
- <warning descr="Annotation '@ Deprecated()' can be simplified">@ Deprecated()</warning>
+ @<warning descr="Unnecessary whitespace in annotation"> </warning>SuppressWarnings(<warning descr="Unnecessary 'value =' in annotation">value = </warning>"blabla")
+ @<warning descr="Unnecessary whitespace in annotation"> </warning>Deprecated<warning descr="Unnecessary '()' in annotation">()</warning>
Object foo() {
return null;
}
@@ -14,8 +14,8 @@ public class SimplifiableAnnotation {
@interface ArrayAnnotation {
String[] array();
}
-<warning descr="Annotation '@ValueAnnotation({\\"the value\\"})' can be simplified">@ValueAnnotation({"the value"})</warning>
-<warning descr="Annotation '@ArrayAnnotation(array = {\\"first\\"})' can be simplified">@ArrayAnnotation(array = {"first"})</warning>
+@ValueAnnotation(<warning descr="Unnecessary '{' in annotation">{</warning>"the value"<warning descr="Unnecessary '}' in annotation">}</warning>)
+@ArrayAnnotation(array = <warning descr="Unnecessary '{' in annotation">{</warning>"first"<warning descr="Unnecessary '}' in annotation">}</warning>)
class MyClass {
@ <error descr="'value' missing though required">ValueAnnotation</error>
@@ -23,7 +23,7 @@ class MyClass {
return -1;
}
- <warning descr="Annotation '@Two(i={1}, j = 2)' can be simplified">@Two(i={1}, j = 2)</warning>
+ @Two(i=<warning descr="Unnecessary '{' in annotation">{</warning>1<warning descr="Unnecessary '}' in annotation">}</warning>, j = 2)
String s;
}
@interface Two {
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspectionTest.java
index fec91135e731..df0048a5218f 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspectionTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspectionTest.java
@@ -1,24 +1,48 @@
package com.siyeh.ig.abstraction;
-import com.intellij.openapi.roots.LanguageLevelProjectExtension;
-import com.intellij.pom.java.LanguageLevel;
-import com.siyeh.ig.IGInspectionTestCase;
+import com.intellij.codeInspection.InspectionProfileEntry;
+import com.siyeh.ig.LightInspectionTestCase;
+import org.jetbrains.annotations.Nullable;
-public class TypeMayBeWeakenedInspectionTest extends IGInspectionTestCase {
+public class TypeMayBeWeakenedInspectionTest extends LightInspectionTestCase {
- public void test() throws Exception {
- final TypeMayBeWeakenedInspection inspection =
- new TypeMayBeWeakenedInspection();
+ public void testTypeMayBeWeakened() { doTest(); }
+ public void testNumberAdderDemo() { doTest(); }
+ public void testAutoClosableTest() { doTest(); }
+
+ @Override
+ protected String[] getEnvironmentClasses() {
+ return new String[] {
+ "package weaken_type.sub;\n" +
+ "public class NumberAdderImpl implements NumberAdder {\n" +
+ " public int doSomething() {\n" +
+ " return getNumberOne() + 1;\n" +
+ " }\n" +
+ " protected int getNumberOne() {\n" +
+ " return 1;\n" +
+ " }\n" +
+ "}",
+ "package weaken_type.sub;\n" +
+ "public class NumberAdderExtension extends NumberAdderImpl {\n" +
+ " @Override\n" +
+ " public int getNumberOne() {\n" +
+ " return super.getNumberOne();\n" +
+ " }\n" +
+ "}"
+ };
+ }
+
+ @Override
+ protected String getBasePath() {
+ return "/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type";
+ }
+
+ @Nullable
+ @Override
+ protected InspectionProfileEntry getInspection() {
+ final TypeMayBeWeakenedInspection inspection = new TypeMayBeWeakenedInspection();
inspection.doNotWeakenToJavaLangObject = false;
inspection.onlyWeakentoInterface = false;
- final LanguageLevelProjectExtension levelProjectExtension = LanguageLevelProjectExtension.getInstance(getProject());
- final LanguageLevel level = levelProjectExtension.getLanguageLevel();
- try {
- levelProjectExtension.setLanguageLevel(LanguageLevel.JDK_1_7);
- doTest("com/siyeh/igtest/abstraction/weaken_type", inspection);
- }
- finally {
- levelProjectExtension.setLanguageLevel(level);
- }
+ return inspection;
}
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java
index ff6d488a6fd9..079bda6ac35f 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java
@@ -43,6 +43,10 @@ public class CastConflictsWithInstanceofInspectionTest extends IGInspectionTestC
doTest();
}
+ public void testOrInstanceofOrInstanceof() throws Exception {
+ doTest();
+ }
+
private void doTest() throws Exception {
doTest("com/siyeh/igtest/bugs/castConflictingInstanceof/" + getTestName(true), new CastConflictsWithInstanceofInspection());
}
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/style/StringBufferReplaceableByStringFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/style/StringBufferReplaceableByStringFixTest.java
index f49e16b89c4a..8c7920b9567d 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/style/StringBufferReplaceableByStringFixTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/style/StringBufferReplaceableByStringFixTest.java
@@ -32,4 +32,5 @@ public class StringBufferReplaceableByStringFixTest extends IGQuickFixesTestCase
public void testCharLiteral() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
public void testEscape() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
public void testUnescape() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
+ public void testMethodCallOnString() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
}
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ExtendsConcreteCollectionInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ExtendsConcreteCollectionInspectionTest.java
index 99c6a2480928..a2b334c2661c 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ExtendsConcreteCollectionInspectionTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ExtendsConcreteCollectionInspectionTest.java
@@ -31,7 +31,7 @@ public class ExtendsConcreteCollectionInspectionTest extends LightInspectionTest
protected String[] getEnvironmentClasses() {
return new String[] {
"package java.util;" +
- "public class LinkedHashMap<K, V> {" +
+ "public class LinkedHashMap<K, V> extends HashMap<K,V> implements Map<K,V>{" +
" protected boolean removeEldestEntry(Map.Entry<K,V> eldest) {\n" +
" return false;\n" +
" }" +
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/javabeans/PropertyValueSetToItselfInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/javabeans/PropertyValueSetToItselfInspectionTest.java
new file mode 100644
index 000000000000..d17387119ae1
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/javabeans/PropertyValueSetToItselfInspectionTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2000-2014 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.javabeans;
+
+import com.intellij.codeInspection.InspectionProfileEntry;
+import com.siyeh.ig.LightInspectionTestCase;
+import org.jetbrains.annotations.Nullable;
+
+public class PropertyValueSetToItselfInspectionTest extends LightInspectionTestCase {
+
+ public void testSimple() {
+ doTest("class Bean {\n" +
+ " private String x;\n" +
+ " public void setX(String x) {\n" +
+ " this.x = x;\n" +
+ " }\n" +
+ " public String getX() { return x; }\n" +
+ " void m(Bean b) {\n" +
+ " (b)./*Property value set to itself*/setX/**/(b.getX());\n" +
+ " this./*Property value set to itself*/setX/**/(getX());\n" +
+ " }\n" +
+ "}");
+ }
+
+ public void testNoWarn() {
+ doTest("class Bean {\n" +
+ " private String x;\n" +
+ " public void setX(String x) {\n" +
+ " this.x = x;\n" +
+ " }\n" +
+ " public String getX() { return x; }\n" +
+ " void m(Bean b, Bean c) {\n" +
+ " (b).setX(c.getX());\n" +
+ " }\n" +
+ "}");
+ }
+
+ @Nullable
+ @Override
+ protected InspectionProfileEntry getInspection() {
+ return new PropertyValueSetToItselfInspection();
+ }
+} \ No newline at end of file