Search in sources :

Example 1 with ConstantFunction

use of com.intellij.util.ConstantFunction in project idea-android-studio-plugin by Haehnchen.

the class FragmentRelatedFileLineMarker method collectSlowLineMarkers.

@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
    for (PsiElement psiElement : elements) {
        List<GotoRelatedItem> gotoRelatedItems = new ArrayList<GotoRelatedItem>();
        List<PsiFile> psiFiles = new ArrayList<PsiFile>();
        // we support all of them :)
        if (psiElement instanceof PsiIdentifier && psiElement.getParent() instanceof PsiClass && !(psiElement.getParent().getParent() instanceof PsiFile)) {
            // simple hack activity provide this on core
            if (isFragmentClass((PsiClass) psiElement.getParent())) {
                Collection<PsiMethodCallExpression> PsiMethodCallExpressions = PsiTreeUtil.collectElementsOfType(psiElement.getParent(), PsiMethodCallExpression.class);
                for (PsiMethodCallExpression methodCallExpression : PsiMethodCallExpressions) {
                    PsiMethod psiMethod = methodCallExpression.resolveMethod();
                    if (psiMethod != null && psiMethod.getName().equals("inflate")) {
                        PsiExpression[] expressions = methodCallExpression.getArgumentList().getExpressions();
                        if (expressions.length > 0 && expressions[0] instanceof PsiReferenceExpression) {
                            PsiFile xmlFile = AndroidUtils.findXmlResource((PsiReferenceExpression) expressions[0]);
                            if (xmlFile != null && !psiFiles.contains(xmlFile)) {
                                psiFiles.add(xmlFile);
                                gotoRelatedItems.add(new GotoRelatedItem(xmlFile));
                            }
                        }
                    }
                }
            }
        }
        if (gotoRelatedItems.size() > 0) {
            result.add(new LineMarkerInfo<PsiElement>(psiElement, psiElement.getTextOffset(), AndroidIcons.AndroidToolWindow, 6, new ConstantFunction<PsiElement, String>("Related Files"), new RelatedPopupGotoLineMarker.NavigationHandler(gotoRelatedItems)));
        }
    }
}
Also used : ConstantFunction(com.intellij.util.ConstantFunction) ArrayList(java.util.ArrayList) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem)

Aggregations

GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)1 ConstantFunction (com.intellij.util.ConstantFunction)1 ArrayList (java.util.ArrayList)1