diff options
Diffstat (limited to 'plugins/InspectionGadgets/InspectionGadgetsAnalysis/src')
18 files changed, 461 insertions, 241 deletions
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml index 6abd21a87c21..e41060528212 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml @@ -1199,7 +1199,15 @@ key="html.tag.can.be.javadoc.tag.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.javadoc.issues" enabledByDefault="false" level="WARNING" implementationClass="com.siyeh.ig.javadoc.HtmlTagCanBeJavadocTagInspection"/> - <localInspection language="XML" shortName="PackageDotHtmlMayBePackageInfo" bundle="com.siyeh.InspectionGadgetsBundle" + <globalInspection language="JAVA" shortName="MissingPackageInfo" bundle="com.siyeh.InspectionGadgetsBundle" + key="missing.package.info.display.name" groupBundle="messages.InspectionsBundle" + groupKey="group.names.javadoc.issues" enabledByDefault="false" level="WARNING" + implementationClass="com.siyeh.ig.javadoc.MissingPackageInfoInspection"/> + <localInspection language="JAVA" shortName="PackageInfoWithoutPackage" bundle="com.siyeh.InspectionGadgetsBundle" + key="package.info.java.without.package.display.name" groupBundle="messages.InspectionsBundle" + groupKey="group.names.javadoc.issues" enabledByDefault="false" level="WARNING" + implementationClass="com.siyeh.ig.javadoc.PackageInfoWithoutPackageInspection"/> + <localInspection shortName="PackageDotHtmlMayBePackageInfo" bundle="com.siyeh.InspectionGadgetsBundle" key="package.dot.html.may.be.package.info.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.javadoc.issues" enabledByDefault="false" level="WARNING" implementationClass="com.siyeh.ig.javadoc.PackageDotHtmlMayBePackageInfoInspection"/> @@ -2003,6 +2011,10 @@ level="WARNING" implementationClass="com.siyeh.ig.redundancy.UnusedLabelInspection"/> <!--group.names.resource.management.issues--> + <localInspection language="JAVA" suppressId="resource" shortName="AutoCloseableResource" bundle="com.siyeh.InspectionGadgetsBundle" + key="auto.closeable.resource.display.name" groupBundle="messages.InspectionsBundle" + groupKey="group.names.resource.management.issues" enabledByDefault="false" level="WARNING" + implementationClass="com.siyeh.ig.resources.AutoCloseableResourceInspection"/> <localInspection language="JAVA" suppressId="ChannelOpenedButNotSafelyClosed" shortName="ChannelResource" bundle="com.siyeh.InspectionGadgetsBundle" key="channel.opened.not.closed.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.resource.management.issues" enabledByDefault="false" level="WARNING" diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties index 6dc0cb80118d..ec62abb3e41c 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties @@ -662,7 +662,6 @@ thrown.exceptions.per.method.display.name=Method with too many exceptions declar public.static.array.field.display.name='public static' array field await.not.in.loop.display.name='await()' not in loop method.names.differ.only.by.case.display.name=Method names differing only by case -method.names.differ.only.by.case.ignore.override.option=Ignore if method is override of super method unsecure.random.number.generation.display.name=Insecure random number generation parameters.per.method.display.name=Method with too many parameters parameters.per.constructor.display.name=Constructor with too many parameters @@ -1250,10 +1249,7 @@ pointless.nullcheck.display.name=Unnecessary 'null' check before 'instanceof' ex pointless.nullcheck.problem.descriptor=Unnecessary 'null' check before 'instanceof' expression pointless.nullcheck.simplify.quickfix=Remove unnecessary ''{0}'' condition introduce.constant.quickfix=Introduce constant -make.class.cloneable.quickfix=Make class 'Cloneable' -make.interface.cloneable.quickfix=Make interface 'Cloneable' make.initialization.explicit.quickfix=Make initialization explicit -make.class.serializable.quickfix=Make class 'Serializable' move.anonymous.to.inner.quickfix=Convert to named inner class anonymous.inner.may.be.named.static.inner.class.quickfix=Convert to named 'static' inner class move.class.quickfix=Move class @@ -1794,7 +1790,7 @@ ignore.single.field.static.imports.option=Ignore single &field static imports ignore.single.method.static.imports.option=Ignore single &method static imports ignore.methods.with.boolean.return.type.option=Ignore methods with &Boolean return type ignore.boolean.methods.in.an.interface.option=Ignore boolean methods in an @&interface -ignore.methods.overriding.super.method=Ignore methods &overriding a super method +ignore.methods.overriding.super.method=Ignore methods &overriding/implementing a super method ignored.io.resource.types=Ignored I/O resource types choose.io.resource.type.to.ignore=Choose I/O resource type to ignore ignore.accesses.from.the.same.class=Ignore accesses from the same class @@ -1903,7 +1899,6 @@ 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> -method.can.be.variable.arity.method.ignore.overriding.methods=Ignore methods overriding a super method convert.to.variable.arity.method.quickfix=Convert to variable arity 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 @@ -2042,4 +2037,14 @@ boolean.parameter.constructor.problem.descriptor='public' constructor <code>#ref boolean.parameters.constructor.problem.descriptor='public' constructor <code>#ref</code> with 'boolean' parameters 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}''
\ No newline at end of file +unnecessary.unicode.escape.problem.descriptor=Unicode escape sequence <code>#ref</code> can be replaced with ''{0}'' +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 +package.info.java.without.package.display.name='package-info.java' without 'package' statement +package.info.without.package.problem.descriptor='package-info.java' does not have a package statement +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.returned.option=Ignore AutoCloseable instances returned from method calls
\ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MismatchedCollectionQueryUpdateInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MismatchedCollectionQueryUpdateInspectionBase.java index 3a291bd6a75b..aa077a540e07 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MismatchedCollectionQueryUpdateInspectionBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MismatchedCollectionQueryUpdateInspectionBase.java @@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable; public class MismatchedCollectionQueryUpdateInspectionBase extends BaseInspection { @SuppressWarnings({"PublicField"}) public final ExternalizableStringSet queryNames = - new ExternalizableStringSet("copyInto", "drainTo", "propertyNames", "save", "store", "write"); + new ExternalizableStringSet("copyInto", "drainTo", "propertyNames", "save", "store", "write", "forEach", "replaceAll"); @SuppressWarnings({"PublicField"}) public final ExternalizableStringSet updateNames = new ExternalizableStringSet("add", "clear", "drainTo", "insert", "load", "offer", "poll", "push", "put", "remove", "replace", diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classmetrics/MethodCountInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classmetrics/MethodCountInspection.java index 53197503432e..9de4ae97e10c 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classmetrics/MethodCountInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classmetrics/MethodCountInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2010 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. @@ -23,6 +23,7 @@ import com.intellij.util.ui.UIUtil; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; +import com.siyeh.ig.psiutils.MethodUtils; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -38,6 +39,9 @@ public class MethodCountInspection extends BaseInspection { @SuppressWarnings({"PublicField"}) public boolean ignoreGettersAndSetters = false; + @SuppressWarnings("PublicField") + public boolean ignoreOverridingMethods = false; + @Override @NotNull public String getID() { @@ -53,8 +57,7 @@ public class MethodCountInspection extends BaseInspection { @Override public JComponent createOptionsPanel() { final JComponent panel = new JPanel(new GridBagLayout()); - final Component label = new JLabel( - InspectionGadgetsBundle.message("method.count.limit.option")); + final Component label = new JLabel(InspectionGadgetsBundle.message("method.count.limit.option")); final JFormattedTextField valueField = prepareNumberEditor("m_limit"); final GridBagConstraints constraints = new GridBagConstraints(); @@ -68,18 +71,23 @@ public class MethodCountInspection extends BaseInspection { constraints.insets.right = 0; panel.add(valueField, constraints); - final CheckBox gettersSettersCheckBox = new CheckBox( - InspectionGadgetsBundle.message( - "method.count.ignore.getters.setters.option"), + final CheckBox gettersSettersCheckBox = new CheckBox(InspectionGadgetsBundle.message("method.count.ignore.getters.setters.option"), this, "ignoreGettersAndSetters"); constraints.gridx = 0; constraints.gridy = 1; - constraints.weighty = 1.0; constraints.gridwidth = 2; - constraints.anchor = GridBagConstraints.NORTHWEST; + constraints.anchor = GridBagConstraints.WEST; panel.add(gettersSettersCheckBox, constraints); + final CheckBox overridingMethodCheckBox = + new CheckBox(InspectionGadgetsBundle.message("ignore.methods.overriding.super.method"), this, "ignoreOverridingMethods"); + + constraints.weighty = 1.0; + constraints.gridy = 2; + constraints.anchor = GridBagConstraints.NORTHWEST; + panel.add(overridingMethodCheckBox, constraints); + return panel; } @@ -88,8 +96,7 @@ public class MethodCountInspection extends BaseInspection { @NotNull public String buildErrorString(Object... infos) { final Integer count = (Integer)infos[0]; - return InspectionGadgetsBundle.message( - "too.many.methods.problem.descriptor", count); + return InspectionGadgetsBundle.message("too.many.methods.problem.descriptor", count); } @Override @@ -101,7 +108,6 @@ public class MethodCountInspection extends BaseInspection { @Override public void visitClass(@NotNull PsiClass aClass) { - // note: no call to super final int methodCount = calculateTotalMethodCount(aClass); if (methodCount <= m_limit) { return; @@ -117,8 +123,12 @@ public class MethodCountInspection extends BaseInspection { continue; } if (ignoreGettersAndSetters) { - if (PropertyUtil.isSimpleGetter(method) || - PropertyUtil.isSimpleSetter(method)) { + if (PropertyUtil.isSimpleGetter(method) || PropertyUtil.isSimpleSetter(method)) { + continue; + } + } + if (ignoreOverridingMethods) { + if (MethodUtils.hasSuper(method)) { continue; } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/cloneable/CloneInNonCloneableClassInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/cloneable/CloneInNonCloneableClassInspection.java index 1995e24a497a..0d210bff4dd6 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/cloneable/CloneInNonCloneableClassInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/cloneable/CloneInNonCloneableClassInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2011 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. @@ -21,7 +21,7 @@ import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; -import com.siyeh.ig.fixes.MakeCloneableFix; +import com.siyeh.ig.fixes.DelegatingFixFactory; import com.siyeh.ig.psiutils.CloneUtils; import org.jetbrains.annotations.NotNull; @@ -30,8 +30,7 @@ public class CloneInNonCloneableClassInspection extends BaseInspection { @Override @NotNull public String getDisplayName() { - return InspectionGadgetsBundle.message( - "clone.method.in.non.cloneable.class.display.name"); + return InspectionGadgetsBundle.message("clone.method.in.non.cloneable.class.display.name"); } @Override @@ -40,21 +39,16 @@ public class CloneInNonCloneableClassInspection extends BaseInspection { final PsiClass aClass = (PsiClass)infos[0]; final String className = aClass.getName(); if (aClass.isInterface()) { - return InspectionGadgetsBundle.message( - "clone.method.in.non.cloneable.interface.problem.descriptor", - className); + return InspectionGadgetsBundle.message("clone.method.in.non.cloneable.interface.problem.descriptor", className); } else { - return InspectionGadgetsBundle.message( - "clone.method.in.non.cloneable.class.problem.descriptor", - className); + return InspectionGadgetsBundle.message("clone.method.in.non.cloneable.class.problem.descriptor", className); } } @Override protected InspectionGadgetsFix buildFix(Object... infos) { - final PsiClass aClass = (PsiClass)infos[0]; - return new MakeCloneableFix(aClass.isInterface()); + return DelegatingFixFactory.createMakeCloneableFix((PsiClass)infos[0]); } @Override @@ -62,8 +56,7 @@ public class CloneInNonCloneableClassInspection extends BaseInspection { return new CloneInNonCloneableClassVisitor(); } - private static class CloneInNonCloneableClassVisitor - extends BaseInspectionVisitor { + private static class CloneInNonCloneableClassVisitor extends BaseInspectionVisitor { @Override public void visitMethod(@NotNull PsiMethod method) { @@ -71,8 +64,7 @@ public class CloneInNonCloneableClassInspection extends BaseInspection { return; } final PsiClass containingClass = method.getContainingClass(); - if (containingClass == null || - CloneUtils.isCloneable(containingClass)) { + if (CloneUtils.isCloneable(containingClass)) { return; } registerMethodError(method, containingClass); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/DelegatingFixFactory.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/DelegatingFixFactory.java new file mode 100644 index 000000000000..f83ad5aeb486 --- /dev/null +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/DelegatingFixFactory.java @@ -0,0 +1,40 @@ +/* + * 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.intention.QuickFixFactory; +import com.intellij.psi.CommonClassNames; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiClassType; +import com.siyeh.ig.DelegatingFix; +import com.siyeh.ig.InspectionGadgetsFix; +import com.siyeh.ig.psiutils.TypeUtils; + +/** + * @author Bas Leijdekkers + */ +public class DelegatingFixFactory { + + public static InspectionGadgetsFix createMakeSerializableFix(PsiClass aClass) { + final PsiClassType type = TypeUtils.getType(CommonClassNames.JAVA_IO_SERIALIZABLE, aClass); + return new DelegatingFix(QuickFixFactory.getInstance().createExtendsListFix(aClass, type, true)); + } + + public static InspectionGadgetsFix createMakeCloneableFix(PsiClass aClass) { + final PsiClassType type = TypeUtils.getType(CommonClassNames.JAVA_LANG_CLONEABLE, aClass); + return new DelegatingFix(QuickFixFactory.getInstance().createExtendsListFix(aClass, type, true)); + } +}
\ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/MakeCloneableFix.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/MakeCloneableFix.java deleted file mode 100644 index d78a3cd982d2..000000000000 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/MakeCloneableFix.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.siyeh.ig.fixes; - -import com.intellij.codeInspection.ProblemDescriptor; -import com.intellij.openapi.project.Project; -import com.intellij.psi.*; -import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.util.IncorrectOperationException; -import com.siyeh.InspectionGadgetsBundle; -import com.siyeh.ig.InspectionGadgetsFix; -import com.siyeh.ig.psiutils.ClassUtils; -import org.jetbrains.annotations.NotNull; - -public class MakeCloneableFix extends InspectionGadgetsFix { - - private final boolean isInterface; - - public MakeCloneableFix(boolean isInterface) { - this.isInterface = isInterface; - } - - @Override - @NotNull - public String getName() { - if (isInterface) { - return InspectionGadgetsBundle.message( - "make.interface.cloneable.quickfix"); - } - else { - return InspectionGadgetsBundle.message( - "make.class.cloneable.quickfix"); - } - } - - @NotNull - @Override - public String getFamilyName() { - return "Make 'Cloneable'"; - } - - @Override - public void doFix(Project project, ProblemDescriptor descriptor) - throws IncorrectOperationException { - final PsiElement nameElement = descriptor.getPsiElement(); - final PsiClass containingClass = - ClassUtils.getContainingClass(nameElement); - if (containingClass == null) { - return; - } - final PsiElementFactory elementFactory = - JavaPsiFacade.getElementFactory(project); - final GlobalSearchScope scope = GlobalSearchScope.allScope(project); - final PsiJavaCodeReferenceElement ref = - elementFactory.createReferenceElementByFQClassName( - CommonClassNames.JAVA_LANG_CLONEABLE, scope); - final PsiReferenceList extendsImplementsList; - if (containingClass.isInterface()) { - extendsImplementsList = containingClass.getExtendsList(); - } - else { - extendsImplementsList = containingClass.getImplementsList(); - } - if (extendsImplementsList == null) { - return; - } - extendsImplementsList.add(ref); - } -} diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/MakeSerializableFix.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/MakeSerializableFix.java deleted file mode 100644 index b0065c4f7a18..000000000000 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/MakeSerializableFix.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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. - * 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.codeInspection.ProblemDescriptor; -import com.intellij.openapi.project.Project; -import com.intellij.psi.*; -import com.intellij.psi.search.GlobalSearchScope; -import com.siyeh.InspectionGadgetsBundle; -import com.siyeh.ig.InspectionGadgetsFix; -import com.siyeh.ig.psiutils.ClassUtils; -import org.jetbrains.annotations.NotNull; - -public class MakeSerializableFix extends InspectionGadgetsFix { - - @Override - @NotNull - public String getName() { - return InspectionGadgetsBundle.message("make.class.serializable.quickfix"); - } - - @NotNull - @Override - public String getFamilyName() { - return getName(); - } - - @Override - public void doFix(Project project, ProblemDescriptor descriptor) { - final PsiElement nameElement = descriptor.getPsiElement(); - final PsiClass containingClass = ClassUtils.getContainingClass(nameElement); - if (containingClass == null) { - return; - } - final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); - final GlobalSearchScope scope = GlobalSearchScope.allScope(project); - final PsiJavaCodeReferenceElement referenceElement = - elementFactory.createReferenceElementByFQClassName(CommonClassNames.JAVA_IO_SERIALIZABLE, scope); - final PsiReferenceList referenceList; - if (containingClass.isInterface()) { - referenceList = containingClass.getExtendsList(); - } - else { - referenceList = containingClass.getImplementsList(); - } - if (referenceList == null) { - return; - } - referenceList.add(referenceElement); - } -}
\ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javabeans/FieldHasSetterButNoGetterInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javabeans/FieldHasSetterButNoGetterInspection.java index 93ea038b1e5d..8520823d8e57 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javabeans/FieldHasSetterButNoGetterInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javabeans/FieldHasSetterButNoGetterInspection.java @@ -52,8 +52,7 @@ public class FieldHasSetterButNoGetterInspection extends BaseInspection { @Override public void visitField(@NotNull PsiField field) { - final Project project = field.getProject(); - final String propertyName = PropertyUtil.suggestPropertyName(project, field); + final String propertyName = PropertyUtil.suggestPropertyName(field); final boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC); final PsiClass containingClass = field.getContainingClass(); final PsiMethod setter = PropertyUtil.findPropertySetter(containingClass, propertyName, isStatic, false); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javadoc/MissingPackageInfoInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javadoc/MissingPackageInfoInspection.java new file mode 100644 index 000000000000..92254308f431 --- /dev/null +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javadoc/MissingPackageInfoInspection.java @@ -0,0 +1,94 @@ +/* + * 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.javadoc; + +import com.intellij.analysis.AnalysisScope; +import com.intellij.codeInspection.CommonProblemDescriptor; +import com.intellij.codeInspection.GlobalInspectionContext; +import com.intellij.codeInspection.InspectionManager; +import com.intellij.codeInspection.reference.RefClass; +import com.intellij.codeInspection.reference.RefEntity; +import com.intellij.codeInspection.reference.RefPackage; +import com.intellij.openapi.project.Project; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiPackage; +import com.intellij.psi.util.PsiUtil; +import com.siyeh.InspectionGadgetsBundle; +import com.siyeh.ig.BaseGlobalInspection; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +/** + * @author Bas Leijdekkers + */ +public class MissingPackageInfoInspection extends BaseGlobalInspection { + + @Nls + @NotNull + @Override + public String getDisplayName() { + return InspectionGadgetsBundle.message("missing.package.info.display.name"); + } + + @Nullable + @Override + public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, + @NotNull AnalysisScope scope, + @NotNull InspectionManager manager, + @NotNull GlobalInspectionContext globalContext) { + if (!(refEntity instanceof RefPackage)) { + return null; + } + final RefPackage refPackage = (RefPackage)refEntity; + final String packageName = refPackage.getQualifiedName(); + final Project project = globalContext.getProject(); + final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(packageName); + if (aPackage == null) { + return null; + } + final List<RefEntity> children = refPackage.getChildren(); + boolean hasClasses = false; + for (RefEntity child : children) { + if (child instanceof RefClass) { + hasClasses = true; + break; + } + } + if (!hasClasses) { + return null; + } + final PsiDirectory[] directories = aPackage.getDirectories(); + for (PsiDirectory directory : directories) { + final boolean packageInfoFound = directory.findFile(PsiPackage.PACKAGE_INFO_FILE) != null; + final boolean packageDotHtmlFound = directory.findFile("package.html") != null; + if (packageInfoFound || packageDotHtmlFound) { + return null; + } + } + if (PsiUtil.isLanguageLevel5OrHigher(aPackage)) { + return new CommonProblemDescriptor[] { + manager.createProblemDescriptor(InspectionGadgetsBundle.message("missing.package.info.problem.descriptor", packageName))}; + } + else { + return new CommonProblemDescriptor[] { + manager.createProblemDescriptor(InspectionGadgetsBundle.message("missing.package.html.problem.descriptor", packageName))}; + } + } +} diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javadoc/PackageInfoWithoutPackageInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javadoc/PackageInfoWithoutPackageInspection.java new file mode 100644 index 000000000000..b0a36b3a6b4d --- /dev/null +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javadoc/PackageInfoWithoutPackageInspection.java @@ -0,0 +1,116 @@ +/* + * 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.javadoc; + +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.*; +import com.siyeh.InspectionGadgetsBundle; +import com.siyeh.ig.BaseInspection; +import com.siyeh.ig.BaseInspectionVisitor; +import com.siyeh.ig.InspectionGadgetsFix; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Bas Leijdekkers + */ +public class PackageInfoWithoutPackageInspection extends BaseInspection { + @Nls + @NotNull + @Override + public String getDisplayName() { + return InspectionGadgetsBundle.message("package.info.java.without.package.display.name"); + } + + @NotNull + @Override + protected String buildErrorString(Object... infos) { + return InspectionGadgetsBundle.message("package.info.without.package.problem.descriptor"); + } + + @Nullable + @Override + protected InspectionGadgetsFix buildFix(Object... infos) { + return new PackageInfoWithoutPackageFix((String)infos[0]); + } + + private static class PackageInfoWithoutPackageFix extends InspectionGadgetsFix { + + private final String myPackageName; + + public PackageInfoWithoutPackageFix(String packageName) { + myPackageName = packageName; + } + + @NotNull + @Override + public String getName() { + return InspectionGadgetsBundle.message("package.info.without.package.quickfix", myPackageName); + } + + @NotNull + @Override + public String getFamilyName() { + return InspectionGadgetsBundle.message("package.info.without.package.family.quickfix"); + } + + @Override + protected void doFix(Project project, ProblemDescriptor descriptor) { + final PsiElement element = descriptor.getPsiElement(); + if (!(element instanceof PsiJavaFile)) { + return; + } + final PsiJavaFile file = (PsiJavaFile)element; + final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); + final PsiPackageStatement packageStatement = factory.createPackageStatement(myPackageName); + file.add(packageStatement); + } + } + + @Override + public BaseInspectionVisitor buildVisitor() { + return new PackageInfoWithoutPackageVisitor(); + } + + private static class PackageInfoWithoutPackageVisitor extends BaseInspectionVisitor { + + @Override + public void visitJavaFile(PsiJavaFile file) { + @NonNls final String name = file.getName(); + if (!PsiPackage.PACKAGE_INFO_FILE.equals(name)) { + return; + } + final PsiPackageStatement packageStatement = file.getPackageStatement(); + if (packageStatement != null) { + return; + } + final JavaDirectoryService directoryService = JavaDirectoryService.getInstance(); + final PsiDirectory directory = file.getContainingDirectory(); + final PsiPackage aPackage = directoryService.getPackage(directory); + if (aPackage == null) { + return; + } + final String packageName = aPackage.getQualifiedName(); + if (packageName.isEmpty()) { + return; + } + registerError(file, packageName); + } + } +} diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/CloneUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/CloneUtils.java index 0ac461beead4..64558049bbec 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/CloneUtils.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/CloneUtils.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. @@ -20,14 +20,14 @@ import com.intellij.psi.util.InheritanceUtil; import com.intellij.psi.util.PsiUtil; import com.siyeh.HardcodedMethodConstants; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class CloneUtils { private CloneUtils() {} - public static boolean isCloneable(@NotNull PsiClass aClass) { - return InheritanceUtil.isInheritor(aClass, - CommonClassNames.JAVA_LANG_CLONEABLE); + public static boolean isCloneable(@Nullable PsiClass aClass) { + return InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_LANG_CLONEABLE); } public static boolean isDirectlyCloneable(@NotNull PsiClass aClass) { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/resources/AutoCloseableResourceInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/resources/AutoCloseableResourceInspection.java new file mode 100644 index 000000000000..420234af766a --- /dev/null +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/resources/AutoCloseableResourceInspection.java @@ -0,0 +1,105 @@ +/* + * 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.resources; + +import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel; +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.psiutils.TypeUtils; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +/** + * @author Bas Leijdekkers + */ +public class AutoCloseableResourceInspection extends BaseInspection { + + @SuppressWarnings("PublicField") + public boolean ignoreFromMethodCall = false; + + @Nls + @NotNull + @Override + public String getDisplayName() { + return InspectionGadgetsBundle.message("auto.closeable.resource.display.name"); + } + + @NotNull + @Override + public String getID() { + return "resource"; // matches Eclipse inspection + } + + @NotNull + @Override + protected String buildErrorString(Object... infos) { + final PsiExpression expression = (PsiExpression)infos[0]; + final PsiType type = expression.getType(); + assert type != null; + final String text = type.getPresentableText(); + return InspectionGadgetsBundle.message("auto.closeable.resource.problem.descriptor", text); + } + + @Nullable + @Override + public JComponent createOptionsPanel() { + return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message("auto.closeable.resource.returned.option"), + this, "ignoreFromMethodCall"); + } + + @Override + public BaseInspectionVisitor buildVisitor() { + return new AutoCloseableResourceVisitor(); + } + + private class AutoCloseableResourceVisitor extends BaseInspectionVisitor { + + @Override + public void visitNewExpression(PsiNewExpression expression) { + super.visitNewExpression(expression); + checkExpression(expression); + } + + @Override + public void visitMethodCallExpression(PsiMethodCallExpression expression) { + super.visitMethodCallExpression(expression); + if (ignoreFromMethodCall) { + return; + } + checkExpression(expression); + } + + private void checkExpression(PsiExpression expression) { + if (!PsiUtil.isLanguageLevel7OrHigher(expression) || !TypeUtils.expressionHasTypeOrSubtype(expression, "java.lang.AutoCloseable")) { + return; + } + final PsiVariable variable = ResourceInspection.getVariable(expression); + if (variable instanceof PsiResourceVariable) { + return; + } + if (ResourceInspection.isResourceEscapingFromMethod(variable, expression)) { + return; + } + registerError(expression, expression); + } + } +} diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/resources/ResourceInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/resources/ResourceInspection.java index 67f5c3373124..0271e4e5de13 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/resources/ResourceInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/resources/ResourceInspection.java @@ -74,6 +74,9 @@ public abstract class ResourceInspection extends BaseInspection { return; } final PsiVariable boundVariable = getVariable(expression); + if (boundVariable instanceof PsiResourceVariable) { + return; + } if (isSafelyClosed(boundVariable, expression, insideTryAllowed)) { return; } @@ -94,7 +97,7 @@ public abstract class ResourceInspection extends BaseInspection { } @Nullable - private static PsiVariable getVariable(@NotNull PsiExpression expression) { + public static PsiVariable getVariable(@NotNull PsiExpression expression) { final PsiElement parent = ParenthesesUtils.getParentSkipParentheses(expression); if (parent instanceof PsiAssignmentExpression) { final PsiAssignmentExpression assignment = (PsiAssignmentExpression)parent; @@ -261,9 +264,9 @@ public abstract class ResourceInspection extends BaseInspection { return referent != null && referent.equals(resource); } - private static boolean isResourceEscapingFromMethod(PsiVariable boundVariable, PsiExpression resourceCreationExpression) { + public static boolean isResourceEscapingFromMethod(PsiVariable boundVariable, PsiExpression resourceCreationExpression) { final PsiElement parent = ParenthesesUtils.getParentSkipParentheses(resourceCreationExpression); - if (parent instanceof PsiReturnStatement || parent instanceof PsiResourceVariable) { + if (parent instanceof PsiReturnStatement) { return true; } else if (parent instanceof PsiAssignmentExpression) { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/ComparatorNotSerializableInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/ComparatorNotSerializableInspection.java index df29cc5e3af4..38973204972c 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/ComparatorNotSerializableInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/ComparatorNotSerializableInspection.java @@ -23,7 +23,7 @@ import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; -import com.siyeh.ig.fixes.MakeSerializableFix; +import com.siyeh.ig.fixes.DelegatingFixFactory; import com.siyeh.ig.psiutils.SerializationUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,7 +45,7 @@ public class ComparatorNotSerializableInspection extends BaseInspection { @Override @Nullable protected InspectionGadgetsFix buildFix(Object... infos) { - return new MakeSerializableFix(); + return DelegatingFixFactory.createMakeSerializableFix((PsiClass)infos[0]); } @Override @@ -61,7 +61,7 @@ public class ComparatorNotSerializableInspection extends BaseInspection { SerializationUtils.isSerializable(aClass)) { return; } - registerClassError(aClass); + registerClassError(aClass, aClass); } } }
\ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/NonSerializableWithSerialVersionUIDFieldInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/NonSerializableWithSerialVersionUIDFieldInspection.java index 9a1d7ca0a280..a9b44ac6cf47 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/NonSerializableWithSerialVersionUIDFieldInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/NonSerializableWithSerialVersionUIDFieldInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2009 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. @@ -21,18 +21,16 @@ import com.intellij.psi.PsiAnonymousClass; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiField; -import com.intellij.util.IncorrectOperationException; import com.siyeh.HardcodedMethodConstants; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; -import com.siyeh.ig.fixes.MakeSerializableFix; +import com.siyeh.ig.fixes.DelegatingFixFactory; import com.siyeh.ig.psiutils.SerializationUtils; import org.jetbrains.annotations.NotNull; -public class NonSerializableWithSerialVersionUIDFieldInspection - extends BaseInspection { +public class NonSerializableWithSerialVersionUIDFieldInspection extends BaseInspection { @Override @NotNull @@ -43,8 +41,7 @@ public class NonSerializableWithSerialVersionUIDFieldInspection @Override @NotNull public String getDisplayName() { - return InspectionGadgetsBundle.message( - "non.serializable.with.serialversionuid.display.name"); + return InspectionGadgetsBundle.message("non.serializable.with.serialversionuid.display.name"); } @Override @@ -73,20 +70,18 @@ public class NonSerializableWithSerialVersionUIDFieldInspection @NotNull protected InspectionGadgetsFix[] buildFixes(Object... infos) { final PsiClass aClass = (PsiClass)infos[0]; - if (aClass.isAnnotationType() || aClass.isInterface() || - aClass instanceof PsiAnonymousClass) { + if (aClass.isAnnotationType() || aClass.isInterface() || aClass instanceof PsiAnonymousClass) { return new InspectionGadgetsFix[]{new RemoveSerialVersionUIDFix()}; } - return new InspectionGadgetsFix[]{new MakeSerializableFix(), - new RemoveSerialVersionUIDFix()}; + return new InspectionGadgetsFix[]{DelegatingFixFactory.createMakeSerializableFix(aClass), new RemoveSerialVersionUIDFix()}; } private static class RemoveSerialVersionUIDFix extends InspectionGadgetsFix { - @Override - @NotNull - public String getFamilyName() { - return getName(); - } + @Override + @NotNull + public String getFamilyName() { + return getName(); + } @Override @NotNull @@ -96,12 +91,10 @@ public class NonSerializableWithSerialVersionUIDFieldInspection } @Override - public void doFix(Project project, ProblemDescriptor descriptor) - throws IncorrectOperationException { + public void doFix(Project project, ProblemDescriptor descriptor) { final PsiElement nameElement = descriptor.getPsiElement(); final PsiClass aClass = (PsiClass)nameElement.getParent(); - final PsiField field = aClass.findFieldByName( - HardcodedMethodConstants.SERIAL_VERSION_UID, false); + final PsiField field = aClass.findFieldByName(HardcodedMethodConstants.SERIAL_VERSION_UID, false); if (field == null) { return; } @@ -114,14 +107,11 @@ public class NonSerializableWithSerialVersionUIDFieldInspection return new NonSerializableWithSerialVersionUIDVisitor(); } - private static class NonSerializableWithSerialVersionUIDVisitor - extends BaseInspectionVisitor { + private static class NonSerializableWithSerialVersionUIDVisitor extends BaseInspectionVisitor { @Override public void visitClass(@NotNull PsiClass aClass) { - // no call to super, so it doesn't drill down - final PsiField field = aClass.findFieldByName( - HardcodedMethodConstants.SERIAL_VERSION_UID, false); + final PsiField field = aClass.findFieldByName(HardcodedMethodConstants.SERIAL_VERSION_UID, false); if (field == null) { return; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/NonSerializableWithSerializationMethodsInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/NonSerializableWithSerializationMethodsInspection.java index bbadd7f5b65e..4a0750a6c8a4 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/NonSerializableWithSerializationMethodsInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/NonSerializableWithSerializationMethodsInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2009 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. @@ -15,18 +15,17 @@ */ package com.siyeh.ig.serialization; -import com.intellij.psi.PsiClass; import com.intellij.psi.PsiAnonymousClass; +import com.intellij.psi.PsiClass; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; -import com.siyeh.ig.fixes.MakeSerializableFix; +import com.siyeh.ig.fixes.DelegatingFixFactory; import com.siyeh.ig.psiutils.SerializationUtils; import org.jetbrains.annotations.NotNull; -public class NonSerializableWithSerializationMethodsInspection - extends BaseInspection { +public class NonSerializableWithSerializationMethodsInspection extends BaseInspection { @Override @NotNull @@ -37,16 +36,16 @@ public class NonSerializableWithSerializationMethodsInspection @Override @NotNull public String getDisplayName() { - return InspectionGadgetsBundle.message( - "non.serializable.class.with.readwriteobject.display.name"); + return InspectionGadgetsBundle.message("non.serializable.class.with.readwriteobject.display.name"); } @Override protected InspectionGadgetsFix buildFix(Object... infos) { - if (infos[2] instanceof PsiAnonymousClass) { + final PsiClass aClass = (PsiClass)infos[2]; + if (aClass instanceof PsiAnonymousClass) { return null; } - return new MakeSerializableFix(); + return DelegatingFixFactory.createMakeSerializableFix(aClass); } @Override @@ -87,30 +86,25 @@ public class NonSerializableWithSerializationMethodsInspection @Override public BaseInspectionVisitor buildVisitor() { - return new NonserializableDefinesSerializationMethodsVisitor(); + return new NonSerializableWithSerializationMethodsVisitor(); } - private static class NonserializableDefinesSerializationMethodsVisitor - extends BaseInspectionVisitor { + private static class NonSerializableWithSerializationMethodsVisitor extends BaseInspectionVisitor { @Override public void visitClass(@NotNull PsiClass aClass) { - // no call to super, so it doesn't drill down if (aClass.isInterface() || aClass.isAnnotationType()) { return; } - final boolean hasReadObject = - SerializationUtils.hasReadObject(aClass); - final boolean hasWriteObject = - SerializationUtils.hasWriteObject(aClass); + final boolean hasReadObject = SerializationUtils.hasReadObject(aClass); + final boolean hasWriteObject = SerializationUtils.hasWriteObject(aClass); if (!hasWriteObject && !hasReadObject) { return; } if (SerializationUtils.isSerializable(aClass)) { return; } - registerClassError(aClass, Boolean.valueOf(hasReadObject), - Boolean.valueOf(hasWriteObject), aClass); + registerClassError(aClass, Boolean.valueOf(hasReadObject), Boolean.valueOf(hasWriteObject), aClass); } } }
\ No newline at end of file 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 0d086823efc4..7e096d987ffa 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java @@ -222,7 +222,13 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection { if (type instanceof PsiPrimitiveType) { if (argument instanceof PsiLiteralExpression) { final PsiLiteralExpression literalExpression = (PsiLiteralExpression)argument; - result.append('"').append(literalExpression.getValue()).append('"'); + if (PsiType.CHAR.equals(literalExpression.getType())) { + final String text = literalExpression.getText(); + result.append('"').append(text.substring(1, text.length() - 1)).append('"'); + } + else { + result.append('"').append(literalExpression.getValue()).append('"'); + } } else { result.append("String.valueOf(").append(argumentText).append(")"); |