use of com.intellij.psi.PsiFileFactory in project intellij-community by JetBrains.
the class PyElementGeneratorImpl method createDummyFile.
public PsiFile createDummyFile(LanguageLevel langLevel, String contents, boolean physical) {
final PsiFileFactory factory = PsiFileFactory.getInstance(myProject);
final String name = getDummyFileName();
final LightVirtualFile virtualFile = new LightVirtualFile(name, PythonFileType.INSTANCE, contents);
virtualFile.putUserData(LanguageLevel.KEY, langLevel);
final PsiFile psiFile = ((PsiFileFactoryImpl) factory).trySetupPsiForFile(virtualFile, PythonLanguage.getInstance(), physical, true);
assert psiFile != null;
return psiFile;
}
use of com.intellij.psi.PsiFileFactory in project intellij-community by JetBrains.
the class EmmetUpdateTagAction method processTags.
private static void processTags(@NotNull Project project, @Nullable String templateText, @NotNull PairProcessor<XmlTag, Boolean> processor) {
if (StringUtil.isNotEmpty(templateText)) {
final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(project);
XmlFile xmlFile = (XmlFile) psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.HTML, templateText);
XmlTag tag = xmlFile.getRootTag();
boolean firstTag = true;
while (tag != null) {
processor.process(tag, firstTag);
firstTag = false;
tag = PsiTreeUtil.getNextSiblingOfType(tag, XmlTag.class);
}
}
}
use of com.intellij.psi.PsiFileFactory in project intellij-community by JetBrains.
the class RenameUtil method createPrefixedNode.
/*private static boolean isTokenOfType(PsiManager manager, String name, TokenSet set) {
final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(RngCompactLanguage.INSTANCE);
assert definition != null;
final Lexer lexer = definition.createLexer(manager.getProject());
lexer.start(name, 0, name.length(), 0);
final IElementType t = lexer.getTokenType();
lexer.advance();
return lexer.getTokenType() == null && set.contains(t);
}*/
public static ASTNode createPrefixedNode(PsiManager manager, String prefix, String localPart) {
final PsiFileFactory f = PsiFileFactory.getInstance(manager.getProject());
final RncFile file = (RncFile) f.createFileFromText("dummy.rnc", RncFileType.getInstance(), "element " + prefix + ":" + localPart + " { text }");
final ASTNode node = findFirstGrammarNode(file);
final ASTNode nameClassNode = node.findChildByType(RncElementTypes.NAME_CLASS);
assert nameClassNode != null;
final ASTNode astNode = nameClassNode.findChildByType(RncElementTypes.NAME);
assert astNode != null;
return astNode;
}
use of com.intellij.psi.PsiFileFactory in project intellij-community by JetBrains.
the class RegExpUtil method getEnumValues.
@Nullable
public static Set<String> getEnumValues(Project project, @NotNull String regExp) {
final PsiFileFactory factory = PsiFileFactory.getInstance(project);
final PsiFile file = factory.createFileFromText("dummy.regexp", RegExpFileType.INSTANCE, regExp);
final RegExpPattern pattern = (RegExpPattern) file.getFirstChild();
if (pattern == null) {
return null;
}
final RegExpBranch[] branches = pattern.getBranches();
final Set<String> values = new HashSet<>();
for (RegExpBranch branch : branches) {
if (analyzeBranch(branch)) {
values.add(branch.getUnescapedText());
}
}
return values;
}
use of com.intellij.psi.PsiFileFactory in project intellij-plugins by JetBrains.
the class DartElementGenerator method createDummyFile.
public static PsiFile createDummyFile(Project myProject, String text) {
final PsiFileFactory factory = PsiFileFactory.getInstance(myProject);
final String name = "dummy." + DartFileType.INSTANCE.getDefaultExtension();
final LightVirtualFile virtualFile = new LightVirtualFile(name, DartFileType.INSTANCE, text);
final PsiFile psiFile = ((PsiFileFactoryImpl) factory).trySetupPsiForFile(virtualFile, DartLanguage.INSTANCE, false, true);
assert psiFile != null;
return psiFile;
}
Aggregations