com.jetbrains.php.lang.psi.elements.ParameterList Java Examples
The following examples show how to use
com.jetbrains.php.lang.psi.elements.ParameterList.
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: PhpPsiHelper.java From idea-php-dotenv-plugin with MIT License | 6 votes |
private static boolean isFunctionParameter(PsiElement psiElement, int parameterIndex, String... funcName) { PsiElement variableContext = psiElement.getContext(); if(!(variableContext instanceof ParameterList)) { return false; } else { ParameterList parameterList = (ParameterList) variableContext; PsiElement context = parameterList.getContext(); if(!(context instanceof FunctionReference)) { return false; } else { FunctionReference methodReference = (FunctionReference) context; String name = methodReference.getName(); return (name != null && Arrays.asList(funcName).contains(name) && getParameterIndex(parameterList, psiElement) == parameterIndex); } } }
Example #2
Source File: BladePsiUtil.java From idea-php-laravel-plugin with MIT License | 6 votes |
public static boolean isDirectiveWithInstance(@NotNull PsiElement psiElement, @NotNull String clazz, @NotNull String method) { PsiElement stringLiteral = psiElement.getParent(); if(stringLiteral instanceof StringLiteralExpression) { PsiElement parameterList = stringLiteral.getParent(); if(parameterList instanceof ParameterList) { PsiElement methodReference = parameterList.getParent(); if(methodReference instanceof MethodReference && method.equals(((MethodReference) methodReference).getName())) { String text = methodReference.getText(); int i = text.indexOf(":"); // method resolve dont work; extract class name from text "Foo::method(..." return i > 0 && StringUtils.stripStart(text.substring(0, i), "\\").equals(clazz); } } } return false; }
Example #3
Source File: BladePattern.java From idea-php-laravel-plugin with MIT License | 6 votes |
/** * "@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 #4
Source File: BladeDirectiveReferences.java From idea-php-laravel-plugin with MIT License | 6 votes |
private boolean isDirectiveWithName(PsiElement psiElement, String directiveName) { PsiElement stringLiteral = psiElement.getParent(); if(stringLiteral instanceof StringLiteralExpression) { PsiElement parameterList = stringLiteral.getParent(); if(parameterList instanceof ParameterList) { PsiElement methodReference = parameterList.getParent(); if(methodReference instanceof MethodReference) { String name = ((MethodReference) methodReference).getName(); if(name != null && name.equalsIgnoreCase(directiveName)) { return true; } } } } return false; }
Example #5
Source File: PsiElementUtils.java From idea-php-laravel-plugin with MIT License | 6 votes |
public static boolean isFunctionReference(@NotNull PsiElement psiElement, @NotNull String functionName, int parameterIndex) { PsiElement parameterList = psiElement.getParent(); if(!(parameterList instanceof ParameterList)) { return false; } ParameterBag index = PhpElementsUtil.getCurrentParameterIndex(psiElement); if(index == null || index.getIndex() != parameterIndex) { return false; } PsiElement functionCall = parameterList.getParent(); if(!(functionCall instanceof FunctionReference)) { return false; } return functionName.equals(((FunctionReference) functionCall).getName()); }
Example #6
Source File: PhpFunctionCompletionContributor.java From idea-php-advanced-autocomplete with MIT License | 6 votes |
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 #7
Source File: PhpHighlightPackParametersUsagesHandlerFactory.java From idea-php-advanced-autocomplete with MIT License | 6 votes |
@Override public @Nullable HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) { ParameterList parameterList = PhpPsiUtil.getParentByCondition(target, true, ParameterList.INSTANCEOF, Statement.INSTANCEOF); if (parameterList == null) { return null; } FunctionReference functionCall = ObjectUtils.tryCast(parameterList.getParent(), FunctionReference.class); String fqn = resolveFqn(functionCall); if (!"\\pack".equals(fqn)) { return null; } PsiElement[] parameters = parameterList.getParameters(); PsiElement selectedParameter = StreamEx.of(parameters).findFirst((p) -> p.getTextRange().containsOffset(editor.getCaretModel().getOffset())).orElse(null); if (selectedParameter == null) { return null; } int selectedIndex = PhpCodeInsightUtil.getParameterIndex(selectedParameter); if (selectedIndex < 0 || selectedIndex >= parameters.length) { return null; } return new PhpHighlightPackParametersUsagesHandler(editor, file, 0, selectedIndex, parameters); }
Example #8
Source File: ConfigUtil.java From idea-php-shopware-plugin with MIT License | 6 votes |
/** * */ @Nullable public static String getNamespaceFromConfigValueParameter(@NotNull StringLiteralExpression parent) { MethodMatcher.MethodMatchParameter match = MethodMatcher.getMatchedSignatureWithDepth(parent, ShopwarePhpCompletion.CONFIG_NAMESPACE, 1); if(match == null) { return null; } PsiElement parameterList = parent.getParent(); if(!(parameterList instanceof ParameterList)) { return null; } PsiElement[] funcParameters = ((ParameterList) parameterList).getParameters(); if(funcParameters.length == 0 || !(funcParameters[0] instanceof StringLiteralExpression)) { return null; } String namespace = ((StringLiteralExpression) funcParameters[0]).getContents(); if(StringUtils.isBlank(namespace)) { return null; } return namespace; }
Example #9
Source File: PhpStringLiteralExpressionReference.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) { if (!Symfony2ProjectComponent.isEnabled(psiElement) || !(psiElement.getContext() instanceof ParameterList)) { return new PsiReference[0]; } ParameterList parameterList = (ParameterList) psiElement.getContext(); PsiElement methodReference = parameterList.getContext(); if (!(methodReference instanceof MethodReference)) { return new PsiReference[0]; } for(Call call: this.oneOfCall) { if (PhpElementsUtil.isMethodReferenceInstanceOf((MethodReference) methodReference, call.getClassName(), call.getMethodName()) && PsiElementUtils.getParameterIndexValue(psiElement) == call.getIndex()) { return this.getPsiReferenceBase(psiElement); } } return new PsiReference[0]; }
Example #10
Source File: MethodArgumentDroppedMatcherInspection.java From idea-php-typo3-plugin with MIT License | 6 votes |
@NotNull @Override public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) { return new PhpElementVisitor() { @Override public void visitPhpMethodReference(MethodReference reference) { ParameterList parameterList = reference.getParameterList(); PhpExpression classReference = reference.getClassReference(); if (classReference != null) { PhpType inferredType = classReference.getInferredType(); String compiledClassMethodKey = inferredType.toString() + "->" + reference.getName(); if (ExtensionScannerUtil.classMethodHasDroppedArguments(reference.getProject(), compiledClassMethodKey)) { int maximumNumberOfArguments = ExtensionScannerUtil.getMaximumNumberOfArguments(reference.getProject(), compiledClassMethodKey); if (parameterList != null && maximumNumberOfArguments != -1 && parameterList.getParameters().length != maximumNumberOfArguments) { problemsHolder.registerProblem(reference, "Number of arguments changes with upcoming TYPO3 version, consider refactoring"); } } } super.visitPhpMethodReference(reference); } }; }
Example #11
Source File: PsiElementUtils.java From yiistorm with MIT License | 6 votes |
@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 #12
Source File: PsiElementUtil.java From Thinkphp5-Plugin with MIT License | 6 votes |
public static boolean isFunctionReference(@NotNull PsiElement psiElement, @NotNull String functionName, int parameterIndex) { PsiElement parameterList = psiElement.getParent(); PsiElement functionCall = parameterList.getParent(); if (parameterIndex != -1) { if (!(parameterList instanceof ParameterList)) { return false; } ParameterBag index = getCurrentParameterIndex(psiElement); if (index == null || index.getIndex() != parameterIndex) { return false; } } else { functionCall = psiElement; } if (!(functionCall instanceof FunctionReference)) { return false; } return functionName.equals(((FunctionReference) functionCall).getName()); }
Example #13
Source File: PsiElementUtils.java From Thinkphp5-Plugin with MIT License | 6 votes |
public static boolean isFunctionReference(@NotNull PsiElement psiElement, @NotNull String functionName, int parameterIndex) { PsiElement parameterList = psiElement.getParent(); if(!(parameterList instanceof ParameterList)) { return false; } ParameterBag index = PhpElementsUtil.getCurrentParameterIndex(psiElement); if(index == null || index.getIndex() != parameterIndex) { return false; } PsiElement functionCall = parameterList.getParent(); if(!(functionCall instanceof FunctionReference)) { return false; } return functionName.equals(((FunctionReference) functionCall).getName()); }
Example #14
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 #15
Source File: PhpDocTagGotoCompletionContributor.java From idea-php-toolbox with MIT License | 5 votes |
@NotNull @Override public ElementPattern<? extends PsiElement> getPattern() { return PlatformPatterns.psiElement().withParent( PlatformPatterns.psiElement(StringLiteralExpression.class) .withParent(ParameterList.class) ); }
Example #16
Source File: PhpAutoPopupTypedHandler.java From idea-php-advanced-autocomplete with MIT License | 5 votes |
@NotNull @Override public Result checkAutoPopup(char charTyped, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { if (!(file instanceof PhpFile)) { return Result.CONTINUE; } if (charTyped != '%') { return Result.CONTINUE; } int offset = editor.getCaretModel().getOffset(); PsiElement psiElement = file.findElementAt(offset); ParameterList parameterList = PhpPsiUtil.getParentByCondition(psiElement, true, ParameterList.INSTANCEOF, Statement.INSTANCEOF); if (parameterList != null) { FunctionReference functionCall = ObjectUtils.tryCast(parameterList.getParent(), FunctionReference.class); String fqn = PhpElementsUtil.resolveFqn(functionCall); if (/*charTyped == '%' &&*/ PhpElementsUtil.isFormatFunction(fqn)) { if (StringUtil.getPrecedingCharNum(editor.getDocument().getCharsSequence(), offset, '%') % 2 == 0) { PhpCompletionUtil.showCompletion(editor); } } } return Result.CONTINUE; }
Example #17
Source File: PsiElementUtils.java From idea-php-toolbox with MIT License | 5 votes |
@Nullable public static ParameterBag getCurrentParameterIndex(PsiElement psiElement) { if (!(psiElement.getContext() instanceof ParameterList)) { return null; } ParameterList parameterList = (ParameterList) psiElement.getContext(); if (!(parameterList.getContext() instanceof ParameterListOwner)) { return null; } return getCurrentParameterIndex(parameterList.getParameters(), psiElement); }
Example #18
Source File: PhpDocTagGotoCompletionContributor.java From idea-php-toolbox with MIT License | 5 votes |
@NotNull @Override public ElementPattern<? extends PsiElement> getPattern() { return PlatformPatterns.psiElement().withParent( PlatformPatterns.psiElement(StringLiteralExpression.class) .withParent(ParameterList.class) ); }
Example #19
Source File: PhpParameterStringCompletionConfidence.java From idea-php-advanced-autocomplete with MIT License | 5 votes |
@NotNull @Override public ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) { if (!(psiFile instanceof PhpFile)) { return ThreeState.UNSURE; } PsiElement context = contextElement.getContext(); if (!(context instanceof StringLiteralExpression)) { return ThreeState.UNSURE; } // // $test == ""; // if(context.getParent() instanceof BinaryExpression) { // return ThreeState.NO; // } // $object->method(""); PsiElement stringContext = context.getContext(); if (stringContext instanceof ParameterList) { return ThreeState.NO; } // // $object->method(... array('foo'); array('bar' => 'foo') ...); // ArrayCreationExpression arrayCreationExpression = PhpElementsUtil.getCompletableArrayCreationElement(context); // if(arrayCreationExpression != null && arrayCreationExpression.getContext() instanceof ParameterList) { // return ThreeState.NO; // } // // $array['value'] // if(PlatformPatterns.psiElement().withSuperParent(2, ArrayIndex.class).accepts(contextElement)) { // return ThreeState.NO; // } return ThreeState.UNSURE; }
Example #20
Source File: ControllerActionGotoRelatedCollectorParameter.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public PsiElement[] getParameterLists() { if(parameterLists != null) { return parameterLists; } return parameterLists = PsiTreeUtil.collectElements(method, psiElement -> psiElement.getParent() instanceof ParameterList ); }
Example #21
Source File: MethodMatcher.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable public MethodMatchParameter match() { if (!Symfony2ProjectComponent.isEnabled(this.psiElement)) { return null; } ArrayCreationExpression arrayCreationExpression = PhpElementsUtil.getCompletableArrayCreationElement(this.psiElement); if (arrayCreationExpression == null) { return null; } PsiElement parameterList = arrayCreationExpression.getContext(); if (!(parameterList instanceof ParameterList)) { return null; } PsiElement methodParameters[] = ((ParameterList) parameterList).getParameters(); if (methodParameters.length < this.parameterIndex) { return null; } if (!(parameterList.getContext() instanceof MethodReference)) { return null; } MethodReference methodReference = (MethodReference) parameterList.getContext(); ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(arrayCreationExpression); if (currentIndex == null || currentIndex.getIndex() != this.parameterIndex) { return null; } CallToSignature matchedMethodSignature = this.isCallTo(methodReference); if(matchedMethodSignature == null) { return null; } return new MethodMatchParameter(matchedMethodSignature, currentIndex, methodParameters, methodReference); }
Example #22
Source File: BladePattern.java From idea-php-laravel-plugin with MIT License | 5 votes |
/** * "@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 #23
Source File: PsiElementUtils.java From idea-php-toolbox with MIT License | 5 votes |
@Nullable public static ParameterBag getCurrentParameterIndex(PsiElement psiElement) { if (!(psiElement.getContext() instanceof ParameterList)) { return null; } ParameterList parameterList = (ParameterList) psiElement.getContext(); if (!(parameterList.getContext() instanceof ParameterListOwner)) { return null; } return getCurrentParameterIndex(parameterList.getParameters(), psiElement); }
Example #24
Source File: PsiElementUtils.java From yiistorm with MIT License | 5 votes |
public static String getMethodParameterAt(ParameterList parameterList, int index) { PsiElement[] parameters = parameterList.getParameters(); if (parameters.length < index + 1) { return null; } return getMethodParameter(parameters[index]); }
Example #25
Source File: BxComponent.java From bxfs with MIT License | 5 votes |
public BxComponent(PsiElement element) { project = element.getProject(); PsiElement[] parameters = ((ParameterList) element.getParent()) .getParameters(); String[] cmpParts = ((StringLiteralExpression) parameters[0]).getContents().split(":"); vendor = cmpParts[0].isEmpty() ? null : cmpParts[0]; component = cmpParts.length > 1 ? cmpParts[1] : null; if (parameters.length > 1 && parameters[1] instanceof StringLiteralExpression) { template = ((StringLiteralExpression) parameters[1]).getContents(); if (template.isEmpty()) template = ".default"; } }
Example #26
Source File: PhpPsiHelper.java From idea-php-dotenv-plugin with MIT License | 5 votes |
private static int getParameterIndex(ParameterList parameterList, PsiElement parameter) { PsiElement[] parameters = parameterList.getParameters(); for(int i = 0; i < parameters.length; i = i + 1) { if(parameters[i].equals(parameter)) { return i; } } return -1; }
Example #27
Source File: PhpStringLiteralExpressionReference.java From yiistorm with MIT License | 5 votes |
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) { ParameterList parameterList = (ParameterList) psiElement.getContext(); if (parameterList == null || !(parameterList.getContext() instanceof MethodReference)) { return new PsiReference[0]; } MethodReference method = (MethodReference) parameterList.getContext(); // System.err.println(referenceClass); return this.getPsiReferenceBase(psiElement); // return new PsiReference[0]; }
Example #28
Source File: ControllerActionLookupElement.java From idea-php-typo3-plugin with MIT License | 5 votes |
@Override public void handleInsert(InsertionContext context) { PsiElement elementAt = context.getFile().findElementAt(context.getStartOffset()); if (elementAt != null) { MethodReference methodReference = PhpLangUtil.getMethodReference(elementAt); if (methodReference != null) { ParameterList parameters = methodReference.getParameterList(); PsiElement[] children = parameters.getChildren(); while (parameters.getFirstChild() != null) { parameters.getFirstChild().delete(); } String shortActionName = controllerAction.getName().replace("Action", ""); parameters.add(PhpPsiElementFactory.createPhpPsiFromText(context.getProject(), StringLiteralExpression.class, "'" + shortActionName + "'")); parameters.add(PhpPsiElementFactory.createComma(context.getProject())); String shortControllerName = controllerAction.getControllerName().replace("Controller", ""); parameters.add(PhpPsiElementFactory.createPhpPsiFromText(context.getProject(), StringLiteralExpression.class, "'" + shortControllerName + "'")); parameters.add(PhpPsiElementFactory.createComma(context.getProject())); String extensionName = controllerAction.getExtensionName(); parameters.add(PhpPsiElementFactory.createPhpPsiFromText(context.getProject(), StringLiteralExpression.class, "'" + extensionName + "'")); } } super.handleInsert(context); }
Example #29
Source File: ExtbasePatterns.java From idea-php-typo3-plugin with MIT License | 5 votes |
@NotNull public static PsiElementPattern.Capture<PsiElement> stringArgumentOnMethodCallPattern() { return PlatformPatterns.psiElement() .withParent( PlatformPatterns.psiElement(StringLiteralExpression.class).withParent( PlatformPatterns.psiElement(ParameterList.class).withParent( PlatformPatterns.psiElement(MethodReference.class) ) ) ); }
Example #30
Source File: PsiElementUtil.java From Thinkphp5-Plugin with MIT License | 5 votes |
@Nullable public static ParameterBag getCurrentParameterIndex(PsiElement psiElement) { if (!(psiElement.getContext() instanceof ParameterList)) { return null; } ParameterList parameterList = (ParameterList) psiElement.getContext(); if (!(parameterList.getContext() instanceof ParameterListOwner)) { return null; } return getCurrentParameterIndex(parameterList.getParameters(), psiElement); }