private static boolean fromInflater(PsiReference reference) { if (reference instanceof PsiReferenceExpression) { PsiReferenceExpression referenceExpression = (PsiReferenceExpression) reference; PsiElement parent = referenceExpression.getParent(); if (parent instanceof PsiMethodCallExpression) { PsiMethodCallExpressionImpl methodCallExpression = (PsiMethodCallExpressionImpl) ((PsiReferenceExpressionImpl) reference).getParent(); PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); PsiExpression qualifierExpression = methodExpression.getQualifierExpression(); if (qualifierExpression != null) { PsiType psiType = qualifierExpression.getType(); if (psiType != null) { String canonicalText = psiType.getCanonicalText(); if ("android.view.LayoutInflater".equals(canonicalText)) { if ("inflate".equals(methodExpression.getReferenceName())) { return true; } } } } } } return false; }
@Override public void getLanguagesToInject( @NotNull final PsiLanguageInjectionHost host, @NotNull final InjectedLanguagePlaces injectionPlacesRegistrar ) { final PsiElement hostParent = host.getParent(); if (host instanceof ImpexStringImpl) { final String hostString = StringUtil.unquoteString(host.getText()).toLowerCase(); if (StringUtil.trim(hostString).startsWith("select ")) { registerInjectionPlace(injectionPlacesRegistrar, host); } } if (hostParent != null) { if (hostParent.getParent() instanceof PsiMethodCallExpressionImpl) { final PsiMethodCallExpressionImpl callExpression = (PsiMethodCallExpressionImpl) hostParent.getParent(); final PsiMethod method = callExpression.resolveMethod(); if (method != null) { final PsiClass containingClass = method.getContainingClass(); if (containingClass != null && "FlexibleSearchService".equals(containingClass.getName()) && "search".equals(method.getName())) { registerInjectionPlace(injectionPlacesRegistrar, host); } } } } }
/** * For the given gutters return all the gutter navigation targets that are {@link PsiMethodCallExpressionImpl} elements. */ static List<PsiMethodCallExpressionImpl> getGuttersWithJavaTarget(List<GotoRelatedItem> gutterList) { return gutterList .stream() .filter(gotoRelatedItem -> gotoRelatedItem.getElement() instanceof PsiLiteralExpression) .map(gotoRelatedItem -> (PsiMethodCallExpressionImpl) gotoRelatedItem.getElement().getParent().getParent()) .collect(Collectors.toList()); }
/** * Override to filter errors related to type incompatibilities arising from a * manifold extension adding an interface to an existing classpath class (as opposed * to a source file). Basically suppress "incompatible type errors" or similar * involving a structural interface extension. */ @Override public boolean accept( @NotNull HighlightInfo hi, @Nullable PsiFile file ) { if( hi.getDescription() == null || hi.getSeverity() != HighlightSeverity.ERROR || file == null ) { return true; } PsiElement firstElem = file.findElementAt( hi.getStartOffset() ); if( firstElem == null ) { return true; } PsiElement elem = firstElem.getParent(); if( elem == null ) { return true; } if( isInvalidStaticMethodOnInterface( hi ) ) { PsiElement lhsType = ((PsiReferenceExpressionImpl)((PsiMethodCallExpressionImpl)elem.getParent()).getMethodExpression().getQualifierExpression()).resolve(); if( lhsType instanceof ManifoldPsiClass || lhsType instanceof ManifoldExtendedPsiClass ) { PsiMethod psiMethod = ((PsiMethodCallExpressionImpl)elem.getParent()).resolveMethod(); if( psiMethod.getContainingClass().isInterface() ) { // ignore "Static method may be invoked on containing interface class only" errors where the method really is directly on a the interface, albeit the delegate return false; } } return true; } //## //## structural interface extensions cannot be added to the psiClass, so for now we suppress "incompatible type errors" or similar involving a structural interface extension. //## Boolean x = acceptInterfaceError( hi, firstElem, elem ); if( x != null ) return x; return true; }
public static ElementPattern<PsiElement> patternForMethodParameter() { return psiElement().withSuperParent(3, PsiMethodCallExpressionImpl.class); }