@Override protected PsiFile createExpressionCodeFragment(@NotNull Project project, @NotNull String text, @Nullable PsiElement context, boolean isPhysical) { return PsiFileFactory.getInstance(project).createFileFromText("dlv-debug.txt", PlainTextLanguage.INSTANCE, text); } }
@NotNull private static GoFile createFileFromText(@NotNull Project project, @NotNull String text) { return (GoFile)PsiFileFactory.getInstance(project).createFileFromText("a.go", GoLanguage.INSTANCE, text); }
@NotNull private static BallerinaFile createFileFromText(@NotNull Project project, @NotNull String text) { return (BallerinaFile) PsiFileFactory.getInstance(project).createFileFromText("a.bal", BallerinaLanguage.INSTANCE, text); }
@Contract(pure = true) @NotNull public static ElixirFile createFile(@NotNull final Project project, @NotNull final String text) { String filename = "dummy." + ElixirFileType.INSTANCE.getDefaultExtension(); return (ElixirFile) PsiFileFactory.getInstance(project).createFileFromText( filename, ElixirFileType.INSTANCE, text ); }
/** * Changes the element's text to a new value * * @param entry element to be changed * @param range range within the element * @param newContent new element text * @return changed element * * @throws IncorrectOperationException if something goes wrong */ @Override public IgnoreEntry handleContentChange(@NotNull IgnoreEntry entry, @NotNull TextRange range, String newContent) throws IncorrectOperationException { if (!(entry.getLanguage() instanceof IgnoreLanguage)) { return entry; } IgnoreLanguage language = (IgnoreLanguage) entry.getLanguage(); IgnoreFileType fileType = (IgnoreFileType) language.getAssociatedFileType(); assert fileType != null; PsiFile file = PsiFileFactory.getInstance(entry.getProject()) .createFileFromText(language.getFilename(), fileType, range.replace(entry.getText(), newContent)); IgnoreEntry newEntry = PsiTreeUtil.findChildOfType(file, IgnoreEntry.class); assert newEntry != null; return (IgnoreEntry) entry.replace(newEntry); }
protected static String buildStubTreeText(@NotNull Project project, @NotNull VirtualFile file, @NotNull String fileContent, boolean checkErrors) throws IOException { String path = file.getPath(); PsiFile psi = PsiFileFactory.getInstance(project).createFileFromText(file.getName(), file.getFileType(), fileContent); if (checkErrors) { assertFalse(path + " contains error elements", DebugUtil.psiToString(psi, true).contains("PsiErrorElement")); } String full = DebugUtil.stubTreeToString(GoFileElementType.INSTANCE.getBuilder().buildStubTree(psi)); psi.putUserData(IndexingDataKeys.VIRTUAL_FILE, file); FileContentImpl content = new FileContentImpl(file, fileContent, file.getCharset()); PsiFile psiFile = content.getPsiFile(); String fast = DebugUtil.stubTreeToString(GoFileElementType.INSTANCE.getBuilder().buildStubTree(psiFile)); if (!Comparing.strEqual(full, fast)) { System.err.println(path); UsefulTestCase.assertSameLines(full, fast); } return fast; }
/** * Creates new Gitignore file or uses an existing one. * * @param directory working directory * @return file */ @Nullable public PsiFile createFromTemplate(final PsiDirectory directory) throws IncorrectOperationException { final String filename = fileType.getIgnoreLanguage().getFilename(); final PsiFile currentFile = directory.findFile(filename); if (currentFile != null) { return currentFile; } final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject()); final IgnoreLanguage language = fileType.getIgnoreLanguage(); String content = StringUtil.join(TEMPLATE_NOTE, Constants.NEWLINE); if (language.isSyntaxSupported() && !IgnoreBundle.Syntax.GLOB.equals(language.getDefaultSyntax())) { content = StringUtil.join( content, IgnoreBundle.Syntax.GLOB.getPresentation(), Constants.NEWLINE, Constants.NEWLINE ); } final PsiFile file = factory.createFileFromText(filename, fileType, content); return (PsiFile) directory.add(file); } }
@NotNull public static PsiFile createDummyFile(@NotNull Project project, @NotNull String filename, @NotNull String content) { return PsiFileFactory.getInstance(project).createFileFromText(filename, YAMLFileType.YML, content, System.currentTimeMillis(), false); } }
@NotNull public static PsiFile createDummyFile(Project p, String fileText) { return PsiFileFactory.getInstance(p).createFileFromText("DUMMY__." + YAMLFileType.YML.getDefaultExtension(), YAMLFileType.YML, fileText, System.currentTimeMillis(), false); }
PsiFileFactory factory = PsiFileFactory.getInstance(getManager().getProject()); PsiFile mirror = factory.createFileFromText( fileName,
@NotNull private PsiElement createXmlFile(@NotNull String content) { return PsiFileFactory.getInstance(getProject()).createFileFromText("DUMMY__." + XmlFileType.INSTANCE.getDefaultExtension(), XmlFileType.INSTANCE, content); } }
@NotNull private PsiElement createYamlFile(@NotNull String content) { return PsiFileFactory.getInstance(getProject()).createFileFromText("DUMMY__." + YAMLFileType.YML.getDefaultExtension(), YAMLFileType.YML, content); } }
@NotNull private PsiElement createXmlFile(@NotNull String content) { return PsiFileFactory.getInstance(getProject()).createFileFromText("DUMMY__." + XmlFileType.INSTANCE.getDefaultExtension(), XmlFileType.INSTANCE, content); } }
@NotNull private XmlFile createXmlFile(@NotNull String content) { return (XmlFile) PsiFileFactory.getInstance(getProject()).createFileFromText("DUMMY__." + XmlFileType.INSTANCE.getDefaultExtension(), XmlFileType.INSTANCE, content); }
/** * @see fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil#getImportedMacrosNamespaces */ public void testGetImportedMacrosNamespaces() { PsiFile psiFile = PsiFileFactory.getInstance(getProject()).createFileFromText(TwigLanguage.INSTANCE, "{% import _self as macros %}\n" + "{% macro foobar %}{% endmacro %}\n" ); assertTrue( TwigUtil.getImportedMacrosNamespaces(psiFile).stream().anyMatch(twigMacro -> "macros.foobar".equals(twigMacro.getName())) ); }
private Collection<TwigBlock> buildBlocks(String content) { return TwigUtil.getBlocksInFile((TwigFile) PsiFileFactory.getInstance(getProject()).createFileFromText("DUMMY__." + TwigFileType.INSTANCE.getDefaultExtension(), TwigFileType.INSTANCE, content, System.currentTimeMillis(), false)); }
/** * @see fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil#getImportedMacrosNamespaces */ public void testGetImportedMacrosNamespacesTargets() { PsiFile psiFile = PsiFileFactory.getInstance(getProject()).createFileFromText(TwigLanguage.INSTANCE, "{% macro my_foobar %}{% endmacro %}\n" + "{% import _self as foobar %}\n" ); assertTrue(TwigUtil.getImportedMacrosNamespaces(psiFile, "foobar.my_foobar").stream().anyMatch( psiElement -> psiElement.getNode().getElementType() == TwigElementTypes.MACRO_TAG )); }
/** * @see TwigUtil#getTwigGlobalsFromYamlConfig */ public void testGetTwigGlobalsFromYamlConfig() { String content = "twig:\n" + " globals:\n" + " ga_tracking: '%ga_tracking%'\n" + " user_management: '@AppBundle\\Service\\UserManagement'\n" ; YAMLFile yamlFile = (YAMLFile) PsiFileFactory.getInstance(getProject()) .createFileFromText("DUMMY__." + YAMLFileType.YML.getDefaultExtension(), YAMLFileType.YML, content, System.currentTimeMillis(), false); Map<String, String> globals = TwigUtil.getTwigGlobalsFromYamlConfig(yamlFile); assertEquals("%ga_tracking%", globals.get("ga_tracking")); assertEquals("@AppBundle\\Service\\UserManagement", globals.get("user_management")); }
public void testGetImportedMacrosTargets() { PsiFile psiFile = PsiFileFactory.getInstance(getProject()).createFileFromText(TwigLanguage.INSTANCE, "{% macro foobar %}{% endmacro %}\n" + "{% from _self import foobar as input, foobar %}\n" ); assertTrue(TwigUtil.getImportedMacros(psiFile, "foobar").stream().anyMatch(psiElement -> psiElement.getNode().getElementType() == TwigElementTypes.MACRO_TAG )); assertTrue(TwigUtil.getImportedMacros(psiFile, "input").stream().anyMatch(psiElement -> psiElement.getNode().getElementType() == TwigElementTypes.MACRO_TAG )); }
/** * @see fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil#getSetDeclaration */ public void testGetSetDeclaration() { PsiFile psiFile = PsiFileFactory.getInstance(getProject()).createFileFromText(TwigLanguage.INSTANCE, "{% set foobar = 'foo' %}\n" + "{% set footag %}{% endset %}\n" ); Collection<String> setDeclaration = TwigUtil.getSetDeclaration(psiFile); assertContainsElements(setDeclaration, "foobar"); assertContainsElements(setDeclaration, "footag"); }