Java源码示例:fr.adrienbrault.idea.symfony2plugin.util.MethodMatcher

示例1
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(PlatformPatterns.psiElement(), psiElement -> {
        if(psiElement == null || !LaravelProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        PsiElement parent = psiElement.getParent();
        if(parent != null && (
            MethodMatcher.getMatchedSignatureWithDepth(parent, DIC) != null ||
            PhpElementsUtil.isFunctionReference(parent, 0, "app")
        )) {
            return new DicGotoCompletionProvider(parent);
        }

        return null;

    });
}
 
示例2
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(PlatformPatterns.psiElement(), psiElement -> {
        if(psiElement == null || !LaravelProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        PsiElement parent = psiElement.getParent();
        if(parent != null && (
            MethodMatcher.getMatchedSignatureWithDepth(parent, URL_GENERATOR) != null ||
            PhpElementsUtil.isFunctionReference(parent, 0, "route") ||
            PhpElementsUtil.isFunctionReference(parent, 0, "link_to_route")
        )) {
            return new RouteNameGotoCompletionProvider(parent);
        }

        return null;
    });
}
 
示例3
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(PlatformPatterns.psiElement(), psiElement -> {
        if(psiElement == null || !LaravelProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        PsiElement parent = psiElement.getParent();
        if(parent != null && (
            MethodMatcher.getMatchedSignatureWithDepth(parent, TRANSLATION_KEY) != null || PhpElementsUtil.isFunctionReference(parent, 0, "trans", "__", "trans_choice")
        )) {
            return new TranslationKey(parent);
        }

        // for blade @lang directive
        if(BladePsiUtil.isDirectiveWithInstance(psiElement, "Illuminate\\Support\\Facades\\Lang", "get")) {
            return new TranslationKey(psiElement);
        }

        return null;
    });
}
 
示例4
/**
 * 
 */
@Nullable
public static String getNamespaceFromConfigValueParameter(@NotNull StringLiteralExpression parent) {
    MethodMatcher.MethodMatchParameter match = MethodMatcher.getMatchedSignatureWithDepth(parent, ShopwarePhpCompletion.CONFIG_NAMESPACE, 1);
    if(match == null) {
        return null;
    }

    PsiElement parameterList = parent.getParent();
    if(!(parameterList instanceof ParameterList)) {
        return null;
    }

    PsiElement[] funcParameters = ((ParameterList) parameterList).getParameters();
    if(funcParameters.length == 0 || !(funcParameters[0] instanceof StringLiteralExpression)) {
        return null;
    }

    String namespace = ((StringLiteralExpression) funcParameters[0]).getContents();
    if(StringUtils.isBlank(namespace)) {
        return null;
    }

    return namespace;
}
 
示例5
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(PlatformPatterns.psiElement().withParent(StringLiteralExpression.class).withLanguage(PhpLanguage.INSTANCE), psiElement -> {

        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        PsiElement parent = psiElement.getParent();
        if(parent == null) {
            return null;
        }

        MethodMatcher.MethodMatchParameter methodMatchParameter = MethodMatcher.getMatchedSignatureWithDepth(parent, CONFIG);
        if(methodMatchParameter == null) {
            return null;
        }

        return new FormReferenceCompletionProvider(parent);

    });
}
 
示例6
private void attachPropertyGoto(StringLiteralExpression psiElement, List<PsiElement> targets) {

        MethodMatcher.MethodMatchParameter methodMatchParameter = MatcherUtil.matchPropertyField(psiElement);
        if(methodMatchParameter == null) {
            return;
        }

        QueryBuilderMethodReferenceParser qb = QueryBuilderCompletionContributor.getQueryBuilderParser(methodMatchParameter.getMethodReference());
        if(qb == null) {
            return;
        }

        QueryBuilderScopeContext collect = qb.collect();
        String propertyContent = psiElement.getContents();

        for(Map.Entry<String, QueryBuilderPropertyAlias> entry: collect.getPropertyAliasMap().entrySet()) {
            if(entry.getKey().equals(propertyContent)) {
                targets.addAll(entry.getValue().getPsiTargets());
            }
        }


    }
 
示例7
private void attachFromIndexGoto(StringLiteralExpression psiElement, List<PsiElement> targets) {

        MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.StringParameterMatcher(psiElement, 2)
            .withSignature("\\Doctrine\\ORM\\QueryBuilder", "from")
            .match();

        if(methodMatchParameter == null) {
            return;
        }

        QueryBuilderMethodReferenceParser qb = QueryBuilderCompletionContributor.getQueryBuilderParser(methodMatchParameter.getMethodReference());
        if(qb == null) {
            return;
        }

        QueryBuilderScopeContext collect = qb.collect();
        String propertyContent = psiElement.getContents();
        for(Map.Entry<String, QueryBuilderPropertyAlias> entry: collect.getPropertyAliasMap().entrySet()) {
            if(entry.getKey().equals(propertyContent)) {
                targets.addAll(entry.getValue().getPsiTargets());
            }
        }

    }
 
示例8
private boolean isTableNameRegistrar(PsiElement context) {

        MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.StringParameterRecursiveMatcher(context, 0)
            .withSignature("Doctrine\\DBAL\\Query\\QueryBuilder", "update")
            .withSignature("Doctrine\\DBAL\\Query\\QueryBuilder", "insert")
            .withSignature("Doctrine\\DBAL\\Query\\QueryBuilder", "from")
            .withSignature("Doctrine\\DBAL\\Query\\QueryBuilder", "delete")
            .withSignature("Doctrine\\DBAL\\Connection", "insert")
            .withSignature("Doctrine\\DBAL\\Connection", "update")
            .match();

        if(methodMatchParameter != null) {
            return true;
        }

        methodMatchParameter = new MethodMatcher.StringParameterRecursiveMatcher(context, 1)
            .withSignature("Doctrine\\DBAL\\Query\\QueryBuilder", "innerJoin")
            .withSignature("Doctrine\\DBAL\\Query\\QueryBuilder", "leftJoin")
            .withSignature("Doctrine\\DBAL\\Query\\QueryBuilder", "join")
            .withSignature("Doctrine\\DBAL\\Query\\QueryBuilder", "rightJoin")
            .match();

        return methodMatchParameter != null;

    }
 
示例9
@Nullable
public static MethodMatcher.MethodMatchParameter matchPropertyField(PsiElement psiElement) {

    if (!Symfony2ProjectComponent.isEnabled(psiElement)) {
        return null;
    }

    MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.StringParameterAnyMatcher(psiElement)
        .withSignature(SELECT_FIELDS)
        .match();

    if(methodMatchParameter == null) {
        methodMatchParameter = new MethodMatcher.StringParameterAnyMatcher(psiElement)
            .withSignature(SELECT_FIELDS_VARIADIC)
            .match();
    }

    if(methodMatchParameter == null) {
        methodMatchParameter = new MethodMatcher.ArrayParameterMatcher(psiElement, 0)
            .withSignature(SELECT_FIELDS)
            .match();
    }

    return methodMatchParameter;
}
 
示例10
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) {
    if(!Symfony2ProjectComponent.isEnabled(psiElement.getProject())) {
        return false;
    }

    PsiElement parent = psiElement.getParent();
    if(!(parent instanceof StringLiteralExpression)) {
        return false;
    }

    String contents = ((StringLiteralExpression) parent).getContents();
    if(StringUtils.isBlank(contents)) {
        return false;
    }

    return null != new MethodMatcher.StringParameterMatcher(parent, 0)
        .withSignature(SymfonyPhpReferenceContributor.REPOSITORY_SIGNATURES)
        .withSignature("Doctrine\\Persistence\\ObjectManager", "find")
        .withSignature("Doctrine\\Common\\Persistence\\ObjectManager", "find") // @TODO: missing somewhere
        .match();
}
 
示例11
@Override
public void visitElement(PsiElement element) {
    if (!(element instanceof StringLiteralExpression)) {
        super.visitElement(element);
        return;
    }

    String contents = ((StringLiteralExpression) element).getContents();
    if (StringUtils.isBlank(contents)) {
        super.visitElement(element);
        return;
    }

    if (null == new MethodMatcher.StringParameterMatcher(element, 1)
        .withSignature(FormUtil.PHP_FORM_BUILDER_SIGNATURES)
        .match()) {

        super.visitElement(element);
        return;
    }

    formTypes.add((StringLiteralExpression) element);

    super.visitElement(element);
}
 
示例12
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) {
    if(!Symfony2ProjectComponent.isEnabled(psiElement.getProject())) {
        return false;
    }

    PsiElement parent = psiElement.getParent();
    if(!(parent instanceof StringLiteralExpression)) {
        return false;
    }

    String contents = ((StringLiteralExpression) parent).getContents();
    if(StringUtils.isBlank(contents)) {
        return false;
    }

    return null != new MethodMatcher.StringParameterMatcher(parent, 1)
        .withSignature(FormUtil.PHP_FORM_BUILDER_SIGNATURES)
        .match();
}
 
示例13
private void attachTemplateShortcuts(List<FoldingDescriptor> descriptors, final StringLiteralExpression stringLiteralExpression) {

        if (MethodMatcher.getMatchedSignatureWithDepth(stringLiteralExpression, SymfonyPhpReferenceContributor.TEMPLATE_SIGNATURES) == null) {
            return;
        }

        String content = stringLiteralExpression.getContents();

        String templateShortcutName = TwigUtil.getFoldingTemplateName(content);
        if(templateShortcutName == null) {
            return;
        }

        final String finalTemplateShortcutName = templateShortcutName;
        descriptors.add(new FoldingDescriptor(stringLiteralExpression.getNode(),
            new TextRange(stringLiteralExpression.getTextRange().getStartOffset() + 1, stringLiteralExpression.getTextRange().getEndOffset() - 1)) {
            @Nullable
            @Override
            public String getPlaceholderText() {
                return finalTemplateShortcutName;
            }
        });

    }
 
示例14
private static void attachFormFields(@Nullable MethodReference methodReference, @NotNull Collection<TwigTypeContainer> targets) {
    if(methodReference != null && PhpElementsUtil.isMethodReferenceInstanceOf(
        methodReference,
        new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "createForm"),
        new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "createForm"),
        new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "createForm")
    )) {
        PsiElement formType = PsiElementUtils.getMethodParameterPsiElementAt(methodReference, 0);
        if(formType != null) {
            PhpClass phpClass = FormUtil.getFormTypeClassOnParameter(formType);

            if(phpClass == null) {
                return;
            }

            Method method = phpClass.findMethodByName("buildForm");
            if(method == null) {
                return;
            }

            targets.addAll(getTwigTypeContainer(method));
        }
    }
}
 
示例15
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(PlatformPatterns.psiElement(), psiElement -> {
        if(psiElement == null || !LaravelProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        PsiElement parent = psiElement.getParent();
        if(parent != null && (PsiElementUtils.isFunctionReference(parent, "config", 0) || MethodMatcher.getMatchedSignatureWithDepth(parent, CONFIG) != null)) {
            return new ConfigKeyProvider(parent);
        }

        return null;
    });
}
 
示例16
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    /*
     * view('caret');
     * Factory::make('caret');
     */
    registrar.register(PlatformPatterns.psiElement().withParent(StringLiteralExpression.class).withLanguage(PhpLanguage.INSTANCE), psiElement -> {
        if(psiElement == null || !LaravelProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        PsiElement stringLiteral = psiElement.getParent();
        if(!(stringLiteral instanceof StringLiteralExpression)) {
            return null;
        }

        if(!(
            PsiElementUtils.isFunctionReference(stringLiteral, "asset", 0)
                || PsiElementUtils.isFunctionReference(stringLiteral, "secure_asset", 0)
                || PsiElementUtils.isFunctionReference(stringLiteral, "secureAsset", 0)
        ) && MethodMatcher.getMatchedSignatureWithDepth(stringLiteral, ASSETS) == null) {
            return null;
        }

        return new AssetGotoCompletionProvider(stringLiteral);
    });
}
 
示例17
private List<Method> getCallToSignatureInterfaceMethods(PsiElement e, Collection<MethodMatcher.CallToSignature> signatures) {
    List<Method> methods = new ArrayList<Method>();
    for(MethodMatcher.CallToSignature signature: signatures) {
        Method method = getInterfaceMethod(e.getProject(), signature.getInstance(), signature.getMethod());
        if(method != null) {
            methods.add(method);
        }
    }
    return methods;
}
 
示例18
public static Collection<MethodMatcher.CallToSignature> getFormBuilderInterface() {
    Collection<MethodMatcher.CallToSignature> signatures = new ArrayList<MethodMatcher.CallToSignature>();

    signatures.add(new MethodMatcher.CallToSignature("\\Symfony\\Component\\Form\\FormBuilderInterface", "add"));
    signatures.add(new MethodMatcher.CallToSignature("\\Symfony\\Component\\Form\\FormBuilderInterface", "create"));
    signatures.add(new MethodMatcher.CallToSignature("\\Symfony\\Component\\Form\\FormInterface", "add"));
    signatures.add(new MethodMatcher.CallToSignature("\\Symfony\\Component\\Form\\FormInterface", "create"));

    return signatures;
}
 
示例19
private void attachNamespaceNavigation(@NotNull PsiElement psiElement, @NotNull List<PsiElement> psiElements) {
    PsiElement parent = psiElement.getParent();
    if(!(parent instanceof StringLiteralExpression)) {
        return;
    }

    String contents = ((StringLiteralExpression) parent).getContents();
    if(StringUtils.isBlank(contents)) {
        return;
    }

    MethodMatcher.MethodMatchParameter match = MethodMatcher.getMatchedSignatureWithDepth(parent, ShopwarePhpCompletion.CONFIG_NAMESPACE);
    if(match == null) {
        return;
    }

    ConfigUtil.visitNamespace(psiElement.getProject(), pair -> {
        if(contents.equalsIgnoreCase(pair.getFirst())) {
            PhpClass phpClass = pair.getSecond();
            PsiElement target = phpClass;

            // PhpClass or "Resources/config.xml" as target
            PsiDirectory pluginDir = phpClass.getContainingFile().getParent();
            if(pluginDir != null) {
                VirtualFile resources = VfsUtil.findRelativeFile(pluginDir.getVirtualFile(), "Resources", "config.xml");
                if(resources != null) {
                    PsiFile file = PsiManager.getInstance(phpClass.getProject()).findFile(resources);
                    if(file instanceof XmlFile) {
                        target = file;
                    }
                }
            }

            psiElements.add(target);
        }
    });
}
 
示例20
private void attachJoinGoto(StringLiteralExpression psiElement, List<PsiElement> targets) {

        MethodMatcher.MethodMatchParameter methodMatchParameter = MatcherUtil.matchJoin(psiElement);
        if(methodMatchParameter == null) {
            return;
        }

        QueryBuilderMethodReferenceParser qb = QueryBuilderCompletionContributor.getQueryBuilderParser(methodMatchParameter.getMethodReference());
        if(qb == null) {
            return;
        }

        String[] joinSplit = StringUtils.split(psiElement.getContents(), ".");
        if(joinSplit.length != 2) {
            return;
        }

        QueryBuilderScopeContext collect = qb.collect();
        if(!collect.getRelationMap().containsKey(joinSplit[0])) {
            return;
        }

        List<QueryBuilderRelation> relations = collect.getRelationMap().get(joinSplit[0]);
        for(QueryBuilderRelation relation: relations) {
            if(joinSplit[1].equals(relation.getFieldName()) && relation.getTargetEntity() != null) {
                PhpClass phpClass = PhpElementsUtil.getClassInterface(psiElement.getProject(), relation.getTargetEntity());
                if(phpClass != null) {
                    targets.add(phpClass);
                }

            }
        }


    }
 
示例21
private void attachExprGoto(StringLiteralExpression psiElement, List<PsiElement> targets) {


        MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.StringParameterMatcher(psiElement, 0)
            .withSignature(QueryBuilderCompletionContributor.EXPR)
            .match();

        if(methodMatchParameter == null) {
            return;
        }

        // simple resolve query inline instance usage
        // $qb->expr()->in('')
        MethodReference methodReference = methodMatchParameter.getMethodReference();
        PsiElement methodReferenceChild = methodReference.getFirstChild();
        if(!(methodReferenceChild instanceof MethodReference)) {
            return;
        }
        QueryBuilderMethodReferenceParser qb = QueryBuilderCompletionContributor.getQueryBuilderParser((MethodReference) methodReferenceChild);
        if(qb == null) {
            return;
        }

        String propertyContent = psiElement.getContents();
        QueryBuilderScopeContext collect = qb.collect();
        for(Map.Entry<String, QueryBuilderPropertyAlias> entry: collect.getPropertyAliasMap().entrySet()) {
            if(entry.getKey().equals(propertyContent)) {
                targets.addAll(entry.getValue().getPsiTargets());
            }
        }
    }
 
示例22
@Nullable
public static MethodMatcher.MethodMatchParameter matchJoin(PsiElement psiElement) {
    return new MethodMatcher.StringParameterMatcher(psiElement, 0)
        .withSignature("\\Doctrine\\ORM\\QueryBuilder", "join")
        .withSignature("\\Doctrine\\ORM\\QueryBuilder", "leftJoin")
        .withSignature("\\Doctrine\\ORM\\QueryBuilder", "rightJoin")
        .withSignature("\\Doctrine\\ORM\\QueryBuilder", "innerJoin")
        .match();
}
 
示例23
@Nullable
@Override
public GotoCompletionProvider getProvider(@NotNull PsiElement psiElement) {
    PsiElement context = psiElement.getContext();
    if (!(context instanceof StringLiteralExpression)) {
        return null;
    }

    MethodMatcher.StringParameterRecursiveMatcher matcher = new MethodMatcher.StringParameterRecursiveMatcher(context, 0);

    String[] methods = new String[] {
        "setDefault", "hasDefault", "isRequired", "isMissing",
        "setAllowedValues", "addAllowedValues", "setAllowedTypes", "addAllowedTypes"
    };

    // @TODO: drop too many classes, add PhpMatcher
    for (String method : methods) {
        matcher.withSignature("Symfony\\Component\\OptionsResolver\\OptionsResolver", method);

        // BC: Symfony < 3
        matcher.withSignature("Symfony\\Component\\OptionsResolver\\OptionsResolverInterface", method);
    }

    if (matcher.match() == null) {
        return null;
    }

    return new FormOptionGotoCompletionProvider(psiElement);
}
 
示例24
private void invoke(@NotNull String routeName, @NotNull final PsiElement element, @NotNull ProblemsHolder holder) {
    MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.StringParameterMatcher(element, 0)
        .withSignature(PhpRouteReferenceContributor.GENERATOR_SIGNATURES)
        .match();

    if(methodMatchParameter == null) {
        return;
    }

    Collection<Route> route = RouteHelper.getRoute(element.getProject(), routeName);
    if(route.size() == 0) {
        holder.registerProblem(element, "Missing Route", ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
    }
}
 
示例25
@Override
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
    registrar.register(PlatformPatterns.psiElement().withParent(StringLiteralExpression.class).withLanguage(PhpLanguage.INSTANCE), psiElement -> {
        PsiElement context = psiElement.getContext();
        if (!(context instanceof StringLiteralExpression)) {
            return null;
        }

        if (MethodMatcher.getMatchedSignatureWithDepth(context, CONSOLE_HELP_SET) == null) {
            return null;
        }

        return new MyGotoCompletionProvider(psiElement);
    });
}
 
示例26
@Override
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {

    registrar.register(PlatformPatterns.psiElement().withParent(StringLiteralExpression.class).withLanguage(PhpLanguage.INSTANCE), psiElement -> {
        PsiElement context = psiElement.getContext();
        if (!(context instanceof StringLiteralExpression)) {
            return null;
        }

        for(String s : new String[] {"Option", "Argument"}) {
            MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.StringParameterRecursiveMatcher(context, 0)
                    .withSignature("Symfony\\Component\\Console\\Input\\InputInterface", "get" + s)
                    .withSignature("Symfony\\Component\\Console\\Input\\InputInterface", "has" + s)
                    .match();

            if(methodMatchParameter != null) {
                PhpClass phpClass = PsiTreeUtil.getParentOfType(methodMatchParameter.getMethodReference(), PhpClass.class);
                if(phpClass != null) {
                    return new CommandGotoCompletionProvider(phpClass, s);
                }

            }
        }

        return null;
    });

}
 
示例27
private void attachRouteShortcuts(List<FoldingDescriptor> descriptors, Collection<StringLiteralExpression> stringLiteralExpressions) {

        Map<String,Route> routes = null;

        for(StringLiteralExpression stringLiteralExpression: stringLiteralExpressions) {

            if (MethodMatcher.getMatchedSignatureWithDepth(stringLiteralExpression, PhpRouteReferenceContributor.GENERATOR_SIGNATURES) != null) {

                // cache routes if we need them
                if(routes == null) {
                    routes = RouteHelper.getAllRoutes(stringLiteralExpression.getProject());
                }

                String contents = stringLiteralExpression.getContents();
                if(contents.length() > 0 && routes.containsKey(contents)) {
                    final Route route = routes.get(contents);

                    final String url = RouteHelper.getRouteUrl(route);
                    if(url != null) {
                        descriptors.add(new FoldingDescriptor(stringLiteralExpression.getNode(),
                            new TextRange(stringLiteralExpression.getTextRange().getStartOffset() + 1, stringLiteralExpression.getTextRange().getEndOffset() - 1)) {
                            @Nullable
                            @Override
                            public String getPlaceholderText() {
                                return url;
                            }
                        });
                    }
                }
            }

        }

    }
 
示例28
private void attachModelShortcuts(List<FoldingDescriptor> descriptors, final StringLiteralExpression stringLiteralExpression) {

        if (MethodMatcher.getMatchedSignatureWithDepth(stringLiteralExpression, SymfonyPhpReferenceContributor.REPOSITORY_SIGNATURES) == null) {
            return;
        }

        String content = stringLiteralExpression.getContents();

        for(String lastChar: new String[] {":", "\\"}) {
            if(content.contains(lastChar)) {
                final String replace = content.substring(content.lastIndexOf(lastChar) + 1);
                if(replace.length() > 0) {
                    descriptors.add(new FoldingDescriptor(stringLiteralExpression.getNode(),
                        new TextRange(stringLiteralExpression.getTextRange().getStartOffset() + 1, stringLiteralExpression.getTextRange().getEndOffset() - 1)) {
                        @Nullable
                        @Override
                        public String getPlaceholderText() {
                            return replace;
                        }
                    });
                }

                return;
            }
        }

    }
 
示例29
@Override
public void collectGotoRelatedItems(ControllerActionGotoRelatedCollectorParameter parameter) {

    List<PsiElement> uniqueTargets = new ArrayList<>();

    for(PsiElement psiElement: parameter.getParameterLists()) {
        MethodMatcher.MethodMatchParameter matchedSignature = MethodMatcher.getMatchedSignatureWithDepth(psiElement, SymfonyPhpReferenceContributor.REPOSITORY_SIGNATURES);
        if (matchedSignature != null) {
            String resolveString = PhpElementsUtil.getStringValue(psiElement);
            if(resolveString != null)  {
                for(PsiElement templateTarget: EntityHelper.getModelPsiTargets(parameter.getProject(), resolveString)) {

                    if(!uniqueTargets.contains(templateTarget)) {

                        uniqueTargets.add(templateTarget);
                        // we can provide targets to model config and direct class targets
                        if(templateTarget instanceof PsiFile) {
                            parameter.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(templateTarget, resolveString).withIcon(templateTarget.getIcon(0), Symfony2Icons.DOCTRINE_LINE_MARKER));
                        } else {
                            // @TODO: we can resolve for model types and provide icons, but not for now
                            parameter.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(templateTarget, resolveString).withIcon(Symfony2Icons.DOCTRINE, Symfony2Icons.DOCTRINE_LINE_MARKER));
                        }
                    }

                }
            }
        }
    }

}
 
示例30
@Nullable
@Override
public GotoCompletionProvider getProvider(@NotNull PsiElement psiElement) {
    PsiElement context = psiElement.getContext();
    if (!(context instanceof StringLiteralExpression)) {
        return null;
    }

    MethodMatcher.MethodMatchParameter match = new MethodMatcher.ArrayParameterMatcher(context, placeHolderParameter)
        .withSignature("Symfony\\Component\\Translation\\TranslatorInterface", method)
        .withSignature("Symfony\\Contracts\\Translation\\TranslatorInterface", method)
        .match();

    if (match == null) {
        return null;
    }

    PsiElement[] parameters = match.getMethodReference().getParameters();
    String key = PhpElementsUtil.getStringValue(parameters[0]);
    if(key == null) {
        return null;
    }

    String domain = "messages";
    if(parameters.length > domainParameter) {
        domain = PhpElementsUtil.getStringValue(parameters[domainParameter]);
        if(domain == null) {
            return null;
        }
    }

    return new MyTranslationPlaceholderGotoCompletionProvider(psiElement, key, domain);
}