Java Code Examples for com.jetbrains.php.lang.psi.elements.PhpClass#getPresentableFQN()

The following examples show how to use com.jetbrains.php.lang.psi.elements.PhpClass#getPresentableFQN() . 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: ControllerCollector.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
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 2
Source File: ControllerCollector.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
public static void visitController(@NotNull final Project project, @NotNull ControllerVisitor 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()) {
                continue;
            }

            String className = phpClass.getPresentableFQN();

            if(StringUtils.isNotBlank(className)) {
                visitor.visit(phpClass, className);
            }
        }
    }
 
Example 3
Source File: ExtJsTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
private void attachModels(Project project, String[] namespaces, List<PsiElement> targets) {

        if(namespaces.length < 5) {
            return;
        }

        // only show on controller context
        if(!"model".equalsIgnoreCase(namespaces[3])) {
            return;
        }

        Set<String> classMap = new HashSet<>(Arrays.asList(
            String.format("Shopware\\Models\\%s\\%s", namespaces[2], ShopwareUtil.toCamelCase(namespaces[4], false)).toLowerCase(),
            String.format("Shopware\\CustomModels\\%s\\%s", namespaces[2], ShopwareUtil.toCamelCase(namespaces[4], false)).toLowerCase()
        ));

        addCustomModelNames(namespaces, classMap);

        // @TODO: to be dropped no need as handled by symfony+annotations plugin
        for(PhpClass phpClass: PhpIndex.getInstance(project).getAllSubclasses("\\Shopware\\Components\\Model\\ModelEntity")) {
            String className = phpClass.getPresentableFQN();
            if(classMap.contains(className.toLowerCase())) {
                targets.add(phpClass);
            }
        }
    }
 
Example 4
Source File: ServiceIndexUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public static PsiElement[] findServiceDefinitions(@Nullable PhpClass phpClass) {

        if(phpClass == null) {
            return new PsiElement[0];
        }

        String phpClassName = phpClass.getPresentableFQN();
        Set<String> serviceNames = ContainerCollectionResolver.ServiceCollector.create(phpClass.getProject()).convertClassNameToServices(phpClassName);

        if(serviceNames.size() == 0) {
            return new PsiElement[0];
        }

        List<PsiElement> psiElements = new ArrayList<>();
        for(String serviceName: serviceNames) {
            psiElements.addAll(findServiceDefinitions(phpClass.getProject(), serviceName));
        }

        return psiElements.toArray(new PsiElement[psiElements.size()]);
    }
 
Example 5
Source File: ServiceIndexUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
public static ClassServiceDefinitionTargetLazyValue findServiceDefinitionsLazy(@Nullable PhpClass phpClass) {
    if(phpClass == null) {
        return null;
    }

    String phpClassName = phpClass.getPresentableFQN();
    Set<String> serviceNames = ContainerCollectionResolver.ServiceCollector.create(phpClass.getProject()).convertClassNameToServices(phpClassName);
    if(serviceNames.size() == 0) {
        return null;
    }

    return new ClassServiceDefinitionTargetLazyValue(phpClass.getProject(), phpClassName);
}
 
Example 6
Source File: DoctrineModelProviderParameter.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
public DoctrineModel(PhpClass phpClass) {
    this.name = phpClass.getPresentableFQN();
    this.phpClass = phpClass;
}
 
Example 7
Source File: DoctrineOrmRepositoryIntention.java    From idea-php-annotation-plugin with MIT License 4 votes vote down vote up
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {

    PhpClass phpClass = getScopedPhpClass(element);
    if(phpClass == null) {
        return;
    }

    String fileName = phpClass.getName() + "Repository.php";
    String namespace = DoctrineUtil.trimBlackSlashes(phpClass.getNamespaceName());
    PsiDirectory dir = phpClass.getContainingFile().getContainingDirectory();

    PsiDirectory repositoryDir = dir;
    if (dir.getParentDirectory() != null) {
        PsiDirectory checkDir = dir.getParentDirectory().findSubdirectory("Repository");

        if (dir.findFile(fileName) == null && checkDir != null) {
            repositoryDir = checkDir;
        }
    }

    String repoClass = phpClass.getPresentableFQN() + "Repository";
    PhpClass repoPhpClass = PhpElementsUtil.getClass(project, repoClass);

    if (repoPhpClass == null && dir != repositoryDir) {
        // Entity/../Repository/
        namespace = phpClass.getNamespaceName();
        namespace = namespace.substring(0, namespace.lastIndexOf("\\"));
        namespace = namespace.substring(0, namespace.lastIndexOf("\\"));
        namespace = namespace + "\\Repository";
        namespace = DoctrineUtil.trimBlackSlashes(namespace);

        repoClass = namespace + "\\" + phpClass.getName() + "Repository";
        repoClass = PhpLangUtil.toPresentableFQN(repoClass);

        repoPhpClass = PhpElementsUtil.getClass(project, repoClass);
    }

    if(repoPhpClass == null) {
        if(repositoryDir.findFile(fileName) == null) {
            final FileTemplate fileTemplate = FileTemplateManager.getInstance(project).getTemplate("Doctrine Entity Repository");
            final Properties defaultProperties = FileTemplateManager.getInstance(project).getDefaultProperties();

            Properties properties = new Properties(defaultProperties);

            properties.setProperty("NAMESPACE", namespace);
            properties.setProperty("NAME", phpClass.getName() + "Repository");

            properties.setProperty("ENTITY_NAMESPACE", DoctrineUtil.trimBlackSlashes(phpClass.getNamespaceName()));
            properties.setProperty("ENTITY_NAME", phpClass.getName());

            try {
                PsiElement newElement = FileTemplateUtil.createFromTemplate(fileTemplate, fileName, properties, repositoryDir);

                new OpenFileDescriptor(project, newElement.getContainingFile().getVirtualFile(), 0).navigate(true);
            } catch (Exception e) {
                return;
            }
        } else {
            if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
                HintManager.getInstance().showErrorHint(editor, "Repository already exists ");
            }
        }
    }

    PhpDocTagAnnotation ormEntityPhpDocBlock = DoctrineUtil.getOrmEntityPhpDocBlock(phpClass);
    if(ormEntityPhpDocBlock != null) {
        PhpDocTag phpDocTag = ormEntityPhpDocBlock.getPhpDocTag();
        PhpPsiElement firstPsiChild = phpDocTag.getFirstPsiChild();
        insertAttribute(editor, repoClass, phpDocTag, firstPsiChild);
    }

}