use of com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl in project smali by JesusFreke.
the class SmaliCodeFragmentFactoryTest method assertVariableType.
private void assertVariableType(PsiElement context, String variableName, String expectedType) {
SmaliCodeFragmentFactory codeFragmentFactory = new SmaliCodeFragmentFactory();
JavaCodeFragment fragment = codeFragmentFactory.createCodeFragment(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, variableName), context, getProject());
Editor editor = createEditor(fragment.getVirtualFile());
editor.getCaretModel().moveToOffset(1);
PsiElement element = fragment.findElementAt(0);
Assert.assertTrue(element.getParent() instanceof PsiReferenceExpressionImpl);
PsiReferenceExpressionImpl reference = (PsiReferenceExpressionImpl) element.getParent();
Assert.assertEquals(expectedType, reference.getType().getCanonicalText());
}
use of com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl in project intellij-community by JetBrains.
the class HighlightUtil method checkReferenceToOurInstanceInsideThisOrSuper.
@Nullable
private static HighlightInfo checkReferenceToOurInstanceInsideThisOrSuper(@NotNull final PsiElement expression, @NotNull PsiClass referencedClass, final String resolvedName, @NotNull PsiFile containingFile) {
if (PsiTreeUtil.getParentOfType(expression, PsiReferenceParameterList.class) != null)
return null;
PsiElement element = expression.getParent();
while (element != null) {
// check if expression inside super()/this() call
if (RefactoringChangeUtil.isSuperOrThisMethodCall(element)) {
PsiElement parentClass = new PsiMatcherImpl(element).parent(PsiMatchers.hasClass(PsiExpressionStatement.class)).parent(PsiMatchers.hasClass(PsiCodeBlock.class)).parent(PsiMatchers.hasClass(PsiMethod.class)).dot(JavaMatchers.isConstructor(true)).parent(PsiMatchers.hasClass(PsiClass.class)).getElement();
if (parentClass == null) {
return null;
}
// only this class/superclasses instance methods are not allowed to call
PsiClass aClass = (PsiClass) parentClass;
if (PsiUtil.isInnerClass(aClass) && referencedClass == aClass.getContainingClass())
return null;
// field or method should be declared in this class or super
if (!InheritanceUtil.isInheritorOrSelf(aClass, referencedClass, true))
return null;
// and point to our instance
if (expression instanceof PsiReferenceExpression && !thisOrSuperReference(((PsiReferenceExpression) expression).getQualifierExpression(), aClass)) {
return null;
}
if (expression instanceof PsiJavaCodeReferenceElement && !aClass.equals(PsiTreeUtil.getParentOfType(expression, PsiClass.class)) && PsiTreeUtil.getParentOfType(expression, PsiTypeElement.class) != null) {
return null;
}
if (expression instanceof PsiJavaCodeReferenceElement && PsiTreeUtil.getParentOfType(expression, PsiClassObjectAccessExpression.class) != null) {
return null;
}
final HighlightInfo highlightInfo = createMemberReferencedError(resolvedName, expression.getTextRange());
if (expression instanceof PsiReferenceExpression && PsiUtil.isInnerClass(aClass)) {
final String referenceName = ((PsiReferenceExpression) expression).getReferenceName();
final PsiClass containingClass = aClass.getContainingClass();
LOG.assertTrue(containingClass != null);
final PsiField fieldInContainingClass = containingClass.findFieldByName(referenceName, true);
if (fieldInContainingClass != null && ((PsiReferenceExpression) expression).getQualifierExpression() == null) {
QuickFixAction.registerQuickFixAction(highlightInfo, new QualifyWithThisFix(containingClass, expression));
}
}
return highlightInfo;
}
if (element instanceof PsiReferenceExpression) {
final PsiElement resolve;
if (element instanceof PsiReferenceExpressionImpl) {
PsiReferenceExpressionImpl referenceExpression = (PsiReferenceExpressionImpl) element;
JavaResolveResult[] results = JavaResolveUtil.resolveWithContainingFile(referenceExpression, PsiReferenceExpressionImpl.OurGenericsResolver.INSTANCE, true, false, containingFile);
resolve = results.length == 1 ? results[0].getElement() : null;
} else {
resolve = ((PsiReferenceExpression) element).resolve();
}
if (resolve instanceof PsiField && ((PsiField) resolve).hasModifierProperty(PsiModifier.STATIC)) {
return null;
}
}
element = element.getParent();
if (element instanceof PsiClass && InheritanceUtil.isInheritorOrSelf((PsiClass) element, referencedClass, true))
return null;
}
return null;
}
use of com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl in project android by JetBrains.
the class PsiCFGDebugUtil method debugOutputPsiReferenceExpression.
private static void debugOutputPsiReferenceExpression(StringBuilder sb, PsiReferenceExpression psiElement) {
sb.append("PsiReferenceExpression: " + psiElement.hashCode() + "\n");
PsiElement e = psiElement.resolve();
sb.append("ResolveType: " + e.getClass().getSimpleName() + " " + e.hashCode() + "\n");
PsiExpression expr = psiElement.getQualifierExpression();
if (expr == null) {
sb.append("Qualifier Expression: " + "null \n");
} else {
sb.append("Qualifier Expression: " + expr.getClass().getSimpleName() + "\n");
sb.append("Qualifier Expression Text: " + expr.getText() + "\n");
}
JavaResolveResult[] results = psiElement.multiResolve(false);
sb.append("MultiResolveResults: " + results.length + "\n");
for (JavaResolveResult curRes : results) {
sb.append("Result: " + curRes.getElement().getClass().getSimpleName() + "\t" + curRes.getElement().getText() + "\n");
}
sb.append("\n");
if (psiElement instanceof PsiReferenceExpressionImpl) {
PsiReferenceExpressionImpl refImpl = (PsiReferenceExpressionImpl) psiElement;
}
}
Aggregations