Java Code Examples for fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrarParameter#register()

The following examples show how to use fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrarParameter#register() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TranslationTagGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@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);
        }
    );
}
 
Example 2
Source File: TranslationReferences.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
@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;
    });
}
 
Example 3
Source File: PhpMessageSubscriberGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@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());
    });
}
 
Example 4
Source File: YamlMenuGotoCompletion.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
@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);
    });
}
 
Example 5
Source File: YamlRouteKeyCompletion.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
@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);
    });
}
 
Example 6
Source File: YamlEntityFormGotoCompletion.java    From idea-php-drupal-symfony2-bridge with MIT License 5 votes vote down vote up
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(YamlElementPatternHelper.getSingleLineScalarKey("_entity_form"), psiElement -> {
        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new MyGotoCompletionProvider(psiElement);
    });
}
 
Example 7
Source File: RenderParameterGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
    registrar.register(
        PlatformPatterns.psiElement().withParent(StringLiteralExpression.class),
        MyTemplateVariablesGotoCompletionProvider::new
    );
}
 
Example 8
Source File: AnnotationExpressionGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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
    );
}
 
Example 9
Source File: DoctrineXmlGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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);
}
 
Example 10
Source File: ConsoleHelperGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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);
    });
}
 
Example 11
Source File: PhpRouteParameterCompletion.java    From idea-php-drupal-symfony2-bridge with MIT License 5 votes vote down vote up
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(getElementPatternPattern(), psiElement -> {
        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new MyGotoCompletionProvider(psiElement);
    });
}
 
Example 12
Source File: ControllerCompletion.java    From idea-php-drupal-symfony2-bridge with MIT License 5 votes vote down vote up
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(YamlElementPatternHelper.getSingleLineScalarKey("_controller"), psiElement -> {
        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new MyGotoCompletionProvider(psiElement);
    });

}
 
Example 13
Source File: PhpEventDispatcherGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 *
 * \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;
    });

}
 
Example 14
Source File: YamlPermissionGotoCompletion.java    From idea-php-drupal-symfony2-bridge with MIT License 5 votes vote down vote up
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
    registrar.register(YamlElementPatternHelper.getSingleLineScalarKey("_permission"), psiElement -> {
        if(!DrupalProjectComponent.isEnabled(psiElement)) {
            return null;
        }

        return new MyGotoCompletionProvider(psiElement);
    });
}
 
Example 15
Source File: AssetGotoCompletionRegistrar.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
@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);
    });
}
 
Example 16
Source File: FilterGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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);
    });
}
 
Example 17
Source File: YamlGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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
    );
}
 
Example 18
Source File: AppConfigReferences.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
@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;
    });
}
 
Example 19
Source File: TaggedParameterGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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()
    );
}
 
Example 20
Source File: ObjectRepositoryFindGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
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;
        });
    }