com.intellij.psi.impl.source.resolve.FileContextUtil Java Examples

The following examples show how to use com.intellij.psi.impl.source.resolve.FileContextUtil. 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: HaxeParserWrapper.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: PsiBuilderImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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);
  }
}
 
Example #3
Source File: GeneratedParserUtilBase.java    From Intellij-Dust with MIT License 5 votes vote down vote up
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;
}
 
Example #4
Source File: PlatformPackageUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #5
Source File: InjectedLanguageManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #6
Source File: GeneratedParserUtilBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: BuildParserDefinition.java    From intellij with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #8
Source File: ResolveScopeManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #9
Source File: GeneratedParserUtilBase.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: GeneratedParserUtilBase.java    From intellij-latte with MIT License 5 votes vote down vote up
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;
}
 
Example #11
Source File: PsiBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T getUserData(@Nonnull Key<T> key) {
  return key == FileContextUtil.CONTAINING_FILE_KEY ? (T)myFile : super.getUserData(key);
}
 
Example #12
Source File: PsiFileImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public PsiElement getContext() {
  return FileContextUtil.getFileContext(this);
}
 
Example #13
Source File: PsiBinaryFileImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public PsiElement getContext() {
  return FileContextUtil.getFileContext(this);
}
 
Example #14
Source File: LiteFixture.java    From consulo with Apache License 2.0 4 votes vote down vote up
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));
  }
}
 
Example #15
Source File: LightPsiFileImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public PsiElement getContext() {
  return FileContextUtil.getFileContext(this);
}
 
Example #16
Source File: MockPsiFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public PsiElement getContext() {
  return FileContextUtil.getFileContext(this);
}
 
Example #17
Source File: InjectionRegistrarImpl.java    From consulo with Apache License 2.0 3 votes vote down vote up
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);
}