Java Code Examples for com.jetbrains.php.lang.psi.elements.MethodReference#getName()
The following examples show how to use
com.jetbrains.php.lang.psi.elements.MethodReference#getName() .
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: 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 2
Source File: ContainerBuilderStubIndex.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override public boolean processAccessVariableInstruction(PhpAccessVariableInstruction instruction) { if (instruction.getAccess().isWrite() || instruction.getAccess().isWriteRef() || !containerParameters.contains(instruction.getVariableName())) return true; MethodReference methodReference = ObjectUtils.tryCast(instruction.getAnchor().getParent(), MethodReference.class); if (methodReference == null || !METHODS.contains(methodReference.getName())) return true; String value = PhpElementsUtil.getFirstArgumentStringValue(methodReference); if (value == null) return true; String methodName = methodReference.getName(); map.computeIfAbsent(methodName, name -> new ContainerBuilderCall()); map.get(methodName).addParameter(value); return true; }
Example 3
Source File: TemplateUtil.java From Thinkphp5-Plugin with MIT License | 5 votes |
private void visitMethodReference(MethodReference methodReference) { String methodName = methodReference.getName(); if (!RENDER_METHODS.contains(methodName)) { return; } PsiElement classReference = methodReference.getFirstChild(); if (!(classReference instanceof ClassReference)) { return; } if (!"View".equals(((ClassReference) classReference).getName())) { return; } PsiElement[] parameters = methodReference.getParameters(); if (parameters.length == 0 || !(parameters[0] instanceof StringLiteralExpression)) { return; } String contents = ((StringLiteralExpression) parameters[0]).getContents(); if (StringUtils.isBlank(contents)) { return; } views.add(Pair.create(contents, parameters[0])); }
Example 4
Source File: MissingModulePHPInspection.java From idea-php-typo3-plugin with MIT License | 5 votes |
@NotNull @Override public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) { return new PhpElementVisitor() { @Override public void visitPhpStringLiteralExpression(StringLiteralExpression expression) { if (!getLoadRequireJsModulePattern().accepts(expression)) { super.visitPhpStringLiteralExpression(expression); return; } PsiElement firstParent = PsiTreeUtil.findFirstParent(expression, e -> e instanceof MethodReference); if (!(firstParent instanceof MethodReference)) { super.visitPhpStringLiteralExpression(expression); return; } MethodReference methodReference = (MethodReference) firstParent; if (methodReference.getName() == null || !methodReference.getName().equals("loadRequireJsModule")) { super.visitPhpStringLiteralExpression(expression); return; } if (expression.getPrevPsiSibling() instanceof StringLiteralExpression) { super.visitPhpStringLiteralExpression(expression); return; } if (JavaScriptUtil.getModuleMap(expression.getProject()).containsKey(expression.getContents())) { return; } problemsHolder.registerProblem(expression, String.format("Unknown JavaScript module \"%s\"", expression.getContents())); } }; }
Example 5
Source File: Symfony2InterfacesUtil.java From idea-php-toolbox with MIT License | 5 votes |
protected boolean isMatchingMethodName(MethodReference methodRef, Method[] expectedMethods) { String methodRefName = methodRef.getName(); for (Method expectedMethod : Arrays.asList(expectedMethods)) { if(expectedMethod == null) { continue; } if(expectedMethod.getName().equalsIgnoreCase(methodRefName)) { return true; } } return false; }
Example 6
Source File: BladeTemplateUtil.java From idea-php-laravel-plugin with MIT License | 5 votes |
private void visitMethodReference(MethodReference methodReference) { String methodName = methodReference.getName(); if(!RENDER_METHODS.contains(methodName)) { return; } PsiElement classReference = methodReference.getFirstChild(); if(!(classReference instanceof ClassReference)) { return; } if(!"View".equals(((ClassReference) classReference).getName())) { return; } PsiElement[] parameters = methodReference.getParameters(); if(parameters.length == 0 || !(parameters[0] instanceof StringLiteralExpression)) { return; } String contents = ((StringLiteralExpression) parameters[0]).getContents(); if(StringUtils.isBlank(contents)) { return; } views.add(Pair.create(contents, parameters[0])); }
Example 7
Source File: Symfony2InterfacesUtil.java From idea-php-toolbox with MIT License | 5 votes |
protected boolean isMatchingMethodName(MethodReference methodRef, Method[] expectedMethods) { String methodRefName = methodRef.getName(); for (Method expectedMethod : Arrays.asList(expectedMethods)) { if(expectedMethod == null) { continue; } if(expectedMethod.getName().equalsIgnoreCase(methodRefName)) { return true; } } return false; }
Example 8
Source File: ObjectRepositoryResultTypeProvider.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable @Override public PhpType getType(PsiElement e) { if (!(e instanceof MethodReference) || !Settings.getInstance(e.getProject()).pluginEnabled) { return null; } MethodReference methodRef = (MethodReference) e; String refSignature = ((MethodReference)e).getSignature(); if(StringUtil.isEmpty(refSignature)) { return null; } String methodRefName = methodRef.getName(); if(null == methodRefName || (!Arrays.asList(new String[] {"find", "findAll"}).contains(methodRefName) && !methodRefName.startsWith("findOneBy") && !methodRefName.startsWith("findBy"))) { return null; } // we can get the repository name from the signature calls // #M#?#M#?#M#C\Foo\Bar\Controller\BarController.get?doctrine.getRepository?EntityBundle:User.find String repositorySignature = methodRef.getSignature(); int lastRepositoryName = repositorySignature.lastIndexOf(ObjectRepositoryTypeProvider.TRIM_KEY); if(lastRepositoryName == -1) { return null; } repositorySignature = repositorySignature.substring(lastRepositoryName); int nextMethodCall = repositorySignature.indexOf('.' + methodRefName); if(nextMethodCall == -1) { return null; } repositorySignature = repositorySignature.substring(1, nextMethodCall); return new PhpType().add("#" + this.getKey() + refSignature + TRIM_KEY + repositorySignature); }