com.intellij.psi.impl.PsiFileFactoryImpl Java Examples

The following examples show how to use com.intellij.psi.impl.PsiFileFactoryImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Trees.java    From antlr4-intellij-adaptor with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static PsiElement createLeafFromText(Project project, Language language, PsiElement context,
											String text, IElementType type)
{
	PsiFileFactoryImpl factory = (PsiFileFactoryImpl) PsiFileFactory.getInstance(project);
	PsiElement el = factory.createElementFromText(text, language, type, context);
	if ( el==null ) return null;
	return PsiTreeUtil.getDeepestFirst(el); // forces parsing of file!!
	// start rule depends on root passed in
}
 
Example #2
Source File: Trees.java    From antlr4-intellij-adaptor with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static PsiFile createFile(Project project, Language language, String text) {
	LanguageFileType ftype = language.getAssociatedFileType();
	if ( ftype==null ) return null;
	String ext = ftype.getDefaultExtension();
	String fileName = "___fubar___."+ext; // random name but must have correct extension
	PsiFileFactoryImpl factory = (PsiFileFactoryImpl)PsiFileFactory.getInstance(project);
	return factory.createFileFromText(fileName, language, text, false, false);
}
 
Example #3
Source File: MyPsiUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static PsiElement createLeafFromText(Project project, PsiElement context,
											String text, IElementType type)
{
	PsiFileFactoryImpl factory = (PsiFileFactoryImpl)PsiFileFactory.getInstance(project);
	PsiElement el = factory.createElementFromText(text,
												  ANTLRv4Language.INSTANCE,
												  type,
												  context);
	return PsiTreeUtil.getDeepestFirst(el); // forces parsing of file!!
	// start rule depends on root passed in
}
 
Example #4
Source File: LightProjectBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void registerServices(@Nonnull InjectingContainerBuilder builder) {
  builder.bind(PsiFileFactory.class).to(PsiFileFactoryImpl.class);
  builder.bind(PsiManager.class).to(PsiManagerImpl.class);
  builder.bind(FileIndexFacade.class).to(LightFileIndexFacade.class);
  builder.bind(PsiModificationTracker.class).to(PsiModificationTrackerImpl.class);
}
 
Example #5
Source File: MyPsiUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static PsiFile createFile(Project project, String text) {
	String fileName = "a.g4"; // random name but must be .g4
	PsiFileFactoryImpl factory = (PsiFileFactoryImpl)PsiFileFactory.getInstance(project);
	return factory.createFileFromText(fileName, ANTLRv4Language.INSTANCE,
									  text, false, false);
}