下面列出了怎么用com.intellij.psi.impl.source.resolve.FileContextUtil的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public ASTNode parse(IElementType t, PsiBuilder b) {
if (debugging) {
HaxeDebugTimeLog timeLog = null;
// The file is attached to the user data. :/ I suspect this was a hack, but it's what we've got available.
PsiFile file = b.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
String description = null != file ? file.getName() : t.toString();
timeLog = HaxeDebugTimeLog.startNew("HaxeParser " + description, HaxeDebugTimeLog.Since.StartAndPrevious);
ASTNode node = super.parse(t, b);
timeLog.stamp("Finished parsing.");
timeLog.printIfTimeExceeds(20 /* milliseconds */);
return node;
}
return super.parse(t,b);
}
@Override
public ASTNode parse(IElementType root, PsiBuilder builder) {
if (debug.getValue()) {
System.err.println(builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY));
}
PsiBuilder.Marker rootMarker = builder.mark();
ParsingContext context = new ParsingContext(builder);
context.statementParser.parseFileInput();
rootMarker.done(root);
return builder.getTreeBuilt();
}
public static void initState(ErrorState state, PsiBuilder builder, IElementType root, TokenSet[] extendsSets) {
state.extendsSets = extendsSets;
PsiFile file = builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY);
Language language = file == null? root.getLanguage() : file.getLanguage();
state.caseSensitive = language.isCaseSensitive();
PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(language);
state.braces = matcher == null ? null : matcher.getPairs();
if (state.braces != null && state.braces.length == 0) state.braces = null;
}
public static void initState(ErrorState state, PsiBuilder builder, IElementType root, TokenSet[] extendsSets) {
state.extendsSets = extendsSets;
PsiFile file = builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY);
Language language = file == null? root.getLanguage() : file.getLanguage();
state.caseSensitive = language.isCaseSensitive();
PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(language);
state.braces = matcher == null ? null : matcher.getPairs();
if (state.braces != null && state.braces.length == 0) state.braces = null;
}
@Override
@Nonnull
public GlobalSearchScope getResolveScope(@Nonnull PsiElement element) {
ProgressIndicatorProvider.checkCanceled();
VirtualFile vFile;
final PsiFile contextFile;
if (element instanceof PsiDirectory) {
vFile = ((PsiDirectory)element).getVirtualFile();
contextFile = null;
}
else {
final PsiFile containingFile = element.getContainingFile();
if (containingFile instanceof PsiCodeFragment) {
final GlobalSearchScope forcedScope = ((PsiCodeFragment)containingFile).getForcedResolveScope();
if (forcedScope != null) {
return forcedScope;
}
final PsiElement context = containingFile.getContext();
if (context == null) {
return GlobalSearchScope.allScope(myProject);
}
return getResolveScope(context);
}
contextFile = containingFile != null ? FileContextUtil.getContextFile(containingFile) : null;
if (contextFile == null) {
return GlobalSearchScope.allScope(myProject);
}
else if (contextFile instanceof FileResolveScopeProvider) {
return ((FileResolveScopeProvider)contextFile).getFileResolveScope();
}
vFile = contextFile.getOriginalFile().getVirtualFile();
}
if (vFile == null || contextFile == null) {
return GlobalSearchScope.allScope(myProject);
}
return myDefaultResolveScopesCache.get(vFile);
}
@Override
public <T> void putUserData(@Nonnull Key<T> key, @Nullable T value) {
if (key == FileContextUtil.CONTAINING_FILE_KEY) {
myFile = (PsiFile)value;
}
else {
super.putUserData(key, value);
}
}
public static void initState(ErrorState state, PsiBuilder builder, IElementType root, TokenSet[] extendsSets) {
state.extendsSets = extendsSets;
PsiFile file = builder.getUserData(FileContextUtil.CONTAINING_FILE_KEY);
state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY);
Language language = file == null? root.getLanguage() : file.getLanguage();
state.caseSensitive = language.isCaseSensitive();
PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(language);
state.braces = matcher == null ? null : matcher.getPairs();
if (state.braces != null && state.braces.length == 0) state.braces = null;
}
@Override
public PsiLanguageInjectionHost getInjectionHost(@Nonnull PsiElement injectedElement) {
final PsiFile file = injectedElement.getContainingFile();
final VirtualFile virtualFile = file == null ? null : file.getVirtualFile();
if (virtualFile instanceof VirtualFileWindow) {
PsiElement host = FileContextUtil.getFileContext(file); // use utility method in case the file's overridden getContext()
if (host instanceof PsiLanguageInjectionHost) {
return (PsiLanguageInjectionHost)host;
}
}
return null;
}
@Nullable
public static PsiDirectory getDirectory(@Nullable PsiElement element) {
if (element == null) return null;
// handle injection and fragment editor
PsiFile file = FileContextUtil.getContextFile(element);
return file == null ? null : file.getContainingDirectory();
}
private static void initState(IElementType root, PsiBuilder builder, ErrorState state) {
PsiFile file = builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY);
Language language = file == null? root.getLanguage() : file.getLanguage();
state.caseSensitive = language.isCaseSensitive();
ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
if (parserDefinition != null) {
state.commentTokens = parserDefinition.getCommentTokens();
state.whitespaceTokens = parserDefinition.getWhitespaceTokens();
}
PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(language);
state.braces = matcher == null ? null : matcher.getPairs();
if (state.braces != null && state.braces.length == 0) state.braces = null;
}
@Override
public PsiElement getContext() {
return FileContextUtil.getFileContext(this);
}
public static void setContext(final PsiFile psiFile, final PsiElement context) {
if (context != null) {
psiFile.putUserData(FileContextUtil.INJECTED_IN_ELEMENT, SmartPointerManager.getInstance(context.getProject()).createSmartPsiElementPointer(context));
}
}
@Override
@SuppressWarnings("unchecked")
public <T> T getUserData(@Nonnull Key<T> key) {
return key == FileContextUtil.CONTAINING_FILE_KEY ? (T)myFile : super.getUserData(key);
}
@Override
public PsiElement getContext() {
return FileContextUtil.getFileContext(this);
}
@Override
public PsiElement getContext() {
return FileContextUtil.getFileContext(this);
}
@Override
public PsiElement getContext() {
return FileContextUtil.getFileContext(this);
}
private static boolean cacheEverything(@Nonnull Place place, @Nonnull DocumentWindowImpl documentWindow, @Nonnull InjectedFileViewProvider viewProvider, @Nonnull PsiFile psiFile) {
FileDocumentManagerImpl.registerDocument(documentWindow, viewProvider.getVirtualFile());
DebugUtil.performPsiModification("MultiHostRegistrar cacheEverything", () -> viewProvider.forceCachedPsi(psiFile));
SmartPsiElementPointer<PsiLanguageInjectionHost> pointer = ((ShredImpl)place.get(0)).getSmartPointer();
psiFile.putUserData(FileContextUtil.INJECTED_IN_ELEMENT, pointer);
keepTreeFromChameleoningBack(psiFile);
return viewProvider.setShreds(place);
}