本文整理汇总了Java中com.siyeh.ig.psiutils.ExpressionUtils.isOffsetArrayAccess方法的典型用法代码示例。如果您正苦于以下问题:Java ExpressionUtils.isOffsetArrayAccess方法的具体用法?Java ExpressionUtils.isOffsetArrayAccess怎么用?Java ExpressionUtils.isOffsetArrayAccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.siyeh.ig.psiutils.ExpressionUtils
的用法示例。
在下文中一共展示了ExpressionUtils.isOffsetArrayAccess方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bodyIsArrayCopy
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
private static boolean bodyIsArrayCopy(
PsiStatement body, PsiVariable variable,
@Nullable PsiVariable variable2) {
if (body instanceof PsiExpressionStatement) {
final PsiExpressionStatement exp =
(PsiExpressionStatement)body;
final PsiExpression expression = exp.getExpression();
return expressionIsArrayCopy(expression, variable, variable2);
}
else if (body instanceof PsiBlockStatement) {
final PsiBlockStatement blockStatement =
(PsiBlockStatement)body;
final PsiCodeBlock codeBlock = blockStatement.getCodeBlock();
final PsiStatement[] statements = codeBlock.getStatements();
if (statements.length == 1) {
return bodyIsArrayCopy(statements[0], variable, variable2);
}
else if (statements.length == 2) {
final PsiStatement statement = statements[0];
if (!(statement instanceof PsiDeclarationStatement)) {
return false;
}
final PsiDeclarationStatement declarationStatement =
(PsiDeclarationStatement)statement;
final PsiElement[] declaredElements =
declarationStatement.getDeclaredElements();
if (declaredElements.length != 1) {
return false;
}
final PsiElement declaredElement = declaredElements[0];
if (!(declaredElement instanceof PsiVariable)) {
return false;
}
final PsiVariable localVariable =
(PsiVariable)declaredElement;
final PsiExpression initializer =
localVariable.getInitializer();
if (!ExpressionUtils.isOffsetArrayAccess(initializer,
variable)) {
return false;
}
return bodyIsArrayCopy(statements[1], variable,
localVariable);
}
}
return false;
}
示例2: expressionIsArrayCopy
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
private static boolean expressionIsArrayCopy(
@Nullable PsiExpression expression,
@NotNull PsiVariable variable,
@Nullable PsiVariable variable2) {
final PsiExpression strippedExpression =
ParenthesesUtils.stripParentheses(expression);
if (strippedExpression == null) {
return false;
}
if (!(strippedExpression instanceof PsiAssignmentExpression)) {
return false;
}
final PsiAssignmentExpression assignment =
(PsiAssignmentExpression)strippedExpression;
final IElementType tokenType = assignment.getOperationTokenType();
if (!tokenType.equals(JavaTokenType.EQ)) {
return false;
}
final PsiExpression lhs = assignment.getLExpression();
if (SideEffectChecker.mayHaveSideEffects(lhs)) {
return false;
}
if (!ExpressionUtils.isOffsetArrayAccess(lhs, variable)) {
return false;
}
final PsiExpression rhs = assignment.getRExpression();
if (rhs == null) {
return false;
}
if (SideEffectChecker.mayHaveSideEffects(rhs)) {
return false;
}
if (!areExpressionsCopyable(lhs, rhs)) {
return false;
}
final PsiType type = lhs.getType();
if (type instanceof PsiPrimitiveType) {
final PsiExpression strippedLhs =
ParenthesesUtils.stripParentheses(lhs);
final PsiExpression strippedRhs =
ParenthesesUtils.stripParentheses(rhs);
if (!areExpressionsCopyable(strippedLhs, strippedRhs)) {
return false;
}
}
if (variable2 == null) {
return ExpressionUtils.isOffsetArrayAccess(rhs, variable);
}
else {
return VariableAccessUtils.evaluatesToVariable(rhs, variable2);
}
}
示例3: bodyIsArrayToCollectionCopy
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
private static boolean bodyIsArrayToCollectionCopy(
PsiStatement body, PsiVariable variable,
boolean shouldBeOffsetArrayAccess) {
if (body instanceof PsiExpressionStatement) {
final PsiExpressionStatement expressionStatement =
(PsiExpressionStatement)body;
final PsiExpression expression =
expressionStatement.getExpression();
return expressionIsArrayToCollectionCopy(expression, variable,
shouldBeOffsetArrayAccess);
}
else if (body instanceof PsiBlockStatement) {
final PsiBlockStatement blockStatement =
(PsiBlockStatement)body;
final PsiCodeBlock codeBlock = blockStatement.getCodeBlock();
final PsiStatement[] statements = codeBlock.getStatements();
if (statements.length == 1) {
return bodyIsArrayToCollectionCopy(statements[0], variable,
shouldBeOffsetArrayAccess);
}
else if (statements.length == 2) {
final PsiStatement statement = statements[0];
if (!(statement instanceof PsiDeclarationStatement)) {
return false;
}
final PsiDeclarationStatement declarationStatement =
(PsiDeclarationStatement)statement;
final PsiElement[] declaredElements =
declarationStatement.getDeclaredElements();
if (declaredElements.length != 1) {
return false;
}
final PsiElement declaredElement = declaredElements[0];
if (!(declaredElement instanceof PsiVariable)) {
return false;
}
final PsiVariable localVariable =
(PsiVariable)declaredElement;
final PsiExpression initializer =
localVariable.getInitializer();
if (!ExpressionUtils.isOffsetArrayAccess(initializer,
variable)) {
return false;
}
return bodyIsArrayToCollectionCopy(statements[1],
localVariable, false);
}
}
return false;
}
示例4: expressionIsArrayToCollectionCopy
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
private static boolean expressionIsArrayToCollectionCopy(
PsiExpression expression, PsiVariable variable,
boolean shouldBeOffsetArrayAccess) {
expression = ParenthesesUtils.stripParentheses(expression);
if (expression == null) {
return false;
}
if (!(expression instanceof PsiMethodCallExpression)) {
return false;
}
final PsiMethodCallExpression methodCallExpression =
(PsiMethodCallExpression)expression;
final PsiExpressionList argumentList =
methodCallExpression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length != 1) {
return false;
}
final PsiReferenceExpression methodExpression =
methodCallExpression.getMethodExpression();
final PsiExpression qualifier =
methodExpression.getQualifierExpression();
if (!(qualifier instanceof PsiReferenceExpression) &&
!(qualifier instanceof PsiThisExpression) &&
!(qualifier instanceof PsiSuperExpression)) {
return false;
}
final PsiExpression argument = arguments[0];
final PsiType argumentType = argument.getType();
if (argumentType instanceof PsiPrimitiveType) {
return false;
}
if (SideEffectChecker.mayHaveSideEffects(argument)) {
return false;
}
if (shouldBeOffsetArrayAccess) {
if (!ExpressionUtils.isOffsetArrayAccess(argument, variable)) {
return false;
}
}
else if (!VariableAccessUtils.evaluatesToVariable(argument,
variable)) {
return false;
}
final PsiMethod method = methodCallExpression.resolveMethod();
if (method == null) {
return false;
}
@NonNls final String name = method.getName();
if (!name.equals("add")) {
return false;
}
final PsiClass containingClass = method.getContainingClass();
return InheritanceUtil.isInheritor(containingClass,
CommonClassNames.JAVA_UTIL_COLLECTION);
}