fr.adrienbrault.idea.symfony2plugin.Settings Java Examples

The following examples show how to use fr.adrienbrault.idea.symfony2plugin.Settings. 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: SymfonyTempCodeInsightFixtureTestCase.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void setUp() throws Exception {
    super.setUp();

    TestFixtureBuilder<IdeaProjectTestFixture> fixtureBuilder = IdeaTestFixtureFactory.getFixtureFactory()
        .createLightFixtureBuilder(new DefaultLightProjectDescriptor());

    myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(
        fixtureBuilder.getFixture(),
        IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture()
    );

    myFixture.setUp();

    project = myFixture.getProject();
    Settings.getInstance(project).pluginEnabled = true;
}
 
Example #2
Source File: LocalProfilerFactory.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public ProfilerIndexInterface createProfilerIndex(@NotNull Project project) {
    File csvIndex = findCsvProfilerFile(project);
    if (csvIndex == null) {
        return null;
    }

    String profilerLocalUrl = Settings.getInstance(project).profilerLocalUrl;

    // fine: user defined base url use this one
    // else no profiler given let profiler try to find url
    String profilerUrl = null;
    if (StringUtils.isNotBlank(profilerLocalUrl)) {
        profilerUrl = profilerLocalUrl;
    }

    return new LocalProfilerIndex(csvIndex, profilerUrl);
}
 
Example #3
Source File: TwigFoldingBuilder.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement psiElement, @NotNull Document document, boolean b) {

    if (!Symfony2ProjectComponent.isEnabled(psiElement) || !(psiElement instanceof TwigFile)) {
        return new FoldingDescriptor[0];
    }

    List<FoldingDescriptor> descriptors = new ArrayList<>();

    if(Settings.getInstance(psiElement.getProject()).codeFoldingTwigRoute) {
        attachPathFoldingDescriptors(psiElement, descriptors);
    }

    if(Settings.getInstance(psiElement.getProject()).codeFoldingTwigTemplate) {
        attachTemplateFoldingDescriptors(psiElement, descriptors);
    }

    if(Settings.getInstance(psiElement.getProject()).codeFoldingTwigConstant) {
        attachConstantFoldingDescriptors(psiElement, descriptors);
    }

    return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
 
Example #4
Source File: TwigBlockUtilTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * fr.adrienbrault.idea.symfony2plugin.twig.utils.TwigBlockUtil#collectParentBlocks
 */
public void testVisit() {
    // skip for no fully project
    if(true) { return; }

    VirtualFile file = createFile("res/foo.html.twig", "{% extends \"foo1.html.twig\" %}{% block foo %}{% endblock %}");
    createFile("res/foo1.html.twig", "{% block foo1 %}{% endblock %}");

    PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);

    Settings.getInstance(getProject()).twigNamespaces.addAll(Collections.singletonList(
        new TwigNamespaceSetting(TwigUtil.MAIN, "res", true, TwigUtil.NamespaceType.ADD_PATH, true)
    ));

    Collection<TwigBlock> walk = TwigBlockUtil.collectParentBlocks(true, psiFile);

    assertNotNull(walk.stream().filter(twigBlock -> "foo".equals(twigBlock.getName())).findFirst().get());
    assertNotNull(walk.stream().filter(twigBlock -> "foo1".equals(twigBlock.getName())).findFirst().get());
}
 
Example #5
Source File: TwigBlockUtilTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * fr.adrienbrault.idea.symfony2plugin.twig.utils.TwigBlockUtil#collectParentBlocks
 */
public void testVisitNotForSelf() {
    // skip for no fully project
    if(true) { return; }

    VirtualFile file = createFile("res/foo.html.twig", "{% extends \"foo1.html.twig\" %}{% block foo %}{% endblock %}");
    createFile("res/foo1.html.twig", "{% block foo1 %}{% endblock %}");

    PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);

    Settings.getInstance(getProject()).twigNamespaces.addAll(Collections.singletonList(
        new TwigNamespaceSetting(TwigUtil.MAIN, "res", true, TwigUtil.NamespaceType.ADD_PATH, true)
    ));

    Collection<TwigBlock> walk = TwigBlockUtil.collectParentBlocks(false, psiFile);

    assertEquals(0, walk.stream().filter(twigBlock -> "foo".equals(twigBlock.getName())).count());
    assertNotNull(walk.stream().filter(twigBlock -> "foo1".equals(twigBlock.getName())).findFirst().get());
}
 
Example #6
Source File: TwigUtilTempTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @see TwigUtil#getTemplatePsiElements
 */
public void testGetTemplatePsiElements() {
    createFile("res/foo.html.twig");

    Settings.getInstance(getProject()).twigNamespaces.addAll(Arrays.asList(
        new TwigNamespaceSetting("Foo", "res", true, TwigUtil.NamespaceType.ADD_PATH, true),
        new TwigNamespaceSetting(TwigUtil.MAIN, "res", true, TwigUtil.NamespaceType.ADD_PATH, true),
        new TwigNamespaceSetting(TwigUtil.MAIN, "res", true, TwigUtil.NamespaceType.BUNDLE, true)
    ));

    String[] strings = {
        "@Foo/foo.html.twig", "@!Foo/foo.html.twig", "foo.html.twig", ":foo.html.twig", "@Foo\\foo.html.twig", "::foo.html.twig"
    };

    for (String file : strings) {
        Collection<PsiFile> templatePsiElements = TwigUtil.getTemplatePsiElements(getProject(), file);

        assertTrue(templatePsiElements.size() > 0);
        assertEquals("foo.html.twig", templatePsiElements.iterator().next().getName());
    }
}
 
Example #7
Source File: TwigBlockUtilTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * fr.adrienbrault.idea.symfony2plugin.twig.utils.TwigBlockUtil#collectParentBlocks
 */
public void testWalkWithSelf() {
    // skip for no fully project
    if(true) { return; }

    VirtualFile file = createFile("res/foo.html.twig", "{% extends \"foo1.html.twig\" %}{% block foo %}{% endblock %}");
    createFile("res/foo1.html.twig", "{% block foo1 %}{% endblock %}");

    PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);

    Settings.getInstance(getProject()).twigNamespaces.addAll(Collections.singletonList(
        new TwigNamespaceSetting(TwigUtil.MAIN, "res", true, TwigUtil.NamespaceType.ADD_PATH, true)
    ));

    Collection<TwigBlock> walk = TwigBlockUtil.collectParentBlocks(true, psiFile);

    assertEquals(1, walk.stream().filter(twigBlock -> "foo".equals(twigBlock.getName())).count());
    assertNotNull(walk.stream().filter(twigBlock -> "foo1".equals(twigBlock.getName())).findFirst().get());
}
 
Example #8
Source File: MethodSignatureTypeProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
private Collection<MethodSignatureSetting> getSignatureSettings(@NotNull PsiElement psiElement) {
    Collection<MethodSignatureSetting> signatures = new ArrayList<>();

    // get user defined settings
    if(Settings.getInstance(psiElement.getProject()).objectSignatureTypeProvider) {
        Collection<MethodSignatureSetting> settingSignatures = Settings.getInstance(psiElement.getProject()).methodSignatureSettings;
        if(settingSignatures != null) {
            signatures.addAll(settingSignatures);
        }
    }

    // load extension
    MethodSignatureTypeProviderExtension[] extensions = EXTENSIONS.getExtensions();
    if(extensions.length > 0) {
        MethodSignatureTypeProviderParameter parameter = new MethodSignatureTypeProviderParameter(psiElement);
        for(MethodSignatureTypeProviderExtension extension: extensions){
            signatures.addAll(extension.getSignatures(parameter));
        }
    }

    return signatures;
}
 
Example #9
Source File: JavascriptServiceNameStrategy.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public String getServiceName(@NotNull ServiceNameStrategyParameter parameter) {

    String serviceJsNameStrategy = Settings.getInstance(parameter.getProject()).serviceJsNameStrategy;
    if(serviceJsNameStrategy == null || StringUtils.isBlank(serviceJsNameStrategy)) {
        return null;
    }

    try {
        Object eval = run(parameter.getProject(), parameter.getClassName(), serviceJsNameStrategy);
        if(!(eval instanceof String)) {
            return null;
        }
        return StringUtils.isNotBlank((String) eval) ? (String) eval : null;
    } catch (ScriptException e) {
        Symfony2ProjectComponent.getLogger().error(String.format("ScriptException: '%s' - Script: '%s'", e.getMessage(), serviceJsNameStrategy));
    }

    return null;
}
 
Example #10
Source File: SymfonyCreateService.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void generateServiceDefinition() {
    String className = classCompletionPanelWrapper.getClassName();
    if(StringUtils.isBlank(className)) {
        return;
    }

    className = StringUtils.stripStart(className,"\\");

    // after cleanup class is empty
    if(StringUtils.isBlank(className)) {
        return;
    }

    ServiceBuilder.OutputType outputType = ServiceBuilder.OutputType.XML;
    if(radioButtonOutYaml.isSelected()) {
        outputType = ServiceBuilder.OutputType.Yaml;
    }

    // save last selection
    Settings.getInstance(project).lastServiceGeneratorLanguage = outputType.toString().toLowerCase();

    textAreaOutput.setText(createServiceAsText(outputType));
}
 
Example #11
Source File: ObjectRepositoryTypeProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement e) {
    if (!Settings.getInstance(e.getProject()).pluginEnabled) {
        return null;
    }

    if(!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "getRepository")) {
        return null;
    }


    String refSignature = ((MethodReference)e).getSignature();
    if(StringUtil.isEmpty(refSignature)) {
        return null;
    }

    String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter((MethodReference) e, TRIM_KEY);
    return signature == null ? null : new PhpType().add("#" + this.getKey() + signature);
}
 
Example #12
Source File: IdeHelper.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public static Collection<String> enablePluginAndConfigure(@NotNull Project project) {
    Settings.getInstance(project).pluginEnabled = true;

    Collection<String> messages = new ArrayList<>();

    Set<String> versions = SymfonyUtil.getVersions(project);
    if (!versions.isEmpty()) {
        messages.add("Symfony Version: " + versions.iterator().next());
    }

    // Symfony 3.0 structure
    if (VfsUtil.findRelativeFile(ProjectUtil.getProjectDir(project), "var", "cache") != null) {
        Settings.getInstance(project).pathToTranslation = "var/cache/dev/translations";
        messages.add("Translations: var/cache/dev/translations");
    }

    // Symfony 4.0 structure
    if (VfsUtil.findRelativeFile(ProjectUtil.getProjectDir(project), "public") != null) {
        Settings.getInstance(project).directoryToWeb = "public";
        messages.add("Web Directory: public");
    }

    // There no clean version when "FooBar:Foo:foo.html.twig" was dropped or deprecated
    // So we disable it in the 4 branch by default; following with a default switch to "false" soon
    if (SymfonyUtil.isVersionGreaterThenEquals(project, "4.0")) {
        Settings.getInstance(project).twigBundleNamespaceSupport = false;
        messages.add("Twig: Bundle names disabled");
    }

    return messages;
}
 
Example #13
Source File: IdeHelper.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public static void notifyEnableMessage(final Project project) {

        Notification notification = new Notification("Symfony Support", "Symfony", "Enable the Symfony Plugin <a href=\"enable\">with auto configuration now</a>, open <a href=\"config\">Project Settings</a> or <a href=\"dismiss\">dismiss</a> further messages", NotificationType.INFORMATION, (notification1, event) -> {

            // handle html click events
            if("config".equals(event.getDescription())) {

                // open settings dialog and show panel
                SettingsForm.show(project);
            } else if("enable".equals(event.getDescription())) {
                Collection<String> messages = enablePluginAndConfigure(project);

                String message = "Plugin enabled";

                if (!messages.isEmpty()) {
                    List<String> collect = messages.stream().map(s -> "<br> - " + s).collect(Collectors.toList());
                    message += StringUtils.join(collect, "");
                }

                Notifications.Bus.notify(new Notification("Symfony Support", "Symfony", message, NotificationType.INFORMATION), project);
            } else if("dismiss".equals(event.getDescription())) {

                // user doesnt want to show notification again
                Settings.getInstance(project).dismissEnableNotification = true;
            }

            notification1.expire();
        });

        Notifications.Bus.notify(notification, project);
    }
 
Example #14
Source File: FilesystemUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * Try to find an "app" directory on configuration or on project directory in root
 * We also support absolute path in configuration
 */
@NotNull
public static Collection<VirtualFile> getAppDirectories(@NotNull Project project) {
    Collection<VirtualFile> virtualFiles = new HashSet<>();

    // find "app" folder on user settings
    String directoryToApp = Settings.getInstance(project).directoryToApp;

    if(FileUtil.isAbsolute(directoryToApp)) {
        // absolute dir given
        VirtualFile fileByIoFile = VfsUtil.findFileByIoFile(new File(directoryToApp), true);
        if(fileByIoFile != null) {
            virtualFiles.add(fileByIoFile);
        }
    } else {
        // relative path resolve
        VirtualFile globalDirectory = VfsUtil.findRelativeFile(
            ProjectUtil.getProjectDir(project),
            directoryToApp.replace("\\", "/").split("/")
        );

        if(globalDirectory != null) {
            virtualFiles.add(globalDirectory);
        }
    }

    // global "app" in root
    VirtualFile templates = VfsUtil.findRelativeFile(ProjectUtil.getProjectDir(project), "app");
    if(templates != null) {
        virtualFiles.add(templates);
    }

    return virtualFiles;
}
 
Example #15
Source File: TranslationIndex.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
private Collection<File> getTranslationRootInner() {
    Collection<File> files = new HashSet<>();

    String translationPath = Settings.getInstance(project).pathToTranslation;
    if (StringUtils.isNotBlank(translationPath)) {
        if (!FileUtil.isAbsolute(translationPath)) {
            translationPath = project.getBasePath() + "/" + translationPath;
        }

        File file = new File(translationPath);
        if(file.exists() && file.isDirectory()) {
            files.add(file);
        }
    }

    VirtualFile baseDir = ProjectUtil.getProjectDir(project);

    for (String containerFile : ServiceContainerUtil.getContainerFiles(project)) {
        // resolve the file
        VirtualFile containerVirtualFile = VfsUtil.findRelativeFile(containerFile, baseDir);
        if (containerVirtualFile == null) {
            continue;
        }

        // get directory of the file; translation folder is same directory
        VirtualFile cacheDirectory = containerVirtualFile.getParent();
        if (cacheDirectory == null) {
            continue;
        }

        // get translation sub directory
        VirtualFile translations = cacheDirectory.findChild("translations");
        if (translations != null) {
            files.add(VfsUtilCore.virtualToIoFile(translations));
        }
    }

    return files;
}
 
Example #16
Source File: SymfonyJavascriptServiceNameForm.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void onSave() {

        String text = textJavascript.getText();
        if(StringUtils.isBlank(text)) {
            text = null;
        }

        Settings.getInstance(project).serviceJsNameStrategy = text;

        dispose();
    }
 
Example #17
Source File: TwigUtilTempTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * @see TwigUtil#getTemplateNamesForFile
 */
public void testGetTemplateNamesForFile() {
    Settings.getInstance(getProject()).twigNamespaces.addAll(createTwigNamespaceSettings());

    assertContainsElements(
        TwigUtil.getTemplateNamesForFile(getProject(), createFile("res/test.html.twig")),
        "@Foo/test.html.twig", "test.html.twig", "::test.html.twig", "FooBundle::test.html.twig"
    );

    assertContainsElements(
        TwigUtil.getTemplateNamesForFile(getProject(), createFile("res/foobar/test.html.twig")),
        "@Foo/foobar/test.html.twig", "foobar/test.html.twig", ":foobar:test.html.twig", "FooBundle:foobar:test.html.twig"
    );
}
 
Example #18
Source File: TwigUtilTempTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void testGetTwigFileNames() {
    createFile("res/foobar/foo.html.twig");

    Settings.getInstance(getProject()).twigNamespaces.addAll(createTwigNamespaceSettings());

    assertContainsElements(
        TwigUtil.getTemplateMap(getProject()).keySet(),
        "@Foo/foobar/foo.html.twig", "FooBundle:foobar:foo.html.twig", ":foobar:foo.html.twig", "foobar/foo.html.twig"
    );
}
 
Example #19
Source File: TwigUtilTempTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void testGetTwigAndPhpTemplateFiles() {
    createFiles("res/foobar/foo.html.twig", "res/foobar/foo.php");

    Settings.getInstance(getProject()).twigNamespaces.addAll(createTwigNamespaceSettings());

    assertContainsElements(
        TwigUtil.getTemplateMap(getProject(), true).keySet(),
        "@Foo/foobar/foo.html.twig", "FooBundle:foobar:foo.html.twig", ":foobar:foo.html.twig", "foobar/foo.html.twig",
        "@Foo/foobar/foo.php", "FooBundle:foobar:foo.php", ":foobar:foo.php", "foobar/foo.php"
    );
}
 
Example #20
Source File: ShopwareApiResourcesTypeProvider.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement e) {
    if (!Settings.getInstance(e.getProject()).pluginEnabled) {
        return null;
    }

    // container calls are only on "get" methods
    if(!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "getResource")) {
        return null;
    }

    String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter((MethodReference) e, TRIM_KEY);
    return signature == null ? null : new PhpType().add("#" + this.getKey() + signature);
}
 
Example #21
Source File: TwigUtilTempTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * @see TwigUtil#getTemplateTargetOnOffset
 */
public void testGetTemplateTargetOnOffset() {
    createFiles("res/foobar/foo.html.twig");
    createFiles("res/foobar/apple/foo.html.twig");

    Settings.getInstance(getProject()).twigNamespaces.addAll(createTwigNamespaceSettings());

    assertIsDirectoryAtOffset("@Foo/foobar/foo.html.twig", 2, "res");
    assertIsDirectoryAtOffset("@Foo/foobar\\foo.html.twig", 6, "foobar");

    assertIsDirectoryAtOffset( "foobar/foo.html.twig", 3, "foobar");
    assertIsDirectoryAtOffset( "foobar/apple/foo.html.twig", 9, "apple");
    assertIsDirectoryAtOffset( "foobar\\apple\\foo.html.twig", 9, "apple");

    assertIsDirectoryAtOffset("@Foo/foobar/foo.html.twig", 6, "foobar");
    assertIsDirectoryAtOffset("@Foo/foobar\\foo.html.twig", 6, "foobar");
    assertIsDirectoryAtOffset("@Foo/foobar/apple/foo.html.twig", 15, "apple");

    assertIsDirectoryAtOffset( "@Foo/foobar/foo.html.twig", 3, "res");
    assertIsDirectoryAtOffset("FooBundle:foobar:foo.html.twig", 6, "res");
    assertIsDirectoryAtOffset("FooBundle:foobar:foo.html.twig", 13, "foobar");
    assertIsDirectoryAtOffset(":foobar:foo.php", 4, "foobar");

    assertIsDirectoryAtOffset(":foobar/apple:foo.php", 10, "apple");
    assertIsDirectoryAtOffset(":foobar\\apple:foo.php", 10, "apple");
    assertIsDirectoryAtOffset(":foobar\\apple\\foo.php", 10, "apple");

    assertTrue(TwigUtil.getTemplateTargetOnOffset(getProject(), "@Foo/foobar/foo.html.twig", 15).size() == 0);
    assertTrue(TwigUtil.getTemplateTargetOnOffset(getProject(), "foo.html.twig", 40).size() == 0);
}
 
Example #22
Source File: TwigUtilTempTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * @see fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil#getPresentableTemplateName
 */
public void testGetPresentableTemplateName() {
    VirtualFile res = createFile("res/foo/foo.html.twig");


    Settings.getInstance(getProject()).twigNamespaces.addAll(Collections.singletonList(
        new TwigNamespaceSetting("Foobar", "res", true, TwigUtil.NamespaceType.BUNDLE, true)
    ));

    PsiFile file = PsiManager.getInstance(getProject()).findFile(res);
    assertEquals("Foobar:foo:foo", TwigUtil.getPresentableTemplateName(file, true));
    assertEquals("Foobar:foo:foo.html.twig", TwigUtil.getPresentableTemplateName(file, false));
}
 
Example #23
Source File: ProfilerSettingsDialog.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
public void reset() {
    Settings setting = Settings.getInstance(project);

    radioLocalProfiler.setSelected(setting.profilerLocalEnabled);
    textLocalProfilerUrl.setText(setting.profilerLocalUrl);
    textLocalProfilerCsvPath.setText(setting.profilerCsvPath);

    radioHttpProfiler.setSelected(setting.profilerHttpEnabled);
    textHttpProfilerUrl.setText(setting.profilerHttpUrl);

    updateDefaultRadio();
}
 
Example #24
Source File: ProfilerSettingsDialog.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
public void apply() throws ConfigurationException {
    Settings settings = Settings.getInstance(project);

    settings.profilerLocalEnabled = radioLocalProfiler.isSelected();
    settings.profilerLocalUrl = textLocalProfilerUrl.getText();
    settings.profilerCsvPath = textLocalProfilerCsvPath.getText();

    settings.profilerHttpEnabled = radioHttpProfiler.isSelected();
    settings.profilerHttpUrl = textHttpProfilerUrl.getText();
}
 
Example #25
Source File: GlobalAppTwigNamespaceExtensionTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void testThatCustomAppDirectoryIsSupported() {
    Settings.getInstance(getProject()).directoryToApp = "foo/app";
    createFile("foo/app/Resources/views/foo.html.twig");

    Collection<TwigPath> namespaces = new GlobalAppTwigNamespaceExtension()
        .getNamespaces(new TwigNamespaceExtensionParameter(getProject()));

    assertNotNull(namespaces.stream()
        .filter(twigPath -> TwigUtil.MAIN.equals(twigPath.getNamespace()) && "app/Resources/views".endsWith(twigPath.getPath()))
        .findFirst()
    );
}
 
Example #26
Source File: ObjectManagerFindTypeProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement e) {
    if (!Settings.getInstance(e.getProject()).pluginEnabled) {
        return null;
    }

    if(!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "find")) {
        return null;
    }

    String refSignature = ((MethodReference)e).getSignature();
    if(StringUtil.isEmpty(refSignature)) {
        return null;
    }

    // we need the param key on getBySignature(), since we are already in the resolved method there attach it to signature
    // param can have dotted values split with \
    PsiElement[] parameters = ((MethodReference)e).getParameters();
    if (parameters.length >= 2) {
        String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter((MethodReference) e, TRIM_KEY);
        if(signature != null) {
            return new PhpType().add("#" + this.getKey() + signature);
        }
    }

    return null;
}
 
Example #27
Source File: ObjectManagerFindContextTypeProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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;
    }

    String signature = null;
    PhpPsiElement firstPsiChild = methodRef.getFirstPsiChild();

    // reduce supported scope here; by checking via "instanceof"
    if (firstPsiChild instanceof Variable) {
        signature = ((Variable) firstPsiChild).getSignature();
    } else if(firstPsiChild instanceof PhpReference) {
        signature = ((PhpReference) firstPsiChild).getSignature();
    }

    if (signature == null || StringUtils.isBlank(signature)) {
        return null;
    }

    return new PhpType().add("#" + this.getKey() + signature + TRIM_KEY + methodRefName);
}
 
Example #28
Source File: ObjectRepositoryResultTypeProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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);
}
 
Example #29
Source File: AssistantReferenceUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
public static ArrayList<MethodParameterSetting> getMethodsParameterSettings(Project project) {

    List<MethodParameterSetting> methodParameterSettings = Settings.getInstance(project).methodParameterSettings;

    if(methodParameterSettings == null) {
        return new ArrayList<>();
    }

    return (ArrayList<MethodParameterSetting>) methodParameterSettings;
}
 
Example #30
Source File: SymfonyContainerTypeProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement e) {
    if (!Settings.getInstance(e.getProject()).pluginEnabled) {
        return null;
    }

    // container calls are only on "get" methods
    if(!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "get")) {
        return null;
    }

    String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter((MethodReference) e, TRIM_KEY);
    return signature == null ? null : new PhpType().add("#" + this.getKey() + signature);
}