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


Java PsiReferenceExpression.resolve方法代码示例

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


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

示例1: visitReferenceExpression

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void visitReferenceExpression(
  @NotNull PsiReferenceExpression referenceExpression) {
  if (used) {
    return;
  }
  super.visitReferenceExpression(referenceExpression);
  final PsiElement target = referenceExpression.resolve();
  if (target == null) {
    return;
  }
  if (target.equals(variable)) {
    used = true;
    //stopWalking();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:VariableUsedVisitor.java

示例2: visitReferenceExpression

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) {
  super.visitReferenceExpression(expression);
  final String name = expression.getReferenceName();
  if (!HardcodedMethodConstants.OUT.equals(name) &&
      !HardcodedMethodConstants.ERR.equals(name)) {
    return;
  }
  final PsiElement referent = expression.resolve();
  if (!(referent instanceof PsiField)) {
    return;
  }
  final PsiField field = (PsiField)referent;
  final PsiClass containingClass = field.getContainingClass();
  if (containingClass == null) {
    return;
  }
  final String className = containingClass.getQualifiedName();
  if (!"java.lang.System".equals(className)) {
    return;
  }
  registerError(expression, expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:SystemOutErrInspectionBase.java

示例3: visitReferenceExpression

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void visitReferenceExpression(
  @NotNull PsiReferenceExpression expression) {
  super.visitReferenceExpression(expression);
  final String name = expression.getReferenceName();
  if (!HardcodedMethodConstants.OUT.equals(name) &&
      !HardcodedMethodConstants.ERR.equals(name)) {
    return;
  }
  final PsiElement referent = expression.resolve();
  if (!(referent instanceof PsiField)) {
    return;
  }
  final PsiField field = (PsiField)referent;
  final PsiClass containingClass = field.getContainingClass();
  if (containingClass == null) {
    return;
  }
  final String className = containingClass.getQualifiedName();
  if (!"java.lang.System".equals(className)) {
    return;
  }
  registerError(expression);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:SystemOutErrInspection.java

示例4: isChainingConstructor

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
private boolean isChainingConstructor(PsiMethod constructor) {
  PsiCodeBlock body = constructor.getBody();
  if (body != null) {
    PsiStatement[] statements = body.getStatements();
    if (statements.length == 1 && statements[0] instanceof PsiExpressionStatement) {
      PsiExpression expression = ((PsiExpressionStatement) statements[0]).getExpression();
      if (expression instanceof PsiMethodCallExpression) {
        PsiReferenceExpression methodExpr = ((PsiMethodCallExpression) expression).getMethodExpression();
        if ("this".equals(methodExpr.getReferenceName())) {
          PsiElement resolved = methodExpr.resolve();
          return resolved instanceof PsiMethod && ((PsiMethod) resolved).isConstructor(); //delegated via "this" call
        }
      }
    }
  }
  return false;
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:18,代码来源:LombokInlineMethodHandler.java

示例5: 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

示例6: 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

示例7: visitReferenceExpression

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void visitReferenceExpression(
  @NotNull PsiReferenceExpression reference) {
  if (used) {
    return;
  }
  super.visitReferenceExpression(reference);
  final PsiElement element = reference.resolve();
  if (parameter.equals(element)) {
    used = true;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:CatchParameterUsedVisitor.java

示例8: doFix

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void doFix(final Project project, ProblemDescriptor descriptor) {
  final PsiElement nameElement = descriptor.getPsiElement();
  final PsiElement parent = nameElement.getParent();
  final PsiField field;
  if (parent instanceof PsiField) {
    field = (PsiField)parent;
  }
  else if (parent instanceof PsiReferenceExpression) {
    final PsiReferenceExpression referenceExpression =
      (PsiReferenceExpression)parent;
    final PsiElement target = referenceExpression.resolve();
    if (!(target instanceof PsiField)) {
      return;
    }
    field = (PsiField)target;
  }
  else {
    return;
  }
  final JavaRefactoringActionHandlerFactory factory =
    JavaRefactoringActionHandlerFactory.getInstance();
  final RefactoringActionHandler renameHandler =
    factory.createEncapsulateFieldsHandler();
  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      renameHandler.invoke(project, new PsiElement[]{field}, null);
    }
  };
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    runnable.run();
  }
  else {
    ApplicationManager.getApplication().invokeLater(runnable, project.getDisposed());
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:38,代码来源:EncapsulateVariableFix.java

示例9: 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

示例10: visitReferenceExpression

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void visitReferenceExpression(
  @NotNull PsiReferenceExpression referenceExpression) {
  if (used) {
    return;
  }
  super.visitReferenceExpression(referenceExpression);
  final PsiElement target = referenceExpression.resolve();
  if (target == null) {
    return;
  }
  if (target.equals(variable)) {
    used = true;
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:16,代码来源:VariableUsedVisitor.java

示例11: getUsedVariable

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public PsiVariable getUsedVariable(PsiReferenceExpression refExpr) {
  if (refExpr.isQualified()) return null;

  PsiElement refElement = refExpr.resolve();
  return refElement instanceof PsiLocalVariable || refElement instanceof PsiParameter ? checkCodeFragment(refElement) : null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:8,代码来源:LocalsControlFlowPolicy.java

示例12: visitReferenceExpression

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public void visitReferenceExpression(
  @NotNull PsiReferenceExpression referenceExpression) {
  if (usedInInnerClass) {
    return;
  }
  super.visitReferenceExpression(referenceExpression);
  if (!inInnerClass) {
    return;
  }
  final PsiElement target = referenceExpression.resolve();
  if (variable.equals(target)) {
    usedInInnerClass = true;
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:16,代码来源:VariableUsedInInnerClassVisitor.java

示例13: getUsedVariable

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public PsiVariable getUsedVariable(@NotNull PsiReferenceExpression refExpr)
{
	PsiElement resolved = refExpr.resolve();
	return resolved instanceof PsiVariable ? (PsiVariable) resolved : null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:7,代码来源:AllVariablesControlFlowPolicy.java

示例14: isInsideSimpleGetter

import com.intellij.psi.PsiReferenceExpression; //导入方法依赖的package包/类
@Override
public boolean isInsideSimpleGetter(@NotNull PsiElement element)
{
	PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
	if(method == null)
	{
		return false;
	}

	final PsiCodeBlock body = method.getBody();
	if(body == null)
	{
		return false;
	}

	final PsiStatement[] statements = body.getStatements();
	if(statements.length != 1)
	{
		return false;
	}

	final PsiStatement statement = statements[0];
	if(!(statement instanceof PsiReturnStatement))
	{
		return false;
	}

	final PsiExpression value = ((PsiReturnStatement) statement).getReturnValue();
	if(!(value instanceof PsiReferenceExpression))
	{
		return false;
	}

	final PsiReferenceExpression reference = (PsiReferenceExpression) value;
	final PsiExpression qualifier = reference.getQualifierExpression();
	//noinspection HardCodedStringLiteral
	if(qualifier != null && !"this".equals(qualifier.getText()))
	{
		return false;
	}

	final PsiElement referent = reference.resolve();
	if(referent == null)
	{
		return false;
	}

	if(!(referent instanceof PsiField))
	{
		return false;
	}

	return Comparing.equal(((PsiField) referent).getContainingClass(), method.getContainingClass());
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:55,代码来源:JavaSimpleGetterProvider.java


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