本文整理汇总了Java中com.siyeh.ig.psiutils.SideEffectChecker.mayHaveSideEffects方法的典型用法代码示例。如果您正苦于以下问题:Java SideEffectChecker.mayHaveSideEffects方法的具体用法?Java SideEffectChecker.mayHaveSideEffects怎么用?Java SideEffectChecker.mayHaveSideEffects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.siyeh.ig.psiutils.SideEffectChecker
的用法示例。
在下文中一共展示了SideEffectChecker.mayHaveSideEffects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitMethodCallExpression
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
if (!MethodCallUtils.isEqualsCall(expression)) {
return;
}
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (qualifier == null) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length != 1) {
return;
}
final PsiExpression argument = arguments[0];
if (!EquivalenceChecker.expressionsAreEquivalent(qualifier, argument) ||
SideEffectChecker.mayHaveSideEffects(qualifier)) {
return;
}
registerMethodCallError(expression);
}
示例2: canConvertToLambdaWithoutSideEffects
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
/**
* Checks whether method reference can be converted to lambda without significant semantics change
* (i.e. method reference qualifier has no side effects)
*
* @param methodReferenceExpression method reference to check
* @return true if method reference can be converted to lambda
*/
public static boolean canConvertToLambdaWithoutSideEffects(PsiMethodReferenceExpression methodReferenceExpression)
{
final PsiExpression qualifierExpression = methodReferenceExpression.getQualifierExpression();
if(qualifierExpression == null)
{
PsiElement resolved = methodReferenceExpression.resolve();
if(resolved == null)
{
return false;
}
PsiClass arrayClass = JavaPsiFacade.getInstance(methodReferenceExpression.getProject()).getElementFactory().getArrayClass(PsiUtil.getLanguageLevel(methodReferenceExpression));
return resolved == arrayClass;
}
return !SideEffectChecker.mayHaveSideEffects(qualifierExpression);
}
示例3: canBeSwitchExpression
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
private static boolean canBeSwitchExpression(PsiExpression expression, LanguageLevel languageLevel) {
if (expression == null || SideEffectChecker.mayHaveSideEffects(expression)) {
return false;
}
final PsiType type = expression.getType();
if (PsiType.CHAR.equals(type) || PsiType.BYTE.equals(type) || PsiType.SHORT.equals(type) || PsiType.INT.equals(type)) {
return true;
}
else if (type instanceof PsiClassType) {
if (type.equalsToText(CommonClassNames.JAVA_LANG_CHARACTER) || type.equalsToText(CommonClassNames.JAVA_LANG_BYTE) ||
type.equalsToText(CommonClassNames.JAVA_LANG_SHORT) || type.equalsToText(CommonClassNames.JAVA_LANG_INTEGER)) {
return true;
}
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_5)) {
final PsiClassType classType = (PsiClassType)type;
final PsiClass aClass = classType.resolve();
if (aClass != null && aClass.isEnum()) {
return true;
}
}
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_7) && type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
return true;
}
}
return false;
}
示例4: mayHaveSideEffects
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
private static boolean mayHaveSideEffects(PsiDeclarationStatement statement) {
for (PsiElement element : statement.getDeclaredElements()) {
if (element instanceof PsiVariable) {
PsiExpression initializer = ((PsiVariable)element).getInitializer();
if (initializer != null && SideEffectChecker.mayHaveSideEffects(initializer)) {
return true;
}
}
}
return false;
}
示例5: visitField
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
@Override
public void visitField(@NotNull PsiField field) {
if (field.hasModifierProperty(PsiModifier.STATIC)) {
return;
}
if (!field.hasModifierProperty(PsiModifier.FINAL)) {
return;
}
final PsiExpression initializer = field.getInitializer();
if (initializer == null) {
return;
}
if (SideEffectChecker.mayHaveSideEffects(initializer)) {
return;
}
final PsiType type = field.getType();
if (!ClassUtils.isImmutable(type)) {
return;
}
final PsiClass containingClass = field.getContainingClass();
if (containingClass != null
&& !containingClass.hasModifierProperty(PsiModifier.STATIC)
&& containingClass.getContainingClass() != null
&& !PsiUtil.isCompileTimeConstant(field)) {
// inner class cannot have static declarations
return;
}
if (containingClass instanceof PsiAnonymousClass && !PsiUtil.isCompileTimeConstant(field)) {
return;
}
if (!canBeStatic(initializer)) {
return;
}
registerFieldError(field);
}
示例6: visitBinaryExpression
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
@Override
public void visitBinaryExpression(PsiBinaryExpression expression) {
super.visitBinaryExpression(expression);
final IElementType tokenType = expression.getOperationTokenType();
if (!JavaTokenType.OROR.equals(tokenType)) {
return;
}
final PsiExpression lhs = ParenthesesUtils.stripParentheses(expression.getLOperand());
final PsiExpression rhs = ParenthesesUtils.stripParentheses(expression.getROperand());
if (!(lhs instanceof PsiBinaryExpression) || !(rhs instanceof PsiBinaryExpression)) {
return;
}
final PsiBinaryExpression lBinaryExpression = (PsiBinaryExpression)lhs;
final PsiBinaryExpression rBinaryExpression = (PsiBinaryExpression)rhs;
final IElementType lTokenType = lBinaryExpression.getOperationTokenType();
final IElementType rTokenType = rBinaryExpression.getOperationTokenType();
if (!JavaTokenType.ANDAND.equals(lTokenType) || !JavaTokenType.ANDAND.equals(rTokenType)) {
return;
}
final PsiExpression expression1 = ParenthesesUtils.stripParentheses(lBinaryExpression.getLOperand());
final PsiExpression expression2 = ParenthesesUtils.stripParentheses(rBinaryExpression.getLOperand());
if (expression1 == null || expression2 == null ||
ParenthesesUtils.stripParentheses(lBinaryExpression.getROperand()) == null ||
ParenthesesUtils.stripParentheses(rBinaryExpression.getROperand()) == null) {
return;
}
if (EquivalenceChecker.expressionsAreEquivalent(BoolUtils.getNegated(expression1), expression2) &&
!SideEffectChecker.mayHaveSideEffects(expression2)) {
registerError(expression);
}
else if (EquivalenceChecker.expressionsAreEquivalent(expression1, BoolUtils.getNegated(expression2)) &&
!SideEffectChecker.mayHaveSideEffects(expression1)) {
registerError(expression);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:BooleanExpressionMayBeConditionalInspection.java
示例7: satisfiedBy
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiAssignmentExpression)) {
return false;
}
final PsiAssignmentExpression assignment = (PsiAssignmentExpression)element;
final IElementType tokenType = assignment.getOperationTokenType();
if (!JavaTokenType.EQ.equals(tokenType)) {
return false;
}
final PsiExpression rhs = assignment.getRExpression();
final PsiExpression expression = PsiUtil.deparenthesizeExpression(rhs);
if (!(expression instanceof PsiPolyadicExpression)) {
return false;
}
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
final PsiExpression[] operands = polyadicExpression.getOperands();
if (operands.length < 2) {
return false;
}
final IElementType rhsTokenType = polyadicExpression.getOperationTokenType();
if (JavaTokenType.OROR.equals(rhsTokenType) || JavaTokenType.ANDAND.equals(rhsTokenType) ||
JavaTokenType.EQEQ.equals(rhsTokenType) || JavaTokenType.NE.equals(rhsTokenType)) {
return false;
}
final PsiExpression lhs = assignment.getLExpression();
if (SideEffectChecker.mayHaveSideEffects(lhs)) {
return false;
}
if (!EquivalenceChecker.expressionsAreEquivalent(lhs, operands[0])) {
return false;
}
return !ErrorUtil.containsError(element);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:ReplaceableWithOperatorAssignmentPredicate.java
示例8: visitField
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
@Override
public void visitField(@NotNull PsiField field) {
if (field.hasModifierProperty(PsiModifier.STATIC)) {
return;
}
if (!field.hasModifierProperty(PsiModifier.FINAL)) {
return;
}
final PsiExpression initializer = field.getInitializer();
if (initializer == null) {
return;
}
if (SideEffectChecker.mayHaveSideEffects(initializer)) {
return;
}
if (!canBeStatic(initializer)) {
return;
}
final PsiType type = field.getType();
if (!ClassUtils.isImmutable(type)) {
return;
}
final PsiClass containingClass = field.getContainingClass();
if (containingClass != null
&& !containingClass.hasModifierProperty(PsiModifier.STATIC)
&& containingClass.getContainingClass() != null
&& !PsiUtil.isCompileTimeConstant(field)) {
// inner class cannot have static declarations
return;
}
registerFieldError(field);
}
示例9: mayHaveSideEffects
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
public static boolean mayHaveSideEffects(@Nullable final PsiElement element) {
return element instanceof PsiExpression && SideEffectChecker.mayHaveSideEffects((PsiExpression)element);
}
示例10: expressionIsArrayCopy
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的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);
}
}
示例11: expressionIsArrayToCollectionCopy
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的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);
}
示例12: visitIfStatement
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
@Override
public void visitIfStatement(
@NotNull PsiIfStatement statement) {
super.visitIfStatement(statement);
final PsiExpression outerCondition = statement.getCondition();
if (outerCondition == null) {
return;
}
if (SideEffectChecker.mayHaveSideEffects(outerCondition)) {
return;
}
PsiStatement thenBranch = statement.getThenBranch();
thenBranch = ControlFlowUtils.stripBraces(thenBranch);
if (!(thenBranch instanceof PsiSynchronizedStatement)) {
return;
}
final PsiSynchronizedStatement synchronizedStatement =
(PsiSynchronizedStatement)thenBranch;
final PsiCodeBlock body = synchronizedStatement.getBody();
if (body == null) {
return;
}
final PsiStatement[] statements = body.getStatements();
if (statements.length != 1) {
return;
}
final PsiStatement firstStatement = statements[0];
if (!(firstStatement instanceof PsiIfStatement)) {
return;
}
final PsiIfStatement innerIf = (PsiIfStatement)firstStatement;
final PsiExpression innerCondition = innerIf.getCondition();
if (!EquivalenceChecker.expressionsAreEquivalent(innerCondition,
outerCondition)) {
return;
}
final PsiField field;
if (ignoreOnVolatileVariables) {
field = findCheckedField(innerCondition);
if (field != null &&
field.hasModifierProperty(PsiModifier.VOLATILE)) {
return;
}
}
else {
field = null;
}
registerStatementError(statement, field);
}
示例13: areExpressionsIdenticalWithoutSideEffects
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
private boolean areExpressionsIdenticalWithoutSideEffects(PsiExpression expression1, PsiExpression expression2, int index) {
return index == 1 && EquivalenceChecker.expressionsAreEquivalent(expression1, expression2) &&
!SideEffectChecker.mayHaveSideEffects(expression1);
}
示例14: mayHaveSideEffects
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
public static boolean mayHaveSideEffects(@Nullable final PsiElement element)
{
return element instanceof PsiExpression && SideEffectChecker.mayHaveSideEffects((PsiExpression) element);
}
示例15: mayHaveSideEffects
import com.siyeh.ig.psiutils.SideEffectChecker; //导入方法依赖的package包/类
@RequiredReadAction
private static boolean mayHaveSideEffects(PsiCodeBlock body, ExpressionRange range)
{
PsiExpression expr = range.restoreExpression(body);
return expr != null && SideEffectChecker.mayHaveSideEffects(expr);
}