本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
};
}
示例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");
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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));
}
}
}
示例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;
}
示例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);
}