Java Code Examples for fr.adrienbrault.idea.symfony2plugin.Settings#getInstance()

The following examples show how to use fr.adrienbrault.idea.symfony2plugin.Settings#getInstance() . 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: 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 2
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 3
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 4
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 5
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 6
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);
}
 
Example 7
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 8
Source File: LocalProfilerFactory.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * find csv on settings or container configuration
 */
@Nullable
private File findCsvProfilerFile(@NotNull Project project) {
    String profilerCsvPath = Settings.getInstance(project).profilerCsvPath;
    if (StringUtils.isBlank(profilerCsvPath)) {
        return getCsvIndex(project);
    }

    VirtualFile relativeFile = VfsUtil.findRelativeFile(ProjectUtil.getProjectDir(project), profilerCsvPath.replace("\\", "/").split("/"));
    if (relativeFile != null) {
        return VfsUtil.virtualToIoFile(relativeFile);
    }

    return null;
}
 
Example 9
Source File: TwigUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
private static TwigNamespaceSetting findManagedTwigNamespace(@NotNull Project project, @NotNull TwigPath twigPath) {
    List<TwigNamespaceSetting> twigNamespaces = Settings.getInstance(project).twigNamespaces;
    if(twigNamespaces == null) {
        return null;
    }

    for(TwigNamespaceSetting twigNamespace: twigNamespaces) {
       if(twigNamespace.equals(project, twigPath)) {
            return twigNamespace;
       }
    }

    return null;
}
 
Example 10
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 11
Source File: PhpFoldingBuilder.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement psiElement, @NotNull Document document, boolean b) {

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

    boolean codeFoldingPhpRoute = Settings.getInstance(psiElement.getProject()).codeFoldingPhpRoute;
    boolean codeFoldingPhpModel = Settings.getInstance(psiElement.getProject()).codeFoldingPhpModel;
    boolean codeFoldingPhpTemplate = Settings.getInstance(psiElement.getProject()).codeFoldingPhpTemplate;

    // we dont need to do anything
    if(!codeFoldingPhpRoute && !codeFoldingPhpModel && !codeFoldingPhpTemplate) {
        return new FoldingDescriptor[0];
    }

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

    Collection<StringLiteralExpression> stringLiteralExpressiones = PsiTreeUtil.findChildrenOfType(psiElement, StringLiteralExpression.class);
    for(StringLiteralExpression stringLiteralExpression: stringLiteralExpressiones) {

        if(codeFoldingPhpModel) {
            attachModelShortcuts(descriptors, stringLiteralExpression);
        }

        if(codeFoldingPhpTemplate) {
            attachTemplateShortcuts(descriptors, stringLiteralExpression);
        }

    }

    // strip ".[php|html].twig"
    if(codeFoldingPhpRoute) {
        attachRouteShortcuts(descriptors, stringLiteralExpressiones);
    }

    return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
 
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: 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 14
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 15
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 16
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 17
Source File: GlobalAppTwigNamespaceExtensionTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void testThatAppDirectoryInRootIsAlwaysSupported() {
    Settings.getInstance(getProject()).directoryToApp = "foo\\app";
    createFile("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 18
Source File: RoutingSettingsForm.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
private Settings getSettings() {
    return Settings.getInstance(this.project);
}
 
Example 19
Source File: DrupalLightCodeInsightFixtureTestCase.java    From idea-php-drupal-symfony2-bridge with MIT License 4 votes vote down vote up
@Override
public void setUp() throws Exception {
    super.setUp();
    Settings.getInstance(myFixture.getProject()).pluginEnabled = true;
}
 
Example 20
Source File: LocalProfilerFactory.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Override
public boolean accepts(@NotNull Project project) {
    return Settings.getInstance(project).profilerLocalEnabled;
}