Java Code Examples for com.intellij.extapi.psi.PsiFileBase

The following examples show how to use com.intellij.extapi.psi.PsiFileBase. These examples are extracted from open source projects. 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 Project: consulo   Source File: InjectedLanguageUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Finds injected language in expression
 *
 * @param expression  where to find
 * @param classToFind class that represents language we look for
 * @param <T>         class that represents language we look for
 * @return instance of class that represents language we look for or null of not found
 */
@Nullable
@SuppressWarnings("unchecked") // We check types dynamically (using isAssignableFrom)
public static <T extends PsiFileBase> T findInjectedFile(@Nonnull final PsiElement expression, @Nonnull final Class<T> classToFind) {
  final List<Pair<PsiElement, TextRange>> files = InjectedLanguageManager.getInstance(expression.getProject()).getInjectedPsiFiles(expression);
  if (files == null) {
    return null;
  }
  for (final Pair<PsiElement, TextRange> fileInfo : files) {
    final PsiElement injectedFile = fileInfo.first;
    if (classToFind.isAssignableFrom(injectedFile.getClass())) {
      return (T)injectedFile;
    }
  }
  return null;
}
 
Example 2
Source Project: consulo-unity3d   Source File: CGParserDefinition.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PsiFile createFile(FileViewProvider viewProvider)
{
	return new PsiFileBase(viewProvider, CGLanguage.INSTANCE)
	{
	};
}
 
Example 3
Source Project: consulo-csharp   Source File: CSharpFileFactory.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private static <T extends PsiElement> T parseFile(CharSequence text, Project project, Class<T> clazz, IElementType elementType)
{
	LightVirtualFile virtualFile = new LightVirtualFile("dummy.cs", CSharpFileType.INSTANCE, text, System.currentTimeMillis());
	SingleRootFileViewProvider viewProvider = new SingleRootFileViewProvider(PsiManager.getInstance(project), virtualFile, false);

	PsiFileBase file = new PsiFileBase(viewProvider, CSharpLanguage.INSTANCE)
	{
		{
			init(elementType, elementType);
		}
	};

	return PsiTreeUtil.findChildOfType(file, clazz);
}