fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionProvider Java Examples
The following examples show how to use
fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionProvider.
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: FormOptionGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable @Override public GotoCompletionProvider getProvider(@NotNull PsiElement psiElement) { if (!Symfony2ProjectComponent.isEnabled(psiElement)) { return null; } ArrayCreationExpression arrayCreationExpression = PhpElementsUtil.getCompletableArrayCreationElement(psiElement.getParent()); if(arrayCreationExpression != null) { PsiElement parameterList = arrayCreationExpression.getParent(); if (parameterList instanceof ParameterList) { PsiElement context = parameterList.getContext(); if(context instanceof MethodReference) { ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(arrayCreationExpression); if(currentIndex != null && currentIndex.getIndex() == 2) { if (PhpElementsUtil.isMethodReferenceInstanceOf((MethodReference) context, FormUtil.PHP_FORM_BUILDER_SIGNATURES)) { return getMatchingOption((ParameterList) parameterList, psiElement); } } } } } return null; }
Example #2
Source File: FormOptionGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private GotoCompletionProvider getMatchingOption(ParameterList parameterList, @NotNull PsiElement psiElement) { // form name can be a string alias; also resolve on constants, properties, ... PsiElement psiElementAt = PsiElementUtils.getMethodParameterPsiElementAt(parameterList, 1); Set<String> formTypeNames = new HashSet<>(); if(psiElementAt != null) { PhpClass phpClass = FormUtil.getFormTypeClassOnParameter(psiElementAt); if(phpClass != null) { formTypeNames.add(phpClass.getFQN()); } } // fallback to form if(formTypeNames.size() == 0) { formTypeNames.add("form"); // old Symfony systems formTypeNames.add("Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType"); } return new FormReferenceCompletionProvider(psiElement, formTypeNames); }
Example #3
Source File: FormGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable private GotoCompletionProvider createTranslationGotoCompletion(@NotNull PsiElement psiElement, @NotNull PsiElement arrayCreation) { int parameterIndexValue = PsiElementUtils.getParameterIndexValue(arrayCreation); if(parameterIndexValue != 2) { return null; } PsiElement parameterList = arrayCreation.getParent(); if(parameterList instanceof ParameterList) { PsiElement methodReference = parameterList.getParent(); if(methodReference instanceof MethodReference) { if(PhpElementsUtil.isMethodReferenceInstanceOf((MethodReference) methodReference, "\\Symfony\\Component\\Form\\FormBuilderInterface", "add") || PhpElementsUtil.isMethodReferenceInstanceOf((MethodReference) methodReference, "\\Symfony\\Component\\Form\\FormBuilderInterface", "create") ) { return new TranslationGotoCompletionProvider(psiElement, extractTranslationDomainFromScope((ArrayCreationExpression) arrayCreation)); } } } return null; }
Example #4
Source File: TaggedParameterGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override public GotoCompletionProvider getProvider(@NotNull PsiElement psiElement) { return new GotoCompletionProvider(psiElement) { @NotNull @Override public Collection<LookupElement> getLookupElements() { return TagNameCompletionProvider.getTagLookupElements(getProject()); } @NotNull @Override public Collection<PsiElement> getPsiTargets(PsiElement element) { String tagName = GotoCompletionUtil.getTextValueForElement(element); if(tagName == null) { return Collections.emptyList(); } return new ArrayList<>(ServiceUtil.getTaggedClasses(element.getProject(), tagName)); } }; }
Example #5
Source File: FormOptionGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@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); }
Example #6
Source File: FormGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable private GotoCompletionProvider createTranslationGotoCompletionWithLabelSwitch(@NotNull PsiElement origin, @NotNull ArrayCreationExpression choices, Processor<ArrayCreationExpression> processor) { PsiElement choicesArrayValue = choices.getParent(); if(choicesArrayValue.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE) { PsiElement choicesValueHash = choicesArrayValue.getParent(); if(choicesValueHash instanceof ArrayHashElement) { PhpPsiElement transKey = ((ArrayHashElement) choicesValueHash).getKey(); String stringValue = PhpElementsUtil.getStringValue(transKey); if("choices".equals(stringValue)) { PsiElement choicesKey = transKey.getParent(); if(choicesKey.getNode().getElementType() == PhpElementTypes.ARRAY_KEY) { PsiElement formOptionsHash = choicesKey.getParent(); if(formOptionsHash instanceof ArrayHashElement) { PsiElement arrayCreation = formOptionsHash.getParent(); if(arrayCreation instanceof ArrayCreationExpression) { if(processor.process((ArrayCreationExpression) arrayCreation)) { return createTranslationGotoCompletion(origin, arrayCreation); } } } } } } } return null; }
Example #7
Source File: TranslationPlaceholderGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@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); }
Example #8
Source File: TranslationPlaceholderGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable @Override public GotoCompletionProvider getProvider(@NotNull PsiElement psiElement) { PsiElement parent = psiElement.getParent(); if(parent.getNode().getElementType() != TwigElementTypes.LITERAL) { return null; } PsiElement functionCall = parent.getParent(); if(functionCall.getNode().getElementType() != TwigElementTypes.FUNCTION_CALL) { return null; } // find translation key: 'symfony.great' PsiElement function = PsiElementUtils.getPrevSiblingOfType(functionCall, TwigPattern.getTranslationKeyPattern(this.filter)); if(function == null) { return null; } String key = function.getText(); if(StringUtils.isBlank(key)) { return null; } String domain = TwigUtil.getPsiElementTranslationDomain(function); if(StringUtils.isBlank(domain)) { return null; } return new MyTranslationPlaceholderGotoCompletionProvider(psiElement, key, domain); }