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