当前位置: 首页>>代码示例>>Java>>正文


Java PsiReferenceExpression.getQualifierExpression方法代码示例

本文整理汇总了Java中com.intellij.psi.PsiReferenceExpression.getQualifierExpression方法的典型用法代码示例。如果您正苦于以下问题:Java PsiReferenceExpression.getQualifierExpression方法的具体用法?Java PsiReferenceExpression.getQualifierExpression怎么用?Java PsiReferenceExpression.getQualifierExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.PsiReferenceExpression的用法示例。


在下文中一共展示了PsiReferenceExpression.getQualifierExpression方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isResourceCreation

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
protected boolean isResourceCreation(PsiExpression expression) {
  if (expression instanceof PsiMethodCallExpression) {
    final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
    final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
    @NonNls final String methodName = methodExpression.getReferenceName();
    if (!"accept".equals(methodName)) {
      return false;
    }
    final PsiExpression qualifier = methodExpression.getQualifierExpression();
    if (qualifier == null || !TypeUtils.expressionHasTypeOrSubtype(qualifier, "java.net.ServerSocket")) {
      return false;
    }
    return TypeUtils.expressionHasTypeOrSubtype(methodCallExpression, "java.net.Socket");
  }
  else if (expression instanceof PsiNewExpression) {
    return TypeUtils.expressionHasTypeOrSubtype(expression, "java.net.Socket", "java.net.DatagramSocket", "java.net.ServerSocket") != null;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:SocketResourceInspection.java

示例2: visitMethodCallExpression

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:EqualsWithItselfInspection.java

示例3: createFix

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Nullable
public static ReplaceWithObjectsEqualsFix createFix(@NotNull PsiMethodCallExpression call, @NotNull PsiReferenceExpression methodExpression)
{
	if(!"equals".equals(methodExpression.getReferenceName()) || call.getArgumentList().getExpressions().length != 1 || !PsiUtil.getLanguageLevel(call).isAtLeast(LanguageLevel.JDK_1_7))
	{
		return null;
	}

	PsiExpression qualifier = methodExpression.getQualifierExpression();
	PsiExpression noParens = PsiUtil.skipParenthesizedExprDown(qualifier);
	if(noParens == null)
	{
		return null;
	}

	PsiMethod method = call.resolveMethod();
	if(method != null && method.getParameterList().getParametersCount() == 1 && method.getParameterList().getParameters()[0].getType().equalsToText(CommonClassNames.JAVA_LANG_OBJECT))
	{
		return new ReplaceWithObjectsEqualsFix(qualifier.getText(), noParens.getText());
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:23,代码来源:ReplaceWithObjectsEqualsFix.java

示例4: markLeakSuspects

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
private void markLeakSuspects(PsiElement element, PsiElement lambdaBody, @NonNull final JavaContext context) {
    if (element instanceof PsiReferenceExpression) {
        PsiReferenceExpression ref = (PsiReferenceExpression) element;

        if (ref.getQualifierExpression() == null) {

            PsiElement res = ref.resolve();
            if (!(res instanceof PsiParameter)) {
                if (!(res instanceof PsiClass)) {

                    boolean error = false;
                    if (res instanceof PsiLocalVariable) {
                        PsiLocalVariable lVar = (PsiLocalVariable) res;
                        if (!isParent(lambdaBody, lVar.getParent())) {
                            error = true;
                        }
                    }

                    if (res instanceof PsiField) {
                        PsiField field = (PsiField) res;
                        final PsiModifierList modifierList = field.getModifierList();
                        if (modifierList == null) {
                            error = true;
                        } else if (!modifierList.hasExplicitModifier(PsiModifier.STATIC)) {
                            error = true;
                        }
                    }

                    if (error) {
                        context.report(ISSUE, element, context.getNameLocation(element), "Possible leak");
                    }
                }
            }
        }
    }

    for (PsiElement psiElement : element.getChildren()) {
        markLeakSuspects(psiElement, lambdaBody, context);
    }
}
 
开发者ID:bjoernQ,项目名称:thinr,代码行数:41,代码来源:ThinrDetector.java

示例5: fixUsage

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
public void fixUsage() throws IncorrectOperationException {
    final PsiReferenceExpression methodExpression = call.getMethodExpression();
    final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
    if (qualifierExpression == null) {
        MutationUtils.replaceExpression(delegateFieldName + '.' + call.getText(), call);
    } else {
        MutationUtils.replaceExpression(delegateFieldName, qualifierExpression);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ReplaceThisCallWithDelegateCall.java

示例6: buildFix

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
protected InspectionGadgetsFix buildFix(Object... infos) {
  return new IntroduceVariableFix(false) {
    @Nullable
    @Override
    public PsiExpression getExpressionToExtract(PsiElement element) {
      final PsiElement parent = element.getParent();
      if (!(parent instanceof PsiReferenceExpression)) {
        return null;
      }
      final PsiReferenceExpression methodExpression = (PsiReferenceExpression)parent;
      return methodExpression.getQualifierExpression();
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:ChainedMethodCallInspection.java

示例7: isResourceCreation

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
protected boolean isResourceCreation(PsiExpression expression) {
  if (!(expression instanceof PsiMethodCallExpression)) {
    return false;
  }
  final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
  final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
  final String methodName = methodExpression.getReferenceName();
  if (!HardcodedMethodConstants.OPEN_SESSION.equals(methodName)) {
    return false;
  }
  final PsiExpression qualifier = methodExpression.getQualifierExpression();
  return qualifier != null && TypeUtils.expressionHasTypeOrSubtype(qualifier, "org.hibernate.SessionFactory");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:HibernateResourceInspection.java

示例8: doFix

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiReferenceExpression expression = (PsiReferenceExpression)descriptor.getPsiElement();
  if (expression.getQualifierExpression() != null) {
    return;
  }
  final PsiElement target = expression.resolve();
  if (!(target instanceof PsiMember)) {
    return;
  }
  final PsiMember member = (PsiMember)target;
  final PsiClass memberClass = member.getContainingClass();
  if (memberClass == null) {
    return;
  }
  PsiClass containingClass = ClassUtils.getContainingClass(expression);
  @NonNls final String newExpression;
  if (InheritanceUtil.isInheritorOrSelf(containingClass, memberClass, true)) {
    newExpression = "this." + expression.getText();
  }
  else {
    containingClass = ClassUtils.getContainingClass(containingClass);
    if (containingClass == null) {
      return;
    }
    while (!InheritanceUtil.isInheritorOrSelf(containingClass, memberClass, true)) {
      containingClass = ClassUtils.getContainingClass(containingClass);
      if (containingClass == null) {
        return;
      }
    }
    newExpression = containingClass.getQualifiedName() + ".this." + expression.getText();
  }
  PsiReplacementUtil.replaceExpressionAndShorten(expression, newExpression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:AddThisQualifierFix.java

示例9: visitMethodCallExpression

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
  final PsiReferenceExpression methodExpression = expression.getMethodExpression();
  final PsiMethod method = expression.resolveMethod();
  if (!MethodUtils.isEquals(method) && !MethodUtils.isHashCode(method)) {
    return;
  }
  final PsiExpression qualifier = methodExpression.getQualifierExpression();
  if (!ExpressionUtils.hasType(qualifier, "java.net.URL")) {
    return;
  }
  registerMethodCallError(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:EqualsHashCodeCalledOnUrlInspection.java

示例10: visitMethodCallExpression

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
  super.visitMethodCallExpression(expression);
  final PsiReferenceExpression methodExpression = expression.getMethodExpression();
  @NonNls final String methodName = methodExpression.getReferenceName();
  if (methodName == null) {
    return;
  }
  final boolean resultSet;
  if (methodName.startsWith("get") || methodName.startsWith("update")) {
    resultSet = true;
  } else if (methodName.startsWith("set")) {
    resultSet = false;
  } else {
    return;
  }
  final PsiExpressionList argumentList = expression.getArgumentList();
  final PsiExpression[] arguments = argumentList.getExpressions();
  if (arguments.length == 0) {
    return;
  }
  final PsiExpression argument = arguments[0];
  final Object val = ExpressionUtils.computeConstantExpression(argument);
  if (!(val instanceof Integer) || ((Integer)val).intValue() != 0) {
    return;
  }
  final PsiExpression qualifier = methodExpression.getQualifierExpression();
  if (resultSet) {
    if (TypeUtils.expressionHasTypeOrSubtype(qualifier, "java.sql.ResultSet")) {
      registerError(argument, Boolean.TRUE);
    }
  } else if (arguments.length > 1) {
    if (TypeUtils.expressionHasTypeOrSubtype(qualifier, "java.sql.PreparedStatement")) {
      registerError(argument, Boolean.FALSE);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:ResultSetIndexZeroInspection.java

示例11: visitMethodCallExpression

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(
  @NotNull PsiMethodCallExpression expression) {
  super.visitMethodCallExpression(expression);
  if (!ThreadingUtils.isWaitCall(expression)) {
    return;
  }
  final PsiReferenceExpression methodExpression = expression.getMethodExpression();
  final PsiExpression qualifier = methodExpression.getQualifierExpression();
  if (!TypeUtils.expressionHasTypeOrSubtype(qualifier,
                                            "java.util.concurrent.locks.Condition")) {
    return;
  }
  registerMethodCallError(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:WaitCalledOnConditionInspection.java

示例12: doFix

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiReferenceExpression expression = (PsiReferenceExpression)descriptor.getPsiElement();
  if (expression.getQualifierExpression() != null) {
    return;
  }
  final PsiElement target = expression.resolve();
  if (!(target instanceof PsiMember)) {
    return;
  }
  final PsiMember member = (PsiMember)target;
  final PsiClass memberClass = member.getContainingClass();
  if (memberClass == null) {
    return;
  }
  PsiClass containingClass = ClassUtils.getContainingClass(expression);
  @NonNls final String newExpression;
  if (InheritanceUtil.isInheritorOrSelf(containingClass, memberClass, true)) {
    newExpression = "this." + expression.getText();
  }
  else {
    containingClass = ClassUtils.getContainingClass(containingClass);
    if (containingClass == null) {
      return;
    }
    while (!InheritanceUtil.isInheritorOrSelf(containingClass, memberClass, true)) {
      containingClass = ClassUtils.getContainingClass(containingClass);
      if (containingClass == null) {
        return;
      }
    }
    newExpression = containingClass.getQualifiedName() + ".this." + expression.getText();
  }
  replaceExpressionAndShorten(expression, newExpression);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:36,代码来源:AddThisQualifierFix.java

示例13: visitMethodCallExpression

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
  super.visitMethodCallExpression(expression);
  final PsiReferenceExpression methodExpression = expression.getMethodExpression();
  @NonNls final String methodName = methodExpression.getReferenceName();
  if (methodName == null) {
    return;
  }
  final boolean resultSet;
  if (methodName.startsWith("get") || methodName.startsWith("update")) {
    resultSet = true;
  } else if (methodName.startsWith("set")) {
    resultSet = false;
  } else {
    return;
  }
  final PsiExpressionList argumentList = expression.getArgumentList();
  final PsiExpression[] arguments = argumentList.getExpressions();
  if (arguments.length == 0) {
    return;
  }
  final PsiExpression argument = arguments[0];
  final Object val = ExpressionUtils.computeConstantExpression(argument);
  if (!(val instanceof Integer) || ((Integer)val).intValue() != 0) {
    return;
  }
  final PsiExpression qualifier = methodExpression.getQualifierExpression();
  if (resultSet) {
    if (TypeUtils.expressionHasTypeOrSubtype(qualifier, "java.sql.ResultSet")) {
      registerError(argument, Boolean.valueOf(resultSet));
    }
  } else {
    if (TypeUtils.expressionHasTypeOrSubtype(qualifier, "java.sql.PreparedStatement")) {
      registerError(argument, Boolean.valueOf(resultSet));
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:38,代码来源:ResultSetIndexZeroInspection.java

示例14: isReferenceToFieldInInstance

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
private boolean isReferenceToFieldInInstance(@Nullable PsiExpression expression, @NotNull PsiField field, @Nullable PsiVariable instance) {
	if (expression != null && expression instanceof PsiReferenceExpression) {
		PsiReferenceExpression referenceExpression = (PsiReferenceExpression) expression;
		PsiExpression qualifierExpression = referenceExpression.getQualifierExpression();
		return referenceExpression.isReferenceTo(field) && qualifierReferencesVariable(qualifierExpression, instance);
	}
	return false;
}
 
开发者ID:jkovacs,项目名称:CopyConstructorPlugin,代码行数:9,代码来源:IncompleteCopyConstructorInspection.java

示例15: processIntention

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
public void processIntention(PsiElement element)
  throws IncorrectOperationException {
  final PsiMethodCallExpression call =
    (PsiMethodCallExpression)element;
  final PsiReferenceExpression methodExpression =
    call.getMethodExpression();
  final String methodName = methodExpression.getReferenceName();
  final PsiExpression target = methodExpression.getQualifierExpression();
  if (target == null) {
    return;
  }
  final PsiExpressionList argumentList = call.getArgumentList();
  final PsiExpression arg = argumentList.getExpressions()[0];
  final PsiExpression strippedTarget =
    ParenthesesUtils.stripParentheses(target);
  if (strippedTarget == null) {
    return;
  }
  final PsiExpression strippedArg =
    ParenthesesUtils.stripParentheses(arg);
  if (strippedArg == null) {
    return;
  }
  final String callString;
  if (ParenthesesUtils.getPrecedence(strippedArg) >
      ParenthesesUtils.METHOD_CALL_PRECEDENCE) {
    callString = '(' + strippedArg.getText() + ")." + methodName + '(' +
                 strippedTarget.getText() + ')';
  }
  else {
    callString = strippedArg.getText() + '.' + methodName + '(' +
                 strippedTarget.getText() + ')';
  }
  replaceExpression(callString, call);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:36,代码来源:FlipCommutativeMethodCallIntention.java


注:本文中的com.intellij.psi.PsiReferenceExpression.getQualifierExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。