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);
}
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);
}
}
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);
}
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");
}
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));
}
}
Aggregations