本文整理匯總了Java中com.siyeh.ig.psiutils.ExpressionUtils.isConstant方法的典型用法代碼示例。如果您正苦於以下問題:Java ExpressionUtils.isConstant方法的具體用法?Java ExpressionUtils.isConstant怎麽用?Java ExpressionUtils.isConstant使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.siyeh.ig.psiutils.ExpressionUtils
的用法示例。
在下文中一共展示了ExpressionUtils.isConstant方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: visitMethod
import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@Override
public void visitMethod(@NotNull PsiMethod method) {
final PsiIdentifier nameIdentifier = method.getNameIdentifier();
if (nameIdentifier == null) {
return;
}
final VariableAccessVisitor visitor = new VariableAccessVisitor();
method.accept(visitor);
final Set<PsiField> fields = visitor.getOveraccessedFields();
for (PsiField field : fields) {
if (ExpressionUtils.isConstant(field)) {
continue;
}
if (m_ignoreFinalFields &&
field.hasModifierProperty(PsiModifier.FINAL)) {
continue;
}
registerError(nameIdentifier, field);
}
}
示例2: visitReferenceExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
final PsiElement target = expression.resolve();
if (target instanceof PsiField && ExpressionUtils.isConstant((PsiField)target)) {
referenceFound = true;
}
else {
super.visitReferenceExpression(expression);
}
}
示例3: isMoveable
import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
protected boolean isMoveable(PsiExpression expression) {
if (expression == null) {
return true;
}
if (PsiUtil.isConstantExpression(expression) || ExpressionUtils.isNullLiteral(expression)) {
return true;
}
if (expression instanceof PsiNewExpression) {
final PsiNewExpression newExpression = (PsiNewExpression)expression;
final PsiExpression[] arrayDimensions = newExpression.getArrayDimensions();
if (arrayDimensions.length > 0) {
for (PsiExpression arrayDimension : arrayDimensions) {
if (!isMoveable(arrayDimension)) {
return false;
}
}
return true;
}
final PsiArrayInitializerExpression arrayInitializer = newExpression.getArrayInitializer();
boolean result = true;
if (arrayInitializer != null) {
final PsiExpression[] initializers = arrayInitializer.getInitializers();
for (final PsiExpression initializerExpression : initializers) {
result &= isMoveable(initializerExpression);
}
}
else if (!m_allowConstructorAsInitializer) {
final PsiType type = newExpression.getType();
if (!ClassUtils.isImmutable(type)) {
return false;
}
}
final PsiExpressionList argumentList = newExpression.getArgumentList();
if (argumentList == null) {
return result;
}
final PsiExpression[] expressions = argumentList.getExpressions();
for (final PsiExpression argumentExpression : expressions) {
result &= isMoveable(argumentExpression);
}
return result;
}
if (expression instanceof PsiReferenceExpression) {
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression;
final PsiElement target = referenceExpression.resolve();
if (!(target instanceof PsiField)) {
return false;
}
final PsiField field = (PsiField)target;
if (ExpressionUtils.isConstant(field)) {
return true;
}
}
return false;
}
示例4: visitReferenceExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@Override
public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) {
super.visitReferenceExpression(expression);
final PsiElement target = expression.resolve();
if (!(target instanceof PsiField)) {
return;
}
final PsiField lockedField = (PsiField)target;
if (!lockedField.hasModifierProperty(PsiModifier.STATIC) || ExpressionUtils.isConstant(lockedField)) {
return;
}
final PsiClass containingClass = lockedField.getContainingClass();
if (!PsiTreeUtil.isAncestor(containingClass, expression, false)) {
return;
}
if (!ignoredClasses.isEmpty()) {
final PsiType type = lockedField.getType();
if (type instanceof PsiClassType) {
final PsiClassType classType = (PsiClassType)type;
final PsiClass aClass = classType.resolve();
if (aClass != null && ignoredClasses.contains(aClass.getQualifiedName())) {
return;
}
}
}
boolean isLockedOnInstance = false;
boolean isLockedOnClass = false;
final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(expression, PsiMethod.class);
if (containingMethod != null && containingMethod.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
if (containingMethod.hasModifierProperty(PsiModifier.STATIC)) {
isLockedOnClass = true;
}
else {
isLockedOnInstance = true;
}
}
final PsiClass expressionClass = PsiTreeUtil.getParentOfType(expression, PsiClass.class);
if (expressionClass == null) {
return;
}
PsiElement elementToCheck = expression;
while (true) {
final PsiSynchronizedStatement synchronizedStatement = PsiTreeUtil.getParentOfType(elementToCheck, PsiSynchronizedStatement.class);
if (synchronizedStatement == null || !PsiTreeUtil.isAncestor(expressionClass, synchronizedStatement, true)) {
break;
}
final PsiExpression lockExpression = synchronizedStatement.getLockExpression();
if (lockExpression instanceof PsiReferenceExpression) {
final PsiReferenceExpression reference = (PsiReferenceExpression)lockExpression;
final PsiElement lockTarget = reference.resolve();
if (lockTarget instanceof PsiField) {
final PsiField lockField = (PsiField)lockTarget;
if (lockField.hasModifierProperty(PsiModifier.STATIC)) {
isLockedOnClass = true;
}
else {
isLockedOnInstance = true;
}
}
}
else if (lockExpression instanceof PsiThisExpression) {
isLockedOnInstance = true;
}
else if (lockExpression instanceof PsiClassObjectAccessExpression) {
isLockedOnClass = true;
}
elementToCheck = synchronizedStatement;
}
if (!isLockedOnInstance || isLockedOnClass) {
return;
}
registerError(expression);
}
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:75,代碼來源:AccessToStaticFieldLockedOnInstanceInspectionBase.java
示例5: isMoveable
import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
private boolean isMoveable(PsiExpression expression) {
if (expression == null) {
return true;
}
if (PsiUtil.isConstantExpression(expression) || ExpressionUtils.isNullLiteral(expression)) {
return true;
}
if (expression instanceof PsiNewExpression) {
final PsiNewExpression newExpression = (PsiNewExpression)expression;
final PsiExpression[] arrayDimensions = newExpression.getArrayDimensions();
if (arrayDimensions.length > 0) {
for (PsiExpression arrayDimension : arrayDimensions) {
if (!isMoveable(arrayDimension)) {
return false;
}
}
return true;
}
final PsiArrayInitializerExpression arrayInitializer = newExpression.getArrayInitializer();
boolean result = true;
if (arrayInitializer != null) {
final PsiExpression[] initializers = arrayInitializer.getInitializers();
for (final PsiExpression initializerExpression : initializers) {
result &= isMoveable(initializerExpression);
}
}
else if (!m_allowConstructorAsInitializer) {
final PsiType type = newExpression.getType();
if (!ClassUtils.isImmutable(type)) {
return false;
}
}
final PsiExpressionList argumentList = newExpression.getArgumentList();
if (argumentList == null) {
return result;
}
final PsiExpression[] expressions = argumentList.getExpressions();
for (final PsiExpression argumentExpression : expressions) {
result &= isMoveable(argumentExpression);
}
return result;
}
if (expression instanceof PsiReferenceExpression) {
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression;
final PsiElement target = referenceExpression.resolve();
if (!(target instanceof PsiField)) {
return false;
}
final PsiField field = (PsiField)target;
if (ExpressionUtils.isConstant(field)) {
return true;
}
}
return false;
}