com.jetbrains.php.lang.PhpLanguage Java Examples

The following examples show how to use com.jetbrains.php.lang.PhpLanguage. 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: PsiElementUtils.java    From yiistorm with MIT License 6 votes vote down vote up
@Nullable
public static MethodReference getMethodReferenceWithFirstStringParameter(PsiElement psiElement) {
    if (!PlatformPatterns.psiElement()
            .withParent(StringLiteralExpression.class).inside(ParameterList.class)
            .withLanguage(PhpLanguage.INSTANCE).accepts(psiElement)) {

        return null;
    }

    ParameterList parameterList = PsiTreeUtil.getParentOfType(psiElement, ParameterList.class);
    if (parameterList == null) {
        return null;
    }

    if (!(parameterList.getContext() instanceof MethodReference)) {
        return null;
    }

    return (MethodReference) parameterList.getContext();
}
 
Example #2
Source File: AnnotationPattern.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
/**
 * only usable up to phpstorm 7
 */
public static ElementPattern<StringLiteralExpression> getPropertyValueString() {

    return PlatformPatterns
            .psiElement(StringLiteralExpression.class).afterLeaf(
                    PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_TEXT).withText("=")
            )
            .withParent(PlatformPatterns
                    .psiElement(PhpDocElementTypes.phpDocAttributeList)
                    .withParent(PlatformPatterns
                            .psiElement(PhpDocElementTypes.phpDocTag)
                    )
            )
            .withLanguage(PhpLanguage.INSTANCE);

}
 
Example #3
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 #4
Source File: BladePattern.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
/**
 * "@foobar(['<caret>'])"
 *
 * whereas "foobar" is registered a directive
 */
public static PsiElementPattern.Capture<PsiElement> getArrayParameterDirectiveForElementType(@NotNull IElementType... elementType) {
    return PlatformPatterns.psiElement()
        .withParent(
            PlatformPatterns.psiElement(StringLiteralExpression.class)
                .withParent(
                    PlatformPatterns.psiElement(PhpElementTypes.ARRAY_VALUE).withParent(
                        PlatformPatterns.psiElement(ArrayCreationExpression.class)
                            .withParent(ParameterList.class)
                    )
                )
                .with(
                    new MyDirectiveInjectionElementPatternCondition(elementType)
                )
        )
        .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #5
Source File: PhpGotoRelatedProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement psiElement) {

    if(!Symfony2ProjectComponent.isEnabled(psiElement)) {
        return Collections.emptyList();
    }

    if(psiElement.getLanguage() != PhpLanguage.INSTANCE) {
        return Collections.emptyList();
    }

    Method method = PsiTreeUtil.getParentOfType(psiElement, Method.class);
    if(method == null || !method.getName().endsWith("Action")) {
        return Collections.emptyList();
    }

    return ControllerMethodLineMarkerProvider.getGotoRelatedItems(method);
}
 
Example #6
Source File: PsiElementUtils.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
public static MethodReference getMethodReferenceWithFirstStringParameter(PsiElement psiElement) {
    if(!PlatformPatterns.psiElement()
        .withParent(StringLiteralExpression.class).inside(ParameterList.class)
        .withLanguage(PhpLanguage.INSTANCE).accepts(psiElement)) {

        return null;
    }

    ParameterList parameterList = PsiTreeUtil.getParentOfType(psiElement, ParameterList.class);
    if (parameterList == null) {
        return null;
    }

    if (!(parameterList.getContext() instanceof MethodReference)) {
        return null;
    }

    return (MethodReference) parameterList.getContext();
}
 
Example #7
Source File: PhpElementsUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
static public PsiElementPattern.Capture<StringLiteralExpression> getFunctionWithFirstStringPattern(@NotNull String... functionName) {
    return PlatformPatterns
        .psiElement(StringLiteralExpression.class)
        .withParent(
            PlatformPatterns.psiElement(ParameterList.class)
                .withFirstChild(
                    PlatformPatterns.psiElement(PhpElementTypes.STRING)
                )
                .withParent(
                    PlatformPatterns.psiElement(FunctionReference.class).with(new PatternCondition<FunctionReference>("function match") {
                        @Override
                        public boolean accepts(@NotNull FunctionReference functionReference, ProcessingContext processingContext) {
                            return ArrayUtils.contains(functionName, functionReference.getName());
                        }
                    })
                )
        )
        .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #8
Source File: YiiAppCompletionContributor.java    From yiistorm with MIT License 6 votes vote down vote up
public static PsiElementPattern.Capture appFieldPattern() {
    return PlatformPatterns.psiElement()
            .withParent(PlatformPatterns.psiElement().withElementType(PhpElementTypes.FIELD_REFERENCE)
                    .withChild(
                            PlatformPatterns.psiElement().withElementType(PhpElementTypes.METHOD_REFERENCE)
                                    .referencing(
                                            PhpPatterns.psiElement().withElementType(PhpElementTypes.CLASS_METHOD)
                                                    .withName("app").withParent(
                                                    PhpPatterns.psiElement()
                                                            .withElementType(PhpElementTypes.CLASS)
                                                            .withName(StandardPatterns.string().oneOf("Yii", "YiiBase"))
                                            )
                                    )
                    )
            ).withLanguage(PhpLanguage.INSTANCE);

}
 
Example #9
Source File: PhpElementsUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * $foo->bar('<caret>')
 */
static public PsiElementPattern.Capture<PsiElement> getParameterInsideMethodReferencePattern() {
    return PlatformPatterns
        .psiElement()
        .withParent(
            PlatformPatterns.psiElement(StringLiteralExpression.class)
                .withParent(
                    PlatformPatterns.psiElement(ParameterList.class)
                        .withParent(
                            PlatformPatterns.psiElement(MethodReference.class)
                        )
                )
        )
        .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #10
Source File: PhpElementsUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * class "Foo" extends
 */
static public PsiElementPattern.Capture<PsiElement> getClassNamePattern() {
    return PlatformPatterns
        .psiElement(PhpTokenTypes.IDENTIFIER)
        .afterLeafSkipping(
            PlatformPatterns.psiElement(PsiWhiteSpace.class),
            PlatformPatterns.psiElement(PhpTokenTypes.kwCLASS)
        )
        .withParent(PhpClass.class)
        .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #11
Source File: PhpElementsUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
static public PsiElementPattern.Capture<StringLiteralExpression> getMethodWithFirstStringPattern() {
    return PlatformPatterns
        .psiElement(StringLiteralExpression.class)
        .withParent(
            PlatformPatterns.psiElement(PhpElementTypes.PARAMETER_LIST)
                .withFirstChild(
                    PlatformPatterns.psiElement(PhpElementTypes.STRING)
                )
                .withParent(
                    PlatformPatterns.psiElement(PhpElementTypes.METHOD_REFERENCE)
                )
        )
        .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #12
Source File: PhpElementsUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
/**
 * return 'value' inside class method
 */
static public PsiElementPattern.Capture<StringLiteralExpression> getMethodReturnPattern() {
    return PlatformPatterns
            .psiElement(StringLiteralExpression.class)
            .withParent(PlatformPatterns.psiElement(PhpReturn.class).inside(Method.class))
            .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #13
Source File: PhpElementsUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * class Foo { function "test" {} }
 */
static public PsiElementPattern.Capture<PsiElement> getClassMethodNamePattern() {
    return PlatformPatterns
        .psiElement(PhpTokenTypes.IDENTIFIER)
        .afterLeafSkipping(
            PlatformPatterns.psiElement(PsiWhiteSpace.class),
            PlatformPatterns.psiElement(PhpTokenTypes.kwFUNCTION)
        )
        .withParent(Method.class)
        .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #14
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 #15
Source File: AnnotationPattern.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
/**
 * only usable up to phpstorm 7
 */
public static ElementPattern<StringLiteralExpression> getDefaultPropertyValueString() {

    return PlatformPatterns
         .psiElement(StringLiteralExpression.class).afterLeaf(
             PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_LPAREN)
         )
         .withParent(PlatformPatterns
             .psiElement(PhpDocElementTypes.phpDocAttributeList)
             .withParent(PlatformPatterns
                 .psiElement(PhpDocElementTypes.phpDocTag)
             )
         )
         .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #16
Source File: PhpElementsUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * return 'value' inside class method
 */
static public ElementPattern<PhpExpression> getMethodReturnPattern() {
    return PlatformPatterns.or(
        PlatformPatterns.psiElement(StringLiteralExpression.class)
            .withParent(PlatformPatterns.psiElement(PhpReturn.class).inside(Method.class))
            .withLanguage(PhpLanguage.INSTANCE),
        PlatformPatterns.psiElement(ClassConstantReference.class)
            .withParent(PlatformPatterns.psiElement(PhpReturn.class).inside(Method.class))
            .withLanguage(PhpLanguage.INSTANCE)
    );
}
 
Example #17
Source File: PhpCommandGotoCompletionRegistrar.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;
        }

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

}
 
Example #18
Source File: AnnotationPattern.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public static ElementPattern<PsiElement> getDocBlockTag() {
    return
        PlatformPatterns.or(
            PlatformPatterns.psiElement()
                .withSuperParent(1, PhpDocPsiElement.class)
                     .withParent(PhpDocComment.class)
            .withLanguage(PhpLanguage.INSTANCE)
        ,
            // all "@<caret>"
            PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_TAG_NAME)
                .withLanguage(PhpLanguage.INSTANCE)
        );
}
 
Example #19
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 #20
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 #21
Source File: FormOptionGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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()
    );
}
 
Example #22
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 #23
Source File: BladePattern.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
/**
 * "@foobar('<caret>')"
 *
 * whereas "foobar" is registered a directive
 */
public static PsiElementPattern.Capture<PsiElement> getParameterDirectiveForElementType(@NotNull IElementType... elementType) {
    return PlatformPatterns.psiElement()
        .withParent(
            PlatformPatterns.psiElement(StringLiteralExpression.class)
                .withParent(PlatformPatterns.psiElement(ParameterList.class)).with(
                    new MyDirectiveInjectionElementPatternCondition(elementType)
            )
        )
        .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #24
Source File: AnnotationGoToDeclarationHandler.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Editor editor) {
    // @Test(<foo>=)
    List<PsiElement> psiElements = new ArrayList<>();
    if(AnnotationPattern.getDocAttribute().accepts(psiElement)) {
        this.addPropertyGoto(psiElement, psiElements);
    }

    // <@Test>
    // <@Test\Test>
    if (PlatformPatterns.psiElement(PhpDocElementTypes.DOC_TAG_NAME).withText(StandardPatterns.string().startsWith("@")).withLanguage(PhpLanguage.INSTANCE).accepts(psiElement)) {
        this.addDocTagNameGoto(psiElement, psiElements);
    }

    // @Route(name=<ClassName>::FOO)
    if (PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER).beforeLeaf(AnnotationPattern.getDocStaticPattern()).withLanguage(PhpLanguage.INSTANCE).accepts(psiElement)) {
        this.addStaticClassTargets(psiElement, psiElements);
    }

    // @Route(name=ClassName::<FOO>)
    if (AnnotationPattern.getClassConstant().accepts(psiElement)) {
        this.addStaticClassConstTargets(psiElement, psiElements);
    }

    return psiElements.toArray(new PsiElement[psiElements.size()]);
}
 
Example #25
Source File: AnnotationUsageLineMarkerProvider.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
/**
 * class "Foo" extends
 */
private static PsiElementPattern.Capture<PsiElement> getClassNamePattern() {
    return PlatformPatterns
        .psiElement(PhpTokenTypes.IDENTIFIER)
        .afterLeafSkipping(
            PlatformPatterns.psiElement(PsiWhiteSpace.class),
            PlatformPatterns.psiElement(PhpTokenTypes.kwCLASS)
        )
        .withParent(PhpClass.class)
        .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #26
Source File: PhpElementsUtil.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
/**
 * return 'value' inside class method
 */
static public ElementPattern<PhpExpression> getMethodReturnPattern() {
    return PlatformPatterns.or(
            PlatformPatterns.psiElement(StringLiteralExpression.class)
                    .withParent(PlatformPatterns.psiElement(PhpReturn.class).inside(Method.class))
                    .withLanguage(PhpLanguage.INSTANCE),
            PlatformPatterns.psiElement(ClassConstantReference.class)
                    .withParent(PlatformPatterns.psiElement(PhpReturn.class).inside(Method.class))
                    .withLanguage(PhpLanguage.INSTANCE)
    );
}
 
Example #27
Source File: PimpleCompletionContributor.java    From silex-idea-plugin with MIT License 5 votes vote down vote up
public PimpleCompletionContributor() {
    // $app['<caret>']
    extend(CompletionType.BASIC, PlatformPatterns.psiElement().withLanguage(PhpLanguage.INSTANCE), new ArrayAccessCompletionProvider());
    // $app[''] = $app->extend('<caret>', ...
    extend(CompletionType.BASIC, PlatformPatterns.psiElement().withLanguage(PhpLanguage.INSTANCE), new ExtendsMethodParameterListCompletionProvider());
    // $app->register(, ['<caret>' =>])
    extend(CompletionType.BASIC, PlatformPatterns.psiElement().withLanguage(PhpLanguage.INSTANCE), new RegisterFunctionValuesCompletionProvider());
}
 
Example #28
Source File: PhpElementsUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
/**
 * return 'value' inside class method
 */
static public PsiElementPattern.Capture<StringLiteralExpression> getMethodReturnPattern() {
    return PlatformPatterns
            .psiElement(StringLiteralExpression.class)
            .withParent(PlatformPatterns.psiElement(PhpReturn.class).inside(Method.class))
            .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #29
Source File: BxSuperglobalsProvider.java    From bxfs with MIT License 5 votes vote down vote up
public BxSuperglobalsProvider() {
	extend(CompletionType.BASIC, PlatformPatterns.psiElement(PhpTokenTypes.VARIABLE).withLanguage(PhpLanguage.INSTANCE), new CompletionProvider<CompletionParameters>() {
		public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
			String currentFileName = parameters.getOriginalFile().getName();
			for (String variable : bxSuperglobals.keySet()) {
				BxSuperglobal superglobal = bxSuperglobals.get(variable);
				if (superglobal.scopeFileNames == null || superglobal.scopeFileNames.contains(currentFileName))
					resultSet.addElement(LookupElementBuilder.create("$" + variable));
			}
		}
	});
}
 
Example #30
Source File: YiiContibutorHelper.java    From yiistorm with MIT License 5 votes vote down vote up
public static PsiElementPattern.Capture firstStringInMethod(String methodName, StringPattern className) {

        return PlatformPatterns.psiElement(PsiElement.class)
                .withParent(
                        YiiContibutorHelper.methodLiteralExpression(methodName, className)
                                .insideStarting(
                                        PlatformPatterns.psiElement().withElementType(PhpElementTypes.PARAMETER_LIST)
                                )
                )
                .withLanguage(PhpLanguage.INSTANCE);

    }