Search in sources :

Example 6 with PsiReferenceExpression

use of com.intellij.psi.PsiReferenceExpression in project intellij-community by JetBrains.

the class AddThisQualifierFix method doFix.

@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
    final PsiReferenceExpression expression = (PsiReferenceExpression) descriptor.getPsiElement();
    if (expression.getQualifierExpression() != null) {
        return;
    }
    final PsiExpression thisQualifier = ExpressionUtils.getQualifierOrThis(expression);
    @NonNls final String newExpression = thisQualifier.getText() + "." + expression.getText();
    PsiReplacementUtil.replaceExpressionAndShorten(expression, newExpression);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) PsiExpression(com.intellij.psi.PsiExpression) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression)

Example 7 with PsiReferenceExpression

use of com.intellij.psi.PsiReferenceExpression in project intellij-community by JetBrains.

the class EncapsulateVariableFix method getElementToRefactor.

@Override
public PsiElement getElementToRefactor(PsiElement element) {
    final PsiElement parent = element.getParent();
    if (parent instanceof PsiReferenceExpression) {
        final PsiReferenceExpression referenceExpression = (PsiReferenceExpression) parent;
        final PsiElement target = referenceExpression.resolve();
        assert target instanceof PsiField;
        return target;
    } else {
        return super.getElementToRefactor(element);
    }
}
Also used : PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiField(com.intellij.psi.PsiField) PsiElement(com.intellij.psi.PsiElement)

Example 8 with PsiReferenceExpression

use of com.intellij.psi.PsiReferenceExpression in project intellij-community by JetBrains.

the class InlineCallFix method doFix.

@Override
public void doFix(final Project project, ProblemDescriptor descriptor) {
    final PsiElement nameElement = descriptor.getPsiElement();
    final PsiReferenceExpression methodExpression = (PsiReferenceExpression) nameElement.getParent();
    if (methodExpression == null)
        return;
    final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) methodExpression.getParent();
    final PsiMethod method = methodCallExpression.resolveMethod();
    if (method == null)
        return;
    inline(project, methodExpression, method);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiElement(com.intellij.psi.PsiElement) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Example 9 with PsiReferenceExpression

use of com.intellij.psi.PsiReferenceExpression in project intellij-community by JetBrains.

the class HibernateResourceInspection method isResourceCreation.

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");
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Example 10 with PsiReferenceExpression

use of com.intellij.psi.PsiReferenceExpression in project android by JetBrains.

the class AndroidResourceQuickFixProvider method registerFixes.

@Override
public void registerFixes(@NotNull PsiReferenceExpression exp, @NotNull QuickFixActionRegistrar registrar) {
    Module contextModule = ModuleUtilCore.findModuleForPsiElement(exp);
    if (contextModule == null) {
        return;
    }
    AndroidFacet facet = AndroidFacet.getInstance(contextModule);
    if (facet == null) {
        return;
    }
    final PsiFile contextFile = exp.getContainingFile();
    if (contextFile == null) {
        return;
    }
    AndroidResourceUtil.MyReferredResourceFieldInfo info = AndroidResourceUtil.getReferredResourceOrManifestField(facet, exp, true);
    if (info == null) {
        final PsiElement parent = exp.getParent();
        if (parent instanceof PsiReferenceExpression) {
            info = AndroidResourceUtil.getReferredResourceOrManifestField(facet, (PsiReferenceExpression) parent, true);
        }
    }
    if (info == null || info.isFromManifest()) {
        return;
    }
    final String resClassName = info.getClassName();
    final String resFieldName = info.getFieldName();
    Module resolvedModule = info.getResolvedModule();
    if (resolvedModule != null && resolvedModule != contextModule) {
        AndroidFacet resolvedFacet = AndroidFacet.getInstance(resolvedModule);
        if (resolvedFacet != null) {
            facet = resolvedFacet;
        }
    }
    ResourceType resourceType = ResourceType.getEnum(resClassName);
    if (AndroidResourceUtil.ALL_VALUE_RESOURCE_TYPES.contains(resourceType)) {
        registrar.register(new CreateValueResourceQuickFix(facet, resourceType, resFieldName, contextFile, true));
    }
    ResourceFolderType folderType = AndroidResourceUtil.XML_FILE_RESOURCE_TYPES.get(resourceType);
    if (folderType != null) {
        registrar.register(new CreateFileResourceQuickFix(facet, folderType, resFieldName, contextFile, true));
    }
}
Also used : AndroidResourceUtil(org.jetbrains.android.util.AndroidResourceUtil) ResourceFolderType(com.android.resources.ResourceFolderType) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiFile(com.intellij.psi.PsiFile) ResourceType(com.android.resources.ResourceType) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)25 PsiElement (com.intellij.psi.PsiElement)15 PsiExpression (com.intellij.psi.PsiExpression)13 PsiField (com.intellij.psi.PsiField)9 PsiMethodCallExpression (com.intellij.psi.PsiMethodCallExpression)9 PsiReference (com.intellij.psi.PsiReference)7 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)6 PsiNewExpression (com.intellij.psi.PsiNewExpression)6 Nullable (com.android.annotations.Nullable)5 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)5 PsiClass (com.intellij.psi.PsiClass)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)5 PsiMethod (com.intellij.psi.PsiMethod)5 ResourceType (com.android.resources.ResourceType)4 PsiStatement (com.intellij.psi.PsiStatement)4 PsiConditionalExpression (com.intellij.psi.PsiConditionalExpression)3 PsiLiteralExpression (com.intellij.psi.PsiLiteralExpression)3 PsiParenthesizedExpression (com.intellij.psi.PsiParenthesizedExpression)3 NonNls (org.jetbrains.annotations.NonNls)3