fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils Java Examples
The following examples show how to use
fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils.
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: PhpTemplateMissingInspection.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable private String getTemplateNameIfMissing(@NotNull PsiElement psiElement) { MethodReference methodReference = PsiElementUtils.getMethodReferenceWithFirstStringParameter(psiElement); if (methodReference == null || !PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, SymfonyPhpReferenceContributor.TEMPLATE_SIGNATURES)) { return null; } ParameterBag parameterBag = PsiElementUtils.getCurrentParameterIndex(psiElement.getParent()); if(parameterBag == null || parameterBag.getIndex() != 0) { return null; } String templateName = PhpElementsUtil.getFirstArgumentStringValue(methodReference); if(templateName == null || StringUtils.isBlank(templateName)) { return null; } if(TwigUtil.getTemplateFiles(psiElement.getProject(), templateName).size() > 0) { return null; } return templateName; }
Example #2
Source File: DoctrineUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * Extract text: @Entity(repositoryClass="foo") */ @Nullable public static String getAnnotationRepositoryClass(@NotNull PhpDocTag phpDocTag, @NotNull PhpClass phpClass) { PsiElement phpDocAttributeList = PsiElementUtils.getChildrenOfType(phpDocTag, PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList)); if(phpDocAttributeList == null) { return null; } // @TODO: use annotation plugin // repositoryClass="Foobar" String text = phpDocAttributeList.getText(); String repositoryClass = EntityHelper.resolveDoctrineLikePropertyClass( phpClass, text, "repositoryClass", aVoid -> AnnotationUtil.getUseImportMap(phpDocTag) ); if (repositoryClass == null) { return null; } return StringUtils.stripStart(repositoryClass, "\\"); }
Example #3
Source File: PhpConfigReferenceContributor.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private static boolean phpStringLiteralExpressionClassReference(String signature, int index, PsiElement psiElement) { if (!(psiElement.getContext() instanceof ParameterList)) { return false; } ParameterList parameterList = (ParameterList) psiElement.getContext(); if (parameterList == null || !(parameterList.getContext() instanceof NewExpression)) { return false; } if(PsiElementUtils.getParameterIndexValue(psiElement) != index) { return false; } NewExpression newExpression = (NewExpression) parameterList.getContext(); ClassReference classReference = newExpression.getClassReference(); if(classReference == null) { return false; } return classReference.getSignature().equals("#C" + signature); }
Example #4
Source File: XmlServiceArgumentInspection.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private void visitService(XmlTag xmlTag, @NotNull ProblemsHolder holder) { if(!ServiceActionUtil.isValidXmlParameterInspectionService(xmlTag)) { return; } final List<String> args = ServiceActionUtil.getXmlMissingArgumentTypes(xmlTag, false, getLazyServiceCollector(xmlTag)); if (args.size() == 0) { return; } PsiElement childrenOfType = PsiElementUtils.getChildrenOfType(xmlTag, PlatformPatterns.psiElement(XmlTokenType.XML_NAME)); if(childrenOfType == null) { return; } holder.registerProblem(childrenOfType, "Missing argument", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new AddServiceXmlArgumentLocalQuickFix(args)); }
Example #5
Source File: YamlHelper.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable public static YAMLKeyValue getYamlKeyValue(@Nullable PsiElement yamlCompoundValue, String keyName, boolean ignoreCase) { if (!(yamlCompoundValue instanceof YAMLMapping)) { return null; } if (!ignoreCase) { return ((YAMLMapping) yamlCompoundValue).getKeyValueByKey(keyName); } YAMLKeyValue classKeyValue; classKeyValue = PsiElementUtils.getChildrenOfType(yamlCompoundValue, PlatformPatterns.psiElement(YAMLKeyValue.class).withName(PlatformPatterns.string().oneOfIgnoreCase(keyName))); if(classKeyValue == null) { return null; } return classKeyValue; }
Example #6
Source File: ServiceDeprecatedClassesInspection.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override public void visitElement(PsiElement element) { MethodReference methodReference = PsiElementUtils.getMethodReferenceWithFirstStringParameter(element); if (methodReference == null || !PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, ServiceContainerUtil.SERVICE_GET_SIGNATURES)) { super.visitElement(element); return; } PsiElement psiElement = element.getParent(); if(!(psiElement instanceof StringLiteralExpression)) { super.visitElement(element); return; } String contents = ((StringLiteralExpression) psiElement).getContents(); if(StringUtils.isNotBlank(contents)) { this.problemRegistrar.attachDeprecatedProblem(element, contents, holder); this.problemRegistrar.attachServiceDeprecatedProblem(element, contents, holder); } super.visitElement(element); }
Example #7
Source File: ServiceDeprecatedClassesInspection.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override public void visitElement(PsiElement element) { boolean serviceArgumentAccepted = XmlHelper.getArgumentServiceIdPattern().accepts(element); if(serviceArgumentAccepted || XmlHelper.getServiceClassAttributeWithIdPattern().accepts(element)) { String text = PsiElementUtils.trimQuote(element.getText()); PsiElement[] psiElements = element.getChildren(); // we need to attach to child because else strike out equal and quote char if(StringUtils.isNotBlank(text) && psiElements.length > 2) { this.problemRegistrar.attachDeprecatedProblem(psiElements[1], text, holder); // check service arguments for "deprecated" defs if(serviceArgumentAccepted) { this.problemRegistrar.attachServiceDeprecatedProblem(psiElements[1], text, holder); } } } super.visitElement(element); }
Example #8
Source File: TaggedExtendsInterfaceClassInspection.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override public void visitElement(PsiElement element) { if(XmlHelper.getServiceClassAttributeWithIdPattern().accepts(element)) { String text = PsiElementUtils.trimQuote(element.getText()); PsiElement[] psiElements = element.getChildren(); // attach problems to string value only if(StringUtils.isNotBlank(text) && psiElements.length > 2) { XmlTag parentOfType = PsiTreeUtil.getParentOfType(element, XmlTag.class); if(parentOfType != null) { registerTaggedProblems(psiElements[1], FormUtil.getTags(parentOfType), text, holder, this.lazyServiceCollector); } } } super.visitElement(element); }
Example #9
Source File: ShopwareUtil.java From idea-php-shopware-plugin with MIT License | 6 votes |
public static void collectBootstrapFiles(StringLiteralExpression literalExpression, final BootstrapFileVisitor visitor) { MethodReference methodReference = PsiElementUtils.getPrevSiblingOfType(literalExpression, PlatformPatterns.psiElement(MethodReference.class).withText(PlatformPatterns.string().contains("Path()"))); if(methodReference == null) { return; } PsiFile currentFile = literalExpression.getContainingFile(); final PsiDirectory psiDirectory = currentFile.getParent(); if(psiDirectory == null) { return; } VfsUtil.processFilesRecursively(psiDirectory.getVirtualFile(), virtualFile -> { if(virtualFile.isDirectory() || "php".equalsIgnoreCase(virtualFile.getExtension())) { String relativePath = VfsUtil.getRelativePath(virtualFile, psiDirectory.getVirtualFile(), '/'); if(StringUtils.isNotBlank(relativePath)) { visitor.visitVariable(virtualFile, relativePath); } } return true; }); }
Example #10
Source File: IndexTranslatorProvider.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@NotNull @Override public Collection<PsiElement> getTranslationTargets(@NotNull Project project, @NotNull String translationKey, @NotNull String domain) { Collection<PsiElement> psiFoundElements = new ArrayList<>(); Collection<VirtualFile> files = new HashSet<>(); FileBasedIndex.getInstance().getFilesWithKey(TranslationStubIndex.KEY, new HashSet<>(Collections.singletonList(domain)), virtualFile -> { files.add(virtualFile); return true; }, GlobalSearchScope.allScope(project)); for (PsiFile psiFile : PsiElementUtils.convertVirtualFilesToPsiFiles(project, files)) { psiFoundElements.addAll(TranslationUtil.getTranslationKeyTargetInsideFile(psiFile, domain, translationKey)); } return psiFoundElements; }
Example #11
Source File: ExtJsTemplateLineMarkerProvider.java From idea-php-shopware-plugin with MIT License | 6 votes |
private void attachControllerAction(PsiElement sourceElement, Collection<LineMarkerInfo> lineMarkerInfos) { if(!ShopwareProjectComponent.isValidForProject(sourceElement)) { return; } String text = PsiElementUtils.trimQuote(sourceElement.getText()); if(text.startsWith("{") && text.endsWith("}")) { List<PsiElement> controllerTargets = ExtJsUtil.getControllerTargets(sourceElement, text); if(controllerTargets.size() > 0) { NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(ShopwarePluginIcons.SHOPWARE_LINEMARKER). setTargets(controllerTargets). setTooltipText("Navigate to action"); lineMarkerInfos.add(builder.createLineMarkerInfo(sourceElement)); } } }
Example #12
Source File: PhpTranslationDomainInspection.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private void invoke(@NotNull ProblemsHolder holder, @NotNull PsiElement psiElement) { if (!(psiElement instanceof StringLiteralExpression) || !(psiElement.getContext() instanceof ParameterList)) { return; } ParameterList parameterList = (ParameterList) psiElement.getContext(); PsiElement methodReference = parameterList.getContext(); if (!(methodReference instanceof MethodReference)) { return; } if (!PhpElementsUtil.isMethodReferenceInstanceOf((MethodReference) methodReference, TranslationUtil.PHP_TRANSLATION_SIGNATURES)) { return; } int domainParameter = 2; if("transChoice".equals(((MethodReference) methodReference).getName())) { domainParameter = 3; } ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(psiElement); if(currentIndex != null && currentIndex.getIndex() == domainParameter) { annotateTranslationDomain((StringLiteralExpression) psiElement, holder); } }
Example #13
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 #14
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 #15
Source File: YamlGoToDeclarationHandler.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@NotNull private Collection<PsiElement> getTagMethodGoto(@NotNull PsiElement psiElement) { String methodName = PsiElementUtils.trimQuote(psiElement.getText()); if(StringUtils.isBlank(methodName)) { return Collections.emptyList(); } String classValue = YamlHelper.getServiceDefinitionClassFromTagMethod(psiElement); if(classValue == null) { return Collections.emptyList(); } PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(psiElement.getProject(), classValue); if(phpClass == null) { return Collections.emptyList(); } Method method = phpClass.findMethodByName(methodName); if(method != null) { return Collections.singletonList(method); } return Collections.emptyList(); }
Example #16
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 #17
Source File: DefaultReferenceProvider.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override public PsiReference getPsiReference(AssistantReferenceProviderParameter parameter) { String translationDomain = "messages"; // more than self match; search for translation_domain provider if(parameter.getConfigsMethodScope().size() > 1) { // last translation domain wins for(MethodParameterSetting config: parameter.getConfigsMethodScope()) { if(config.getReferenceProviderName().equals("translation_domain")) { String parameterValue = PsiElementUtils.getMethodParameterAt(parameter.getMethodReference(), config.getIndexParameter()); if(parameterValue != null) { translationDomain = parameterValue; } } } } return new TranslationReference(parameter.getPsiElement(), translationDomain); }
Example #18
Source File: YamlGoToDeclarationHandler.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@NotNull private Collection<PsiElement> getMethodGoto(@NotNull PsiElement psiElement) { Collection<PsiElement> results = new ArrayList<>(); PsiElement parent = psiElement.getParent(); if(parent instanceof YAMLScalar) { YamlHelper.visitServiceCall((YAMLScalar) parent, clazz -> { PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(psiElement.getProject(),clazz); if(phpClass != null) { for(Method method: PhpElementsUtil.getClassPublicMethod(phpClass)) { if(method.getName().equals(PsiElementUtils.trimQuote(psiElement.getText()))) { results.add(method); } } } }); } return results; }
Example #19
Source File: YamlClassInspection.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private void invoke(@NotNull final PsiElement psiElement, @NotNull ProblemsHolder holder) { String className = PsiElementUtils.getText(psiElement); if (YamlHelper.isValidParameterName(className)) { String resolvedParameter = ContainerCollectionResolver.resolveParameter(psiElement.getProject(), className); if (resolvedParameter != null && PhpIndex.getInstance(psiElement.getProject()).getAnyByFQN(resolvedParameter).size() > 0) { return; } } PhpClass foundClass = PhpElementsUtil.getClassInterface(psiElement.getProject(), className); if (foundClass == null) { holder.registerProblem(psiElement, MESSAGE_MISSING_CLASS, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } else if (!foundClass.getPresentableFQN().equals(className)) { holder.registerProblem(psiElement, MESSAGE_WRONG_CASING, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new CorrectClassNameCasingYamlLocalQuickFix(foundClass.getPresentableFQN())); } }
Example #20
Source File: YamlCompletionContributor.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private static void addYamlClassMethods(@Nullable PsiElement psiElement, CompletionResultSet completionResultSet, String classTag) { if(psiElement == null) { return; } YAMLKeyValue classKeyValue = PsiElementUtils.getChildrenOfType(psiElement, PlatformPatterns.psiElement(YAMLKeyValue.class).withName(classTag)); if(classKeyValue == null) { return; } PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(psiElement.getProject(), classKeyValue.getValueText()); if(phpClass != null) { PhpElementsUtil.addClassPublicMethodCompletion(completionResultSet, phpClass); } }
Example #21
Source File: EventMethodCallInspection.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private void registerMethodProblem(final @NotNull PsiElement psiElement, @NotNull ProblemsHolder holder, @Nullable PhpClass phpClass) { if(phpClass == null) { return; } final String methodName = PsiElementUtils.trimQuote(psiElement.getText()); if(phpClass.findMethodByName(methodName) != null) { return; } holder.registerProblem( psiElement, "Missing Method", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new CreateMethodQuickFix(phpClass, methodName, new MyCreateMethodQuickFix()) ); }
Example #22
Source File: TwigControllerUsageControllerRelatedGotoCollector.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override public void collectGotoRelatedItems(ControllerActionGotoRelatedCollectorParameter parameter) { Method method = parameter.getMethod(); PhpClass containingClass = method.getContainingClass(); if (containingClass == null) { return; } String controllerAction = StringUtils.stripStart(containingClass.getPresentableFQN(), "\\") + "::" + method.getName(); Collection<VirtualFile> targets = new HashSet<>(); FileBasedIndex.getInstance().getFilesWithKey(TwigControllerStubIndex.KEY, new HashSet<>(Collections.singletonList(controllerAction)), virtualFile -> { targets.add(virtualFile); return true; }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(parameter.getProject()), TwigFileType.INSTANCE)); for (PsiFile psiFile: PsiElementUtils.convertVirtualFilesToPsiFiles(parameter.getProject(), targets)) { TwigUtil.visitControllerFunctions(psiFile, pair -> { if (pair.getFirst().equalsIgnoreCase(controllerAction)) { parameter.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(pair.getSecond()).withIcon(TwigIcons.TwigFileIcon, Symfony2Icons.TWIG_LINE_MARKER)); } }); } }
Example #23
Source File: FileResourceUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * Gives targets to files which relative to current file directory */ @NotNull public static Collection<PsiFile> getFileResourceTargetsInDirectoryScope(@NotNull PsiFile psiFile, @NotNull String content) { // bundle scope if(content.startsWith("@")) { return Collections.emptyList(); } PsiDirectory containingDirectory = psiFile.getContainingDirectory(); if(containingDirectory == null) { return Collections.emptyList(); } VirtualFile relativeFile = VfsUtil.findRelativeFile(content, containingDirectory.getVirtualFile()); if(relativeFile == null) { return Collections.emptyList(); } PsiFile targetFile = PsiElementUtils.virtualFileToPsiFile(psiFile.getProject(), relativeFile); if(targetFile == null) { return Collections.emptyList(); } return Collections.singletonList(targetFile); }
Example #24
Source File: FormFieldResolver.java From idea-php-symfony2-plugin with MIT License | 6 votes |
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)); } } }
Example #25
Source File: FormFieldResolver.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private static List<TwigTypeContainer> getTwigTypeContainer(Method method) { MethodReference[] formBuilderTypes = FormUtil.getFormBuilderTypes(method); List<TwigTypeContainer> twigTypeContainers = new ArrayList<>(); for(MethodReference methodReference: formBuilderTypes) { String fieldName = PsiElementUtils.getMethodParameterAt(methodReference, 0); PsiElement psiElement = PsiElementUtils.getMethodParameterPsiElementAt(methodReference, 1); TwigTypeContainer twigTypeContainer = new TwigTypeContainer(fieldName); // find form field type if(psiElement != null) { PhpClass phpClass = FormUtil.getFormTypeClassOnParameter(psiElement); if(phpClass != null) { twigTypeContainer.withDataHolder(new FormDataHolder(phpClass)); } } twigTypeContainers.add(twigTypeContainer); } return twigTypeContainers; }
Example #26
Source File: BlockGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@NotNull public Collection<PsiElement> getPsiTargets(PsiElement element) { String blockName = PsiElementUtils.trimQuote(element.getText()); if(StringUtils.isBlank(blockName)) { return Collections.emptyList(); } Collection<PsiElement> psiElements = new HashSet<>(); psiElements.addAll( TwigBlockUtil.getBlockOverwriteTargets(element.getContainingFile(), blockName, true) ); psiElements.addAll( TwigBlockUtil.getBlockImplementationTargets(element) ); // filter self navigation return psiElements.stream() .filter(psiElement -> psiElement != element) .collect(Collectors.toSet()); }
Example #27
Source File: FormFieldNameReference.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public static LookupElement[] getFormLookups(Method method) { MethodReference[] formBuilderTypes = FormUtil.getFormBuilderTypes(method); List<LookupElement> lookupElements = new ArrayList<>(); for(MethodReference methodReference: formBuilderTypes) { String fieldName = PsiElementUtils.getMethodParameterAt(methodReference, 0); if(fieldName != null) { LookupElementBuilder lookup = LookupElementBuilder.create(fieldName).withIcon(Symfony2Icons.FORM_TYPE); String fieldType = PsiElementUtils.getMethodParameterAt(methodReference, 1); if(fieldType != null) { lookup = lookup.withTypeText(fieldType, true); } lookupElements.add(lookup); } } return lookupElements.toArray(new LookupElement[lookupElements.size()]); }
Example #28
Source File: TwigTypeResolveUtil.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * Get the "for IN" variable identifier as separated string * * {% for car in "cars" %} * {% for car in "cars"|length %} * {% for car in "cars.test" %} */ @NotNull private static Collection<String> getForTagIdentifierAsString(PsiElement forTag) { if(forTag.getNode().getElementType() != TwigElementTypes.FOR_TAG) { return Collections.emptyList(); } // getChildren hack PsiElement firstChild = forTag.getFirstChild(); if(firstChild == null) { return Collections.emptyList(); } // find IN token PsiElement psiIn = PsiElementUtils.getNextSiblingOfType(firstChild, PlatformPatterns.psiElement(TwigTokenTypes.IN)); if(psiIn == null) { return Collections.emptyList(); } // find next IDENTIFIER, eg skip whitespaces PsiElement psiIdentifier = PsiElementUtils.getNextSiblingOfType(psiIn, PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER)); if(psiIdentifier == null) { return Collections.emptyList(); } // find non common token type. we only allow: "test.test" PsiElement afterInVarPsiElement = PsiElementUtils.getNextSiblingOfType(psiIdentifier, PlatformPatterns.psiElement().andNot(PlatformPatterns.or( PlatformPatterns.psiElement((TwigTokenTypes.IDENTIFIER)), PlatformPatterns.psiElement((TwigTokenTypes.DOT)) ))); if(afterInVarPsiElement == null) { return Collections.emptyList(); } return TwigTypeResolveUtil.formatPsiTypeName(afterInVarPsiElement); }
Example #29
Source File: TranslationUtil.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * Get targets for translation based on the domain path inside the compiled container * * TODO: completely remove this? support translation paths from service compiler */ public static Collection<PsiElement> getTranslationKeyFromCompiledContainerDomain(@NotNull Project project, @NotNull String domain, @NotNull String translationKey) { Collection<PsiElement> psiFoundElements = new ArrayList<>(); // search for available domain files for(PsiFile psiFile : PsiElementUtils.convertVirtualFilesToPsiFiles(project, TranslationUtil.getDomainFilesFromCompiledContainer(project, domain))) { psiFoundElements.addAll(getTranslationKeyTargetInsideFile(psiFile, domain, translationKey)); } return psiFoundElements; }
Example #30
Source File: TranslationUtil.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public static List<PsiFile> getDomainPsiFiles(@NotNull Project project, @NotNull String domainName) { Set<VirtualFile> files = new HashSet<>(); for (TranslatorProvider translationProvider : getTranslationProviders()) { files.addAll(translationProvider.getDomainPsiFiles(project, domainName)); } return new ArrayList<>(PsiElementUtils.convertVirtualFilesToPsiFiles(project, files)); }