mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 09:03:31 +07:00
check enum constants for variables that can be passed as arguments
This commit is contained in:
+20
-34
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,14 +44,29 @@ class VariablePassedAsArgumentExcludedVisitor extends JavaRecursiveElementVisito
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call) {
|
||||
public void visitCallExpression(PsiCallExpression callExpression) {
|
||||
if (passed) {
|
||||
return;
|
||||
}
|
||||
super.visitMethodCallExpression(call);
|
||||
super.visitCallExpression(callExpression);
|
||||
visitCall(callExpression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnumConstant(PsiEnumConstant enumConstant) {
|
||||
if (passed) {
|
||||
return;
|
||||
}
|
||||
super.visitEnumConstant(enumConstant);
|
||||
visitCall(enumConstant);
|
||||
}
|
||||
|
||||
private void visitCall(PsiCall call) {
|
||||
final PsiExpressionList argumentList = call.getArgumentList();
|
||||
final PsiExpression[] arguments = argumentList.getExpressions();
|
||||
for (PsiExpression argument : arguments) {
|
||||
if (argumentList == null) {
|
||||
return;
|
||||
}
|
||||
for (PsiExpression argument : argumentList.getExpressions()) {
|
||||
if (!VariableAccessUtils.mayEvaluateToVariable(argument, variable, myBuilderPattern)) {
|
||||
continue;
|
||||
}
|
||||
@@ -69,35 +84,6 @@ class VariablePassedAsArgumentExcludedVisitor extends JavaRecursiveElementVisito
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNewExpression(@NotNull PsiNewExpression newExpression) {
|
||||
if (passed) {
|
||||
return;
|
||||
}
|
||||
super.visitNewExpression(newExpression);
|
||||
final PsiExpressionList argumentList = newExpression.getArgumentList();
|
||||
if (argumentList == null) {
|
||||
return;
|
||||
}
|
||||
final PsiExpression[] arguments = argumentList.getExpressions();
|
||||
for (PsiExpression argument : arguments) {
|
||||
if (!VariableAccessUtils.mayEvaluateToVariable(argument, variable, myBuilderPattern)) {
|
||||
continue;
|
||||
}
|
||||
final PsiMethod constructor = newExpression.resolveConstructor();
|
||||
if (constructor != null) {
|
||||
final PsiClass aClass = constructor.getContainingClass();
|
||||
if (aClass != null) {
|
||||
final String name = aClass.getQualifiedName();
|
||||
if (excludes.contains(name)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
passed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPassed() {
|
||||
return passed;
|
||||
}
|
||||
|
||||
+12
-16
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,33 +37,29 @@ class VariablePassedAsArgumentVisitor extends JavaRecursiveElementVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call) {
|
||||
public void visitCallExpression(PsiCallExpression callExpression) {
|
||||
super.visitCallExpression(callExpression);
|
||||
if (passed) {
|
||||
return;
|
||||
}
|
||||
super.visitMethodCallExpression(call);
|
||||
final PsiExpressionList argumentList = call.getArgumentList();
|
||||
final PsiExpression[] arguments = argumentList.getExpressions();
|
||||
for (PsiExpression argument : arguments) {
|
||||
if (VariableAccessUtils.mayEvaluateToVariable(argument, variable)) {
|
||||
passed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
visitCall(callExpression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNewExpression(@NotNull PsiNewExpression newExpression) {
|
||||
public void visitEnumConstant(PsiEnumConstant enumConstant) {
|
||||
if (passed) {
|
||||
return;
|
||||
}
|
||||
super.visitNewExpression(newExpression);
|
||||
final PsiExpressionList argumentList = newExpression.getArgumentList();
|
||||
super.visitEnumConstant(enumConstant);
|
||||
visitCall(enumConstant);
|
||||
}
|
||||
|
||||
private void visitCall(PsiCall call) {
|
||||
final PsiExpressionList argumentList = call.getArgumentList();
|
||||
if (argumentList == null) {
|
||||
return;
|
||||
}
|
||||
final PsiExpression[] arguments = argumentList.getExpressions();
|
||||
for (PsiExpression argument : arguments) {
|
||||
for (PsiExpression argument : argumentList.getExpressions()) {
|
||||
if (VariableAccessUtils.mayEvaluateToVariable(argument, variable)) {
|
||||
passed = true;
|
||||
break;
|
||||
|
||||
+14
@@ -275,4 +275,18 @@ class SimpleAdd {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
class EnumConstant {
|
||||
private static final List<String> CONSTANT_ARRAY = new ArrayList();
|
||||
static {
|
||||
CONSTANT_ARRAY.add("asdf");
|
||||
}
|
||||
|
||||
enum SomeEnum {
|
||||
ITEM(CONSTANT_ARRAY); // passed as argument
|
||||
private final List<String> myPatterns;
|
||||
SomeEnum(List<String> patterns) {
|
||||
myPatterns = patterns;
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -31,3 +31,15 @@ interface List<T> {
|
||||
interface Consumer<T> {
|
||||
void accept(T t);
|
||||
}
|
||||
class EnumConstant {
|
||||
private static final StringBuilder sb = new StringBuilder();
|
||||
static {
|
||||
sb.append("");
|
||||
}
|
||||
|
||||
enum SomeEnum {
|
||||
ITEM(sb); // passed as argument
|
||||
|
||||
SomeEnum(StringBuilder sb) {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user