Java Code Examples for com.jetbrains.php.lang.psi.elements.Method#getContainingClass()
The following examples show how to use
com.jetbrains.php.lang.psi.elements.Method#getContainingClass() .
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: Symfony2InterfacesUtil.java From Thinkphp5-Plugin with MIT License | 6 votes |
protected boolean isCallTo(Method e, Method[] expectedMethods) { PhpClass methodClass = e.getContainingClass(); if (methodClass == null) { return false; } for (Method expectedMethod : expectedMethods) { // @TODO: its stuff from beginning times :) if (expectedMethod == null) { continue; } PhpClass containingClass = expectedMethod.getContainingClass(); if (containingClass != null && expectedMethod.getName().equals(e.getName()) && isInstanceOf(methodClass, containingClass)) { return true; } } return false; }
Example 2
Source File: AnnotationRouteElementWalkingVisitor.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * FooController::fooAction */ @Nullable private String getController(@NotNull PhpDocTag phpDocTag) { Method method = AnnotationBackportUtil.getMethodScope(phpDocTag); if(method == null) { return null; } PhpClass containingClass = method.getContainingClass(); if(containingClass == null) { return null; } return String.format("%s::%s", StringUtils.stripStart(containingClass.getFQN(), "\\"), method.getName() ); }
Example 3
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 4
Source File: Symfony2InterfacesUtil.java From idea-php-toolbox with MIT License | 6 votes |
protected boolean isCallTo(Method e, Method[] expectedMethods) { PhpClass methodClass = e.getContainingClass(); if(methodClass == null) { return false; } for (Method expectedMethod : expectedMethods) { // @TODO: its stuff from beginning times :) if(expectedMethod == null) { continue; } PhpClass containingClass = expectedMethod.getContainingClass(); if (containingClass != null && expectedMethod.getName().equalsIgnoreCase(e.getName()) && isInstanceOf(methodClass, containingClass)) { return true; } } return false; }
Example 5
Source File: Symfony2InterfacesUtil.java From idea-php-toolbox with MIT License | 6 votes |
protected boolean isCallTo(Method e, Method[] expectedMethods) { PhpClass methodClass = e.getContainingClass(); if(methodClass == null) { return false; } for (Method expectedMethod : expectedMethods) { // @TODO: its stuff from beginning times :) if(expectedMethod == null) { continue; } PhpClass containingClass = expectedMethod.getContainingClass(); if (containingClass != null && expectedMethod.getName().equalsIgnoreCase(e.getName()) && isInstanceOf(methodClass, containingClass)) { return true; } } return false; }
Example 6
Source File: ControllerCollector.java From idea-php-laravel-plugin with MIT License | 6 votes |
public static void visitControllerActions(@NotNull final Project project, @NotNull ControllerActionVisitor visitor) { Collection<PhpClass> allSubclasses = new HashSet<PhpClass>() {{ addAll(PhpIndex.getInstance(project).getAllSubclasses("\\Illuminate\\Routing\\Controller")); addAll(PhpIndex.getInstance(project).getAllSubclasses("\\App\\Http\\Controllers\\Controller")); }}; for(PhpClass phpClass: allSubclasses) { if(!phpClass.isAbstract()) { for(Method method: phpClass.getMethods()) { String className = phpClass.getPresentableFQN(); String methodName = method.getName(); if(!method.isStatic() && method.getAccess().isPublic() && !methodName.startsWith("__")) { PhpClass phpTrait = method.getContainingClass(); if(phpTrait == null || !commonControllerTraits.contains(phpTrait.getName())) { if(StringUtils.isNotBlank(className)) { visitor.visit(phpClass, method, className + "@" + methodName); } } } } } } }
Example 7
Source File: Symfony2InterfacesUtil.java From idea-php-laravel-plugin with MIT License | 6 votes |
protected boolean isCallTo(Method e, Method[] expectedMethods) { PhpClass methodClass = e.getContainingClass(); if(methodClass == null) { return false; } for (Method expectedMethod : expectedMethods) { // @TODO: its stuff from beginning times :) if(expectedMethod == null) { continue; } PhpClass containingClass = expectedMethod.getContainingClass(); if (containingClass != null && expectedMethod.getName().equals(e.getName()) && isInstanceOf(methodClass, containingClass)) { return true; } } return false; }
Example 8
Source File: EventMethodCallInspection.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Override public void visitElement(PsiElement element) { super.visitElement(element); if(!(element instanceof StringLiteralExpression)) { return; } PsiElement arrayValue = element.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")) { String contents = ((StringLiteralExpression) element).getContents(); if(StringUtils.isNotBlank(contents) && containingClass.findMethodByName(contents) == null) { registerMethodProblem(element, holder, containingClass); } } } } } } }
Example 9
Source File: ServiceRouteContainer.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@NotNull public Collection<Route> getMethodMatches(@NotNull Method method) { PhpClass originClass = method.getContainingClass(); if(originClass == null) { return Collections.emptyList(); } String classFqn = StringUtils.stripStart(originClass.getFQN(), "\\"); Collection<Route> routes = new ArrayList<>(); for (Route route : this.routes) { String serviceRoute = route.getController(); if(serviceRoute == null) { continue; } // if controller matches: // service_id:methodName String[] split = serviceRoute.split(":"); if(split.length != 2 || !split[1].equals(method.getName())) { continue; } // cache PhpClass resolve if(!serviceCache.containsKey(split[0])) { serviceCache.put(split[0], ServiceUtil.getResolvedClassDefinition(method.getProject(), split[0], getLazyServiceCollector(method.getProject()))); } PhpClass phpClass = serviceCache.get(split[0]); if(phpClass != null && classFqn.equals(phpClass.getPresentableFQN())) { Method targetMethod = phpClass.findMethodByName(split[1]); if(targetMethod != null) { routes.add(route); } } } return routes; }
Example 10
Source File: ReturnSourceUtil.java From idea-php-toolbox with MIT License | 5 votes |
public static LookupElementBuilder buildLookupElement(@NotNull Method method, @NotNull String contents, @Nullable JsonRawLookupElement jsonRawLookupElement) { LookupElementBuilder lookupElement = LookupElementBuilder.create(contents); PhpClass phpClass = method.getContainingClass(); if(phpClass != null) { lookupElement = lookupElement.withTypeText(phpClass.getPresentableFQN(), true); lookupElement = lookupElement.withIcon(phpClass.getIcon()); } return JsonParseUtil.getDecoratedLookupElementBuilder( lookupElement, jsonRawLookupElement ); }
Example 11
Source File: ControllerActionReferenceProvider.java From idea-php-shopware-plugin with MIT License | 5 votes |
private LookupElementBuilder attachTypeText(LookupElementBuilder builder, Method method) { PhpClass phpClass = method.getContainingClass(); if(phpClass == null) { return builder; } return builder.withTypeText(phpClass.getPresentableFQN(), true); }
Example 12
Source File: ReturnSourceUtil.java From idea-php-toolbox with MIT License | 5 votes |
public static LookupElementBuilder buildLookupElement(@NotNull Method method, @NotNull String contents, @Nullable JsonRawLookupElement jsonRawLookupElement) { LookupElementBuilder lookupElement = LookupElementBuilder.create(contents); PhpClass phpClass = method.getContainingClass(); if(phpClass != null) { lookupElement = lookupElement.withTypeText(phpClass.getPresentableFQN(), true); lookupElement = lookupElement.withIcon(phpClass.getIcon()); } return JsonParseUtil.getDecoratedLookupElementBuilder( lookupElement, jsonRawLookupElement ); }
Example 13
Source File: ControllerActionIndex.java From idea-php-typo3-plugin with MIT License | 5 votes |
@Override public void visitElement(@NotNull PsiElement element) { if (element instanceof Method) { Method m = (Method) element; if (!m.getName().endsWith("Action") || !m.getModifier().isPublic()) { super.visitElement(element); return; } StubControllerAction stubControllerAction = new StubControllerAction(); PhpClass containingClass = m.getContainingClass(); if (containingClass == null) { super.visitElement(element); return; } if (!ExtbaseUtility.isActionController(containingClass)) { super.visitElement(element); return; } stubControllerAction.setName(m.getName()); stubControllerAction.setControllerName(containingClass.getName()); stubControllerAction.setControllerFQN(containingClass.getFQN()); stubControllerAction.setTextRange(m.getTextRange()); map.put(m.getName().replace("Action", ""), stubControllerAction); } super.visitElement(element); }
Example 14
Source File: Symfony2InterfacesUtil.java From idea-php-laravel-plugin with MIT License | 4 votes |
protected boolean isCallTo(PsiElement e, Method[] expectedMethods, int deepness) { if (!(e instanceof MethodReference)) { return false; } MethodReference methodRef = (MethodReference) e; // resolve is also called on invalid php code like "use <xxx>" // so double check the method name before resolve the method if(!isMatchingMethodName(methodRef, expectedMethods)) { return false; } PsiReference psiReference = methodRef.getReference(); if (null == psiReference) { return false; } Method method = getMultiResolvedMethod(psiReference); if (method == null) { return false; } PhpClass methodClass = method.getContainingClass(); if(methodClass == null) { return false; } for (Method expectedMethod : expectedMethods) { // @TODO: its stuff from beginning times :) if(expectedMethod == null) { continue; } PhpClass containingClass = expectedMethod.getContainingClass(); if (null != containingClass && expectedMethod.getName().equals(method.getName()) && isInstanceOf(methodClass, containingClass)) { return true; } } return false; }
Example 15
Source File: Symfony2InterfacesUtil.java From idea-php-toolbox with MIT License | 4 votes |
protected boolean isCallTo(PsiElement e, Method[] expectedMethods, int deepness) { if (!(e instanceof MethodReference)) { return false; } MethodReference methodRef = (MethodReference) e; // resolve is also called on invalid php code like "use <xxx>" // so double check the method name before resolve the method if(!isMatchingMethodName(methodRef, expectedMethods)) { return false; } PsiReference psiReference = methodRef.getReference(); if (null == psiReference) { return false; } Method[] multiResolvedMethod = getMultiResolvedMethod(psiReference); if(multiResolvedMethod == null) { return false; } for (Method method : multiResolvedMethod) { PhpClass methodClass = method.getContainingClass(); if(methodClass == null) { continue; } for (Method expectedMethod : expectedMethods) { // @TODO: its stuff from beginning times :) if(expectedMethod == null) { continue; } PhpClass containingClass = expectedMethod.getContainingClass(); if (null != containingClass && expectedMethod.getName().equalsIgnoreCase(method.getName()) && isInstanceOf(methodClass, containingClass)) { return true; } } } return false; }
Example 16
Source File: Symfony2InterfacesUtil.java From idea-php-toolbox with MIT License | 4 votes |
protected boolean isCallTo(PsiElement e, Method[] expectedMethods, int deepness) { if (!(e instanceof MethodReference)) { return false; } MethodReference methodRef = (MethodReference) e; // resolve is also called on invalid php code like "use <xxx>" // so double check the method name before resolve the method if(!isMatchingMethodName(methodRef, expectedMethods)) { return false; } PsiReference psiReference = methodRef.getReference(); if (null == psiReference) { return false; } Method[] multiResolvedMethod = getMultiResolvedMethod(psiReference); if(multiResolvedMethod == null) { return false; } for (Method method : multiResolvedMethod) { PhpClass methodClass = method.getContainingClass(); if(methodClass == null) { continue; } for (Method expectedMethod : expectedMethods) { // @TODO: its stuff from beginning times :) if(expectedMethod == null) { continue; } PhpClass containingClass = expectedMethod.getContainingClass(); if (null != containingClass && expectedMethod.getName().equalsIgnoreCase(method.getName()) && isInstanceOf(methodClass, containingClass)) { return true; } } } return false; }
Example 17
Source File: ResolveEngine.java From intellij-neos with GNU General Public License v3.0 | 4 votes |
/** * Find template for controller action * * @param method Controller action method * @return VirtualFile */ public static VirtualFile findTemplate(Method method) { PsiFile file = method.getContainingFile(); if (method.getContainingClass() != null) { String actionName = method.getName(); if (!actionName.endsWith("Action")) { return null; } actionName = actionName.replace("Action", ""); if (actionName.length() < 2) { return null; } actionName = actionName.substring(0, 1).toUpperCase() + actionName.substring(1); String controllerName = method.getContainingClass().getName(); controllerName = controllerName.replace("Controller", ""); JsonFile composerFile = ComposerUtil.getComposerManifest(file.getContainingDirectory()); if (composerFile != null) { String namespace = method.getNamespaceName(); namespace = namespace.substring(1); Map<String, String> namespaceMappings = ComposerUtil.getNamespaceMappings(composerFile); for(String key : namespaceMappings.keySet()) { if (namespace.startsWith(key)) { namespace = namespace.replace(key, "") .replace("\\", "/"); if (namespace.startsWith("/") && namespace.length() > 1) { namespace = namespace.substring(1); } namespace = namespace.replace("Controller/", ""); break; } } String resourceFile = "Resources/Private/Templates/" + namespace + controllerName + "/" + actionName + ".html"; return composerFile.getContainingDirectory().getVirtualFile().findFileByRelativePath(resourceFile); } } return null; }
Example 18
Source File: ExtbaseUtils.java From idea-php-typo3-plugin with MIT License | 4 votes |
public static boolean methodInstanceOf(@NotNull String className, @NotNull Method method) { PhpClass containingClass = method.getContainingClass(); return containingClass != null && containingClass.getPresentableFQN().equals(className); }
Example 19
Source File: Symfony2InterfacesUtil.java From Thinkphp5-Plugin with MIT License | 4 votes |
protected boolean isCallTo(PsiElement e, Method[] expectedMethods, int deepness) { if (!(e instanceof MethodReference)) { return false; } MethodReference methodRef = (MethodReference) e; // resolve is also called on invalid php code like "use <xxx>" // so double check the method name before resolve the method if (!isMatchingMethodName(methodRef, expectedMethods)) { return false; } PsiReference psiReference = methodRef.getReference(); if (null == psiReference) { return false; } Method method = getMultiResolvedMethod(psiReference); if (method == null) { return false; } PhpClass methodClass = method.getContainingClass(); if (methodClass == null) { return false; } for (Method expectedMethod : expectedMethods) { // @TODO: its stuff from beginning times :) if (expectedMethod == null) { continue; } PhpClass containingClass = expectedMethod.getContainingClass(); if (null != containingClass && expectedMethod.getName().equals(method.getName()) && isInstanceOf(methodClass, containingClass)) { return true; } } return false; }