summaryrefslogtreecommitdiff
path: root/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com')
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties34
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspectionVisitor.java11
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/VariableNotUsedInsideIfInspection.java45
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/dataflow/NegativelyNamedBooleanVariableInspectionBase.java72
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/ConvertToVarargsMethodFix.java125
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/ProblematicVarargsMethodOverrideInspection.java81
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/SuppressionAnnotationInspectionBase.java9
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspection.java47
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java2
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/DefiniteAssignment.java7
10 files changed, 340 insertions, 93 deletions
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
index 1f3e7e82dcd1..36709b62b934 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
@@ -910,7 +910,7 @@ limited.scope.inner.class.problem.descriptor=Limited-scope inner class <code>#re
final.method.problem.descriptor=Method declared <code>#ref</code> #loc
class.initializer.problem.descriptor=Non-'static' initializer #loc
class.may.be.interface.problem.descriptor=<code>#ref</code> may be interface #loc
-non.protected.constructor.in.abstract.class.problem.descriptor=Constructor <code>#ref</code> is not declared 'protected' in 'abstract' class #loc
+non.protected.constructor.in.abstract.class.problem.descriptor=Constructor <code>#ref()</code> is not declared 'protected' in 'abstract' class #loc
class.without.constructor.problem.descriptor=Class <code>#ref</code> has no constructor #loc
abstract.class.without.abstract.methods.problem.descriptor=Class <code>#ref</code> is declared 'abstract', and has no 'abstract' methods #loc
final.method.in.final.class.problem.descriptor=Method declared <code>#ref</code> in 'final' class #loc
@@ -1428,7 +1428,7 @@ indexof.replaceable.by.contains.display.name='indexOf()' expression is replaceab
replace.indexof.with.contains.quickfix=Replace 'indexOf()' with 'contains()'
overloaded.methods.with.same.number.parameters.problem.descriptor=Multiple methods named <code>#ref</code> with the same number of parameters #loc
overloaded.vararg.method.problem.descriptor=Overloaded variable argument method <code>#ref()</code> #loc
-overloaded.vararg.constructor.problem.descriptor=Overloaded variable argument constructor <code>#ref</code> #loc
+overloaded.vararg.constructor.problem.descriptor=Overloaded variable argument constructor <code>#ref()</code> #loc
cached.number.constructor.call.display.name=Number constructor call with primitive argument
cached.number.constructor.call.problem.descriptor=Number constructor call with primitive argument <code>#ref</code> #loc
cached.number.constructor.call.quickfix=Replace with ''{0}.valueOf()'' call
@@ -1731,7 +1731,8 @@ field.may.be.final.display.name=Field may be 'final'
field.may.be.final.problem.descriptor=Field <code>#ref</code> may be 'final' #loc
cast.that.loses.precision.option=Ignore casts from int to char
variable.not.used.inside.if.display.name=Reference checked for 'null' is not used inside 'if'
-variable.not.used.inside.if.problem.descriptor=<code>#ref</code> is not used inside if #loc
+variable.not.used.inside.if.problem.descriptor=<code>#ref</code> checked for 'null' is not used inside 'if' #loc
+variable.not.used.inside.conditional.problem.descriptor=<code>#ref</code> checked for 'null' is not used inside conditional #loc
if.may.be.conditional.display.name='if' statement could be replaced with conditional expression
if.may.be.conditional.problem.descriptor=<code>#ref</code> could be replaced with conditional expression #loc
if.may.be.conditional.quickfix=Replace with conditional expression
@@ -1901,7 +1902,7 @@ arrays.hash.code.quickfix=Replace with 'Arrays.hashCode()'
method.can.be.variable.arity.method.display.name=Method can be variable arity method
method.can.be.variable.arity.method.problem.descriptor=<code>#ref()</code> can be converted to variable arity method #loc
method.can.be.variable.arity.method.ignore.byte.short.option=<html>Ignore methods with a last parameter of type byte[] or short[]</html>
-convert.to.variable.arity.method.quickfix=Convert to variable arity method
+convert.to.variable.arity.method.quickfix=Convert to varargs method
mismatched.string.builder.query.update.display.name=Mismatched query and update of StringBuilder
mismatched.string.builder.updated.problem.descriptor=Contents of {0} <code>#ref</code> are updated, but never queried #loc
mismatched.string.builder.queried.problem.descriptor=Contents of {0} <code>#ref</code> are queried, but never updated #loc
@@ -2026,7 +2027,7 @@ placeholder.count.matches.argument.count.display.name=Number of placeholders doe
placeholder.count.matches.argument.count.more.problem.descriptor=<code>#ref()</code> call has more arguments ({0}) than placeholders ({1}) #loc
placeholder.count.matches.argument.count.fewer.problem.descriptor=<code>#ref()</code> call has fewer arguments ({0}) than placeholders ({1}) #loc
assignment.to.superclass.field.display.name=Constructor assigns value to field defined in superclass
-assignment.to.superclass.field.problem.descriptor=Assignment to field ''{0}'' defined in superclass ''{1}''
+assignment.to.superclass.field.problem.descriptor=Assignment to field ''{0}'' defined in superclass ''{1}'' #loc
junit.rule.display.name=Malformed @Rule/@ClassRule field
junit.rule.problem.descriptor=Fields annotated with @{0} should be {1}
junit.rule.type.problem.descriptor=Field type should be subtype of org.junit.rules.TestRule
@@ -2036,13 +2037,13 @@ inner.class.referenced.via.subclass.display.name=Inner class referenced via subc
inner.class.referenced.via.subclass.problem.descriptor=Inner class <code>#ref</code> declared in class ''{0}'' but referenced via subclass ''{1}'' #loc
inner.class.referenced.via.subclass.quickfix=Rationalize inner class access
boolean.parameter.display.name='public' method with 'boolean' parameter
-boolean.parameter.problem.descriptor='public' method <code>#ref</code> with 'boolean' parameter
-boolean.parameters.problem.descriptor='public' method <code>#ref</code> with 'boolean' parameters
-boolean.parameter.constructor.problem.descriptor='public' constructor <code>#ref</code> with 'boolean' parameter
-boolean.parameters.constructor.problem.descriptor='public' constructor <code>#ref</code> with 'boolean' parameters
+boolean.parameter.problem.descriptor='public' method <code>#ref()</code> with 'boolean' parameter #loc
+boolean.parameters.problem.descriptor='public' method <code>#ref()</code> with 'boolean' parameters #loc
+boolean.parameter.constructor.problem.descriptor='public' constructor <code>#ref()</code> with 'boolean' parameter #loc
+boolean.parameters.constructor.problem.descriptor='public' constructor <code>#ref()</code> with 'boolean' parameters #loc
boolean.parameter.only.report.multiple.option=Only report methods with multiple boolean parameters
unnecessary.unicode.escape.display.name=Unnecessary unicode escape sequence
-unnecessary.unicode.escape.problem.descriptor=Unicode escape sequence <code>#ref</code> can be replaced with ''{0}''
+unnecessary.unicode.escape.problem.descriptor=Unicode escape sequence <code>#ref</code> can be replaced with ''{0}'' #loc
missing.package.info.display.name=Missing 'package-info.java'
missing.package.info.problem.descriptor=Package ''{0}'' is missing a <code>package-info.java</code> file
missing.package.html.problem.descriptor=Package ''{0}'' is missing a <code>package.html</code> file
@@ -2051,5 +2052,16 @@ package.info.without.package.problem.descriptor='package-info.java' does not hav
package.info.without.package.quickfix=add ''package {0};''
package.info.without.package.family.quickfix=add package statement
auto.closeable.resource.display.name=AutoCloseable used without 'try'-with-resources
-auto.closeable.resource.problem.descriptor=''{0}'' used without ''try''-with-resources statement
+auto.closeable.resource.problem.descriptor=''{0}'' used without ''try''-with-resources statement #loc
auto.closeable.resource.returned.option=Ignore AutoCloseable instances returned from method calls
+problematic.whitespace.display.name=Problematic whitespace
+problematic.whitespace.tabs.problem.descriptor=File ''{0}'' uses tabs for indentation
+problematic.whitespace.spaces.problem.descriptor=File ''{0}'' uses spaces for indentation
+problematic.whitespace.show.whitespaces.quickfix=Toggle show whitespace in the editor
+problematic.varargs.method.display.name=Non-varargs method overrides varargs method
+problematic.varargs.method.override.problem.descriptor=Non-varargs method <code>#ref()</code> overrides varargs method #loc
+negatively.named.boolean.variable.problem.descriptor=Boolean variable <code>#ref</code> is negatively named #loc
+negatively.named.boolean.variable.display.name=Negatively named boolean variable
+invert.quickfix.family.name=Invert boolean
+invert.method.quickfix=Invert method
+invert.quickfix=Invert ''{0}''
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspectionVisitor.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/BaseInspectionVisitor.java
index 028b3591837f..1ba34a6235d8 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-2012 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 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.
@@ -222,17 +222,10 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor {
}
@Override
- public void visitReferenceExpression(
- PsiReferenceExpression expression) {
+ public void visitReferenceExpression(PsiReferenceExpression expression) {
visitExpression(expression);
}
- @Override
- public final void visitWhiteSpace(PsiWhiteSpace space) {
- // none of our inspections need to do anything with white space,
- // so this is a performance optimization
- }
-
public final void setProblemsHolder(ProblemsHolder holder) {
this.holder = holder;
}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/VariableNotUsedInsideIfInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/VariableNotUsedInsideIfInspection.java
index f6dc0e40fbc0..bae56e94b550 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/VariableNotUsedInsideIfInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/VariableNotUsedInsideIfInspection.java
@@ -31,15 +31,19 @@ public class VariableNotUsedInsideIfInspection extends BaseInspection {
@Nls
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "variable.not.used.inside.if.display.name");
+ return InspectionGadgetsBundle.message("variable.not.used.inside.if.display.name");
}
@Override
@NotNull
protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "variable.not.used.inside.if.problem.descriptor");
+ final boolean isIf = ((Boolean)infos[0]).booleanValue();
+ if (isIf) {
+ return InspectionGadgetsBundle.message("variable.not.used.inside.if.problem.descriptor");
+ }
+ else {
+ return InspectionGadgetsBundle.message("variable.not.used.inside.conditional.problem.descriptor");
+ }
}
@Override
@@ -63,10 +67,14 @@ public class VariableNotUsedInsideIfInspection extends BaseInspection {
}
final IElementType tokenType = binaryExpression.getOperationTokenType();
if (tokenType == JavaTokenType.EQEQ) {
- checkVariableUsage(referenceExpression, expression.getThenExpression(), expression.getElseExpression());
+ if (checkVariableUsage(referenceExpression, expression.getThenExpression(), expression.getElseExpression())) {
+ registerError(referenceExpression, Boolean.FALSE);
+ }
}
else if (tokenType == JavaTokenType.NE) {
- checkVariableUsage(referenceExpression, expression.getElseExpression(), expression.getThenExpression());
+ if (checkVariableUsage(referenceExpression, expression.getElseExpression(), expression.getThenExpression())) {
+ registerError(referenceExpression, Boolean.FALSE);
+ }
}
}
@@ -84,29 +92,30 @@ public class VariableNotUsedInsideIfInspection extends BaseInspection {
}
final IElementType tokenType = binaryExpression.getOperationTokenType();
if (tokenType == JavaTokenType.EQEQ) {
- checkVariableUsage(referenceExpression, statement.getThenBranch(), statement.getElseBranch());
+ if (checkVariableUsage(referenceExpression, statement.getThenBranch(), statement.getElseBranch())) {
+ registerError(referenceExpression, Boolean.TRUE);
+ }
}
else if (tokenType == JavaTokenType.NE) {
- checkVariableUsage(referenceExpression, statement.getElseBranch(), statement.getThenBranch());
+ if (checkVariableUsage(referenceExpression, statement.getElseBranch(), statement.getThenBranch())) {
+ registerError(referenceExpression, Boolean.TRUE);
+ }
}
}
- private void checkVariableUsage(PsiReferenceExpression referenceExpression, PsiElement thenContext, PsiElement elseContext) {
- if (thenContext == null) {
- return;
- }
+ private boolean checkVariableUsage(PsiReferenceExpression referenceExpression, PsiElement thenContext, PsiElement elseContext) {
final PsiElement target = referenceExpression.resolve();
if (!(target instanceof PsiVariable)) {
- return;
+ return false;
}
final PsiVariable variable = (PsiVariable)target;
- if (contextExits(thenContext) || VariableAccessUtils.variableIsAssigned(variable, thenContext)) {
- return;
+ if (thenContext != null && (contextExits(thenContext) || VariableAccessUtils.variableIsAssigned(variable, thenContext))) {
+ return false;
}
- if (elseContext != null && (contextExits(elseContext) || VariableAccessUtils.variableIsUsed(variable, elseContext))) {
- return;
+ if (elseContext == null || VariableAccessUtils.variableIsUsed(variable, elseContext)) {
+ return false;
}
- registerError(referenceExpression);
+ return true;
}
private static PsiReferenceExpression extractVariableReference(PsiBinaryExpression expression) {
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/dataflow/NegativelyNamedBooleanVariableInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/dataflow/NegativelyNamedBooleanVariableInspectionBase.java
new file mode 100644
index 000000000000..0d3ba0321c12
--- /dev/null
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/dataflow/NegativelyNamedBooleanVariableInspectionBase.java
@@ -0,0 +1,72 @@
+/*
+ * 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.dataflow;
+
+import com.intellij.psi.PsiType;
+import com.intellij.psi.PsiVariable;
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.BaseInspection;
+import com.siyeh.ig.BaseInspectionVisitor;
+import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class NegativelyNamedBooleanVariableInspectionBase extends BaseInspection {
+
+ @NonNls
+ private static final String[] NEGATIVE_NAMES = {"not", "isNot", "shouldNot", "shallNot", "willNot", "cannot", "cant", "hasNot",
+ "couldNot", "hidden", "isHidden", "disabled", "isDisabled"};
+
+ @Nls
+ @NotNull
+ @Override
+ public String getDisplayName() {
+ return InspectionGadgetsBundle.message("negatively.named.boolean.variable.display.name");
+ }
+
+ @NotNull
+ @Override
+ protected String buildErrorString(Object... infos) {
+ return InspectionGadgetsBundle.message("negatively.named.boolean.variable.problem.descriptor");
+ }
+
+ @Override
+ public BaseInspectionVisitor buildVisitor() {
+ return new NegativelyNamedBooleanVariableVisitor();
+ }
+
+ private static class NegativelyNamedBooleanVariableVisitor extends BaseInspectionVisitor {
+
+ @Override
+ public void visitVariable(PsiVariable variable) {
+ super.visitVariable(variable);
+ if (!PsiType.BOOLEAN.equals(variable.getType())) {
+ return;
+ }
+ final String name = variable.getName();
+ for (final String negativeName : NEGATIVE_NAMES) {
+ if (name.startsWith(negativeName) &&
+ (name.length() == negativeName.length() || Character.isUpperCase(name.charAt(negativeName.length())))) {
+ registerVariableError(variable, variable);
+ break;
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/ConvertToVarargsMethodFix.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/ConvertToVarargsMethodFix.java
new file mode 100644
index 000000000000..2c0212fafc2f
--- /dev/null
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/ConvertToVarargsMethodFix.java
@@ -0,0 +1,125 @@
+/*
+ * 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.fixes;
+
+import com.intellij.codeInsight.FileModificationService;
+import com.intellij.codeInspection.ProblemDescriptor;
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.*;
+import com.intellij.psi.search.searches.ReferencesSearch;
+import com.intellij.util.IncorrectOperationException;
+import com.intellij.util.Query;
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.InspectionGadgetsFix;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class ConvertToVarargsMethodFix extends InspectionGadgetsFix {
+
+ @Override
+ @NotNull
+ public String getFamilyName() {
+ return getName();
+ }
+
+ @NotNull
+ @Override
+ public String getName() {
+ return InspectionGadgetsBundle.message("convert.to.variable.arity.method.quickfix");
+ }
+
+ @Override
+ protected boolean prepareForWriting() {
+ return false;
+ }
+
+ @Override
+ protected void doFix(Project project, ProblemDescriptor descriptor) {
+ final PsiElement element = descriptor.getPsiElement();
+ final PsiElement parent = element.getParent();
+ if (!(parent instanceof PsiMethod)) {
+ return;
+ }
+ final PsiMethod method = (PsiMethod)parent;
+ final Collection<PsiElement> writtenElements = new ArrayList<PsiElement>();
+ final Collection<PsiReferenceExpression> methodCalls = new ArrayList<PsiReferenceExpression>();
+ writtenElements.add(method);
+ for (final PsiReference reference : ReferencesSearch.search(method, method.getUseScope(), false)) {
+ final PsiElement referenceElement = reference.getElement();
+ if (referenceElement instanceof PsiReferenceExpression) {
+ writtenElements.add(referenceElement);
+ methodCalls.add((PsiReferenceExpression)referenceElement);
+ }
+ }
+ if (!FileModificationService.getInstance().preparePsiElementsForWrite(writtenElements)) {
+ return;
+ }
+ makeMethodVarargs(method);
+ makeMethodCallsVarargs(methodCalls);
+ }
+
+ private static void makeMethodVarargs(PsiMethod method) {
+ final PsiParameterList parameterList = method.getParameterList();
+ if (parameterList.getParametersCount() == 0) {
+ return;
+ }
+ final PsiParameter[] parameters = parameterList.getParameters();
+ final PsiParameter lastParameter = parameters[parameters.length - 1];
+ final PsiType type = lastParameter.getType();
+ if (!(type instanceof PsiArrayType)) {
+ return;
+ }
+ final PsiArrayType arrayType = (PsiArrayType)type;
+ final PsiType componentType = arrayType.getComponentType();
+ final PsiElementFactory factory = JavaPsiFacade.getElementFactory(method.getProject());
+ final PsiType ellipsisType = PsiEllipsisType.createEllipsis(componentType, type.getAnnotations());
+ final PsiTypeElement newTypeElement = factory.createTypeElement(ellipsisType);
+ final PsiTypeElement typeElement = lastParameter.getTypeElement();
+ if (typeElement != null) {
+ typeElement.replace(newTypeElement);
+ }
+ }
+
+ private static void makeMethodCallsVarargs(Collection<PsiReferenceExpression> referenceExpressions) {
+ for (final PsiReferenceExpression referenceExpression : referenceExpressions) {
+ final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)referenceExpression.getParent();
+ final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
+ final PsiExpression[] arguments = argumentList.getExpressions();
+ if (arguments.length == 0) {
+ continue;
+ }
+ final PsiExpression lastArgument = arguments[arguments.length - 1];
+ if (!(lastArgument instanceof PsiNewExpression)) {
+ continue;
+ }
+ final PsiNewExpression newExpression = (PsiNewExpression)lastArgument;
+ final PsiArrayInitializerExpression arrayInitializerExpression = newExpression.getArrayInitializer();
+ if (arrayInitializerExpression == null) {
+ continue;
+ }
+ final PsiExpression[] initializers = arrayInitializerExpression.getInitializers();
+ for (final PsiExpression initializer : initializers) {
+ argumentList.add(initializer);
+ }
+ lastArgument.delete();
+ }
+ }
+}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/ProblematicVarargsMethodOverrideInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/ProblematicVarargsMethodOverrideInspection.java
new file mode 100644
index 000000000000..bf121ff8c08a
--- /dev/null
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/ProblematicVarargsMethodOverrideInspection.java
@@ -0,0 +1,81 @@
+/*
+ * 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.inheritance;
+
+import com.intellij.psi.*;
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.BaseInspection;
+import com.siyeh.ig.BaseInspectionVisitor;
+import com.siyeh.ig.InspectionGadgetsFix;
+import com.siyeh.ig.fixes.ConvertToVarargsMethodFix;
+import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class ProblematicVarargsMethodOverrideInspection extends BaseInspection {
+
+ @Nls
+ @NotNull
+ @Override
+ public String getDisplayName() {
+ return InspectionGadgetsBundle.message("problematic.varargs.method.display.name");
+ }
+
+ @NotNull
+ @Override
+ protected String buildErrorString(Object... infos) {
+ return InspectionGadgetsBundle.message("problematic.varargs.method.override.problem.descriptor");
+ }
+
+ @Nullable
+ @Override
+ protected InspectionGadgetsFix buildFix(Object... infos) {
+ return new ConvertToVarargsMethodFix();
+ }
+
+ @Override
+ public BaseInspectionVisitor buildVisitor() {
+ return new NonVarargsMethodOverridesVarArgsMethodVisitor();
+ }
+
+ private static class NonVarargsMethodOverridesVarArgsMethodVisitor extends BaseInspectionVisitor {
+
+ @Override
+ public void visitMethod(PsiMethod method) {
+ super.visitMethod(method);
+ final PsiParameterList parameterList = method.getParameterList();
+ final PsiParameter[] parameters = parameterList.getParameters();
+ if (parameters.length == 0) {
+ return;
+ }
+ final PsiParameter parameter = parameters[parameters.length - 1];
+ final PsiType type = parameter.getType();
+ if (!(type instanceof PsiArrayType)) {
+ return;
+ }
+ final PsiMethod[] superMethods = method.findDeepestSuperMethods();
+ for (final PsiMethod superMethod : superMethods) {
+ if (superMethod.isVarArgs()) {
+ registerMethodError(method);
+ return;
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/SuppressionAnnotationInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/SuppressionAnnotationInspectionBase.java
index e7bb24672173..2eb1cc379117 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/SuppressionAnnotationInspectionBase.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/SuppressionAnnotationInspectionBase.java
@@ -62,9 +62,12 @@ public class SuppressionAnnotationInspectionBase extends BaseInspection {
&& !tokenType.equals(JavaTokenType.C_STYLE_COMMENT)) {
return;
}
- @NonNls final String strippedComment = commentText.substring(2).trim();
- if (strippedComment.startsWith(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME)) {
- registerError(comment);
+
+ if (commentText.length() > 2) {
+ @NonNls final String strippedComment = commentText.substring(2).trim();
+ if (strippedComment.startsWith(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME)) {
+ registerError(comment);
+ }
}
}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspection.java
index ef1591864c0e..74a0a9b5a06e 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspection.java
@@ -15,15 +15,14 @@
*/
package com.siyeh.ig.migration;
-import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
-import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
+import com.siyeh.ig.fixes.ConvertToVarargsMethodFix;
import com.siyeh.ig.psiutils.LibraryUtil;
import com.siyeh.ig.psiutils.MethodUtils;
import org.jetbrains.annotations.Nls;
@@ -64,49 +63,7 @@ public class MethodCanBeVariableArityMethodInspection extends BaseInspection {
@Override
protected InspectionGadgetsFix buildFix(Object... infos) {
- return new MethodCanBeVariableArityMethodFix();
- }
-
- private static class MethodCanBeVariableArityMethodFix extends InspectionGadgetsFix {
- @Override
- @NotNull
- public String getFamilyName() {
- return getName();
- }
-
- @NotNull
- @Override
- public String getName() {
- return InspectionGadgetsBundle.message("convert.to.variable.arity.method.quickfix");
- }
-
- @Override
- protected void doFix(Project project, ProblemDescriptor descriptor) {
- final PsiElement element = descriptor.getPsiElement();
- final PsiElement parent = element.getParent();
- if (!(parent instanceof PsiMethod)) {
- return;
- }
- final PsiMethod method = (PsiMethod)parent;
- final PsiParameterList parameterList = method.getParameterList();
- if (parameterList.getParametersCount() == 0) {
- return;
- }
- final PsiParameter[] parameters = parameterList.getParameters();
- final PsiParameter lastParameter = parameters[parameters.length - 1];
- final PsiType type = lastParameter.getType();
- if (!(type instanceof PsiArrayType)) {
- return;
- }
- final PsiArrayType arrayType = (PsiArrayType)type;
- final PsiType componentType = arrayType.getComponentType();
- final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
- final PsiTypeElement newTypeElement = factory.createTypeElementFromText(componentType.getCanonicalText() + "...", method);
- final PsiTypeElement typeElement = lastParameter.getTypeElement();
- if (typeElement != null) {
- typeElement.replace(newTypeElement);
- }
- }
+ return new ConvertToVarargsMethodFix();
}
@Override
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java
index e8bf9a978aff..f7eeccffb09d 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java
@@ -140,7 +140,7 @@ public class UnnecessaryExplicitNumericCastInspection extends BaseInspection {
}
}
- static boolean isPrimitiveNumericCastNecessary(PsiTypeCastExpression expression) {
+ public static boolean isPrimitiveNumericCastNecessary(PsiTypeCastExpression expression) {
final PsiType castType = expression.getType();
if (castType == null) {
return true;
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/DefiniteAssignment.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/DefiniteAssignment.java
index 893de087fa06..325ddc29256c 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/DefiniteAssignment.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/DefiniteAssignment.java
@@ -13,11 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-/**
- * (c) 2013 Desert Island BV
- * created: 03 09 2013
- */
package com.siyeh.ig.psiutils;
import com.intellij.psi.*;
@@ -31,7 +26,7 @@ import java.util.Map;
/**
* @author Bas Leijdekkers
*/
-public class DefiniteAssignment {
+class DefiniteAssignment {
@NotNull
private final PsiVariable variable;