Java源码示例:fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrarParameter

示例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
public static Collection<GotoCompletionContributor> getContributors(final PsiElement psiElement) {
    Collection<GotoCompletionContributor> contributors = new ArrayList<>();

    GotoCompletionRegistrarParameter registrar = (pattern, contributor) -> {
        if(pattern.accepts(psiElement)) {
            contributors.add(contributor);
        }
    };

    for(GotoCompletionRegistrar register: CONTRIBUTORS) {
        // filter on language
        if(register instanceof GotoCompletionLanguageRegistrar) {
            if(((GotoCompletionLanguageRegistrar) register).support(psiElement.getLanguage())) {
                register.register(registrar);
            }
        } else {
            register.register(registrar);
        }
    }

    return contributors;
}
 
示例5
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    PsiElementPattern.Capture<PsiElement> menuPattern = PlatformPatterns.psiElement().inFile(PlatformPatterns.psiFile().withName(PlatformPatterns.string().endsWith(".menu.yml")));

    registrar.register(PlatformPatterns.and(YamlElementPatternHelper.getSingleLineScalarKey("parent"), menuPattern), psiElement -> {
        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new ParentMenu(psiElement);
    });


    registrar.register(PlatformPatterns.and(YamlElementPatternHelper.getWithFirstRootKey(), menuPattern), psiElement -> {
        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new MenuKeys(psiElement);
    });
}
 
示例6
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    PsiElementPattern.Capture<PsiElement> filePattern = PlatformPatterns.psiElement().inFile(PlatformPatterns.psiFile().withName(PlatformPatterns.string().endsWith(".routing.yml")));

    registrar.register(PlatformPatterns.and(YamlElementPatternHelper.getParentKeyName("defaults"), filePattern), psiElement -> {
        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new DefaultRoutes(psiElement);
    });

    registrar.register(PlatformPatterns.and(YamlElementPatternHelper.getParentKeyName("requirements"), filePattern), psiElement -> {
        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new EntityAccessRoutes(psiElement);
    });
}
 
示例7
@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);

    });
}
 
示例8
public static Collection<GotoCompletionContributor> getContributors(final PsiElement psiElement) {

        final Collection<GotoCompletionContributor> contributors = new ArrayList<>();

        GotoCompletionRegistrarParameter registrar = (pattern, contributor) -> {
            if(pattern.accepts(psiElement)) {
                contributors.add(contributor);
            }
        };

        for(GotoCompletionRegistrar register: EXTENSIONS.getExtensions()) {
            register.register(registrar);
        }

        return contributors;
    }
 
示例9
@Override
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
    // {% trans from "app" %}<caret>{% endtrans %}
    registrar.register(
        getTranslationTagValuePattern(), psiElement -> {
            TwigCompositeElement element = getTagOnTwigViewProvider(psiElement);
            if(element == null) {
                return null;
            }

            String domain = TwigUtil.getDomainFromTranslationTag(element);
            if(domain == null) {
                domain = TwigUtil.getTransDefaultDomainOnScope(element);
            }

            // overall fallback if no "trans*" scope was found
            if(domain == null) {
                domain = "messages";
            }

            return new MyTranslationGotoCompletionProvider(element, domain);
        }
    );
}
 
示例10
@Override
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
    registrar.register(REGISTRAR_PATTERN, psiElement -> {
        Method method = PsiTreeUtil.getParentOfType(psiElement, Method.class, true, Function.class);

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

        if (!PhpElementsUtil.isMethodInstanceOf(method, "\\Symfony\\Component\\Messenger\\Handler\\MessageSubscriberInterface", "getHandledMessages")) {
            return null;
        }

        return new PhpClassPublicMethodProvider(method.getContainingClass());
    });
}
 
示例11
@Override
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
    // {{ 'symfony.great'|trans({'fo<caret>f'}, 'symfony')) }}
    registrar.register(
        TwigPattern.getFunctionWithFirstParameterAsKeyLiteralPattern("trans"),
        new MyTwigTransFilterCompletionContributor("trans")
    );

    // {{ 'symfony.great'|transchoice(12, {'fo<caret>f'}, 'symfony')) }}
    registrar.register(
        TwigPattern.getFunctionWithSecondParameterAsKeyLiteralPattern("transchoice"),
        new MyTwigTransFilterCompletionContributor("transchoice")
    );

    // $x->trans('symfony.great', ['%fo<caret>obar%', null], 'symfony')
    registrar.register(
        PlatformPatterns.psiElement().withParent(StringLiteralExpression.class),
        new MyPhpTranslationCompletionContributor("trans", 1, 2)
    );

    // $x->transChoice('symfony.great', 10, ['%fo<caret>obar%', null], 'symfony')
    registrar.register(
        PlatformPatterns.psiElement().withParent(StringLiteralExpression.class),
        new MyPhpTranslationCompletionContributor("transChoice", 2, 3)
    );
}
 
示例12
@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;
    });
}
 
示例13
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(PlatformPatterns.psiElement(), psiElement -> {
        if(psiElement == null || !psiElement.getContainingFile().getName().contains("app.php")) {
            return null;
        }

        // array('providers' => array('foo'))
        PsiElement literal = psiElement.getParent();
        if(literal instanceof StringLiteralExpression) {
            PsiElement arrayValue = literal.getParent();
            if(arrayValue.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE) {
                PsiElement arrayCreation = arrayValue.getParent();
                if(arrayCreation instanceof ArrayCreationExpression) {
                    PsiElement arrayValueKey = arrayCreation.getParent();
                    if(arrayValueKey.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE) {
                        PsiElement hashArrayElement = arrayValueKey.getParent();
                        if(hashArrayElement instanceof ArrayHashElement) {
                            PhpPsiElement key = ((ArrayHashElement) hashArrayElement).getKey();
                            if(key instanceof StringLiteralExpression && "providers".equals(((StringLiteralExpression) key).getContents())) {
                                return new ProviderName(psiElement);
                            }

                        }
                    }
                }
            }
        }

        return null;
    });

}
 
示例14
@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);
    });
}
 
示例15
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(YamlElementPatternHelper.getSingleLineScalarKey("_permission"), psiElement -> {
        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new MyGotoCompletionProvider(psiElement);
    });
}
 
示例16
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(YamlElementPatternHelper.getSingleLineScalarKey("_entity_form"), psiElement -> {
        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new MyGotoCompletionProvider(psiElement);
    });
}
 
示例17
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(YamlElementPatternHelper.getSingleLineScalarKey("_controller"), psiElement -> {
        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new MyGotoCompletionProvider(psiElement);
    });

}
 
示例18
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(getElementPatternPattern(), psiElement -> {
        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new MyGotoCompletionProvider(psiElement);
    });
}
 
示例19
@Override
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
    registrar.register(XmlPatterns.psiElement().withParent(PlatformPatterns.or(
        DoctrineMetadataPattern.getXmlModelClass(),
        DoctrineMetadataPattern.getXmlRepositoryClass(),
        DoctrineMetadataPattern.getXmlTargetDocumentClass(),
        DoctrineMetadataPattern.getXmlTargetEntityClass(),
        DoctrineMetadataPattern.getEmbeddableNameClassPattern()
    )), ClassGotoCompletionProvider::new);
}
 
示例20
@Override
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
    // "@Security("is_granted('POST_SHOW', post) and has_role('ROLE_ADMIN')")"
    registrar.register(
        PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_STRING)
        .withParent(PlatformPatterns.psiElement(StringLiteralExpression.class)
            .withParent(PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList)
                .withParent(PlatformPatterns.psiElement(PhpDocTag.class)
                    .with(PhpDocInstancePatternCondition.INSTANCE)
                )
            )
        ),
        MyGotoCompletionProvider::new
    );
}
 
示例21
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
    registrar.register(
        PlatformPatterns.psiElement().withLanguage(PhpLanguage.INSTANCE),
        new FormOptionBuilderCompletionContributor()
    );

    /*
     * eg "$resolver->setDefault('<caret>')"
     */
    registrar.register(
        PlatformPatterns.psiElement().withParent(PhpElementsUtil.getMethodWithFirstStringPattern()),
        new OptionDefaultCompletionContributor()
    );
}
 
示例22
@Override
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
    // arguments: [!tagged twig.extension]
    // <argument type="tagged" tag="foobar" />
    registrar.register(
        PlatformPatterns.or(
            YamlElementPatternHelper.getTaggedServicePattern(),
            XmlPatterns.psiElement().withParent(XmlHelper.getTypeTaggedTagAttribute())
        ),
        new MyTagGotoCompletionContributor()
    );
}
 
示例23
@Override
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
    // defaults:
    //   route: <caret>
    registrar.register(
        YamlElementPatternHelper.getSingleLineScalarKey("route"),
        RouteGotoCompletionProvider::new
    );

    // defaults:
    //   template: <caret>
    registrar.register(
        YamlElementPatternHelper.getSingleLineScalarKey("template"),
        TemplateGotoCompletionRegistrar::new
    );

    // foo.service:
    //   decorates: <caret>
    registrar.register(
        YamlElementPatternHelper.getSingleLineScalarKey("decorates"),
        MyDecoratedServiceCompletionProvider::new
    );

    // key: !php/const <caret>
    registrar.register(
        YamlElementPatternHelper.getPhpConstPattern(),
        PhpConstGotoCompletionProvider::new
    );
}
 
示例24
@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);
    });
}
 
示例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;
        }

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

}
 
示例26
@Override
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
    registrar.register(
        PlatformPatterns.psiElement().withParent(StringLiteralExpression.class),
        MyTemplateVariablesGotoCompletionProvider::new
    );
}
 
示例27
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
    // {% trans foo<caret>bar %}
    registrar.register(TwigPattern.getFilterTagPattern(), psiElement -> {
        if (!Symfony2ProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new MyFilterTagGotoCompletionProvider(psiElement);
    });
}
 
示例28
/**
 *
 * \Symfony\Component\EventDispatcher\EventSubscriberInterface::getSubscribedEvents
 *
 * return array(
 *  'pre.foo' => array('preFoo', 10),
 *  'post.foo' => array('postFoo'),
 * ');
 *
 */
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {

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

        PsiElement arrayValue = parent.getParent();
        if(arrayValue != null && arrayValue.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE) {
            PhpReturn phpReturn = PsiTreeUtil.getParentOfType(arrayValue, PhpReturn.class);
            if(phpReturn != null) {
                Method method = PsiTreeUtil.getParentOfType(arrayValue, Method.class);
                if(method != null) {
                    String name = method.getName();
                    if("getSubscribedEvents".equals(name)) {
                        PhpClass containingClass = method.getContainingClass();
                        if(containingClass != null && PhpElementsUtil.isInstanceOf(containingClass, "\\Symfony\\Component\\EventDispatcher\\EventSubscriberInterface")) {
                            return new PhpClassPublicMethodProvider(containingClass);
                        }
                    }
                }
            }
        }

        return null;
    });

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

        if(BladePsiUtil.isDirective(psiElement, BladeTokenTypes.SECTION_DIRECTIVE)) {
            return new BladeSectionGotoCompletionProvider(psiElement, BladeTokenTypes.SECTION_DIRECTIVE, BladeTokenTypes.YIELD_DIRECTIVE);
        }

        return null;

    });

    // @extends('extends.bade')
    // @include('include.include')
    registrar.register(PlatformPatterns.psiElement().inVirtualFile(PlatformPatterns.virtualFile().withName(PlatformPatterns.string().endsWith("blade.php"))), psiElement -> {
        if(psiElement == null || !LaravelProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        if(isDirectiveWithName(psiElement, "make")) {
            return new BladeExtendGotoProvider(psiElement);
        }

        return null;

    });

    // @push('my_stack')
    registrar.register(PlatformPatterns.psiElement().inVirtualFile(PlatformPatterns.virtualFile().withName(PlatformPatterns.string().endsWith("blade.php"))), psiElement -> {
        if(psiElement == null || !LaravelProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        if(BladePsiUtil.isDirective(psiElement, BladeTokenTypes.PUSH_DIRECTIVE)) {
            return new BladeSectionGotoCompletionProvider(psiElement, BladeTokenTypes.STACK_DIRECTIVE);
        }

        return null;
    });

    // @inject('metrics', 'App\Services\MetricsService')
    registrar.register(BladePattern.getDirectiveParameterPattern("inject"), psiElement -> {
        if(psiElement == null || !LaravelProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new MyInjectedClassGotoCompletionProvider(psiElement);
    });

    registrar.register(PlatformPatterns.psiElement().withLanguage(BladeLanguage.INSTANCE)
            .withElementType(BladeTokenTypes.CUSTOM_DIRECTIVE), psiElement -> {
        if(psiElement == null || !LaravelProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new CustomDirectivesGotoCompletionProvider(psiElement);
    });
}
 
示例30
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {

        // "@var $om \Doctrine\Common\Persistence\ObjectManager"
        // "$om->getRepository('Foo\Bar')->" + s + "(['foo' => 'foo', '<caret>' => 'foo'])"
        registrar.register(PhpElementsUtil.getParameterListArrayValuePattern(), psiElement -> {
            PsiElement context = psiElement.getContext();
            if (!(context instanceof StringLiteralExpression)) {
                return null;
            }

            MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.ArrayParameterMatcher(context, 0)
                .withSignature("\\Doctrine\\Common\\Persistence\\ObjectRepository", "findOneBy")
                .withSignature("\\Doctrine\\Common\\Persistence\\ObjectRepository", "findBy")
                .withSignature("\\Doctrine\\Persistence\\ObjectRepository", "findOneBy")
                .withSignature("\\Doctrine\\Persistence\\ObjectRepository", "findBy")
                .match();

            if(methodMatchParameter != null) {
                MethodReference methodReference = methodMatchParameter.getMethodReference();

                // extract from type provide on completion:
                // $foo->getRepository('MODEL')->findBy()
                Collection<PhpClass> phpClasses = PhpElementsUtil.getClassFromPhpTypeSetArrayClean(psiElement.getProject(), methodReference.getType().getTypes());

                // resolve every direct repository instance $this->findBy()
                // or direct repository instance $repository->findBy()
                if(phpClasses.size() == 0) {
                    PhpExpression classReference = methodReference.getClassReference();
                    if(classReference != null) {
                        PhpType type = classReference.getType();
                        for (String s : type.getTypes()) {
                            // dont visit type providers
                            if(PhpType.isUnresolved(s)) {
                                continue;
                            }

                            for (DoctrineModelInterface doctrineModel : DoctrineMetadataUtil.findMetadataModelForRepositoryClass(psiElement.getProject(), s)) {
                                phpClasses.addAll(PhpElementsUtil.getClassesInterface(psiElement.getProject(), doctrineModel.getClassName()));
                            }
                        }
                    }
                }

                if(phpClasses.size() == 0) {
                    return null;
                }

                return new MyArrayFieldMetadataGotoCompletionRegistrar(psiElement, phpClasses);
            }

            return null;
        });
    }