mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
converted to walking visitor
This commit is contained in:
+18
-15
@@ -24,15 +24,13 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class JCiPUtil {
|
||||
class JCiPUtil {
|
||||
@NonNls
|
||||
private static final String IMMUTABLE = "net.jcip.annotations.Immutable";
|
||||
@NonNls
|
||||
private static final String GUARDED_BY = "net.jcip.annotations.GuardedBy";
|
||||
@NonNls
|
||||
private static final String THREAD_SAFE = "net.jcip.annotations.ThreadSafe";
|
||||
|
||||
public static boolean isJCiPAnnotation(String ref) {
|
||||
static boolean isJCiPAnnotation(String ref) {
|
||||
return "Immutable".equals(ref) || "GuardedBy".equals(ref) || "ThreadSafe".equals("ref");
|
||||
}
|
||||
|
||||
@@ -49,18 +47,23 @@ public class JCiPUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String findGuardForMember(PsiMember member) {
|
||||
static String findGuardForMember(PsiMember member) {
|
||||
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(member, GUARDED_BY);
|
||||
if (annotation != null) {
|
||||
return getGuardValue(annotation);
|
||||
}
|
||||
|
||||
if (member instanceof PsiCompiledElement) {
|
||||
member = (PsiMember)member.getNavigationElement();
|
||||
if (member == null || member instanceof PsiCompiledElement) {
|
||||
return null; // can't analyze compiled code
|
||||
}
|
||||
}
|
||||
final GuardedTagVisitor visitor = new GuardedTagVisitor();
|
||||
member.accept(visitor);
|
||||
return visitor.getGuardString();
|
||||
}
|
||||
|
||||
public static boolean isGuardedBy(PsiMember member, String guard) {
|
||||
static boolean isGuardedBy(PsiMember member, String guard) {
|
||||
|
||||
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(member, GUARDED_BY);
|
||||
if (annotation != null) {
|
||||
@@ -69,7 +72,7 @@ public class JCiPUtil {
|
||||
final String fieldName = '"' + guard + '"';
|
||||
for (PsiNameValuePair pair : pairs) {
|
||||
final String name = pair.getName();
|
||||
if (("value".equals(name) || name == null)) {
|
||||
if ("value".equals(name) || name == null) {
|
||||
final PsiAnnotationMemberValue value = pair.getValue();
|
||||
if (value != null && value.getText().equals(fieldName)) {
|
||||
return true;
|
||||
@@ -84,18 +87,18 @@ public class JCiPUtil {
|
||||
return isGuardedBy(member, field.getName());
|
||||
}
|
||||
|
||||
public static boolean isGuardedByAnnotation(PsiAnnotation annotation) {
|
||||
static boolean isGuardedByAnnotation(PsiAnnotation annotation) {
|
||||
return GUARDED_BY.equals(annotation.getQualifiedName());
|
||||
}
|
||||
|
||||
public static boolean isGuardedByTag(PsiDocTag tag) {
|
||||
static boolean isGuardedByTag(PsiDocTag tag) {
|
||||
final String text = tag.getText();
|
||||
|
||||
return text.startsWith("@GuardedBy") && text.contains("(") && text.contains(")");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getGuardValue(PsiAnnotation annotation) {
|
||||
static String getGuardValue(PsiAnnotation annotation) {
|
||||
final PsiAnnotationParameterList parameters = annotation.getParameterList();
|
||||
final PsiNameValuePair[] pairs = parameters.getAttributes();
|
||||
for (PsiNameValuePair pair : pairs) {
|
||||
@@ -117,13 +120,13 @@ public class JCiPUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getGuardValue(PsiDocTag tag) {
|
||||
static String getGuardValue(PsiDocTag tag) {
|
||||
final String text = tag.getText();
|
||||
return text.substring(text.indexOf((int)'(') + 1, text.indexOf((int)')')).trim();
|
||||
}
|
||||
|
||||
private static class GuardedTagVisitor extends JavaRecursiveElementVisitor {
|
||||
private String guardString = null;
|
||||
private static class GuardedTagVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private String guardString;
|
||||
|
||||
@Override
|
||||
public void visitDocTag(PsiDocTag tag) {
|
||||
@@ -135,7 +138,7 @@ public class JCiPUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getGuardString() {
|
||||
private String getGuardString() {
|
||||
return guardString;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -61,9 +61,11 @@ public class StringExpressionHelper {
|
||||
if (body != null) {
|
||||
final Set<PsiExpression> returns = new com.intellij.util.containers.HashSet<PsiExpression>();
|
||||
|
||||
body.accept(new JavaRecursiveElementVisitor() {
|
||||
body.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
public void visitClass(PsiClass aClass) {}
|
||||
|
||||
@Override
|
||||
public void visitLambdaExpression(PsiLambdaExpression expression) {}
|
||||
|
||||
@Override
|
||||
@@ -129,7 +131,7 @@ public class StringExpressionHelper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Pair<PsiElement, String> evaluatePsiLiteralExpression(@NotNull PsiElement expression) {
|
||||
private static Pair<PsiElement, String> evaluatePsiLiteralExpression(@NotNull PsiElement expression) {
|
||||
return Pair.create(expression, ElementManipulators.getValueText(expression));
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -62,7 +62,7 @@ public class FieldNotUsedInToStringInspection extends AbstractToStringInspection
|
||||
|
||||
private final ProblemsHolder myHolder;
|
||||
|
||||
public FieldNotUsedInToStringVisitor(ProblemsHolder holder) {
|
||||
private FieldNotUsedInToStringVisitor(ProblemsHolder holder) {
|
||||
myHolder = holder;
|
||||
}
|
||||
|
||||
@@ -116,12 +116,12 @@ public class FieldNotUsedInToStringInspection extends AbstractToStringInspection
|
||||
}
|
||||
}
|
||||
|
||||
private static class FieldUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class FieldUsedVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final THashSet<PsiField> myUnusedFields = new THashSet<PsiField>();
|
||||
private final THashSet<PsiMethod> myUnusedMethods = new THashSet<PsiMethod>();
|
||||
|
||||
public FieldUsedVisitor(PsiField[] fields, PsiMethod[] methods) {
|
||||
FieldUsedVisitor(PsiField[] fields, PsiMethod[] methods) {
|
||||
Collections.addAll(myUnusedFields, fields);
|
||||
Collections.addAll(myUnusedMethods, methods);
|
||||
}
|
||||
@@ -168,11 +168,11 @@ public class FieldNotUsedInToStringInspection extends AbstractToStringInspection
|
||||
return false;
|
||||
}
|
||||
|
||||
public THashSet<PsiField> getUnusedFields() {
|
||||
THashSet<PsiField> getUnusedFields() {
|
||||
return myUnusedFields;
|
||||
}
|
||||
|
||||
public THashSet<PsiMethod> getUnusedMethods() {
|
||||
THashSet<PsiMethod> getUnusedMethods() {
|
||||
return myUnusedMethods;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -41,7 +41,7 @@ import java.util.List;
|
||||
public class NullityInferrer {
|
||||
private static final int MAX_PASSES = 10;
|
||||
public static final String NOTHING_FOUND_TO_INFER = "Nothing found to infer";
|
||||
private int numAnnotationsAdded = 0;
|
||||
private int numAnnotationsAdded;
|
||||
private final List<SmartPsiElementPointer<? extends PsiModifierListOwner>> myNotNullSet = new ArrayList<SmartPsiElementPointer<? extends PsiModifierListOwner>>();
|
||||
private final List<SmartPsiElementPointer<? extends PsiModifierListOwner>> myNullableSet = new ArrayList<SmartPsiElementPointer<? extends PsiModifierListOwner>>();
|
||||
private final boolean myAnnotateLocalVariables;
|
||||
@@ -62,7 +62,7 @@ public class NullityInferrer {
|
||||
return visitor.isNeverNull();
|
||||
}
|
||||
|
||||
protected boolean expressionIsSometimesNull(@Nullable PsiExpression expression) {
|
||||
private boolean expressionIsSometimesNull(@Nullable PsiExpression expression) {
|
||||
if (expression == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ public class NullityInferrer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void nothingFoundMessage(final Project project) {
|
||||
static void nothingFoundMessage(final Project project) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -234,7 +234,7 @@ public class NullityInferrer {
|
||||
}
|
||||
|
||||
private static class NullableUsageInfo extends UsageInfo {
|
||||
public NullableUsageInfo(@NotNull PsiElement element) {
|
||||
private NullableUsageInfo(@NotNull PsiElement element) {
|
||||
super(element);
|
||||
}
|
||||
}
|
||||
@@ -354,7 +354,7 @@ public class NullityInferrer {
|
||||
}
|
||||
|
||||
private class ExpressionIsSometimesNullVisitor extends JavaRecursiveElementWalkingVisitor{
|
||||
private boolean sometimesNull = false;
|
||||
private boolean sometimesNull;
|
||||
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
@@ -466,7 +466,7 @@ public class NullityInferrer {
|
||||
return myNullableSet.contains(pointer);
|
||||
}
|
||||
|
||||
private class NullityInferrerVisitor extends JavaRecursiveElementVisitor{
|
||||
private class NullityInferrerVisitor extends JavaRecursiveElementWalkingVisitor{
|
||||
|
||||
@Override
|
||||
public void visitMethod(@NotNull PsiMethod method) {
|
||||
|
||||
@@ -127,8 +127,8 @@ public class RedundantCastUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyIsRedundantVisitor extends JavaRecursiveElementVisitor {
|
||||
private boolean isRedundant = false;
|
||||
private static class MyIsRedundantVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean isRedundant;
|
||||
private final boolean myRecursive;
|
||||
|
||||
private MyIsRedundantVisitor(final boolean recursive) {
|
||||
@@ -710,7 +710,7 @@ public class RedundantCastUtil {
|
||||
return result.get().booleanValue();
|
||||
}
|
||||
|
||||
public static boolean isTypeCastSemantic(PsiTypeCastExpression typeCast) {
|
||||
private static boolean isTypeCastSemantic(PsiTypeCastExpression typeCast) {
|
||||
PsiExpression operand = typeCast.getOperand();
|
||||
if (operand == null) return false;
|
||||
|
||||
|
||||
+2
-2
@@ -17,13 +17,13 @@ class Test {
|
||||
return (str);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
String foo2(@Nullable String str) {
|
||||
if (str == null) return "null";
|
||||
return ((String)str);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
String fram(@Nullable String str, boolean b) {
|
||||
if (str != null) {
|
||||
return b ? str : "not null strimg";
|
||||
|
||||
@@ -50,7 +50,7 @@ public class Extensions {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ExtensionsArea getArea(@Nullable AreaInstance areaInstance) {
|
||||
public static ExtensionsArea getArea(@Nullable("null means root") AreaInstance areaInstance) {
|
||||
if (areaInstance == null) {
|
||||
return ourRootArea;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class Extensions {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> T[] getExtensions(String extensionPointName, @Nullable AreaInstance areaInstance) {
|
||||
public static <T> T[] getExtensions(String extensionPointName, @Nullable("null means root") AreaInstance areaInstance) {
|
||||
ExtensionsArea area = getArea(areaInstance);
|
||||
ExtensionPoint<T> extensionPoint = area.getExtensionPoint(extensionPointName);
|
||||
return extensionPoint.getExtensions();
|
||||
@@ -122,7 +122,7 @@ public class Extensions {
|
||||
throw new IllegalArgumentException("could not find extension implementation " + extClass);
|
||||
}
|
||||
|
||||
public static void instantiateArea(@NonNls @NotNull String areaClass, @NotNull AreaInstance areaInstance, @Nullable AreaInstance parentAreaInstance) {
|
||||
public static void instantiateArea(@NonNls @NotNull String areaClass, @NotNull AreaInstance areaInstance, @Nullable("null means root") AreaInstance parentAreaInstance) {
|
||||
AreaClassConfiguration configuration = ourAreaClass2Configuration.get(areaClass);
|
||||
if (configuration == null) {
|
||||
throw new IllegalArgumentException("Area class is not registered: " + areaClass);
|
||||
|
||||
+3
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -25,7 +25,6 @@ import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.CommonProcessors;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.hash.HashSet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -35,7 +34,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public class BooleanMethodIsAlwaysInvertedInspectionBase extends GlobalJavaBatchInspectionTool {
|
||||
class BooleanMethodIsAlwaysInvertedInspectionBase extends GlobalJavaBatchInspectionTool {
|
||||
private static final Key<Boolean> ALWAYS_INVERTED = Key.create("ALWAYS_INVERTED_METHOD");
|
||||
|
||||
private static boolean hasNonInvertedCalls(final RefMethod refMethod) {
|
||||
@@ -67,7 +66,7 @@ public class BooleanMethodIsAlwaysInvertedInspectionBase extends GlobalJavaBatch
|
||||
if (!(psiElement instanceof PsiMethod)) return;
|
||||
final PsiMethod psiMethod = (PsiMethod)psiElement;
|
||||
if (!PsiType.BOOLEAN.equals(psiMethod.getReturnType())) return;
|
||||
element.accept(new JavaRecursiveElementVisitor() {
|
||||
element.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
public void visitMethodCallExpression(PsiMethodCallExpression call) {
|
||||
super.visitMethodCallExpression(call);
|
||||
|
||||
+5
-6
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.siyeh.ig.abstraction;
|
||||
|
||||
import com.intellij.psi.JavaRecursiveElementVisitor;
|
||||
import com.intellij.psi.JavaRecursiveElementWalkingVisitor;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiMethodCallExpression;
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
class ClassAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
class ClassAccessVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final Map<PsiClass, Integer> m_accessCounts =
|
||||
new HashMap<PsiClass, Integer>(2);
|
||||
@@ -35,7 +35,6 @@ class ClassAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
private final PsiClass currentClass;
|
||||
|
||||
ClassAccessVisitor(PsiClass currentClass) {
|
||||
super();
|
||||
this.currentClass = currentClass;
|
||||
}
|
||||
|
||||
@@ -78,17 +77,17 @@ class ClassAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
final Map<PsiClass, Integer> accessCounts = m_accessCounts;
|
||||
final Integer count = accessCounts.get(calledClass);
|
||||
if (count == null) {
|
||||
accessCounts.put(calledClass, Integer.valueOf(1));
|
||||
accessCounts.put(calledClass, 1);
|
||||
}
|
||||
else if (count.equals(Integer.valueOf(1))) {
|
||||
accessCounts.put(calledClass, Integer.valueOf(2));
|
||||
accessCounts.put(calledClass, 2);
|
||||
}
|
||||
else {
|
||||
overAccessedClasses.add(calledClass);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<PsiClass> getOveraccessedClasses() {
|
||||
Set<PsiClass> getOveraccessedClasses() {
|
||||
return Collections.unmodifiableSet(m_overAccessedClasses);
|
||||
}
|
||||
}
|
||||
+6
-8
@@ -74,11 +74,10 @@ public class AssertWithSideEffectsInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private static class SideEffectVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class SideEffectVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean hasSideEffects;
|
||||
|
||||
private boolean hasSideEffects = false;
|
||||
|
||||
public boolean hasSideEffects() {
|
||||
boolean hasSideEffects() {
|
||||
return hasSideEffects;
|
||||
}
|
||||
|
||||
@@ -146,9 +145,8 @@ public class AssertWithSideEffectsInspection extends BaseInspection {
|
||||
return visitor.hasSideEffects();
|
||||
}
|
||||
|
||||
private static class MethodSideEffectVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean hasSideEffects = false;
|
||||
private static class MethodSideEffectVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean hasSideEffects;
|
||||
|
||||
@Override
|
||||
public void visitAssignmentExpression(PsiAssignmentExpression expression) {
|
||||
@@ -194,7 +192,7 @@ public class AssertWithSideEffectsInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasSideEffects() {
|
||||
private boolean hasSideEffects() {
|
||||
return hasSideEffects;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
class CollectionQueryUpdateCalledVisitor extends JavaRecursiveElementVisitor {
|
||||
class CollectionQueryUpdateCalledVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private static final HashSet<String> COLLECTIONS_QUERIES =
|
||||
ContainerUtil.newHashSet("binarySearch", "disjoint", "frequency", "indexOfSubList", "lastIndexOfSubList", "max", "min", "nCopies",
|
||||
@@ -46,7 +46,7 @@ class CollectionQueryUpdateCalledVisitor extends JavaRecursiveElementVisitor {
|
||||
@NonNls private final Set<String> myQueryUpdateNames;
|
||||
private final boolean myCheckForQuery;
|
||||
|
||||
private boolean myQueriedUpdated = false;
|
||||
private boolean myQueriedUpdated;
|
||||
private final PsiVariable variable;
|
||||
|
||||
CollectionQueryUpdateCalledVisitor(@Nullable PsiVariable variable, Set<String> queryUpdateNames, boolean checkForQuery) {
|
||||
@@ -245,7 +245,7 @@ class CollectionQueryUpdateCalledVisitor extends JavaRecursiveElementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isQueriedUpdated() {
|
||||
boolean isQueriedUpdated() {
|
||||
return myQueriedUpdated;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -81,12 +81,12 @@ public class ComparatorMethodParameterNotUsedInspection
|
||||
}
|
||||
|
||||
private static class ParameterAccessVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final Set<PsiParameter> parameters;
|
||||
|
||||
ParameterAccessVisitor(@NotNull PsiParameter[] parameters) {
|
||||
this.parameters = new HashSet(Arrays.asList(parameters));
|
||||
private ParameterAccessVisitor(@NotNull PsiParameter[] parameters) {
|
||||
this.parameters = new HashSet<PsiParameter>(Arrays.asList(parameters));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,7 +109,7 @@ public class ComparatorMethodParameterNotUsedInspection
|
||||
parameters.remove(parameter);
|
||||
}
|
||||
|
||||
public Collection<PsiParameter> getUnusedParameters() {
|
||||
private Collection<PsiParameter> getUnusedParameters() {
|
||||
return Collections.unmodifiableSet(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -151,13 +151,12 @@ public class ForLoopThatDoesntUseLoopVariableInspection
|
||||
}
|
||||
}
|
||||
|
||||
private static class UseVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class UseVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiLocalVariable variable;
|
||||
private boolean used = false;
|
||||
private boolean used;
|
||||
|
||||
private UseVisitor(PsiLocalVariable var) {
|
||||
super();
|
||||
variable = var;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -84,9 +84,9 @@ public class IteratorNextDoesNotThrowNoSuchElementExceptionInspection
|
||||
}
|
||||
|
||||
private static class CalledMethodsVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean noSuchElementExceptionThrown = false;
|
||||
private boolean noSuchElementExceptionThrown;
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(
|
||||
@@ -110,7 +110,7 @@ public class IteratorNextDoesNotThrowNoSuchElementExceptionInspection
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNoSuchElementExceptionThrown() {
|
||||
boolean isNoSuchElementExceptionThrown() {
|
||||
return noSuchElementExceptionThrown;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -185,7 +185,7 @@ public class MismatchedArrayReadWriteInspection extends BaseInspection {
|
||||
final PsiArrayInitializerExpression arrayInitializer = newExpression.getArrayInitializer();
|
||||
return arrayInitializer == null || isDefaultArrayInitializer(arrayInitializer);
|
||||
}
|
||||
else if (initializer instanceof PsiArrayInitializerExpression) {
|
||||
if (initializer instanceof PsiArrayInitializerExpression) {
|
||||
final PsiArrayInitializerExpression arrayInitializerExpression = (PsiArrayInitializerExpression)initializer;
|
||||
final PsiExpression[] initializers = arrayInitializerExpression.getInitializers();
|
||||
return initializers.length == 0;
|
||||
@@ -193,27 +193,27 @@ public class MismatchedArrayReadWriteInspection extends BaseInspection {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean variableIsWritten(@NotNull PsiVariable variable, @NotNull PsiElement context) {
|
||||
private static boolean variableIsWritten(@NotNull PsiVariable variable, @NotNull PsiElement context) {
|
||||
final VariableReadWriteVisitor visitor = new VariableReadWriteVisitor(variable, true);
|
||||
context.accept(visitor);
|
||||
return visitor.isPassed();
|
||||
}
|
||||
|
||||
public static boolean variableIsRead(@NotNull PsiVariable variable, @NotNull PsiElement context) {
|
||||
private static boolean variableIsRead(@NotNull PsiVariable variable, @NotNull PsiElement context) {
|
||||
final VariableReadWriteVisitor visitor =
|
||||
new VariableReadWriteVisitor(variable, false);
|
||||
context.accept(visitor);
|
||||
return visitor.isPassed();
|
||||
}
|
||||
|
||||
static class VariableReadWriteVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class VariableReadWriteVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
@NotNull
|
||||
private final PsiVariable variable;
|
||||
private final boolean write;
|
||||
private boolean passed = false;
|
||||
private boolean passed;
|
||||
|
||||
VariableReadWriteVisitor(@NotNull PsiVariable variable, boolean write) {
|
||||
private VariableReadWriteVisitor(@NotNull PsiVariable variable, boolean write) {
|
||||
this.variable = variable;
|
||||
this.write = write;
|
||||
}
|
||||
|
||||
+6
-7
@@ -42,11 +42,11 @@ public class MismatchedCollectionQueryUpdateInspectionBase extends BaseInspectio
|
||||
UPDATE_EXCLUDES.add("java.util.Collections");
|
||||
}
|
||||
|
||||
@SuppressWarnings({"PublicField"})
|
||||
@SuppressWarnings("PublicField")
|
||||
public final ExternalizableStringSet queryNames =
|
||||
new ExternalizableStringSet("copyInto", "drainTo", "parallelStream", "propertyNames", "save", "store", "stream", "write", "forEach",
|
||||
"replaceAll");
|
||||
@SuppressWarnings({"PublicField"})
|
||||
@SuppressWarnings("PublicField")
|
||||
public final ExternalizableStringSet updateNames =
|
||||
new ExternalizableStringSet("add", "clear", "drainTo", "insert", "load", "offer", "poll", "push", "put", "remove", "replace",
|
||||
"retain", "set", "take", "compute");
|
||||
@@ -121,12 +121,11 @@ public class MismatchedCollectionQueryUpdateInspectionBase extends BaseInspectio
|
||||
return new MismatchedCollectionQueryUpdateVisitor();
|
||||
}
|
||||
|
||||
private static class CollectionQueriedByAssignmentVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean mayBeQueried = false;
|
||||
private static class CollectionQueriedByAssignmentVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean mayBeQueried;
|
||||
@NotNull private final PsiVariable variable;
|
||||
|
||||
CollectionQueriedByAssignmentVisitor(@NotNull PsiVariable variable) {
|
||||
private CollectionQueriedByAssignmentVisitor(@NotNull PsiVariable variable) {
|
||||
this.variable = variable;
|
||||
}
|
||||
|
||||
@@ -181,7 +180,7 @@ public class MismatchedCollectionQueryUpdateInspectionBase extends BaseInspectio
|
||||
mayBeQueried = true;
|
||||
}
|
||||
|
||||
public boolean mayBeQueried() {
|
||||
private boolean mayBeQueried() {
|
||||
return mayBeQueried;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-13
@@ -35,7 +35,7 @@ import java.util.Set;
|
||||
public class MismatchedStringBuilderQueryUpdateInspection extends BaseInspection {
|
||||
|
||||
@NonNls
|
||||
private static final Set<String> returnSelfNames = new HashSet();
|
||||
private static final Set<String> returnSelfNames = new HashSet<String>();
|
||||
|
||||
static {
|
||||
returnSelfNames.add("append");
|
||||
@@ -198,10 +198,9 @@ public class MismatchedStringBuilderQueryUpdateInspection extends BaseInspection
|
||||
return visitor.isUpdated();
|
||||
}
|
||||
|
||||
private static class StringBuilderUpdateCalledVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private static class StringBuilderUpdateCalledVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
@NonNls
|
||||
private static final Set<String> updateNames = new HashSet();
|
||||
private static final Set<String> updateNames = new HashSet<String>();
|
||||
|
||||
static {
|
||||
updateNames.add("append");
|
||||
@@ -215,7 +214,7 @@ public class MismatchedStringBuilderQueryUpdateInspection extends BaseInspection
|
||||
}
|
||||
|
||||
private final PsiVariable variable;
|
||||
boolean updated = false;
|
||||
private boolean updated;
|
||||
|
||||
public StringBuilderUpdateCalledVisitor(PsiVariable variable) {
|
||||
this.variable = variable;
|
||||
@@ -255,16 +254,15 @@ public class MismatchedStringBuilderQueryUpdateInspection extends BaseInspection
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isStringBuilderQueried(PsiVariable variable, PsiElement context) {
|
||||
private static boolean isStringBuilderQueried(PsiVariable variable, PsiElement context) {
|
||||
final StringBuilderQueryCalledVisitor visitor = new StringBuilderQueryCalledVisitor(variable);
|
||||
context.accept(visitor);
|
||||
return visitor.isQueried();
|
||||
}
|
||||
|
||||
private static class StringBuilderQueryCalledVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private static class StringBuilderQueryCalledVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
@NonNls
|
||||
private static final Set<String> queryNames = new HashSet();
|
||||
private static final Set<String> queryNames = new HashSet<String>();
|
||||
|
||||
static {
|
||||
queryNames.add("toString");
|
||||
@@ -285,7 +283,7 @@ public class MismatchedStringBuilderQueryUpdateInspection extends BaseInspection
|
||||
}
|
||||
|
||||
private final PsiVariable variable;
|
||||
private boolean queried = false;
|
||||
private boolean queried;
|
||||
|
||||
private StringBuilderQueryCalledVisitor(PsiVariable variable) {
|
||||
this.variable = variable;
|
||||
@@ -356,14 +354,14 @@ public class MismatchedStringBuilderQueryUpdateInspection extends BaseInspection
|
||||
final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)parent;
|
||||
return isVariableValueUsed(parenthesizedExpression);
|
||||
}
|
||||
else if (parent instanceof PsiTypeCastExpression) {
|
||||
if (parent instanceof PsiTypeCastExpression) {
|
||||
final PsiTypeCastExpression typeCastExpression = (PsiTypeCastExpression)parent;
|
||||
return isVariableValueUsed(typeCastExpression);
|
||||
}
|
||||
else if (parent instanceof PsiReturnStatement) {
|
||||
if (parent instanceof PsiReturnStatement) {
|
||||
return true;
|
||||
}
|
||||
else if (parent instanceof PsiExpressionList) {
|
||||
if (parent instanceof PsiExpressionList) {
|
||||
final PsiElement grandParent = parent.getParent();
|
||||
if (grandParent instanceof PsiMethodCallExpression) {
|
||||
return true;
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -20,8 +20,8 @@ import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class NonFinalFieldsVisitor extends BaseInspectionVisitor {
|
||||
protected void checkUsedNonFinalFields(PsiMethod method) {
|
||||
method.accept(new JavaRecursiveElementVisitor() {
|
||||
void checkUsedNonFinalFields(PsiMethod method) {
|
||||
method.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
|
||||
@Override
|
||||
public void visitClass(PsiClass aClass) {
|
||||
|
||||
+2
-3
@@ -20,14 +20,13 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class ParameterClassCheckVisitor extends JavaRecursiveElementVisitor {
|
||||
class ParameterClassCheckVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiParameter parameter;
|
||||
|
||||
private boolean checked = false;
|
||||
private boolean checked;
|
||||
|
||||
ParameterClassCheckVisitor(@NotNull PsiParameter parameter) {
|
||||
super();
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
|
||||
+2
-5
@@ -18,11 +18,8 @@ package com.siyeh.ig.bugs;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class ThisPassedAsArgumentVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean passed = false;
|
||||
|
||||
public ThisPassedAsArgumentVisitor() {}
|
||||
class ThisPassedAsArgumentVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean passed;
|
||||
|
||||
@Override
|
||||
public void visitElement(@NotNull PsiElement element) {
|
||||
|
||||
+3
-4
@@ -27,8 +27,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
class CouplingVisitor extends JavaRecursiveElementVisitor {
|
||||
private boolean m_inClass = false;
|
||||
class CouplingVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean m_inClass;
|
||||
private final PsiClass m_class;
|
||||
private final boolean m_includeJavaClasses;
|
||||
private final boolean m_includeLibraryClasses;
|
||||
@@ -36,7 +36,6 @@ class CouplingVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
CouplingVisitor(PsiClass aClass, boolean includeJavaClasses,
|
||||
boolean includeLibraryClasses) {
|
||||
super();
|
||||
m_class = aClass;
|
||||
m_includeJavaClasses = includeJavaClasses;
|
||||
m_includeLibraryClasses = includeLibraryClasses;
|
||||
@@ -185,7 +184,7 @@ class CouplingVisitor extends JavaRecursiveElementVisitor {
|
||||
m_dependencies.add(baseTypeName);
|
||||
}
|
||||
|
||||
public int getNumDependencies() {
|
||||
int getNumDependencies() {
|
||||
return m_dependencies.size();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CyclomaticComplexityVisitor extends JavaRecursiveElementVisitor {
|
||||
public class CyclomaticComplexityVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private int m_complexity = 1;
|
||||
|
||||
@Override
|
||||
|
||||
+3
-4
@@ -19,9 +19,8 @@ import com.intellij.psi.*;
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class CallToSuperCloneVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean callToSuperCloneFound = false;
|
||||
class CallToSuperCloneVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean callToSuperCloneFound;
|
||||
|
||||
@Override
|
||||
public void visitElement(@NotNull PsiElement element) {
|
||||
@@ -51,7 +50,7 @@ class CallToSuperCloneVisitor extends JavaRecursiveElementVisitor {
|
||||
callToSuperCloneFound = true;
|
||||
}
|
||||
|
||||
public boolean isCallToSuperCloneFound() {
|
||||
boolean isCallToSuperCloneFound() {
|
||||
return callToSuperCloneFound;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class CloneCallsConstructorsInspection extends BaseInspection {
|
||||
if (aClass == null || aClass.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
return;
|
||||
}
|
||||
method.accept(new JavaRecursiveElementVisitor() {
|
||||
method.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
|
||||
@Override
|
||||
public void visitNewExpression(
|
||||
|
||||
+13
-16
@@ -53,7 +53,7 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean m_ignoreExpressionsContainingConstants = false;
|
||||
public boolean m_ignoreExpressionsContainingConstants;
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
@@ -104,13 +104,13 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
private void buildSimplifiedPolyadicExpression(PsiPolyadicExpression expression, StringBuilder out) {
|
||||
final IElementType tokenType = expression.getOperationTokenType();
|
||||
final PsiExpression[] operands = expression.getOperands();
|
||||
final List<PsiExpression> expressions = new ArrayList();
|
||||
final List<PsiExpression> expressions = new ArrayList<PsiExpression>();
|
||||
if (tokenType.equals(JavaTokenType.ANDAND) || tokenType.equals(JavaTokenType.AND)) {
|
||||
for (PsiExpression operand : operands) {
|
||||
if (evaluate(operand) == Boolean.TRUE) {
|
||||
continue;
|
||||
}
|
||||
else if (evaluate(operand) == Boolean.FALSE) {
|
||||
if (evaluate(operand) == Boolean.FALSE) {
|
||||
out.append(PsiKeyword.FALSE);
|
||||
return;
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
if (evaluate(operand) == Boolean.FALSE) {
|
||||
continue;
|
||||
}
|
||||
else if (evaluate(operand) == Boolean.TRUE) {
|
||||
if (evaluate(operand) == Boolean.TRUE) {
|
||||
out.append(PsiKeyword.TRUE);
|
||||
return;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
if (evaluate(operand) == Boolean.FALSE) {
|
||||
continue;
|
||||
}
|
||||
else if (evaluate(operand) == Boolean.TRUE) {
|
||||
if (evaluate(operand) == Boolean.TRUE) {
|
||||
negate = !negate;
|
||||
continue;
|
||||
}
|
||||
@@ -167,7 +167,7 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
if (evaluate(operand) == Boolean.TRUE) {
|
||||
continue;
|
||||
}
|
||||
else if (evaluate(operand) == Boolean.FALSE) {
|
||||
if (evaluate(operand) == Boolean.FALSE) {
|
||||
negate = !negate;
|
||||
continue;
|
||||
}
|
||||
@@ -322,7 +322,7 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
if (expression instanceof PsiPrefixExpression) {
|
||||
return evaluate(expression) != null;
|
||||
}
|
||||
else if (expression instanceof PsiPolyadicExpression) {
|
||||
if (expression instanceof PsiPolyadicExpression) {
|
||||
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
|
||||
final IElementType sign = polyadicExpression.getOperationTokenType();
|
||||
if (!booleanTokens.contains(sign)) {
|
||||
@@ -338,12 +338,9 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
if (type == null || !type.equals(PsiType.BOOLEAN) && !type.equalsToText(CommonClassNames.JAVA_LANG_BOOLEAN)) {
|
||||
return false;
|
||||
}
|
||||
containsConstant |= (evaluate(operand) != null);
|
||||
containsConstant |= evaluate(operand) != null;
|
||||
}
|
||||
if (!containsConstant) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return containsConstant;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -358,7 +355,7 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)expression;
|
||||
return evaluate(parenthesizedExpression.getExpression());
|
||||
}
|
||||
else if (expression instanceof PsiPolyadicExpression) {
|
||||
if (expression instanceof PsiPolyadicExpression) {
|
||||
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
|
||||
final IElementType tokenType = polyadicExpression.getOperationTokenType();
|
||||
if (tokenType.equals(JavaTokenType.OROR)) {
|
||||
@@ -404,9 +401,9 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
return visitor.containsReference();
|
||||
}
|
||||
|
||||
private static class ReferenceVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class ReferenceVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean referenceFound = false;
|
||||
private boolean referenceFound;
|
||||
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
@@ -427,7 +424,7 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsReference() {
|
||||
private boolean containsReference() {
|
||||
return referenceFound;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-6
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.siyeh.ig.controlflow;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.codeInspection.ui.SingleIntegerFieldOptionsPanel;
|
||||
import com.intellij.psi.*;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
@@ -72,7 +72,7 @@ public class SwitchStatementDensityInspection extends BaseInspection {
|
||||
if (intDensity > m_limit) {
|
||||
return;
|
||||
}
|
||||
registerStatementError(statement, Integer.valueOf(intDensity));
|
||||
registerStatementError(statement, intDensity);
|
||||
}
|
||||
|
||||
private double calculateDensity(@NotNull PsiCodeBlock body, int branchCount) {
|
||||
@@ -82,9 +82,8 @@ public class SwitchStatementDensityInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private static class StatementCountVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private int statementCount = 0;
|
||||
private static class StatementCountVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private int statementCount;
|
||||
|
||||
@Override
|
||||
public void visitStatement(@NotNull PsiStatement statement) {
|
||||
@@ -95,7 +94,7 @@ public class SwitchStatementDensityInspection extends BaseInspection {
|
||||
statementCount++;
|
||||
}
|
||||
|
||||
public int getStatementCount() {
|
||||
int getStatementCount() {
|
||||
return statementCount;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -80,11 +80,11 @@ public class SwitchStatementWithConfusingDeclarationInspection extends BaseInspe
|
||||
}
|
||||
}
|
||||
|
||||
class LocalVariableAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
private class LocalVariableAccessVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final Set<PsiLocalVariable> myVariablesInPreviousBranches;
|
||||
|
||||
public LocalVariableAccessVisitor(Set<PsiLocalVariable> variablesInPreviousBranches) {
|
||||
private LocalVariableAccessVisitor(Set<PsiLocalVariable> variablesInPreviousBranches) {
|
||||
myVariablesInPreviousBranches = variablesInPreviousBranches;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -25,7 +25,7 @@ import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BooleanVariableAlwaysNegatedInspectionBase extends BaseInspection {
|
||||
class BooleanVariableAlwaysNegatedInspectionBase extends BaseInspection {
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@@ -94,11 +94,11 @@ public class BooleanVariableAlwaysNegatedInspectionBase extends BaseInspection {
|
||||
}
|
||||
|
||||
private static class AlwaysNegatedVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiVariable variable;
|
||||
private boolean alwaysNegated = true;
|
||||
private boolean read = false;
|
||||
private boolean read;
|
||||
|
||||
private AlwaysNegatedVisitor(PsiVariable variable) {
|
||||
this.variable = variable;
|
||||
@@ -143,7 +143,7 @@ public class BooleanVariableAlwaysNegatedInspectionBase extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAlwaysNegated() {
|
||||
boolean isAlwaysNegated() {
|
||||
return alwaysNegated;
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -15,19 +15,18 @@
|
||||
*/
|
||||
package com.siyeh.ig.errorhandling;
|
||||
|
||||
import com.intellij.psi.JavaRecursiveElementVisitor;
|
||||
import com.intellij.psi.JavaRecursiveElementWalkingVisitor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import com.intellij.psi.PsiReferenceExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class CatchParameterUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
class CatchParameterUsedVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiParameter parameter;
|
||||
private boolean used = false;
|
||||
private boolean used;
|
||||
|
||||
CatchParameterUsedVisitor(PsiParameter variable) {
|
||||
super();
|
||||
parameter = variable;
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -37,10 +37,10 @@ import java.util.Set;
|
||||
public class ExceptionFromCatchWhichDoesntWrapInspection extends BaseInspection {
|
||||
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean ignoreGetMessage = false;
|
||||
public boolean ignoreGetMessage;
|
||||
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean ignoreCantWrap = false;
|
||||
public boolean ignoreCantWrap;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -131,13 +131,13 @@ public class ExceptionFromCatchWhichDoesntWrapInspection extends BaseInspection
|
||||
}
|
||||
}
|
||||
|
||||
private class ReferenceFinder extends JavaRecursiveElementVisitor {
|
||||
private class ReferenceFinder extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final Set<PsiReferenceExpression> visited = new HashSet();
|
||||
private boolean argumentsContainCatchParameter = false;
|
||||
private final Set<PsiReferenceExpression> visited = new HashSet<PsiReferenceExpression>();
|
||||
private boolean argumentsContainCatchParameter;
|
||||
private final PsiParameter parameter;
|
||||
|
||||
public ReferenceFinder(PsiParameter parameter) {
|
||||
ReferenceFinder(PsiParameter parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ public class ExceptionFromCatchWhichDoesntWrapInspection extends BaseInspection
|
||||
}
|
||||
}
|
||||
|
||||
public boolean usesParameter() {
|
||||
boolean usesParameter() {
|
||||
return argumentsContainCatchParameter;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -20,9 +20,8 @@ import com.siyeh.HardcodedMethodConstants;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class CallToSuperFinalizeVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean callToSuperFinalizeFound = false;
|
||||
class CallToSuperFinalizeVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean callToSuperFinalizeFound;
|
||||
|
||||
@Override
|
||||
public void visitElement(@NotNull PsiElement element) {
|
||||
@@ -62,7 +61,7 @@ class CallToSuperFinalizeVisitor extends JavaRecursiveElementVisitor {
|
||||
callToSuperFinalizeFound = true;
|
||||
}
|
||||
|
||||
public boolean isCallToSuperFinalizeFound() {
|
||||
boolean isCallToSuperFinalizeFound() {
|
||||
return callToSuperFinalizeFound;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -26,7 +26,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
class ImportsAreUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
class ImportsAreUsedVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiJavaFile myFile;
|
||||
private final List<PsiImportStatementBase> importStatements;
|
||||
@@ -142,7 +142,7 @@ class ImportsAreUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PsiImportStatementBase[] getUnusedImportStatements() {
|
||||
PsiImportStatementBase[] getUnusedImportStatements() {
|
||||
if (importStatements.isEmpty()) {
|
||||
return PsiImportStatementBase.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
+5
-5
@@ -31,12 +31,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class RefusedBequestInspectionBase extends BaseInspection {
|
||||
|
||||
@SuppressWarnings("PublicField") public boolean ignoreEmptySuperMethods = false;
|
||||
@SuppressWarnings("PublicField") public boolean ignoreEmptySuperMethods;
|
||||
|
||||
@SuppressWarnings("PublicField") final ExternalizableStringSet annotations =
|
||||
new ExternalizableStringSet("javax.annotation.OverridingMethodsMustInvokeSuper");
|
||||
|
||||
@SuppressWarnings("PublicField") boolean onlyReportWhenAnnotated = false;
|
||||
@SuppressWarnings("PublicField") boolean onlyReportWhenAnnotated;
|
||||
|
||||
@Override
|
||||
public void writeSettings(@NotNull Element node) throws WriteExternalException {
|
||||
@@ -143,10 +143,10 @@ public class RefusedBequestInspectionBase extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private static class SuperCallVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class SuperCallVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiMethod methodToSearchFor;
|
||||
private boolean hasSuperCall = false;
|
||||
private boolean hasSuperCall;
|
||||
|
||||
SuperCallVisitor(PsiMethod methodToSearchFor) {
|
||||
this.methodToSearchFor = methodToSearchFor;
|
||||
@@ -185,7 +185,7 @@ public class RefusedBequestInspectionBase extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasSuperCall() {
|
||||
boolean hasSuperCall() {
|
||||
return hasSuperCall;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -166,13 +166,11 @@ public class ConnectionResourceInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private static class CloseVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean containsClose = false;
|
||||
private static class CloseVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean containsClose;
|
||||
private final PsiVariable objectToClose;
|
||||
|
||||
private CloseVisitor(PsiVariable objectToClose) {
|
||||
super();
|
||||
this.objectToClose = objectToClose;
|
||||
}
|
||||
|
||||
@@ -213,7 +211,7 @@ public class ConnectionResourceInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsStreamClose() {
|
||||
boolean containsStreamClose() {
|
||||
return containsClose;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -77,7 +77,7 @@ public class MethodCallInLoopConditionInspectionBase extends BaseInspection {
|
||||
}
|
||||
|
||||
private void checkForMethodCalls(PsiExpression condition) {
|
||||
final PsiElementVisitor visitor = new JavaRecursiveElementVisitor() {
|
||||
final PsiElementVisitor visitor = new JavaRecursiveElementWalkingVisitor() {
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(
|
||||
|
||||
+3
-5
@@ -148,13 +148,11 @@ public class RecordStoreResourceInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private static class CloseVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean containsClose = false;
|
||||
private static class CloseVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean containsClose;
|
||||
private final PsiVariable objectToClose;
|
||||
|
||||
private CloseVisitor(PsiVariable objectToClose) {
|
||||
super();
|
||||
this.objectToClose = objectToClose;
|
||||
}
|
||||
|
||||
@@ -194,7 +192,7 @@ public class RecordStoreResourceInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsStreamClose() {
|
||||
boolean containsStreamClose() {
|
||||
return containsClose;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -21,8 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
class VariableAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
class VariableAccessVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private final Map<PsiField, Integer> m_accessCounts =
|
||||
new HashMap<PsiField, Integer>(2);
|
||||
private final Set<PsiField> m_overAccessedFields =
|
||||
@@ -52,17 +51,17 @@ class VariableAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
final Map<PsiField, Integer> accessCounts = m_accessCounts;
|
||||
final Integer count = accessCounts.get(field);
|
||||
if (count == null) {
|
||||
accessCounts.put(field, Integer.valueOf(1));
|
||||
accessCounts.put(field, 1);
|
||||
}
|
||||
else if (count.intValue() == 1) {
|
||||
accessCounts.put(field, Integer.valueOf(2));
|
||||
accessCounts.put(field, 2);
|
||||
}
|
||||
else {
|
||||
overAccessedFields.add(field);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<PsiField> getOveraccessedFields() {
|
||||
Set<PsiField> getOveraccessedFields() {
|
||||
return Collections.unmodifiableSet(m_overAccessedFields);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -19,9 +19,8 @@ import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class CallToSuperSetupVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean callToSuperSetupFound = false;
|
||||
class CallToSuperSetupVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean callToSuperSetupFound;
|
||||
|
||||
@Override
|
||||
public void visitElement(@NotNull PsiElement element) {
|
||||
@@ -51,7 +50,7 @@ class CallToSuperSetupVisitor extends JavaRecursiveElementVisitor {
|
||||
callToSuperSetupFound = true;
|
||||
}
|
||||
|
||||
public boolean isCallToSuperSetupFound() {
|
||||
boolean isCallToSuperSetupFound() {
|
||||
return callToSuperSetupFound;
|
||||
}
|
||||
}
|
||||
+3
-4
@@ -19,9 +19,8 @@ import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class CallToSuperTeardownVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean callToSuperTearDownFound = false;
|
||||
class CallToSuperTeardownVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean callToSuperTearDownFound;
|
||||
|
||||
@Override
|
||||
public void visitElement(@NotNull PsiElement element) {
|
||||
@@ -51,7 +50,7 @@ class CallToSuperTeardownVisitor extends JavaRecursiveElementVisitor {
|
||||
callToSuperTearDownFound = true;
|
||||
}
|
||||
|
||||
public boolean isCallToSuperTeardownFound() {
|
||||
boolean isCallToSuperTeardownFound() {
|
||||
return callToSuperTearDownFound;
|
||||
}
|
||||
}
|
||||
+7
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -48,9 +48,9 @@ public class TestMethodWithoutAssertionInspectionBase extends BaseInspection {
|
||||
"org.mockito.InOrder,verify," +
|
||||
"org.junit.rules.ExpectedException,expect.*," +
|
||||
"org.hamcrest.MatcherAssert,assertThat";
|
||||
@SuppressWarnings({"PublicField"})
|
||||
public boolean assertKeywordIsAssertion = false;
|
||||
private Map<String, Pattern> patternCache = null;
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean assertKeywordIsAssertion;
|
||||
private Map<String, Pattern> patternCache;
|
||||
|
||||
public TestMethodWithoutAssertionInspectionBase() {
|
||||
parseString(assertionMethods, classNames, methodNamePatterns);
|
||||
@@ -196,9 +196,8 @@ public class TestMethodWithoutAssertionInspectionBase extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private class ContainsAssertionVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean containsAssertion = false;
|
||||
private class ContainsAssertionVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean containsAssertion;
|
||||
|
||||
@Override
|
||||
public void visitElement(@NotNull PsiElement element) {
|
||||
@@ -249,7 +248,7 @@ public class TestMethodWithoutAssertionInspectionBase extends BaseInspection {
|
||||
containsAssertion = true;
|
||||
}
|
||||
|
||||
public boolean containsAssertion() {
|
||||
boolean containsAssertion() {
|
||||
return containsAssertion;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -28,8 +28,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PublicMethodWithoutLoggingInspectionBase extends BaseInspection {
|
||||
protected final List<String> loggerClassNames = new ArrayList<String>();
|
||||
class PublicMethodWithoutLoggingInspectionBase extends BaseInspection {
|
||||
final List<String> loggerClassNames = new ArrayList<String>();
|
||||
@SuppressWarnings("PublicField")
|
||||
public String loggerClassName = "java.util.logging.Logger" + ',' +
|
||||
"org.slf4j.Logger" + ',' +
|
||||
@@ -100,9 +100,8 @@ public class PublicMethodWithoutLoggingInspectionBase extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private class ContainsLoggingCallVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean containsLoggingCall = false;
|
||||
private class ContainsLoggingCallVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean containsLoggingCall;
|
||||
|
||||
@Override
|
||||
public void visitElement(@NotNull PsiElement element) {
|
||||
@@ -135,7 +134,7 @@ public class PublicMethodWithoutLoggingInspectionBase extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsLoggingCall() {
|
||||
private boolean containsLoggingCall() {
|
||||
return containsLoggingCall;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -85,9 +85,9 @@ public class AnonymousInnerClassMayBeStaticInspectionBase extends BaseInspection
|
||||
return visitor.hasReferenceToLocalClass();
|
||||
}
|
||||
|
||||
private static class LocalClassReferenceVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class LocalClassReferenceVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean referenceToLocalClass = false;
|
||||
private boolean referenceToLocalClass;
|
||||
|
||||
@Override
|
||||
public void visitReferenceElement(PsiJavaCodeReferenceElement reference) {
|
||||
@@ -102,7 +102,7 @@ public class AnonymousInnerClassMayBeStaticInspectionBase extends BaseInspection
|
||||
referenceToLocalClass = true;
|
||||
}
|
||||
|
||||
public boolean hasReferenceToLocalClass() {
|
||||
private boolean hasReferenceToLocalClass() {
|
||||
return referenceToLocalClass;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-8
@@ -21,16 +21,16 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class InnerClassReferenceVisitor extends JavaRecursiveElementVisitor {
|
||||
class InnerClassReferenceVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiClass innerClass;
|
||||
private boolean referencesStaticallyAccessible = true;
|
||||
|
||||
public InnerClassReferenceVisitor(@NotNull PsiClass innerClass) {
|
||||
InnerClassReferenceVisitor(@NotNull PsiClass innerClass) {
|
||||
this.innerClass = innerClass;
|
||||
}
|
||||
|
||||
public boolean canInnerClassBeStatic() {
|
||||
boolean canInnerClassBeStatic() {
|
||||
final PsiClass superClass = innerClass.getSuperClass();
|
||||
if (superClass != null && !isClassStaticallyAccessible(superClass)) {
|
||||
return false;
|
||||
@@ -70,10 +70,7 @@ class InnerClassReferenceVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean hasContainingClassQualifier(PsiQualifiedExpression expression) {
|
||||
final PsiJavaCodeReferenceElement qualifier = expression.getQualifier();
|
||||
if (qualifier == null) {
|
||||
return false;
|
||||
}
|
||||
return !innerClass.equals(qualifier.resolve());
|
||||
return qualifier != null && !innerClass.equals(qualifier.resolve());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -144,7 +141,7 @@ class InnerClassReferenceVisitor extends JavaRecursiveElementVisitor {
|
||||
}
|
||||
final PsiClassType classType = (PsiClassType)type;
|
||||
final PsiClass aClass = classType.resolve();
|
||||
if ((aClass instanceof PsiTypeParameter) && !PsiTreeUtil.isAncestor(innerClass, aClass, true)) {
|
||||
if (aClass instanceof PsiTypeParameter && !PsiTreeUtil.isAncestor(innerClass, aClass, true)) {
|
||||
referencesStaticallyAccessible = false;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -27,8 +27,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
class CouplingVisitor extends JavaRecursiveElementVisitor {
|
||||
private boolean m_inClass = false;
|
||||
class CouplingVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean m_inClass;
|
||||
private final PsiMethod m_method;
|
||||
private final boolean m_includeJavaClasses;
|
||||
private final boolean m_includeLibraryClasses;
|
||||
@@ -36,7 +36,6 @@ class CouplingVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
CouplingVisitor(@NotNull PsiMethod method, boolean includeJavaClasses,
|
||||
boolean includeLibraryClasses) {
|
||||
super();
|
||||
m_method = method;
|
||||
m_includeJavaClasses = includeJavaClasses;
|
||||
m_includeLibraryClasses = includeLibraryClasses;
|
||||
@@ -168,7 +167,7 @@ class CouplingVisitor extends JavaRecursiveElementVisitor {
|
||||
m_dependencies.add(baseTypeName);
|
||||
}
|
||||
|
||||
public int getNumDependencies() {
|
||||
int getNumDependencies() {
|
||||
return m_dependencies.size();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,8 +18,8 @@ package com.siyeh.ig.methodmetrics;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class LoopCountVisitor extends JavaRecursiveElementVisitor {
|
||||
private int m_count = 0;
|
||||
class LoopCountVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private int m_count;
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -18,12 +18,12 @@ package com.siyeh.ig.methodmetrics;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class NCSSVisitor extends JavaRecursiveElementVisitor {
|
||||
private int m_statementCount = 0;
|
||||
class NCSSVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private int m_statementCount;
|
||||
|
||||
@Override
|
||||
public void visitAnonymousClass(@NotNull PsiAnonymousClass aClass) {
|
||||
// to call to super, to keep this from drilling down
|
||||
// no call to super, to keep this from drilling down
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,7 +36,7 @@ class NCSSVisitor extends JavaRecursiveElementVisitor {
|
||||
m_statementCount++;
|
||||
}
|
||||
|
||||
public int getStatementCount() {
|
||||
int getStatementCount() {
|
||||
return m_statementCount;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-8
@@ -19,10 +19,10 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class NegationCountVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
class NegationCountVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private final boolean myIgnoreInAssertStatements;
|
||||
private int m_count = 0;
|
||||
private int m_count;
|
||||
private boolean ignoring;
|
||||
|
||||
public NegationCountVisitor(boolean ignoreInAssertStatements) {
|
||||
myIgnoreInAssertStatements = ignoreInAssertStatements;
|
||||
@@ -32,7 +32,7 @@ class NegationCountVisitor extends JavaRecursiveElementVisitor {
|
||||
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
|
||||
super.visitBinaryExpression(expression);
|
||||
final IElementType tokenType = expression.getOperationTokenType();
|
||||
if (tokenType.equals(JavaTokenType.NE)) {
|
||||
if (!ignoring && tokenType.equals(JavaTokenType.NE)) {
|
||||
m_count++;
|
||||
}
|
||||
}
|
||||
@@ -45,17 +45,24 @@ class NegationCountVisitor extends JavaRecursiveElementVisitor {
|
||||
@Override
|
||||
public void visitPrefixExpression(@NotNull PsiPrefixExpression expression) {
|
||||
super.visitPrefixExpression(expression);
|
||||
if (expression.getOperationTokenType().equals(JavaTokenType.EXCL)) {
|
||||
if (!ignoring && expression.getOperationTokenType().equals(JavaTokenType.EXCL)) {
|
||||
m_count++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAssertStatement(PsiAssertStatement statement) {
|
||||
final int count = m_count;
|
||||
super.visitAssertStatement(statement);
|
||||
if (myIgnoreInAssertStatements) {
|
||||
m_count = count;
|
||||
ignoring = true;
|
||||
}
|
||||
super.visitAssertStatement(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void elementFinished(@NotNull PsiElement element) {
|
||||
super.elementFinished(element);
|
||||
if (element instanceof PsiAssertStatement) {
|
||||
ignoring = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -18,9 +18,9 @@ package com.siyeh.ig.methodmetrics;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class NestingDepthVisitor extends JavaRecursiveElementVisitor {
|
||||
private int m_maximumDepth = 0;
|
||||
private int m_currentDepth = 0;
|
||||
class NestingDepthVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private int m_maximumDepth;
|
||||
private int m_currentDepth;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -116,7 +116,7 @@ class NestingDepthVisitor extends JavaRecursiveElementVisitor {
|
||||
m_currentDepth--;
|
||||
}
|
||||
|
||||
public int getMaximumDepth() {
|
||||
int getMaximumDepth() {
|
||||
return m_maximumDepth;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -18,13 +18,13 @@ package com.siyeh.ig.methodmetrics;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class ReturnPointCountVisitor extends JavaRecursiveElementVisitor {
|
||||
class ReturnPointCountVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private int m_count = 0;
|
||||
private int m_count;
|
||||
private final boolean ignoreGuardClauses;
|
||||
private boolean previousWasGuardClause = true;
|
||||
|
||||
public ReturnPointCountVisitor(boolean ignoreGuardClauses) {
|
||||
ReturnPointCountVisitor(boolean ignoreGuardClauses) {
|
||||
this.ignoreGuardClauses = ignoreGuardClauses;
|
||||
}
|
||||
|
||||
@@ -91,9 +91,11 @@ class ReturnPointCountVisitor extends JavaRecursiveElementVisitor {
|
||||
return m_count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLambdaExpression(PsiLambdaExpression expression) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClass(PsiClass aClass) {
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -26,9 +26,9 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EnumerationCanBeIterationInspectionBase extends BaseInspection {
|
||||
protected static final int KEEP_NOTHING = 0;
|
||||
protected static final int KEEP_INITIALIZATION = 1;
|
||||
protected static final int KEEP_DECLARATION = 2;
|
||||
static final int KEEP_NOTHING = 0;
|
||||
static final int KEEP_INITIALIZATION = 1;
|
||||
static final int KEEP_DECLARATION = 2;
|
||||
@NonNls
|
||||
static final String ITERATOR_TEXT = "iterator()";
|
||||
@NonNls
|
||||
@@ -148,12 +148,12 @@ public class EnumerationCanBeIterationInspectionBase extends BaseInspection {
|
||||
}
|
||||
|
||||
private static class EnumerationMethodCalledVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiVariable variable;
|
||||
private boolean enumerationMethodCalled = false;
|
||||
private boolean enumerationMethodCalled;
|
||||
|
||||
EnumerationMethodCalledVisitor(@NotNull PsiVariable variable) {
|
||||
private EnumerationMethodCalledVisitor(@NotNull PsiVariable variable) {
|
||||
this.variable = variable;
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ public class EnumerationCanBeIterationInspectionBase extends BaseInspection {
|
||||
enumerationMethodCalled = this.variable.equals(variable);
|
||||
}
|
||||
|
||||
public boolean isEnumerationMethodCalled() {
|
||||
private boolean isEnumerationMethodCalled() {
|
||||
return enumerationMethodCalled;
|
||||
}
|
||||
}
|
||||
|
||||
+20
-20
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -33,9 +33,9 @@ public class ForCanBeForeachInspectionBase extends BaseInspection {
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean REPORT_INDEXED_LOOP = true;
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean ignoreUntypedCollections = false;
|
||||
public boolean ignoreUntypedCollections;
|
||||
|
||||
protected static boolean isIndexedListLoopStatement(PsiForStatement forStatement, boolean ignoreUntypedCollections) {
|
||||
static boolean isIndexedListLoopStatement(PsiForStatement forStatement, boolean ignoreUntypedCollections) {
|
||||
final PsiStatement initialization = forStatement.getInitialization();
|
||||
if (!(initialization instanceof PsiDeclarationStatement)) {
|
||||
return false;
|
||||
@@ -406,7 +406,7 @@ public class ForCanBeForeachInspectionBase extends BaseInspection {
|
||||
}
|
||||
return getCollectionFromListMethodCall(rhs, HardcodedMethodConstants.SIZE, secondDeclaredElement);
|
||||
}
|
||||
else if (tokenType.equals(JavaTokenType.GT)) {
|
||||
if (tokenType.equals(JavaTokenType.GT)) {
|
||||
if (!VariableAccessUtils.evaluatesToVariable(rhs, variable)) {
|
||||
return null;
|
||||
}
|
||||
@@ -558,12 +558,12 @@ public class ForCanBeForeachInspectionBase extends BaseInspection {
|
||||
}
|
||||
|
||||
private static class NumCallsToIteratorNextVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private int numCallsToIteratorNext = 0;
|
||||
private int numCallsToIteratorNext;
|
||||
private final PsiVariable iterator;
|
||||
|
||||
NumCallsToIteratorNextVisitor(PsiVariable iterator) {
|
||||
private NumCallsToIteratorNextVisitor(PsiVariable iterator) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
@@ -594,18 +594,18 @@ public class ForCanBeForeachInspectionBase extends BaseInspection {
|
||||
numCallsToIteratorNext++;
|
||||
}
|
||||
|
||||
public int getNumCallsToIteratorNext() {
|
||||
private int getNumCallsToIteratorNext() {
|
||||
return numCallsToIteratorNext;
|
||||
}
|
||||
}
|
||||
|
||||
private static class IteratorMethodCallVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean methodCalled = false;
|
||||
private boolean methodCalled;
|
||||
private final PsiVariable iterator;
|
||||
|
||||
IteratorMethodCallVisitor(PsiVariable iterator) {
|
||||
private IteratorMethodCallVisitor(PsiVariable iterator) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
@@ -650,20 +650,20 @@ public class ForCanBeForeachInspectionBase extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMethodCalled() {
|
||||
private boolean isMethodCalled() {
|
||||
return methodCalled;
|
||||
}
|
||||
}
|
||||
|
||||
private static class VariableOnlyUsedAsIndexVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean indexVariableUsedOnlyAsIndex = true;
|
||||
private final PsiVariable arrayVariable;
|
||||
private final PsiVariable indexVariable;
|
||||
|
||||
VariableOnlyUsedAsIndexVisitor(PsiVariable arrayVariable,
|
||||
PsiVariable indexVariable) {
|
||||
private VariableOnlyUsedAsIndexVisitor(PsiVariable arrayVariable,
|
||||
PsiVariable indexVariable) {
|
||||
this.arrayVariable = arrayVariable;
|
||||
this.indexVariable = indexVariable;
|
||||
}
|
||||
@@ -725,20 +725,20 @@ public class ForCanBeForeachInspectionBase extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isIndexVariableUsedOnlyAsIndex() {
|
||||
private boolean isIndexVariableUsedOnlyAsIndex() {
|
||||
return indexVariableUsedOnlyAsIndex;
|
||||
}
|
||||
}
|
||||
|
||||
private static class VariableOnlyUsedAsListIndexVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean indexVariableUsedOnlyAsIndex = true;
|
||||
private boolean listGetCalled = false;
|
||||
private boolean listGetCalled;
|
||||
private final PsiVariable indexVariable;
|
||||
private final Holder collection;
|
||||
|
||||
VariableOnlyUsedAsListIndexVisitor(
|
||||
private VariableOnlyUsedAsListIndexVisitor(
|
||||
@NotNull Holder collection,
|
||||
@NotNull PsiVariable indexVariable) {
|
||||
this.collection = collection;
|
||||
@@ -779,7 +779,7 @@ public class ForCanBeForeachInspectionBase extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isIndexVariableUsedOnlyAsIndex() {
|
||||
private boolean isIndexVariableUsedOnlyAsIndex() {
|
||||
return indexVariableUsedOnlyAsIndex && listGetCalled;
|
||||
}
|
||||
|
||||
|
||||
+15
-15
@@ -104,7 +104,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
|
||||
}
|
||||
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
|
||||
@NonNls final StringBuilder newTryStatementText = new StringBuilder("try (");
|
||||
final Set<Integer> unwantedChildren = new HashSet(2);
|
||||
final Set<Integer> unwantedChildren = new HashSet<Integer>(2);
|
||||
boolean separator = false;
|
||||
for (final PsiLocalVariable variable : variables) {
|
||||
final boolean hasInitializer;
|
||||
@@ -128,10 +128,10 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
unwantedChildren.add(Integer.valueOf(index));
|
||||
unwantedChildren.add(index);
|
||||
final PsiExpressionStatement expressionStatement = (PsiExpressionStatement)tryBlockChildren[index];
|
||||
if (expressionStatement.getNextSibling() instanceof PsiWhiteSpace) {
|
||||
unwantedChildren.add(Integer.valueOf(index + 1));
|
||||
unwantedChildren.add(index + 1);
|
||||
}
|
||||
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)expressionStatement.getExpression();
|
||||
final PsiExpression rhs = assignmentExpression.getRExpression();
|
||||
@@ -145,7 +145,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
|
||||
int j = 1;
|
||||
while (!unwantedChildren.contains(Integer.valueOf(j)) && j < tryBlockChildren.length - 1) {
|
||||
tryStatement.getParent().addBefore(tryBlockChildren[j], tryStatement);
|
||||
unwantedChildren.add(Integer.valueOf(j));
|
||||
unwantedChildren.add(j);
|
||||
j++;
|
||||
}
|
||||
newTryStatementText.append(") {");
|
||||
@@ -165,7 +165,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
|
||||
final PsiElement[] finallyChildren = finallyBlock.getChildren();
|
||||
boolean appended = false;
|
||||
final int finallyChildrenLength = finallyChildren.length - 1;
|
||||
final List<PsiElement> savedComments = new ArrayList();
|
||||
final List<PsiElement> savedComments = new ArrayList<PsiElement>();
|
||||
for (int i = 1; i < finallyChildrenLength; i++) {
|
||||
final PsiElement child = finallyChildren[i];
|
||||
if (isCloseStatement(child, variables)) {
|
||||
@@ -335,7 +335,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isVariableUsedOutsideContext(PsiVariable variable, PsiElement context) {
|
||||
private static boolean isVariableUsedOutsideContext(PsiVariable variable, PsiElement context) {
|
||||
final VariableUsedOutsideContextVisitor visitor = new VariableUsedOutsideContextVisitor(variable, context);
|
||||
final PsiElement declarationScope = PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class);
|
||||
if (declarationScope == null) {
|
||||
@@ -345,16 +345,16 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
|
||||
return visitor.variableIsUsed();
|
||||
}
|
||||
|
||||
static List<PsiLocalVariable> collectVariables(PsiTryStatement tryStatement) {
|
||||
private static List<PsiLocalVariable> collectVariables(PsiTryStatement tryStatement) {
|
||||
final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
|
||||
if (finallyBlock == null) {
|
||||
return Collections.EMPTY_LIST;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final PsiStatement[] statements = finallyBlock.getStatements();
|
||||
if (statements.length == 0) {
|
||||
return Collections.EMPTY_LIST;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final List<PsiLocalVariable> variables = new ArrayList();
|
||||
final List<PsiLocalVariable> variables = new ArrayList<PsiLocalVariable>();
|
||||
for (PsiStatement statement : statements) {
|
||||
final PsiLocalVariable variable = findAutoCloseableVariable(statement);
|
||||
if (variable != null) {
|
||||
@@ -366,7 +366,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static PsiLocalVariable findAutoCloseableVariable(PsiStatement statement) {
|
||||
private static PsiLocalVariable findAutoCloseableVariable(PsiStatement statement) {
|
||||
if (statement instanceof PsiIfStatement) {
|
||||
final PsiIfStatement ifStatement = (PsiIfStatement)statement;
|
||||
if (ifStatement.getElseBranch() != null) {
|
||||
@@ -460,7 +460,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
|
||||
return aClass != null && InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE);
|
||||
}
|
||||
|
||||
static int findInitialization(PsiElement[] elements, PsiVariable variable, boolean hasInitializer) {
|
||||
private static int findInitialization(PsiElement[] elements, PsiVariable variable, boolean hasInitializer) {
|
||||
int result = -1;
|
||||
final int statementsLength = elements.length;
|
||||
for (int i = 0; i < statementsLength; i++) {
|
||||
@@ -469,7 +469,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
|
||||
if (result >= 0 && !hasInitializer) {
|
||||
return -1;
|
||||
}
|
||||
else if (hasInitializer) {
|
||||
if (hasInitializer) {
|
||||
return i;
|
||||
}
|
||||
result = i;
|
||||
@@ -500,9 +500,9 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
|
||||
return variable.equals(target);
|
||||
}
|
||||
|
||||
static class VariableUsedOutsideContextVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class VariableUsedOutsideContextVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean used = false;
|
||||
private boolean used;
|
||||
@NotNull private final PsiVariable variable;
|
||||
private final PsiElement skipContext;
|
||||
|
||||
|
||||
+10
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class WhileCanBeForeachInspectionBase extends BaseInspection {
|
||||
@Nullable
|
||||
public static PsiStatement getPreviousStatement(PsiElement context) {
|
||||
static PsiStatement getPreviousStatement(PsiElement context) {
|
||||
final PsiElement prevStatement = PsiTreeUtil.skipSiblingsBackward(context, PsiWhiteSpace.class, PsiComment.class);
|
||||
if (!(prevStatement instanceof PsiStatement)) {
|
||||
return null;
|
||||
@@ -73,7 +73,6 @@ public class WhileCanBeForeachInspectionBase extends BaseInspection {
|
||||
}
|
||||
|
||||
private static class WhileCanBeForeachVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitWhileStatement(@NotNull PsiWhileStatement whileStatement) {
|
||||
super.visitWhileStatement(whileStatement);
|
||||
@@ -221,8 +220,7 @@ public class WhileCanBeForeachInspectionBase extends BaseInspection {
|
||||
}
|
||||
|
||||
private static class NumberCallsToIteratorNextVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private int numCallsToIteratorNext = 0;
|
||||
private int numCallsToIteratorNext;
|
||||
private final PsiVariable iterator;
|
||||
|
||||
private NumberCallsToIteratorNextVisitor(PsiVariable iterator) {
|
||||
@@ -249,17 +247,16 @@ public class WhileCanBeForeachInspectionBase extends BaseInspection {
|
||||
numCallsToIteratorNext++;
|
||||
}
|
||||
|
||||
public int getNumCallsToIteratorNext() {
|
||||
int getNumCallsToIteratorNext() {
|
||||
return numCallsToIteratorNext;
|
||||
}
|
||||
}
|
||||
|
||||
private static class IteratorMethodCallVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean methodCalled = false;
|
||||
private boolean methodCalled;
|
||||
private final PsiVariable iterator;
|
||||
|
||||
IteratorMethodCallVisitor(PsiVariable iterator) {
|
||||
IteratorMethodCallVisitor(@NotNull PsiVariable iterator) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
@@ -292,17 +289,16 @@ public class WhileCanBeForeachInspectionBase extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMethodCalled() {
|
||||
boolean isMethodCalled() {
|
||||
return methodCalled;
|
||||
}
|
||||
}
|
||||
|
||||
private static class IteratorHasNextVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean hasNextCalled = false;
|
||||
private boolean hasNextCalled;
|
||||
private final PsiVariable iterator;
|
||||
|
||||
private IteratorHasNextVisitor(PsiVariable iterator) {
|
||||
private IteratorHasNextVisitor(@NotNull PsiVariable iterator) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
@@ -332,7 +328,7 @@ public class WhileCanBeForeachInspectionBase extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isHasNextCalled() {
|
||||
boolean isHasNextCalled() {
|
||||
return hasNextCalled;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ package com.siyeh.ig.performance;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class CanBeStaticVisitor extends JavaRecursiveElementVisitor {
|
||||
class CanBeStaticVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean canBeStatic = true;
|
||||
|
||||
@Override
|
||||
|
||||
+6
-5
@@ -107,7 +107,7 @@ public class CollectionContainsUrlInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
private static ClassType getClassType(@Nullable PsiClass aClass) {
|
||||
return isMapOrSet(aClass, new HashSet());
|
||||
return isMapOrSet(aClass, new HashSet<PsiClass>());
|
||||
}
|
||||
|
||||
private static ClassType isMapOrSet(
|
||||
@@ -122,7 +122,7 @@ public class CollectionContainsUrlInspection extends BaseInspection {
|
||||
if (CommonClassNames.JAVA_UTIL_SET.equals(className)) {
|
||||
return ClassType.SET;
|
||||
}
|
||||
else if (CommonClassNames.JAVA_UTIL_MAP.equals(className)) {
|
||||
if (CommonClassNames.JAVA_UTIL_MAP.equals(className)) {
|
||||
return ClassType.MAP;
|
||||
}
|
||||
final PsiClass[] supers = aClass.getSupers();
|
||||
@@ -138,9 +138,9 @@ public class CollectionContainsUrlInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
private static class UrlAddedVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean urlAdded = false;
|
||||
private boolean urlAdded;
|
||||
private final PsiVariable variable;
|
||||
private final ClassType collectionType;
|
||||
|
||||
@@ -194,7 +194,7 @@ public class CollectionContainsUrlInspection extends BaseInspection {
|
||||
urlAdded = true;
|
||||
}
|
||||
|
||||
public boolean isUrlAdded() {
|
||||
boolean isUrlAdded() {
|
||||
return urlAdded;
|
||||
}
|
||||
}
|
||||
@@ -203,6 +203,7 @@ public class CollectionContainsUrlInspection extends BaseInspection {
|
||||
|
||||
SET, MAP, OTHER;
|
||||
|
||||
@NotNull
|
||||
public String toString() {
|
||||
final String string = super.toString();
|
||||
return string.charAt(0) + string.substring(1).toLowerCase();
|
||||
|
||||
+9
-10
@@ -184,21 +184,20 @@ public class KeySetIterationMayUseEntrySetInspection extends BaseInspection {
|
||||
else {
|
||||
baseName = "entry";
|
||||
}
|
||||
if (baseName == null || baseName.length() == 0) {
|
||||
if (baseName == null || baseName.isEmpty()) {
|
||||
baseName = "entry";
|
||||
}
|
||||
return codeStyleManager.suggestUniqueVariableName(baseName, scope, true);
|
||||
}
|
||||
|
||||
private static class ParameterAccessCollector extends JavaRecursiveElementVisitor {
|
||||
|
||||
private static class ParameterAccessCollector extends JavaRecursiveElementWalkingVisitor {
|
||||
private final PsiParameter parameter;
|
||||
private final PsiElement map;
|
||||
private final String parameterName;
|
||||
|
||||
private final List<PsiExpression> parameterAccesses = new ArrayList();
|
||||
private final List<PsiExpression> parameterAccesses = new ArrayList<PsiExpression>();
|
||||
|
||||
public ParameterAccessCollector(PsiParameter parameter, PsiElement map) {
|
||||
private ParameterAccessCollector(PsiParameter parameter, PsiElement map) {
|
||||
this.parameter = parameter;
|
||||
parameterName = parameter.getName();
|
||||
this.map = map;
|
||||
@@ -261,7 +260,7 @@ public class KeySetIterationMayUseEntrySetInspection extends BaseInspection {
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<PsiExpression> getParameterAccesses() {
|
||||
private List<PsiExpression> getParameterAccesses() {
|
||||
Collections.reverse(parameterAccesses);
|
||||
return parameterAccesses;
|
||||
}
|
||||
@@ -339,12 +338,12 @@ public class KeySetIterationMayUseEntrySetInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetValueFromMapChecker extends JavaRecursiveElementVisitor {
|
||||
private static class GetValueFromMapChecker extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiVariable key;
|
||||
private final PsiVariable map;
|
||||
private boolean getValueFromMap = false;
|
||||
private boolean tainted = false;
|
||||
private boolean getValueFromMap;
|
||||
private boolean tainted;
|
||||
|
||||
GetValueFromMapChecker(@NotNull PsiVariable map, @NotNull PsiVariable key) {
|
||||
this.map = map;
|
||||
@@ -403,7 +402,7 @@ public class KeySetIterationMayUseEntrySetInspection extends BaseInspection {
|
||||
getValueFromMap = true;
|
||||
}
|
||||
|
||||
public boolean isGetValueFromMap() {
|
||||
boolean isGetValueFromMap() {
|
||||
return getValueFromMap && !tainted;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -20,15 +20,13 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.siyeh.ig.psiutils.ControlFlowUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class StringVariableIsAppendedToVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean appendedTo = false;
|
||||
class StringVariableIsAppendedToVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean appendedTo;
|
||||
private final PsiVariable variable;
|
||||
private final boolean onlyWarnOnLoop;
|
||||
|
||||
StringVariableIsAppendedToVisitor(PsiVariable variable,
|
||||
boolean onlyWarnOnLoop) {
|
||||
super();
|
||||
this.variable = variable;
|
||||
this.onlyWarnOnLoop = onlyWarnOnLoop;
|
||||
}
|
||||
@@ -94,7 +92,7 @@ class StringVariableIsAppendedToVisitor extends JavaRecursiveElementVisitor {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAppendedTo() {
|
||||
boolean isAppendedTo() {
|
||||
return appendedTo;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -170,12 +170,12 @@ public class TailRecursionInspection extends BaseInspection {
|
||||
return visitor.containsCallOnOtherInstance();
|
||||
}
|
||||
|
||||
private static class MethodContainsCallOnOtherInstanceVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class MethodContainsCallOnOtherInstanceVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean containsCallOnOtherInstance = false;
|
||||
private boolean containsCallOnOtherInstance;
|
||||
private final PsiClass aClass;
|
||||
|
||||
MethodContainsCallOnOtherInstanceVisitor(PsiClass aClass) {
|
||||
private MethodContainsCallOnOtherInstanceVisitor(PsiClass aClass) {
|
||||
this.aClass = aClass;
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ public class TailRecursionInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsCallOnOtherInstance() {
|
||||
private boolean containsCallOnOtherInstance() {
|
||||
return containsCallOnOtherInstance;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -20,12 +20,12 @@ import com.siyeh.HardcodedMethodConstants;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class ArrayContentsAccessedVisitor extends JavaRecursiveElementVisitor {
|
||||
class ArrayContentsAccessedVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean accessed = false;
|
||||
private boolean accessed;
|
||||
private final PsiVariable variable;
|
||||
|
||||
public ArrayContentsAccessedVisitor(@NotNull PsiVariable variable) {
|
||||
ArrayContentsAccessedVisitor(@NotNull PsiVariable variable) {
|
||||
this.variable = variable;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -20,12 +20,12 @@ import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class ArrayContentsAssignedVisitor extends JavaRecursiveElementVisitor {
|
||||
class ArrayContentsAssignedVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean assigned = false;
|
||||
private boolean assigned;
|
||||
private final PsiVariable variable;
|
||||
|
||||
public ArrayContentsAssignedVisitor(@NotNull PsiVariable variable) {
|
||||
ArrayContentsAssignedVisitor(@NotNull PsiVariable variable) {
|
||||
this.variable = variable;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -85,7 +85,7 @@ public class ExceptionUtils {
|
||||
return throwable.equals(element);
|
||||
}
|
||||
|
||||
public static boolean statementThrowsException(PsiStatement statement) {
|
||||
static boolean statementThrowsException(PsiStatement statement) {
|
||||
if (statement == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ public class ExceptionUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean blockThrowsException(@Nullable PsiCodeBlock block) {
|
||||
static boolean blockThrowsException(@Nullable PsiCodeBlock block) {
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -233,11 +233,11 @@ public class ExceptionUtils {
|
||||
return out;
|
||||
}
|
||||
|
||||
private static class ExceptionsThrownVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class ExceptionsThrownVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final Set<PsiType> m_exceptionsThrown;
|
||||
|
||||
public ExceptionsThrownVisitor(Set<PsiType> thrownTypes) {
|
||||
private ExceptionsThrownVisitor(Set<PsiType> thrownTypes) {
|
||||
m_exceptionsThrown = thrownTypes;
|
||||
}
|
||||
|
||||
|
||||
+10
-21
@@ -167,7 +167,7 @@ public final class ImportUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean hasExactImportConflict(String fqName, PsiJavaFile file) {
|
||||
private static boolean hasExactImportConflict(String fqName, PsiJavaFile file) {
|
||||
final PsiImportList imports = file.getImportList();
|
||||
if (imports == null) {
|
||||
return false;
|
||||
@@ -472,7 +472,7 @@ public final class ImportUtils {
|
||||
}
|
||||
|
||||
private static List<PsiImportStaticStatement> getMatchingImports(@NotNull PsiImportList importList, @NotNull String className) {
|
||||
final List<PsiImportStaticStatement> imports = new ArrayList();
|
||||
final List<PsiImportStaticStatement> imports = new ArrayList<PsiImportStaticStatement>();
|
||||
for (PsiImportStaticStatement staticStatement : importList.getImportStaticStatements()) {
|
||||
final PsiClass psiClass = staticStatement.resolveTargetClass();
|
||||
if (psiClass == null) {
|
||||
@@ -534,25 +534,14 @@ public final class ImportUtils {
|
||||
return visitor.isReferenceFound();
|
||||
}
|
||||
|
||||
private static boolean membersReferenced(PsiMember[] members, PsiElement context) {
|
||||
final MemberReferenceVisitor visitor = new MemberReferenceVisitor(members);
|
||||
context.accept(visitor);
|
||||
return visitor.isReferenceFound();
|
||||
}
|
||||
|
||||
private static class MemberReferenceVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private static class MemberReferenceVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private final PsiMember[] members;
|
||||
private boolean referenceFound = false;
|
||||
private boolean referenceFound;
|
||||
|
||||
public MemberReferenceVisitor(PsiMember member) {
|
||||
private MemberReferenceVisitor(PsiMember member) {
|
||||
members = new PsiMember[]{member};
|
||||
}
|
||||
|
||||
public MemberReferenceVisitor(PsiMember[] members) {
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReferenceElement(PsiJavaCodeReferenceElement reference) {
|
||||
if (referenceFound) {
|
||||
@@ -571,7 +560,7 @@ public final class ImportUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isReferenceFound() {
|
||||
private boolean isReferenceFound() {
|
||||
return referenceFound;
|
||||
}
|
||||
}
|
||||
@@ -579,7 +568,7 @@ public final class ImportUtils {
|
||||
/**
|
||||
* @return true, if the element contains a reference to a different class than fullyQualifiedName but which has the same class name
|
||||
*/
|
||||
public static boolean containsConflictingReference(PsiFile element, String fullyQualifiedName) {
|
||||
private static boolean containsConflictingReference(PsiFile element, String fullyQualifiedName) {
|
||||
final Map<String, Boolean> cachedValue =
|
||||
CachedValuesManager.getCachedValue(element, new CachedValueProvider<Map<String, Boolean>>() {
|
||||
@Nullable
|
||||
@@ -602,11 +591,11 @@ public final class ImportUtils {
|
||||
return conflictingRef.booleanValue();
|
||||
}
|
||||
|
||||
private static class ConflictingClassReferenceVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class ConflictingClassReferenceVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final String name;
|
||||
private final String fullyQualifiedName;
|
||||
private boolean referenceFound = false;
|
||||
private boolean referenceFound;
|
||||
|
||||
private ConflictingClassReferenceVisitor(String fullyQualifiedName) {
|
||||
name = ClassUtil.extractClassName(fullyQualifiedName);
|
||||
@@ -642,7 +631,7 @@ public final class ImportUtils {
|
||||
referenceFound = true;
|
||||
}
|
||||
|
||||
public boolean isConflictingReferenceFound() {
|
||||
private boolean isConflictingReferenceFound() {
|
||||
return referenceFound;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -57,17 +57,17 @@ public class IteratorUtils {
|
||||
}
|
||||
|
||||
private static class CallsIteratorNextVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private static final Pattern SCANNER_PATTERN = Pattern.compile("next.*");
|
||||
|
||||
private final boolean checkTarget;
|
||||
private final boolean checkScanner;
|
||||
private final PsiVariable target;
|
||||
private boolean doesCallIteratorNext = false;
|
||||
private boolean doesCallIteratorNext;
|
||||
|
||||
CallsIteratorNextVisitor(PsiVariable target, boolean checkTarget,
|
||||
boolean checkScanner) {
|
||||
private CallsIteratorNextVisitor(PsiVariable target, boolean checkTarget,
|
||||
boolean checkScanner) {
|
||||
this.checkTarget = checkTarget;
|
||||
this.target = target;
|
||||
this.checkScanner = checkScanner;
|
||||
@@ -129,7 +129,7 @@ public class IteratorUtils {
|
||||
doesCallIteratorNext = true;
|
||||
}
|
||||
|
||||
public boolean callsIteratorNext() {
|
||||
private boolean callsIteratorNext() {
|
||||
return doesCallIteratorNext;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -18,14 +18,13 @@ package com.siyeh.ig.psiutils;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class RecursionVisitor extends JavaRecursiveElementVisitor {
|
||||
class RecursionVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean recursive = false;
|
||||
private boolean recursive;
|
||||
private final PsiMethod method;
|
||||
private final String methodName;
|
||||
|
||||
public RecursionVisitor(@NotNull PsiMethod method) {
|
||||
super();
|
||||
RecursionVisitor(@NotNull PsiMethod method) {
|
||||
this.method = method;
|
||||
methodName = method.getName();
|
||||
}
|
||||
|
||||
+7
-13
@@ -190,7 +190,7 @@ public class VariableAccessUtils {
|
||||
return mayEvaluateToVariable(expression, variable, false);
|
||||
}
|
||||
|
||||
public static boolean mayEvaluateToVariable(@Nullable PsiExpression expression, @NotNull PsiVariable variable, boolean builderPattern) {
|
||||
static boolean mayEvaluateToVariable(@Nullable PsiExpression expression, @NotNull PsiVariable variable, boolean builderPattern) {
|
||||
if (expression == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -268,13 +268,7 @@ public class VariableAccessUtils {
|
||||
|
||||
public static boolean variableIsUsed(@NotNull PsiVariable variable,
|
||||
@Nullable PsiElement context) {
|
||||
if (context == null) {
|
||||
return false;
|
||||
}
|
||||
final VariableUsedVisitor visitor =
|
||||
new VariableUsedVisitor(variable);
|
||||
context.accept(visitor);
|
||||
return visitor.isUsed();
|
||||
return context != null && VariableUsedVisitor.isVariableUsedIn(variable, context);
|
||||
}
|
||||
|
||||
public static boolean variableIsDecremented(@NotNull PsiVariable variable, @Nullable PsiStatement statement) {
|
||||
@@ -303,7 +297,7 @@ public class VariableAccessUtils {
|
||||
final PsiExpression operand = prefixExpression.getOperand();
|
||||
return evaluatesToVariable(operand, variable);
|
||||
}
|
||||
else if (expression instanceof PsiPostfixExpression) {
|
||||
if (expression instanceof PsiPostfixExpression) {
|
||||
final PsiPostfixExpression postfixExpression =
|
||||
(PsiPostfixExpression)expression;
|
||||
final IElementType tokenType = postfixExpression.getOperationTokenType();
|
||||
@@ -313,7 +307,7 @@ public class VariableAccessUtils {
|
||||
final PsiExpression operand = postfixExpression.getOperand();
|
||||
return evaluatesToVariable(operand, variable);
|
||||
}
|
||||
else if (expression instanceof PsiAssignmentExpression) {
|
||||
if (expression instanceof PsiAssignmentExpression) {
|
||||
final PsiAssignmentExpression assignmentExpression =
|
||||
(PsiAssignmentExpression)expression;
|
||||
final IElementType tokenType =
|
||||
@@ -357,7 +351,7 @@ public class VariableAccessUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean variableIsAssignedBeforeReference(
|
||||
static boolean variableIsAssignedBeforeReference(
|
||||
@NotNull PsiReferenceExpression referenceExpression,
|
||||
@Nullable PsiElement context) {
|
||||
if (context == null) {
|
||||
@@ -432,9 +426,9 @@ public class VariableAccessUtils {
|
||||
return visitor.isAssigned();
|
||||
}
|
||||
|
||||
private static class VariableCollectingVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class VariableCollectingVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final Set<PsiVariable> usedVariables = new HashSet();
|
||||
private final Set<PsiVariable> usedVariables = new HashSet<PsiVariable>();
|
||||
|
||||
@Override
|
||||
public void visitReferenceExpression(
|
||||
|
||||
+4
-4
@@ -19,17 +19,17 @@ import com.intellij.psi.*;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class VariablePassedAsArgumentExcludedVisitor extends JavaRecursiveElementVisitor {
|
||||
class VariablePassedAsArgumentExcludedVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
@NotNull
|
||||
private final PsiVariable variable;
|
||||
private final Processor<PsiCall> myCallProcessor;
|
||||
private final boolean myBuilderPattern;
|
||||
|
||||
private boolean passed = false;
|
||||
private boolean passed;
|
||||
|
||||
public VariablePassedAsArgumentExcludedVisitor(@NotNull PsiVariable variable, boolean builderPattern,
|
||||
@NotNull Processor<PsiCall> callProcessor) {
|
||||
VariablePassedAsArgumentExcludedVisitor(@NotNull PsiVariable variable, boolean builderPattern,
|
||||
@NotNull Processor<PsiCall> callProcessor) {
|
||||
this.variable = variable;
|
||||
myCallProcessor = callProcessor;
|
||||
myBuilderPattern = builderPattern;
|
||||
|
||||
+3
-4
@@ -18,14 +18,13 @@ package com.siyeh.ig.psiutils;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class VariablePassedAsArgumentVisitor extends JavaRecursiveElementVisitor {
|
||||
class VariablePassedAsArgumentVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
@NotNull
|
||||
private final PsiVariable variable;
|
||||
private boolean passed = false;
|
||||
private boolean passed;
|
||||
|
||||
public VariablePassedAsArgumentVisitor(@NotNull PsiVariable variable) {
|
||||
super();
|
||||
VariablePassedAsArgumentVisitor(@NotNull PsiVariable variable) {
|
||||
this.variable = variable;
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -18,14 +18,12 @@ package com.siyeh.ig.psiutils;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class VariableUsedInArrayInitializerVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
class VariableUsedInArrayInitializerVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
@NotNull
|
||||
private final PsiVariable variable;
|
||||
private boolean passed = false;
|
||||
private boolean passed;
|
||||
|
||||
public VariableUsedInArrayInitializerVisitor(@NotNull PsiVariable variable) {
|
||||
super();
|
||||
VariableUsedInArrayInitializerVisitor(@NotNull PsiVariable variable) {
|
||||
this.variable = variable;
|
||||
}
|
||||
|
||||
|
||||
+20
-35
@@ -16,16 +16,14 @@
|
||||
package com.siyeh.ig.psiutils;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class VariableUsedInInnerClassVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
class VariableUsedInInnerClassVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
@NotNull private final PsiVariable variable;
|
||||
private boolean usedInInnerClass = false;
|
||||
private boolean inInnerClass = false;
|
||||
private boolean usedInInnerClass;
|
||||
private int inInnerClassCount;
|
||||
|
||||
public VariableUsedInInnerClassVisitor(@NotNull PsiVariable variable) {
|
||||
VariableUsedInInnerClassVisitor(@NotNull PsiVariable variable) {
|
||||
this.variable = variable;
|
||||
}
|
||||
|
||||
@@ -37,31 +35,19 @@ class VariableUsedInInnerClassVisitor extends JavaRecursiveElementVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClass(@NotNull PsiClass aClass) {
|
||||
if (usedInInnerClass) {
|
||||
return;
|
||||
}
|
||||
final boolean wasInInnerClass = inInnerClass;
|
||||
if (!inInnerClass) {
|
||||
inInnerClass = true;
|
||||
if (aClass instanceof PsiAnonymousClass) {
|
||||
final PsiExpressionList argumentList = ((PsiAnonymousClass)aClass).getArgumentList();
|
||||
if (argumentList != null) {
|
||||
for (PsiClass localAndAnonymousClasses : PsiTreeUtil.findChildrenOfType(argumentList, PsiClass.class)) {
|
||||
localAndAnonymousClasses.accept(this);
|
||||
}
|
||||
}
|
||||
public void visitJavaToken(PsiJavaToken token) {
|
||||
super.visitJavaToken(token);
|
||||
PsiElement parent = token.getParent();
|
||||
if (parent instanceof PsiClass) {
|
||||
PsiClass aClass = (PsiClass)parent;
|
||||
// have to be that complex because anonymous class argument list should not be treated as insideInner
|
||||
if (token.getTokenType() == JavaTokenType.LBRACE && aClass.getLBrace() == token) {
|
||||
inInnerClassCount++;
|
||||
}
|
||||
PsiElement child = aClass.getLBrace();
|
||||
while (child != null) {
|
||||
child.accept(this);
|
||||
child = child.getNextSibling();
|
||||
if (token.getTokenType() == JavaTokenType.RBRACE && aClass.getRBrace() == token) {
|
||||
inInnerClassCount--;
|
||||
}
|
||||
} else {
|
||||
inInnerClass = true;
|
||||
super.visitClass(aClass);
|
||||
}
|
||||
inInnerClass = wasInInnerClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,16 +56,15 @@ class VariableUsedInInnerClassVisitor extends JavaRecursiveElementVisitor {
|
||||
return;
|
||||
}
|
||||
super.visitReferenceExpression(referenceExpression);
|
||||
if (!inInnerClass) {
|
||||
return;
|
||||
}
|
||||
final PsiElement target = referenceExpression.resolve();
|
||||
if (variable.equals(target)) {
|
||||
usedInInnerClass = true;
|
||||
if (inInnerClassCount > 0) {
|
||||
final PsiElement target = referenceExpression.resolve();
|
||||
if (variable.equals(target)) {
|
||||
usedInInnerClass = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUsedInInnerClass() {
|
||||
boolean isUsedInInnerClass() {
|
||||
return usedInInnerClass;
|
||||
}
|
||||
}
|
||||
+11
-5
@@ -15,18 +15,17 @@
|
||||
*/
|
||||
package com.siyeh.ig.psiutils;
|
||||
|
||||
import com.intellij.psi.JavaRecursiveElementVisitor;
|
||||
import com.intellij.psi.JavaRecursiveElementWalkingVisitor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReferenceExpression;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class VariableUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean used = false;
|
||||
class VariableUsedVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean used;
|
||||
@NotNull private final PsiVariable variable;
|
||||
|
||||
public VariableUsedVisitor(@NotNull PsiVariable variable) {
|
||||
private VariableUsedVisitor(@NotNull PsiVariable variable) {
|
||||
this.variable = variable;
|
||||
}
|
||||
|
||||
@@ -51,10 +50,17 @@ class VariableUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
}
|
||||
if (target.equals(variable)) {
|
||||
used = true;
|
||||
//stopWalking();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUsed() {
|
||||
return used;
|
||||
}
|
||||
|
||||
static boolean isVariableUsedIn(@NotNull PsiVariable variable, @NotNull PsiElement code) {
|
||||
VariableUsedVisitor visitor = new VariableUsedVisitor(variable);
|
||||
code.accept(visitor);
|
||||
return visitor.isUsed();
|
||||
}
|
||||
}
|
||||
+12
-34
@@ -19,12 +19,12 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class VariableValueUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
class VariableValueUsedVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
@NotNull
|
||||
private final PsiVariable variable;
|
||||
private boolean read = false;
|
||||
private boolean written = false;
|
||||
private boolean read;
|
||||
private boolean written;
|
||||
|
||||
VariableValueUsedVisitor(@NotNull PsiVariable variable) {
|
||||
this.variable = variable;
|
||||
@@ -59,10 +59,7 @@ class VariableValueUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
if (rhs == null) {
|
||||
return;
|
||||
}
|
||||
final VariableUsedVisitor visitor =
|
||||
new VariableUsedVisitor(variable);
|
||||
rhs.accept(visitor);
|
||||
read = visitor.isUsed();
|
||||
read = VariableUsedVisitor.isVariableUsedIn(variable, rhs);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,10 +122,7 @@ class VariableValueUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
if (initalizer == null) {
|
||||
return;
|
||||
}
|
||||
final VariableUsedVisitor visitor =
|
||||
new VariableUsedVisitor(variable);
|
||||
initalizer.accept(visitor);
|
||||
read = visitor.isUsed();
|
||||
read = VariableUsedVisitor.isVariableUsedIn(variable, initalizer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,11 +136,8 @@ class VariableValueUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
call.getMethodExpression();
|
||||
final PsiExpression qualifier =
|
||||
methodExpression.getQualifierExpression();
|
||||
final VariableUsedVisitor visitor =
|
||||
new VariableUsedVisitor(variable);
|
||||
if (qualifier != null) {
|
||||
qualifier.accept(visitor);
|
||||
if (visitor.isUsed()) {
|
||||
if (VariableUsedVisitor.isVariableUsedIn(variable, qualifier)) {
|
||||
read = true;
|
||||
return;
|
||||
}
|
||||
@@ -154,8 +145,7 @@ class VariableValueUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
final PsiExpressionList argumentList = call.getArgumentList();
|
||||
final PsiExpression[] arguments = argumentList.getExpressions();
|
||||
for (final PsiExpression argument : arguments) {
|
||||
argument.accept(visitor);
|
||||
if (visitor.isUsed()) {
|
||||
if (VariableUsedVisitor.isVariableUsedIn(variable, argument)) {
|
||||
read = true;
|
||||
return;
|
||||
}
|
||||
@@ -176,10 +166,7 @@ class VariableValueUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
}
|
||||
final PsiExpression[] arguments = argumentList.getExpressions();
|
||||
for (final PsiExpression argument : arguments) {
|
||||
final VariableUsedVisitor visitor =
|
||||
new VariableUsedVisitor(variable);
|
||||
argument.accept(visitor);
|
||||
if (visitor.isUsed()) {
|
||||
if (VariableUsedVisitor.isVariableUsedIn(variable, argument)) {
|
||||
read = true;
|
||||
return;
|
||||
}
|
||||
@@ -195,10 +182,7 @@ class VariableValueUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
super.visitArrayInitializerExpression(expression);
|
||||
final PsiExpression[] arguments = expression.getInitializers();
|
||||
for (final PsiExpression argument : arguments) {
|
||||
final VariableUsedVisitor visitor =
|
||||
new VariableUsedVisitor(variable);
|
||||
argument.accept(visitor);
|
||||
if (visitor.isUsed()) {
|
||||
if (VariableUsedVisitor.isVariableUsedIn(variable, argument)) {
|
||||
read = true;
|
||||
return;
|
||||
}
|
||||
@@ -216,10 +200,7 @@ class VariableValueUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
if (returnValue == null) {
|
||||
return;
|
||||
}
|
||||
final VariableUsedVisitor visitor =
|
||||
new VariableUsedVisitor(variable);
|
||||
returnValue.accept(visitor);
|
||||
read = visitor.isUsed();
|
||||
read = VariableUsedVisitor.isVariableUsedIn(variable, returnValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,13 +212,10 @@ class VariableValueUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
return;
|
||||
}
|
||||
super.visitClass(aClass);
|
||||
final VariableUsedVisitor visitor =
|
||||
new VariableUsedVisitor(variable);
|
||||
aClass.accept(visitor);
|
||||
read = visitor.isUsed();
|
||||
read = VariableUsedVisitor.isVariableUsedIn(variable, aClass);
|
||||
}
|
||||
|
||||
public boolean isVariableValueUsed() {
|
||||
boolean isVariableValueUsed() {
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -107,10 +107,10 @@ public class UnusedLabelInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private static class LabelFinder extends JavaRecursiveElementVisitor {
|
||||
private static class LabelFinder extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private boolean found = false;
|
||||
private String label = null;
|
||||
private boolean found;
|
||||
private final String label;
|
||||
|
||||
private LabelFinder(PsiLabeledStatement target) {
|
||||
final PsiIdentifier labelIdentifier = target.getLabelIdentifier();
|
||||
@@ -161,7 +161,7 @@ public class UnusedLabelInspection extends BaseInspection {
|
||||
return labelText.equals(label);
|
||||
}
|
||||
|
||||
public boolean jumpFound() {
|
||||
boolean jumpFound() {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-12
@@ -33,8 +33,8 @@ import javax.swing.*;
|
||||
|
||||
public abstract class ResourceInspection extends BaseInspection {
|
||||
|
||||
@SuppressWarnings({"PublicField"})
|
||||
public boolean insideTryAllowed = false;
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean insideTryAllowed;
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
@@ -177,7 +177,7 @@ public abstract class ResourceInspection extends BaseInspection {
|
||||
return !result.get().booleanValue();
|
||||
}
|
||||
|
||||
protected static boolean isResourceClosedInFinally(@NotNull PsiTryStatement tryStatement, @NotNull PsiVariable variable) {
|
||||
static boolean isResourceClosedInFinally(@NotNull PsiTryStatement tryStatement, @NotNull PsiVariable variable) {
|
||||
final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
|
||||
if (finallyBlock == null) {
|
||||
return false;
|
||||
@@ -201,7 +201,7 @@ public abstract class ResourceInspection extends BaseInspection {
|
||||
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
|
||||
return isResourceClose(methodCallExpression, variable);
|
||||
}
|
||||
else if (statement instanceof PsiTryStatement) {
|
||||
if (statement instanceof PsiTryStatement) {
|
||||
final PsiTryStatement tryStatement = (PsiTryStatement)statement;
|
||||
final PsiCodeBlock tryBlock = tryStatement.getTryBlock();
|
||||
if (tryBlock == null) {
|
||||
@@ -278,7 +278,7 @@ public abstract class ResourceInspection extends BaseInspection {
|
||||
return referent != null && referent.equals(resource);
|
||||
}
|
||||
|
||||
public static boolean isResourceEscapingFromMethod(PsiVariable boundVariable, PsiExpression resourceCreationExpression) {
|
||||
static boolean isResourceEscapingFromMethod(PsiVariable boundVariable, PsiExpression resourceCreationExpression) {
|
||||
if (resourceCreationExpression instanceof PsiMethodCallExpression) {
|
||||
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)resourceCreationExpression;
|
||||
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
|
||||
@@ -305,7 +305,7 @@ public abstract class ResourceInspection extends BaseInspection {
|
||||
if (parent instanceof PsiReturnStatement) {
|
||||
return true;
|
||||
}
|
||||
else if (parent instanceof PsiAssignmentExpression) {
|
||||
if (parent instanceof PsiAssignmentExpression) {
|
||||
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parent;
|
||||
if (ParenthesesUtils.stripParentheses(assignmentExpression.getRExpression()) != resourceCreationExpression) {
|
||||
return true; // non-sensical code
|
||||
@@ -340,9 +340,8 @@ public abstract class ResourceInspection extends BaseInspection {
|
||||
return visitor.isEscaped();
|
||||
}
|
||||
|
||||
private static class CloseVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean containsClose = false;
|
||||
private static class CloseVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean containsClose;
|
||||
private final PsiVariable resource;
|
||||
private final String resourceName;
|
||||
|
||||
@@ -423,15 +422,15 @@ public abstract class ResourceInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsClose() {
|
||||
private boolean containsClose() {
|
||||
return containsClose;
|
||||
}
|
||||
}
|
||||
|
||||
private static class EscapeVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class EscapeVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiVariable boundVariable;
|
||||
private boolean escaped = false;
|
||||
private boolean escaped;
|
||||
|
||||
public EscapeVisitor(@NotNull PsiVariable boundVariable) {
|
||||
this.boundVariable = boundVariable;
|
||||
|
||||
+13
-13
@@ -232,7 +232,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
if (arguments.length == 0) {
|
||||
return null;
|
||||
}
|
||||
else if (arguments.length > 1) {
|
||||
if (arguments.length > 1) {
|
||||
if (result.length() != 0) {
|
||||
insertPlus(result);
|
||||
}
|
||||
@@ -303,7 +303,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
result.insert(index - 1, "+ ");
|
||||
return;
|
||||
}
|
||||
else if (c == '\n') {
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
index--;
|
||||
@@ -315,14 +315,14 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private static class StringBuildingVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class StringBuildingVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiVariable myVariable;
|
||||
private final StringBuilder myBuilder;
|
||||
private final List<PsiMethodCallExpression> expressions = ContainerUtil.newArrayList();
|
||||
private boolean myProblem = false;
|
||||
private boolean myProblem;
|
||||
|
||||
public StringBuildingVisitor(@NotNull PsiVariable variable, StringBuilder builder) {
|
||||
private StringBuildingVisitor(@NotNull PsiVariable variable, StringBuilder builder) {
|
||||
myVariable = variable;
|
||||
myBuilder = builder;
|
||||
}
|
||||
@@ -362,7 +362,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
return expressions;
|
||||
}
|
||||
|
||||
public boolean hadProblem() {
|
||||
private boolean hadProblem() {
|
||||
return myProblem;
|
||||
}
|
||||
}
|
||||
@@ -431,7 +431,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAppendCall(PsiElement element) {
|
||||
private static boolean isAppendCall(PsiElement element) {
|
||||
if (!(element instanceof PsiMethodCallExpression)) {
|
||||
return false;
|
||||
}
|
||||
@@ -450,7 +450,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
return arguments.length == 1;
|
||||
}
|
||||
|
||||
public static boolean isToStringCall(PsiElement element) {
|
||||
private static boolean isToStringCall(PsiElement element) {
|
||||
if (!(element instanceof PsiMethodCallExpression)) {
|
||||
return false;
|
||||
}
|
||||
@@ -488,15 +488,15 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class ReplaceableByStringVisitor extends JavaRecursiveElementVisitor {
|
||||
private static class ReplaceableByStringVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiElement myParent;
|
||||
private final PsiVariable myVariable;
|
||||
private boolean myReplaceable = true;
|
||||
private boolean myPossibleSideEffect = false;
|
||||
private boolean myToStringFound = false;
|
||||
private boolean myPossibleSideEffect;
|
||||
private boolean myToStringFound;
|
||||
|
||||
public ReplaceableByStringVisitor(@NotNull PsiVariable variable) {
|
||||
ReplaceableByStringVisitor(@NotNull PsiVariable variable) {
|
||||
myVariable = variable;
|
||||
myParent = PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class, PsiIfStatement.class, PsiLoopStatement.class);
|
||||
}
|
||||
@@ -577,7 +577,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (grandParent instanceof PsiNewExpression) {
|
||||
if (grandParent instanceof PsiNewExpression) {
|
||||
final PsiLocalVariable variable = PsiTreeUtil.getParentOfType(grandParent, PsiLocalVariable.class, true, PsiExpressionList.class);
|
||||
if (!myVariable.equals(variable)) {
|
||||
return false;
|
||||
|
||||
+3
-4
@@ -89,13 +89,12 @@ public class AwaitWithoutCorrespondingSignalInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
private static class ContainsSignalVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiField target;
|
||||
private boolean containsSignal = false;
|
||||
private boolean containsSignal;
|
||||
|
||||
ContainsSignalVisitor(PsiField target) {
|
||||
super();
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@@ -134,7 +133,7 @@ public class AwaitWithoutCorrespondingSignalInspection extends BaseInspection {
|
||||
containsSignal = true;
|
||||
}
|
||||
|
||||
public boolean containsSignal() {
|
||||
boolean containsSignal() {
|
||||
return containsSignal;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -88,13 +88,12 @@ public class NotifyWithoutCorrespondingWaitInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
private static class ContainsWaitVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiField target;
|
||||
private boolean containsWait = false;
|
||||
private boolean containsWait;
|
||||
|
||||
ContainsWaitVisitor(PsiField target) {
|
||||
super();
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@@ -133,7 +132,7 @@ public class NotifyWithoutCorrespondingWaitInspection extends BaseInspection {
|
||||
containsWait = true;
|
||||
}
|
||||
|
||||
public boolean containsWait() {
|
||||
boolean containsWait() {
|
||||
return containsWait;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -168,9 +168,8 @@ public class SafeLockInspection extends BaseInspection { // todo extend Resource
|
||||
}
|
||||
}
|
||||
|
||||
private static class UnlockVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private boolean containsUnlock = false;
|
||||
private static class UnlockVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private boolean containsUnlock;
|
||||
private final PsiVariable variable;
|
||||
private final LockType type;
|
||||
|
||||
@@ -238,12 +237,12 @@ public class SafeLockInspection extends BaseInspection { // todo extend Resource
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsUnlock() {
|
||||
boolean containsUnlock() {
|
||||
return containsUnlock;
|
||||
}
|
||||
}
|
||||
|
||||
enum LockType {
|
||||
private enum LockType {
|
||||
READ, WRITE, REGULAR
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -88,13 +88,12 @@ public class SignalWithoutCorrespondingAwaitInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
private static class ContainsAwaitVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiField target;
|
||||
private boolean containsAwait = false;
|
||||
private boolean containsAwait;
|
||||
|
||||
ContainsAwaitVisitor(PsiField target) {
|
||||
super();
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@@ -133,7 +132,7 @@ public class SignalWithoutCorrespondingAwaitInspection extends BaseInspection {
|
||||
containsAwait = true;
|
||||
}
|
||||
|
||||
public boolean containsAwait() {
|
||||
boolean containsAwait() {
|
||||
return containsAwait;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -69,8 +69,7 @@ public class ThreadStartInConstructionInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private class ThreadStartVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
private class ThreadStartVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
@Override
|
||||
public void visitClass(PsiClass aClass) {
|
||||
// Do not recurse into.
|
||||
|
||||
+38
-30
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.siyeh.ig.threading;
|
||||
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
@@ -28,7 +29,7 @@ import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
class VariableAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
class VariableAccessVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiClass aClass;
|
||||
private final Set<PsiField> m_synchronizedAccesses =
|
||||
@@ -41,12 +42,12 @@ class VariableAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
new HashSet<PsiMethod>();
|
||||
private final Set<PsiMethod> unusedMethods = new HashSet<PsiMethod>();
|
||||
private final Set<PsiMethod> usedMethods = new HashSet<PsiMethod>();
|
||||
private boolean m_inInitializer = false;
|
||||
private boolean m_inSynchronizedContext = false;
|
||||
private boolean privateMethodUsagesCalculated = false;
|
||||
private boolean m_inInitializer;
|
||||
private int m_inSynchronizedContextCount;
|
||||
private boolean privateMethodUsagesCalculated;
|
||||
private final boolean countGettersAndSetters;
|
||||
|
||||
VariableAccessVisitor(PsiClass aClass, boolean countGettersAndSetters) {
|
||||
VariableAccessVisitor(@NotNull PsiClass aClass, boolean countGettersAndSetters) {
|
||||
this.aClass = aClass;
|
||||
this.countGettersAndSetters = countGettersAndSetters;
|
||||
}
|
||||
@@ -54,20 +55,16 @@ class VariableAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
@Override
|
||||
public void visitClass(PsiClass classToVisit) {
|
||||
calculatePrivateMethodUsagesIfNecessary();
|
||||
final boolean wasInSync = m_inSynchronizedContext;
|
||||
if (!classToVisit.equals(aClass)) {
|
||||
m_inSynchronizedContext = false;
|
||||
m_inSynchronizedContextCount -= 1000;
|
||||
}
|
||||
super.visitClass(classToVisit);
|
||||
m_inSynchronizedContext = wasInSync;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLambdaExpression(PsiLambdaExpression expression) {
|
||||
final boolean wasInSync = m_inSynchronizedContext;
|
||||
m_inSynchronizedContext = false;
|
||||
m_inSynchronizedContextCount -= 1000;
|
||||
super.visitLambdaExpression(expression);
|
||||
m_inSynchronizedContext = wasInSync;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,7 +80,7 @@ class VariableAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
}
|
||||
if (m_inInitializer) {
|
||||
}
|
||||
else if (m_inSynchronizedContext) {
|
||||
else if (m_inSynchronizedContextCount > 0) {
|
||||
m_synchronizedAccesses.add((PsiField)element);
|
||||
}
|
||||
else if (ref.getParent() instanceof PsiSynchronizedStatement) {
|
||||
@@ -119,7 +116,7 @@ class VariableAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
}
|
||||
if (m_inInitializer) {
|
||||
}
|
||||
else if (m_inSynchronizedContext) {
|
||||
else if (m_inSynchronizedContextCount > 0) {
|
||||
m_synchronizedAccesses.add(field);
|
||||
}
|
||||
else {
|
||||
@@ -129,19 +126,22 @@ class VariableAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
|
||||
@Override
|
||||
public void visitCodeBlock(PsiCodeBlock block) {
|
||||
final boolean wasInSync = m_inSynchronizedContext;
|
||||
if (block.getParent() instanceof PsiSynchronizedStatement) {
|
||||
m_inSynchronizedContext = true;
|
||||
m_inSynchronizedContextCount ++;
|
||||
}
|
||||
super.visitCodeBlock(block);
|
||||
m_inSynchronizedContext = wasInSync;
|
||||
}
|
||||
|
||||
private static final Key<Boolean> CODE_BLOCK_CONTAINS_HOLDS_LOCK_CALL = Key.create("CODE_BLOCK_CONTAINS_HOLDS_LOCK_CALL");
|
||||
@Override
|
||||
public void visitAssertStatement(PsiAssertStatement statement) {
|
||||
final PsiExpression condition = statement.getAssertCondition();
|
||||
if (SynchronizationUtil.isCallToHoldsLock(condition)) {
|
||||
m_inSynchronizedContext = true;
|
||||
m_inSynchronizedContextCount ++;
|
||||
PsiElement codeBlock = statement.getParent();
|
||||
if (codeBlock != null) {
|
||||
codeBlock.putUserData(CODE_BLOCK_CONTAINS_HOLDS_LOCK_CALL, true);
|
||||
}
|
||||
}
|
||||
super.visitAssertStatement(statement);
|
||||
}
|
||||
@@ -156,22 +156,14 @@ class VariableAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
final boolean methodIsSynchronized =
|
||||
method.hasModifierProperty(PsiModifier.SYNCHRONIZED)
|
||||
|| methodIsAlwaysUsedSynchronized(method);
|
||||
boolean wasInSync = false;
|
||||
if (methodIsSynchronized) {
|
||||
wasInSync = m_inSynchronizedContext;
|
||||
m_inSynchronizedContext = true;
|
||||
m_inSynchronizedContextCount++;
|
||||
}
|
||||
final boolean isConstructor = method.isConstructor();
|
||||
if (isConstructor) {
|
||||
m_inInitializer = true;
|
||||
}
|
||||
super.visitMethod(method);
|
||||
if (methodIsSynchronized) {
|
||||
m_inSynchronizedContext = wasInSync;
|
||||
}
|
||||
if (isConstructor) {
|
||||
m_inInitializer = false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean methodIsAlwaysUsedSynchronized(PsiMethod method) {
|
||||
@@ -261,7 +253,7 @@ class VariableAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
private static HashMap<PsiMethod, Collection<PsiReference>>
|
||||
buildReferenceMap(Set<PsiMethod> privateMethods) {
|
||||
final HashMap<PsiMethod, Collection<PsiReference>> referenceMap =
|
||||
new HashMap();
|
||||
new HashMap<PsiMethod, Collection<PsiReference>>();
|
||||
for (PsiMethod method : privateMethods) {
|
||||
final SearchScope scope = method.getUseScope();
|
||||
final Collection<PsiReference> references =
|
||||
@@ -343,17 +335,33 @@ class VariableAccessVisitor extends JavaRecursiveElementVisitor {
|
||||
public void visitClassInitializer(@NotNull PsiClassInitializer initializer) {
|
||||
m_inInitializer = true;
|
||||
super.visitClassInitializer(initializer);
|
||||
m_inInitializer = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitField(@NotNull PsiField field) {
|
||||
m_inInitializer = true;
|
||||
super.visitField(field);
|
||||
m_inInitializer = false;
|
||||
}
|
||||
|
||||
public Set<PsiField> getInappropriatelyAccessedFields() {
|
||||
@Override
|
||||
protected void elementFinished(@NotNull PsiElement element) {
|
||||
if (element instanceof PsiField || element instanceof PsiClassInitializer || element instanceof PsiMethod && ((PsiMethod)element).isConstructor()) {
|
||||
m_inInitializer = false;
|
||||
}
|
||||
if (element instanceof PsiClass && !element.equals(aClass) || element instanceof PsiLambdaExpression) {
|
||||
m_inSynchronizedContextCount += 1000;
|
||||
}
|
||||
if (element instanceof PsiCodeBlock && element.getParent() instanceof PsiSynchronizedStatement
|
||||
|| element instanceof PsiMethod && ((PsiMethod)element).hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
|
||||
m_inSynchronizedContextCount --;
|
||||
}
|
||||
if (element.getUserData(CODE_BLOCK_CONTAINS_HOLDS_LOCK_CALL) != null) {
|
||||
m_inSynchronizedContextCount --;
|
||||
element.putUserData(CODE_BLOCK_CONTAINS_HOLDS_LOCK_CALL, null);
|
||||
}
|
||||
}
|
||||
|
||||
Set<PsiField> getInappropriatelyAccessedFields() {
|
||||
final Set<PsiField> out =
|
||||
new HashSet<PsiField>(m_synchronizedAccesses);
|
||||
out.retainAll(m_unsynchronizedAccesses);
|
||||
|
||||
+2
-2
@@ -58,8 +58,8 @@ public class WaitWhileHoldingTwoLocksInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
private void checkErrorsIn(PsiElement context) {
|
||||
context.accept(new JavaRecursiveElementVisitor() {
|
||||
private int m_numLocksHeld = 0;
|
||||
context.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
private int m_numLocksHeld;
|
||||
|
||||
@Override
|
||||
public void visitClass(PsiClass aClass) {
|
||||
|
||||
+3
-4
@@ -89,13 +89,12 @@ public class WaitWithoutCorrespondingNotifyInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
private static class ContainsNotifyVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final PsiField target;
|
||||
private boolean containsNotify = false;
|
||||
private boolean containsNotify;
|
||||
|
||||
ContainsNotifyVisitor(PsiField target) {
|
||||
super();
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@@ -134,7 +133,7 @@ public class WaitWithoutCorrespondingNotifyInspection extends BaseInspection {
|
||||
containsNotify = true;
|
||||
}
|
||||
|
||||
public boolean containsNotify() {
|
||||
boolean containsNotify() {
|
||||
return containsNotify;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -75,7 +75,7 @@ class AnonymousClassVariableHidesOuterClassVariableVisitor extends BaseInspectio
|
||||
}
|
||||
}
|
||||
|
||||
private static class VariableCollector extends JavaRecursiveElementVisitor {
|
||||
private static class VariableCollector extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private static final PsiVariable[] EMPTY_VARIABLE_LIST = {};
|
||||
|
||||
|
||||
+2
-2
@@ -49,7 +49,7 @@ import java.util.List;
|
||||
public class UnnecessaryFullyQualifiedNameInspection extends BaseInspection implements CleanupLocalInspectionTool {
|
||||
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean m_ignoreJavadoc = false; // left here to prevent changes to project files.
|
||||
public boolean m_ignoreJavadoc; // left here to prevent changes to project files.
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -124,7 +124,7 @@ public class UnnecessaryFullyQualifiedNameInspection extends BaseInspection impl
|
||||
elementCount));
|
||||
}
|
||||
|
||||
private static class QualificationRemover extends JavaRecursiveElementVisitor {
|
||||
private static class QualificationRemover extends JavaRecursiveElementWalkingVisitor {
|
||||
private final String fullyQualifiedText;
|
||||
private final List<PsiElement> shortenedElements = new ArrayList<PsiElement>();
|
||||
|
||||
|
||||
+3
-3
@@ -126,7 +126,7 @@ public class UnqualifiedInnerClassAccessInspection extends UnqualifiedInnerClass
|
||||
}
|
||||
final Collection<PsiJavaCodeReferenceElement> references = referenceCollector.getReferences();
|
||||
final SmartPointerManager pointerManager = SmartPointerManager.getInstance(project);
|
||||
final List<SmartPsiElementPointer> pointers = new ArrayList();
|
||||
final List<SmartPsiElementPointer> pointers = new ArrayList<SmartPsiElementPointer>();
|
||||
for (PsiJavaCodeReferenceElement reference : references) {
|
||||
final SmartPsiElementPointer<PsiJavaCodeReferenceElement> pointer = pointerManager.createSmartPsiElementPointer(reference);
|
||||
pointers.add(pointer);
|
||||
@@ -146,7 +146,7 @@ public class UnqualifiedInnerClassAccessInspection extends UnqualifiedInnerClass
|
||||
document.replaceString(0, document.getTextLength(), text);
|
||||
documentManager.commitDocument(document);
|
||||
if (pointers.size() > 1) {
|
||||
final List<PsiElement> elements = new ArrayList();
|
||||
final List<PsiElement> elements = new ArrayList<PsiElement>();
|
||||
for (SmartPsiElementPointer pointer : pointers) {
|
||||
elements.add(pointer.getElement());
|
||||
}
|
||||
@@ -203,7 +203,7 @@ public class UnqualifiedInnerClassAccessInspection extends UnqualifiedInnerClass
|
||||
}
|
||||
}
|
||||
|
||||
private static class ReferenceCollector extends JavaRecursiveElementVisitor {
|
||||
private static class ReferenceCollector extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private final String name;
|
||||
private final boolean onDemand;
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -57,7 +57,7 @@ public class AppEngineForbiddenCodeInspection extends BaseJavaLocalInspectionToo
|
||||
|
||||
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
|
||||
final List<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>();
|
||||
file.accept(new JavaRecursiveElementVisitor() {
|
||||
file.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
public void visitDocComment(PsiDocComment comment) {
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
|
||||
};
|
||||
}
|
||||
|
||||
private class StringI18nVisitor extends JavaRecursiveElementVisitor {
|
||||
private class StringI18nVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private final List<ProblemDescriptor> myProblems = new ArrayList<ProblemDescriptor>();
|
||||
private final InspectionManager myManager;
|
||||
private final boolean myOnTheFly;
|
||||
|
||||
Reference in New Issue
Block a user