com.jetbrains.php.lang.psi.elements.StringLiteralExpression Java Examples

The following examples show how to use com.jetbrains.php.lang.psi.elements.StringLiteralExpression. 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: ConfigCompletionGoto.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
@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);

    });
}
 
Example #2
Source File: PhpFunctionCompletionContributor.java    From idea-php-advanced-autocomplete with MIT License 6 votes vote down vote up
private String[] collectMetaArgumentsSets(PsiElement position) {
    Collection<String> argumentsSets = new ArrayList<>();

    PhpNamespace root = PsiTreeUtil.getParentOfType(position, PhpNamespace.class);
    if (root == null || !"PHPSTORM_META".equals(root.getName())) {
        return new String[0];
    }

    Collection<ParameterList> arguments = PsiTreeUtil.findChildrenOfType(root, ParameterList.class);
    for (ParameterList args : arguments) {
        PsiElement parent = args.getParent();
        if (!(parent instanceof FunctionReference) || !"registerArgumentsSet".equals(((FunctionReference)parent).getName())) {
            continue;
        }

        StringLiteralExpression arg0 = PsiTreeUtil.findChildOfType(args, StringLiteralExpression.class);
        if (arg0 == null) {
            continue;
        }

        argumentsSets.add(arg0.getContents());
    }

    return argumentsSets.toArray(new String[0]);
}
 
Example #3
Source File: DoctrineAnnotationTypeProvider.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter referencesByElementParameter) {

    if(annotationPropertyParameter.getType() != AnnotationPropertyParameter.Type.PROPERTY_VALUE) {
        return null;
    }

    String propertyName = annotationPropertyParameter.getPropertyName();
    if(propertyName == null || !propertyName.equals("repositoryClass")) {
        return null;
    }

    String presentableFQN = annotationPropertyParameter.getPhpClass().getPresentableFQN();
    if(!PhpLangUtil.equalsClassNames("Doctrine\\ORM\\Mapping\\Entity", presentableFQN)) {
        return null;
    }

    return new PsiReference[] {
        new DoctrineRepositoryReference((StringLiteralExpression) annotationPropertyParameter.getElement())
    };

}
 
Example #4
Source File: FormStringToClassConstantIntention.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@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();
}
 
Example #5
Source File: QueryBuilderGotoDeclarationHandler.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
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());
            }
        }


    }
 
Example #6
Source File: ClassCompletionProviderAbstract.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter parameter, PhpAnnotationReferenceProviderParameter referencesByElementParameter) {
    if(!supports(parameter)) {
        return new PsiReference[0];
    }

    PsiElement element = parameter.getElement();
    if(!(element instanceof StringLiteralExpression) || StringUtils.isBlank(((StringLiteralExpression) element).getContents())) {
        return new PsiReference[0];
    }

    return new PsiReference[] {
        new PhpClassReference((StringLiteralExpression) element)
    };
}
 
Example #7
Source File: BladeTemplateUtil.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
private void visitFunctionReference(FunctionReference functionReference) {

            if(!"view".equals(functionReference.getName())) {
                return;
            }

            PsiElement[] parameters = functionReference.getParameters();

            if(parameters.length < 1 || !(parameters[0] instanceof StringLiteralExpression)) {
                return;
            }

            String contents = ((StringLiteralExpression) parameters[0]).getContents();
            if(StringUtils.isBlank(contents)) {
                return;
            }

            views.add(Pair.create(contents, parameters[0]));
        }
 
Example #8
Source File: CompletionNavigationProvider.java    From idea-php-generics-plugin with MIT License 6 votes vote down vote up
private Collection<PsiElement> collectArrayKeyParameterTargets(PsiElement psiElement) {
    Collection<PsiElement> psiElements = new HashSet<>();

    ArrayCreationExpression parentOfType = PsiTreeUtil.getParentOfType(psiElement, ArrayCreationExpression.class);

    if (parentOfType != null) {
        String contents = ((StringLiteralExpression) psiElement).getContents();

        psiElements.addAll(GenericsUtil.getTypesForParameter(parentOfType).stream()
            .filter(parameterArrayType -> parameterArrayType.getKey().equalsIgnoreCase(contents))
            .map(ParameterArrayType::getContext).collect(Collectors.toSet())
        );
    }

    return psiElements;
}
 
Example #9
Source File: IsGrantedAnnotationReferences.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter phpAnnotationReferenceProviderParameter) {
    Project project = annotationPropertyParameter.getProject();
    if(!Symfony2ProjectComponent.isEnabled(project) || !(annotationPropertyParameter.getElement() instanceof StringLiteralExpression) || !PhpElementsUtil.isEqualClassName(annotationPropertyParameter.getPhpClass(), IS_GRANTED_CLASS)) {
        return new PsiReference[0];
    }

    if(annotationPropertyParameter.getType() != AnnotationPropertyParameter.Type.DEFAULT) {
        return new PsiReference[0];
    }

    return new PsiReference[] {
        new VoterReference(((StringLiteralExpression) annotationPropertyParameter.getElement()))
    };
}
 
Example #10
Source File: DoctrineRepositoryClassConstantIntention.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@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();
}
 
Example #11
Source File: AssistantReferenceUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
public static PsiReference[] getPsiReference(MethodParameterSetting methodParameterSetting, StringLiteralExpression psiElement, List<MethodParameterSetting> configsMethodScope, MethodReference method) {

    // custom references
    if(methodParameterSetting.hasAssistantPsiReferenceContributor()) {
        return methodParameterSetting.getAssistantPsiReferenceContributor().getPsiReferences(psiElement);
    }

    // build provider parameter
    AssistantReferenceProvider.AssistantReferenceProviderParameter assistantReferenceProviderParameter = new AssistantReferenceProvider.AssistantReferenceProviderParameter(
        psiElement,
        methodParameterSetting,
        configsMethodScope,
        method
    );

    String ReferenceProvider = methodParameterSetting.getReferenceProviderName();
    for(AssistantReferenceProvider referenceProvider: DefaultReferenceProvider.DEFAULT_PROVIDERS) {
        if(referenceProvider.getAlias().equals(ReferenceProvider)) {
            return new PsiReference[] { referenceProvider.getPsiReference(assistantReferenceProviderParameter) };
        }
    }

    return new PsiReference[0];
}
 
Example #12
Source File: InvalidQuantityInspection.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    if (!TYPO3CMSProjectSettings.isEnabled(problemsHolder.getProject())) {
        return new PhpElementVisitor() {
        };
    }

    return new PhpElementVisitor() {
        @Override
        public void visitPhpElement(PhpPsiElement element) {

            boolean isArrayStringValue = PhpElementsUtil.isStringArrayValue().accepts(element);
            if (!isArrayStringValue || !insideTCAColumnDefinition(element)) {
                return;
            }

            String arrayIndex = extractArrayIndexFromValue(element);
            if (arrayIndex != null && Arrays.asList(TCAUtil.TCA_NUMERIC_CONFIG_KEYS).contains(arrayIndex)) {
                if (element instanceof StringLiteralExpression) {
                    problemsHolder.registerProblem(element, "Config key only accepts integer values");
                }
            }
        }
    };
}
 
Example #13
Source File: DoctrineAnnotationFieldTypeProvider.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter referencesByElementParameter) {

    if(annotationPropertyParameter.getType() != AnnotationPropertyParameter.Type.PROPERTY_VALUE) {
        return null;
    }

    String propertyName = annotationPropertyParameter.getPropertyName();
    if(propertyName == null || !propertyName.equals("type")) {
        return null;
    }

    String presentableFQN = annotationPropertyParameter.getPhpClass().getPresentableFQN();
    if(!presentableFQN.startsWith("\\")) {
        presentableFQN = "\\" + presentableFQN;
    }

    if(!presentableFQN.equals("\\Doctrine\\ORM\\Mapping\\Column")) {
        return null;
    }

    return new PsiReference[] {
        new DoctrineColumnTypeReference((StringLiteralExpression) annotationPropertyParameter.getElement())
    };
}
 
Example #14
Source File: PhpGoToDeclarationHandler.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Editor editor) {

    if(!DrupalProjectComponent.isEnabled(psiElement)) {
        return new PsiElement[0];
    }

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

    PsiElement context = psiElement.getContext();
    if(context instanceof StringLiteralExpression && DrupalPattern.isAfterArrayKey(psiElement, "route_name")) {
        PsiElement routeTarget = RouteHelper.getRouteNameTarget(psiElement.getProject(), ((StringLiteralExpression) context).getContents());
        if(routeTarget != null) {
            psiElementList.add(routeTarget);
        }
    }

    return psiElementList.toArray(new PsiElement[psiElementList.size()]);
}
 
Example #15
Source File: PhpHighlightPackParametersUsagesHandler.java    From idea-php-advanced-autocomplete with MIT License 6 votes vote down vote up
@NotNull
private static HashMap<Integer, RelativeRange> getRelativeSpecificationRanges(HashMap<Integer, PhpPackFormatSpecificationParser.PackSpecification> specifications, List<StringLiteralExpression> targets) {
    Map<TextRange, StringLiteralExpression> rangesInsideResultingFormatString = getRangesWithExpressionInsideResultingFormatString(targets);
    HashMap<Integer, RelativeRange> result = new HashMap<>();

    for (Map.Entry<Integer, PhpPackFormatSpecificationParser.PackSpecification> entry : specifications.entrySet()) {
        PhpPackFormatSpecificationParser.PackSpecification specification = entry.getValue();
        for (Map.Entry<TextRange, StringLiteralExpression> e : rangesInsideResultingFormatString.entrySet()) {
            TextRange expressionRangeInsideFormatString = e.getKey();
            TextRange specificationRangeInsideFormatString = expressionRangeInsideFormatString.intersection(specification.getRangeInElement());
            if (specificationRangeInsideFormatString != null && !specificationRangeInsideFormatString.isEmpty()) {
                result.put(entry.getKey(), new RelativeRange(e.getValue(), specificationRangeInsideFormatString.shiftLeft(expressionRangeInsideFormatString.getStartOffset())));
            }
        }
    }

    return result;
}
 
Example #16
Source File: DoctrineRepositoryClassConstantIntention.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) throws IncorrectOperationException {
    PsiElement parent = psiElement.getParent();
    if(!(parent instanceof StringLiteralExpression)) {
        return;
    }

    try {
        PhpClass phpClass = EntityHelper.resolveShortcutName(project, ((StringLiteralExpression) parent).getContents());
        if(phpClass == null) {
            throw new Exception("Can not resolve model class");
        }
        PhpElementsUtil.replaceElementWithClassConstant(phpClass, parent);
    } catch (Exception e) {
        HintManager.getInstance().showErrorHint(editor, e.getMessage());
    }
}
 
Example #17
Source File: PhpGoToHandler.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
private void attachNamespaceValueNavigation(@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;
    }

    String namespace = ConfigUtil.getNamespaceFromConfigValueParameter((StringLiteralExpression) parent);
    if (namespace == null) {
        return;
    }

    ConfigUtil.visitNamespaceConfigurations(psiElement.getProject(), namespace, pair -> {
        if(contents.equalsIgnoreCase(pair.getFirst())) {
            psiElements.add(pair.getSecond());
        }
    });
}
 
Example #18
Source File: CreateMissingTranslationQuickFix.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
/**
 * Called to apply the fix.
 *
 * @param project    {@link Project}
 * @param descriptor problem reported by the tool which provided this quick fix action
 */
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement psiElement = descriptor.getPsiElement();
    if (psiElement instanceof StringLiteralExpression) {
        StringLiteralExpression stringElement = (StringLiteralExpression) psiElement;
        String contents = stringElement.getContents();

        String fileName = TranslationUtil.extractResourceFilenameFromTranslationString(contents);
        String key = TranslationUtil.extractTranslationKeyTranslationString(contents);
        if (fileName != null) {
            PsiElement[] elementsForKey = ResourcePathIndex.findElementsForKey(project, fileName);
            if (elementsForKey.length > 0) {
                // TranslationUtil.add();
            }
        }
    }
}
 
Example #19
Source File: CompletionNavigationProvider.java    From idea-php-generics-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement sourceElement, int offset, Editor editor) {
    if (sourceElement == null) {
        return new PsiElement[0];
    }

    Collection<PsiElement> psiElements = new HashSet<>();

    PsiElement parent = sourceElement.getParent();
    if (parent instanceof StringLiteralExpression && PhpElementsUtil.getParameterListArrayValuePattern().accepts(sourceElement)) {
        psiElements.addAll(collectArrayKeyParameterTargets(parent));
    }

    return psiElements.toArray(new PsiElement[0]);
}
 
Example #20
Source File: PhpFunctionRegistrarMatcher.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
@Override
public boolean matches(@NotNull LanguageMatcherParameter parameter) {

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

    Collection<JsonSignature> signatures = ContainerUtil.filter(
        parameter.getRegistrar().getSignatures(),
        ContainerConditions.DEFAULT_TYPE_FILTER
    );

    if(signatures.size() == 0) {
        return false;
    }

    return PhpMatcherUtil.matchesArraySignature(parent, signatures);
}
 
Example #21
Source File: DoctrineAnnotationTargetEntityReferences.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter phpAnnotationReferenceProviderParameter) {

    if(!Symfony2ProjectComponent.isEnabled(annotationPropertyParameter.getProject()) || !(annotationPropertyParameter.getElement() instanceof StringLiteralExpression) || !PhpElementsUtil.isEqualClassName(annotationPropertyParameter.getPhpClass(),
        "\\Doctrine\\ORM\\Mapping\\ManyToOne",
        "\\Doctrine\\ORM\\Mapping\\ManyToMany",
        "\\Doctrine\\ORM\\Mapping\\OneToOne",
        "\\Doctrine\\ORM\\Mapping\\OneToMany")
        )
    {
        return new PsiReference[0];
    }

    // @Foo(targetEntity="Foo\Class")
    if(annotationPropertyParameter.getType() == AnnotationPropertyParameter.Type.PROPERTY_VALUE && "targetEntity".equals(annotationPropertyParameter.getPropertyName())) {
        return new PsiReference[]{ new EntityReference((StringLiteralExpression) annotationPropertyParameter.getElement(), true) };
    }

    return new PsiReference[0];
}
 
Example #22
Source File: MethodParameterRegistrarMatcher.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Override
public boolean matches(@NotNull LanguageMatcherParameter parameter) {

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

    Collection<JsonSignature> signatures = ContainerUtil.filter(
        parameter.getSignatures(),
        ContainerConditions.DEFAULT_TYPE_FILTER
    );

    for (JsonSignature signature : signatures) {

        if(StringUtils.isBlank(signature.getMethod()) || StringUtils.isBlank(signature.getClassName())) {
            continue;
        }

        if(signature.getMethod().equals("__construct") &&
           new MethodMatcher.NewExpressionParameterMatcher(parent, signature.getIndex()).withSignature(signature.getClassName(), signature.getMethod()).match() != null
           )
        {
            return true;
        }

        if (MethodMatcher.getMatchedSignatureWithDepth(parent, new MethodMatcher.CallToSignature[]{new MethodMatcher.CallToSignature(signature.getClassName(), signature.getMethod())}, signature.getIndex()) != null) {
            return true;
        }
    }

    return false;
}
 
Example #23
Source File: TranslationFoldingBuilder.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
    if (!TYPO3CMSProjectSettings.isEnabled(root) || !TYPO3CMSProjectSettings.getInstance(root.getProject()).translationEnableTextFolding) {
        return FoldingDescriptor.EMPTY;
    }

    FoldingGroup group = FoldingGroup.newGroup("TYPO3Translation");

    List<FoldingDescriptor> descriptors = new ArrayList<>();
    Collection<StringLiteralExpression> literalExpressions = PsiTreeUtil.findChildrenOfType(root, StringLiteralExpression.class);

    for (final StringLiteralExpression literalExpression : literalExpressions) {
        String value = literalExpression.getContents();

        if (value.startsWith("LLL:")) {
            final String transResult = Translator.translateLLLString(literalExpression);

            if (transResult != null) {
                TextRange foldingRange = new TextRange(literalExpression.getTextRange().getStartOffset() + 1, literalExpression.getTextRange().getEndOffset() - 1);
                descriptors.add(new FoldingDescriptor(literalExpression.getNode(), foldingRange, group) {
                    @Override
                    public String getPlaceholderText() {

                        return transResult;
                    }
                });
            }
        }
    }

    return descriptors.toArray(new FoldingDescriptor[0]);
}
 
Example #24
Source File: BladeDirectiveReferencesTest.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
public void testLangDirectoryReferences() {
    assertCompletionContains(
        BladeFileType.INSTANCE,
        "@lang('<caret>')",
        "foo.between.numeric", "foo.sub-title", "foo.title"
    );

    assertNavigationMatch(
        BladeFileType.INSTANCE,
        "@lang('foo.between.numeric<caret>')",
        PlatformPatterns.psiElement(StringLiteralExpression.class).inFile(PlatformPatterns.psiFile().withName("foo.php"))
    );
}
 
Example #25
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 #26
Source File: AnnotationPattern.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
/**
 * matches "@Callback(propertyName="<value>")"
 */
public static PsiElementPattern.Capture<StringLiteralExpression> getPropertyIdentifierValue(String propertyName) {
    return PlatformPatterns.psiElement(StringLiteralExpression.class)
        .afterLeafSkipping(
            PlatformPatterns.or(
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_TEXT).withText("=")
            ),
            PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER).withText(propertyName)
        )
        .withParent(PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList));
}
 
Example #27
Source File: ReturnStringSignatureRegistrarMatcher.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Override
public boolean matches(@NotNull LanguageMatcherParameter parameter) {

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

    PsiElement phpReturn = parent.getParent();
    if(!(phpReturn instanceof PhpReturn)) {
        return false;
    }

    return PhpMatcherUtil.isMachingReturnArray(parameter.getSignatures(), phpReturn);
}
 
Example #28
Source File: QueryBuilderGotoDeclarationHandler.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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());
            }
        }
    }
 
Example #29
Source File: AnnotationPattern.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
/**
 * matches "@Callback("<value>", foo...)"
 */
public static PsiElementPattern.Capture<PsiElement> getDefaultPropertyValue() {
    return PlatformPatterns
        .psiElement(PhpDocTokenTypes.DOC_STRING)
        .withParent(PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(PlatformPatterns
            .psiElement(PhpDocElementTypes.phpDocAttributeList)
            .withParent(PlatformPatterns
                .psiElement(PhpDocElementTypes.phpDocTag)
            )
        ))
        .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #30
Source File: ThemeUtil.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@NotNull
public static PsiElementPattern.Capture<PsiElement> getJavascriptClassFieldPattern() {
    return PlatformPatterns.psiElement().withParent(
        PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(
            PlatformPatterns.psiElement(PhpElementTypes.ARRAY_VALUE).withParent(
                PlatformPatterns.psiElement(ArrayCreationExpression.class).withParent(
                    PlatformPatterns.psiElement(Field.class).withName("javascript")
                )
            )
        )
    );

}