How can I create a new resource file from an IntelliJ Idea plugin?

Answered

Hi, I need to create a new file to insert in the resources folder of the project where a plugin is working on.

How can I execute this operation?

0
6 comments

Hi, thank you I'll take a look and let you know 

0

Sorry, but I'm not figuring out how to do, also with the references link you shared to me, there are some snippets of code available?

0

Yes, but is the class how its works and not how I could implement it.

My scenario is this, from BaseIntentionAction I need to work from this ovveride method for my custom Annotator: 

@Override
    public void invoke(@NotNull Project project, Editor editor, PsiFile psiFile) throws IncorrectOperationException {
    	// here should be located the code to create a file for IntelliJ
    }	
0

Hi, I red with more attention to look to your reference links and this is what I have figure out:

@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile psiFile) throws IncorrectOperationException {
        for (VirtualFile virtualFile : ProjectRootManager.getInstance(project).getContentRoots()) {
            String path = virtualFile.getPath();
            if(path.endsWith("main")) {
                VirtualFile resDirectory = virtualFile.findOrCreateChildData("any_requestor", "resources");
                PsiDirectoryFactory.getInstance(project)
                        .createDirectory(resDirectory)
                        .createFile("your_file_here")
                        .getVirtualFile().setBinaryContent("content_of_your_file".getBytes(UTF_8));
            }
        }
        // your_code_HERE
}
0

Please sign in to leave a comment.