Search in sources :

Example 1 with PsiFileFactory

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;
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl) PsiFile(com.intellij.psi.PsiFile)

Example 2 with PsiFileFactory

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);
        }
    }
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag)

Example 3 with PsiFileFactory

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;
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) ASTNode(com.intellij.lang.ASTNode) RncFile(org.intellij.plugins.relaxNG.compact.psi.RncFile)

Example 4 with PsiFileFactory

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;
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) RegExpPattern(org.intellij.lang.regexp.psi.RegExpPattern) RegExpBranch(org.intellij.lang.regexp.psi.RegExpBranch) PsiFile(com.intellij.psi.PsiFile) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with PsiFileFactory

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;
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl) PsiFile(com.intellij.psi.PsiFile)

Aggregations

PsiFileFactory (com.intellij.psi.PsiFileFactory)19 PsiFile (com.intellij.psi.PsiFile)13 ASTNode (com.intellij.lang.ASTNode)5 PsiFileFactoryImpl (com.intellij.psi.impl.PsiFileFactoryImpl)4 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)4 RegExpPattern (org.intellij.lang.regexp.psi.RegExpPattern)4 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 RncFile (org.intellij.plugins.relaxNG.compact.psi.RncFile)3 NotNull (org.jetbrains.annotations.NotNull)3 Document (com.intellij.openapi.editor.Document)2 PsiElement (com.intellij.psi.PsiElement)2 Nullable (org.jetbrains.annotations.Nullable)2 ReformatCodeProcessor (com.intellij.codeInsight.actions.ReformatCodeProcessor)1 XmlZenCodingGenerator (com.intellij.codeInsight.template.emmet.generators.XmlZenCodingGenerator)1 ZenCodingGenerator (com.intellij.codeInsight.template.emmet.generators.ZenCodingGenerator)1 TemplateImpl (com.intellij.codeInsight.template.impl.TemplateImpl)1 CreateFileAction (com.intellij.ide.actions.CreateFileAction)1 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)1 FileType (com.intellij.openapi.fileTypes.FileType)1 Project (com.intellij.openapi.project.Project)1