Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create use alias setting from third party plugin #97

Closed
cedricziel opened this issue Nov 28, 2017 · 5 comments
Closed

Create use alias setting from third party plugin #97

cedricziel opened this issue Nov 28, 2017 · 5 comments

Comments

@cedricziel
Copy link
Collaborator

Hi,

Can I create a new UseAliasOption programmatically from a third-party plugin?

@cedricziel
Copy link
Collaborator Author

Found it. I can simply write into your application settings. Neat!

For those who are searching:

package com.cedricziel.idea.typo3.optional.annotation;

import com.intellij.openapi.components.ProjectComponent;
import de.espend.idea.php.annotation.ApplicationSettings;
import de.espend.idea.php.annotation.dict.UseAliasOption;

import java.util.List;

public class UseAliasProvider implements ProjectComponent {
    @Override
    public void projectOpened() {
        String className = "TYPO3\\CMS\\Extbase\\Annotation\\Inject";
        String alias = "inject";

        UseAliasOption injectUseAlias = new UseAliasOption(className, alias, true);
        List<UseAliasOption> useAliasOptions = ApplicationSettings.getInstance().useAliasOptions;

        boolean isAlreadyPresent = false;
        for (UseAliasOption option : useAliasOptions) {
            if (option.getClassName() != null && option.getClassName().equals(className)) {
                option.setAlias(alias);
                isAlreadyPresent = true;
            }
        }

        if (!isAlreadyPresent) {
            useAliasOptions.add(injectUseAlias);
        }
    }
}

@Haehnchen
Copy link
Owner

wtf? @cedricziel i will better provide you an extension point :)

@Haehnchen Haehnchen reopened this Nov 28, 2017
@cedricziel
Copy link
Collaborator Author

That would be perfect, but I didn't want to steal your time ;)

@Haehnchen
Copy link
Owner

already in ;)

@cedricziel
Copy link
Collaborator Author

Neat, thx a bunch!

Haehnchen added a commit that referenced this issue Nov 28, 2017
create use alias setting from third party plugin #97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants