@SuppressWarnings("deprecation") @Override @NotNull public PsiElement getNavigationElement() { for (ClsCustomNavigationPolicy customNavigationPolicy : Extensions.getExtensions(ClsCustomNavigationPolicy.EP_NAME)) { if (customNavigationPolicy instanceof ClsCustomNavigationPolicyEx) { PsiFile navigationElement = ((ClsCustomNavigationPolicyEx)customNavigationPolicy).getFileNavigationElement(this); if (navigationElement != null) { return navigationElement; } } } return CachedValuesManager.getCachedValue(this, new CachedValueProvider<PsiElement>() { @Nullable @Override public Result<PsiElement> compute() { PsiElement target = JavaPsiImplementationHelper.getInstance(getProject()).getClsFileNavigationElement(ClsFileImpl.this); ModificationTracker tracker = FileIndexFacade.getInstance(getProject()).getRootModificationTracker(); return Result.create(target, ClsFileImpl.this, target.getContainingFile(), tracker); } }); }
private LanguageLevel getLanguageLevelInner() { if (myOriginalFile instanceof PsiJavaFile) { return ((PsiJavaFile)myOriginalFile).getLanguageLevel(); } LanguageLevel forcedLanguageLevel = getUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY); if (forcedLanguageLevel != null) return forcedLanguageLevel; VirtualFile virtualFile = getVirtualFile(); if (virtualFile == null) virtualFile = getUserData(IndexingDataKeys.VIRTUAL_FILE); final Project project = getProject(); if (virtualFile == null) { final PsiFile originalFile = getOriginalFile(); if (originalFile instanceof PsiJavaFile && originalFile != this) { return ((PsiJavaFile)originalFile).getLanguageLevel(); } return LanguageLevelProjectExtension.getInstance(project).getLanguageLevel(); } return JavaPsiImplementationHelper.getInstance(project).getEffectiveLanguageLevel(virtualFile); }
public JavaCoreProjectEnvironment(Disposable parentDisposable, CoreApplicationEnvironment applicationEnvironment) { super(parentDisposable, applicationEnvironment); myProject.registerService(PsiElementFactory.class, new PsiElementFactoryImpl(myPsiManager)); myProject.registerService(JavaPsiImplementationHelper.class, createJavaPsiImplementationHelper()); myProject.registerService(PsiResolveHelper.class, new PsiResolveHelperImpl(myPsiManager)); myProject.registerService(LanguageLevelProjectExtension.class, new CoreLanguageLevelProjectExtension()); myProject.registerService(JavaResolveCache.class, new JavaResolveCache(myMessageBus)); myProject.registerService(JavaCodeStyleSettingsFacade.class, new CoreJavaCodeStyleSettingsFacade()); myProject.registerService(JavaCodeStyleManager.class, new CoreJavaCodeStyleManager()); myPackageIndex = createCorePackageIndex(); myProject.registerService(PackageIndex.class, myPackageIndex); myFileManager = createCoreFileManager(); myProject.registerService(JavaFileManager.class, myFileManager); JavaPsiFacadeImpl javaPsiFacade = new JavaPsiFacadeImpl(myProject, myPsiManager, myFileManager, myMessageBus); myProject.registerService(JavaPsiFacade.class, javaPsiFacade); }
public JavaCoreProjectEnvironment(Disposable parentDisposable, CoreApplicationEnvironment applicationEnvironment) { super(parentDisposable, applicationEnvironment); myProject.registerService(PsiElementFactory.class, new PsiElementFactoryImpl(myPsiManager)); myProject.registerService(JavaPsiImplementationHelper.class, createJavaPsiImplementationHelper()); myProject.registerService(PsiResolveHelper.class, new PsiResolveHelperImpl(myPsiManager)); myProject.registerService(LanguageLevelProjectExtension.class, new CoreLanguageLevelProjectExtension()); myProject.registerService(JavaResolveCache.class, new JavaResolveCache(myMessageBus)); myProject.registerService(JavaCodeStyleSettingsFacade.class, new CoreJavaCodeStyleSettingsFacade()); myProject.registerService(JavaCodeStyleManager.class, new CoreJavaCodeStyleManager()); registerProjectExtensionPoint(PsiElementFinder.EP_NAME, PsiElementFinder.class); myPackageIndex = createCorePackageIndex(); myProject.registerService(PackageIndex.class, myPackageIndex); myFileManager = createCoreFileManager(); myProject.registerService(JavaFileManager.class, myFileManager); JavaPsiFacadeImpl javaPsiFacade = new JavaPsiFacadeImpl(myProject, myPsiManager, myFileManager, myMessageBus); registerProjectComponent(JavaPsiFacade.class, javaPsiFacade); myProject.registerService(JavaPsiFacade.class, javaPsiFacade); }
@Override public TreeElement addInternal(TreeElement first, ASTNode last, ASTNode anchor, Boolean before) { if(before == null) { if(first == last && (first.getElementType() == JavaElementType.IMPORT_STATEMENT || first.getElementType() == JavaElementType.IMPORT_STATIC_STATEMENT)) { final PsiImportList list = (PsiImportList) SourceTreeToPsiMap.treeElementToPsi(this); final PsiImportStatementBase statement = (PsiImportStatementBase) SourceTreeToPsiMap.treeElementToPsi(first); final JavaPsiImplementationHelper instance = JavaPsiImplementationHelper.getInstance(list.getProject()); if(instance != null) { anchor = instance.getDefaultImportAnchor(list, statement); } before = Boolean.TRUE; } } return super.addInternal(first, last, anchor, before); }
public JavaCoreProjectEnvironment(Disposable parentDisposable, CoreApplicationEnvironment applicationEnvironment) { super(parentDisposable, applicationEnvironment); myProject.registerService(PsiElementFactory.class, new PsiElementFactoryImpl(myPsiManager)); myProject.registerService(JavaPsiImplementationHelper.class, createJavaPsiImplementationHelper()); myProject.registerService(PsiResolveHelper.class, new PsiResolveHelperImpl(myPsiManager)); myProject.registerService(JavaResolveCache.class, new JavaResolveCache(myMessageBus)); myProject.registerService(JavaCodeStyleSettingsFacade.class, new CoreJavaCodeStyleSettingsFacade()); myProject.registerService(JavaCodeStyleManager.class, new CoreJavaCodeStyleManager()); registerProjectExtensionPoint(PsiElementFinder.EP_NAME, PsiElementFinder.class); /* myPackageIndex = createCorePackageIndex(); myProject.registerService(PackageIndex.class, myPackageIndex); */ myFileManager = createCoreFileManager(); myProject.registerService(JavaFileManager.class, myFileManager); PsiPackageManager manager = new PsiPackageManagerImpl(getProject(), DirectoryIndex.getInstance(getProject())); myProject.registerService(PsiPackageManager.class, manager); JavaPsiFacadeImpl javaPsiFacade = new JavaPsiFacadeImpl(myProject, manager); registerProjectComponent(JavaPsiFacade.class, javaPsiFacade); myProject.registerService(JavaPsiFacade.class, javaPsiFacade); }
@Override public TreeElement addInternal(TreeElement first, ASTNode last, ASTNode anchor, Boolean before){ if (before == null){ if (first == last && (first.getElementType() == JavaElementType.IMPORT_STATEMENT || first.getElementType() == JavaElementType.IMPORT_STATIC_STATEMENT)){ final PsiImportList list = (PsiImportList)SourceTreeToPsiMap.treeElementToPsi(this); final PsiImportStatementBase statement = (PsiImportStatementBase)SourceTreeToPsiMap.treeElementToPsi(first); final JavaPsiImplementationHelper instance = JavaPsiImplementationHelper.getInstance(list.getProject()); if (instance != null) { anchor = instance.getDefaultImportAnchor(list, statement); } before = Boolean.TRUE; } } return super.addInternal(first, last, anchor, before); }
@Override @NotNull public PsiElement getNavigationElement() { for (ClsCustomNavigationPolicy customNavigationPolicy : Extensions.getExtensions(ClsCustomNavigationPolicy.EP_NAME)) { if (customNavigationPolicy instanceof ClsCustomNavigationPolicyEx) { PsiFile navigationElement = ((ClsCustomNavigationPolicyEx)customNavigationPolicy).getFileNavigationElement(this); if (navigationElement != null) { return navigationElement; } } } return JavaPsiImplementationHelper.getInstance(getProject()).getClsFileNavigationElement(this); }
private LanguageLevel getLanguageLevelInner() { if (myOriginalFile instanceof PsiJavaFile) { return ((PsiJavaFile)myOriginalFile).getLanguageLevel(); } LanguageLevel forcedLanguageLevel = getUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY); if (forcedLanguageLevel != null) return forcedLanguageLevel; VirtualFile virtualFile = getVirtualFile(); if (virtualFile == null) virtualFile = getUserData(IndexingDataKeys.VIRTUAL_FILE); final Project project = getProject(); if (virtualFile == null) { final PsiFile originalFile = getOriginalFile(); if (originalFile instanceof PsiJavaFile && originalFile != this) { return ((PsiJavaFile)originalFile).getLanguageLevel(); } return LanguageLevelProjectExtension.getInstance(project).getLanguageLevel(); } final VirtualFile folder = virtualFile.getParent(); if (folder != null) { final LanguageLevel level = folder.getUserData(LanguageLevel.KEY); if (level != null) return level; } final LanguageLevel classesLanguageLevel = JavaPsiImplementationHelper.getInstance(project).getClassesLanguageLevel(virtualFile); if (classesLanguageLevel != null) { return classesLanguageLevel; } return PsiUtil.getLanguageLevel(project); }
@Override @NotNull @SuppressWarnings("deprecation") public PsiElement getNavigationElement() { for(ClsCustomNavigationPolicy customNavigationPolicy : Extensions.getExtensions(ClsCustomNavigationPolicy.EP_NAME)) { if(customNavigationPolicy instanceof ClsCustomNavigationPolicyEx) { try { PsiFile navigationElement = ((ClsCustomNavigationPolicyEx) customNavigationPolicy).getFileNavigationElement(this); if(navigationElement != null) { return navigationElement; } } catch(IndexNotReadyException ignore) { } } } return CachedValuesManager.getCachedValue(this, () -> { PsiElement target = JavaPsiImplementationHelper.getInstance(getProject()).getClsFileNavigationElement(this); ModificationTracker tracker = FileIndexFacade.getInstance(getProject()).getRootModificationTracker(); return CachedValueProvider.Result.create(target, this, target.getContainingFile(), tracker); }); }
@Override public PsiElement getOriginalElement() { return CachedValuesManager.getCachedValue(this, new CachedValueProvider<PsiClass>() { @Nullable @Override public Result<PsiClass> compute() { final JavaPsiImplementationHelper helper = JavaPsiImplementationHelper.getInstance(getProject()); final PsiClass result = helper != null ? helper.getOriginalClass(PsiClassImpl.this) : PsiClassImpl.this; return Result.create(result, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); } }); }
/** * SyntaxHighlighterFactory implementation (for Java source files). */ @Override @NotNull public SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile file) { return new JavaFileHighlighter(project == null ? LanguageLevel.HIGHEST : JavaPsiImplementationHelper.getInstance(project).getEffectiveLanguageLevel(file)); }
@Override public LanguageLevel getLanguageLevel(@NotNull PsiDirectory dir) { return JavaPsiImplementationHelper.getInstance(dir.getProject()).getEffectiveLanguageLevel(dir.getVirtualFile()); }
private LanguageLevel getLanguageLevelInner() { if(myOriginalFile instanceof PsiJavaFile) { return ((PsiJavaFile) myOriginalFile).getLanguageLevel(); } final LanguageLevel forcedLanguageLevel = getUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY); if(forcedLanguageLevel != null) { return forcedLanguageLevel; } VirtualFile virtualFile = getVirtualFile(); if(virtualFile == null) { virtualFile = getUserData(IndexingDataKeys.VIRTUAL_FILE); } final Project project = getProject(); if(virtualFile == null) { final PsiFile originalFile = getOriginalFile(); if(originalFile instanceof PsiJavaFile && originalFile != this) { return ((PsiJavaFile) originalFile).getLanguageLevel(); } final Module moduleForPsiElement = ModuleUtilCore.findModuleForPsiElement(originalFile); if(moduleForPsiElement != null) { return EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(moduleForPsiElement); } } else { final VirtualFile folder = virtualFile.getParent(); if(folder != null) { final LanguageLevel level = folder.getUserData(LanguageLevel.KEY); if(level != null) { return level; } } final LanguageLevel classesLanguageLevel = JavaPsiImplementationHelper.getInstance(project).getClassesLanguageLevel(virtualFile); if(classesLanguageLevel != null) { return classesLanguageLevel; } } return LanguageLevel.HIGHEST; }