@Nullable private static IProperty getResolvedProperty(@NotNull final XmlAttributeValue codeValue) { return CachedValuesManager.getCachedValue(codeValue, KEY, () -> { List<IProperty> allProperties = new SmartList<>(); for (PsiReference nextRef : codeValue.getReferences()) { if (nextRef instanceof PsiPolyVariantReference) { Arrays.stream(((PsiPolyVariantReference) nextRef).multiResolve(false)) .filter(ResolveResult::isValidResult) .map(ResolveResult::getElement) .map(o -> ObjectUtils.tryCast(o, IProperty.class)) .filter(Objects::nonNull) .forEach(allProperties::add); } else { Optional.ofNullable(nextRef.resolve()) .map(o -> ObjectUtils.tryCast(o, IProperty.class)) .ifPresent(allProperties::add); } } IProperty theChosenOne = chooseForLocale(allProperties); return new CachedValueProvider.Result<>(theChosenOne, PsiModificationTracker.MODIFICATION_COUNT); }); }
public PsiDisjunctionType(@NotNull List<PsiType> types, @NotNull PsiManager psiManager) { super(PsiAnnotation.EMPTY_ARRAY); myManager = psiManager; myTypes = Collections.unmodifiableList(types); myLubCache = CachedValuesManager.getManager(myManager.getProject()).createCachedValue(new CachedValueProvider<PsiType>() { @Override public Result<PsiType> compute() { PsiType lub = myTypes.get(0); for (int i = 1; i < myTypes.size(); i++) { lub = GenericsUtil.getLeastUpperBound(lub, myTypes.get(i), myManager); if (lub == null) { lub = PsiType.getJavaLangObject(myManager, GlobalSearchScope.allScope(myManager.getProject())); break; } } return Result.create(lub, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); } }, false); }
@NotNull public static List<MethodContract> inferContracts(@NotNull final PsiMethod method) { if (!InferenceFromSourceUtil.shouldInferFromSource(method)) { return Collections.emptyList(); } return CachedValuesManager.getCachedValue(method, new CachedValueProvider<List<MethodContract>>() { @Nullable @Override public Result<List<MethodContract>> compute() { List<MethodContract> result = RecursionManager.doPreventingRecursion(method, true, new Computable<List<MethodContract>>() { @Override public List<MethodContract> compute() { return new ContractInferenceInterpreter(method).inferContracts(); } }); if (result == null) result = Collections.emptyList(); return Result.create(result, method, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); } }); }
public static Nullness inferNullity(final PsiMethod method) { if (!InferenceFromSourceUtil.shouldInferFromSource(method)) { return Nullness.UNKNOWN; } PsiType type = method.getReturnType(); if (type == null || type instanceof PsiPrimitiveType) { return Nullness.UNKNOWN; } return CachedValuesManager.getCachedValue(method, new CachedValueProvider<Nullness>() { @Nullable @Override public Result<Nullness> compute() { Nullness result = RecursionManager.doPreventingRecursion(method, true, new Computable<Nullness>() { @Override public Nullness compute() { return doInferNullity(method); } }); if (result == null) result = Nullness.UNKNOWN; return Result.create(result, method, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); } }); }
public void testClassShouldNotAppearWithoutEvents_WithoutPsi() throws IOException { final GlobalSearchScope allScope = GlobalSearchScope.allScope(getProject()); final JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject()); final PsiManager psiManager = PsiManager.getInstance(getProject()); final PsiModificationTracker tracker = psiManager.getModificationTracker(); final VirtualFile file = myFixture.getTempDirFixture().createFile("Foo.java", ""); final Document document = FileDocumentManager.getInstance().getDocument(file); assertNotNull(document); assertNull(facade.findClass("Foo", allScope)); long count1 = tracker.getJavaStructureModificationCount(); PlatformTestUtil.tryGcSoftlyReachableObjects(); assertNull(PsiDocumentManager.getInstance(getProject()).getCachedPsiFile(document)); document.insertString(0, "class Foo {}"); assertFalse(count1 == tracker.getJavaStructureModificationCount()); assertTrue(PsiDocumentManager.getInstance(getProject()).isCommitted(document)); assertNotNull(facade.findClass("Foo", allScope)); PsiJavaFile psiFile = (PsiJavaFile)psiManager.findFile(file); assertSize(1, psiFile.getClasses()); assertEquals("class Foo {}", psiFile.getText()); assertEquals("class Foo {}", psiFile.getNode().getText()); }
public void testClassShouldNotDisappearWithoutEvents_NoDocument() throws IOException { PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker(); final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject()); final VirtualFile file = myFixture.addFileToProject("Foo.java", "class Foo {}").getVirtualFile(); assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject()))); long count1 = tracker.getJavaStructureModificationCount(); // gc softly-referenced file and document PlatformTestUtil.tryGcSoftlyReachableObjects(); assertNull(FileDocumentManager.getInstance().getCachedDocument(file)); assertNull(psiManager.getFileManager().getCachedPsiFile(file)); VfsUtil.saveText(file, ""); assertNull(FileDocumentManager.getInstance().getCachedDocument(file)); assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject()))); assertFalse(count1 == tracker.getJavaStructureModificationCount()); }
public void testClassShouldNotDisappearWithoutEvents_VirtualFileDeleted() throws IOException { PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker(); final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject()); final VirtualFile file = myFixture.addFileToProject("Foo.java", "class Foo {}").getVirtualFile(); assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject()))); long count1 = tracker.getJavaStructureModificationCount(); // gc softly-referenced file and document PlatformTestUtil.tryGcSoftlyReachableObjects(); assertNull(FileDocumentManager.getInstance().getCachedDocument(file)); assertNull(psiManager.getFileManager().getCachedPsiFile(file)); file.delete(this); assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject()))); assertFalse(count1 == tracker.getJavaStructureModificationCount()); }
public void testClassShouldNotDisappearWithoutEvents_ParentVirtualDirectoryDeleted() throws IOException { PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker(); final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject()); final VirtualFile file = myFixture.addFileToProject("foo/Foo.java", "package foo; class Foo {}").getVirtualFile(); assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", GlobalSearchScope.allScope(getProject()))); long count1 = tracker.getJavaStructureModificationCount(); // gc softly-referenced file and document PlatformTestUtil.tryGcSoftlyReachableObjects(); assertNull(FileDocumentManager.getInstance().getCachedDocument(file)); assertNull(psiManager.getFileManager().getCachedPsiFile(file)); file.getParent().delete(this); assertNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", GlobalSearchScope.allScope(getProject()))); assertFalse(count1 == tracker.getJavaStructureModificationCount()); }
public void testVirtualFileRename_WithPsi() throws IOException { PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker(); final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject()); GlobalSearchScope scope = GlobalSearchScope.allScope(getProject()); final VirtualFile file = myFixture.addFileToProject("foo/Foo.java", "package foo; class Foo {}").getVirtualFile(); assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", scope)); long count1 = tracker.getModificationCount(); long hc = psiManager.findFile(file).hashCode(); long stamp1 = psiManager.findFile(file).getModificationStamp(); file.rename(this, "Bar.java"); assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", scope)); assertTrue(count1 != tracker.getModificationCount()); assertTrue(stamp1 != psiManager.findFile(file).getModificationStamp()); assertEquals(hc, psiManager.findFile(file).hashCode()); }
@Override public CachedValueProvider.Result<MultiHostRegistrarImpl> compute(PsiElement element) { PsiFile hostPsiFile = element.getContainingFile(); if (hostPsiFile == null) return null; FileViewProvider viewProvider = hostPsiFile.getViewProvider(); final DocumentEx hostDocument = (DocumentEx)viewProvider.getDocument(); if (hostDocument == null) return null; PsiManager psiManager = viewProvider.getManager(); final Project project = psiManager.getProject(); InjectedLanguageManagerImpl injectedManager = InjectedLanguageManagerImpl.getInstanceImpl(project); final MultiHostRegistrarImpl result = doCompute(element, injectedManager, project, hostPsiFile); return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT, hostDocument); }
private DomElementsProblemsHolderImpl _getOrCreateProblemsHolder(final DomFileElement element) { DomElementsProblemsHolderImpl holder; final DomElement rootElement = element.getRootElement(); final XmlTag rootTag = rootElement.getXmlTag(); if (rootTag == null) return new DomElementsProblemsHolderImpl(element); holder = rootTag.getUserData(DOM_PROBLEM_HOLDER_KEY); if (isHolderOutdated(element.getFile()) || holder == null) { holder = new DomElementsProblemsHolderImpl(element); rootTag.putUserData(DOM_PROBLEM_HOLDER_KEY, holder); final CachedValue<Boolean> cachedValue = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<Boolean>() { @Override public Result<Boolean> compute() { return new Result<Boolean>(Boolean.FALSE, element, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, DomElementAnnotationsManagerImpl.this, ProjectRootManager.getInstance(myProject)); } }, false); cachedValue.getValue(); element.getFile().putUserData(CACHED_VALUE_KEY, cachedValue); } return holder; }
@Override public Object invoke(final DomInvocationHandler<?, ?> handler, final Object[] args) throws Throwable { if (myConverter == Converter.EMPTY_CONVERTER) { return getValueInner(handler, myConverter); } CachedValue<List<Pair<Converter,Object>>> value = handler.getUserData(DOM_VALUE_KEY); if (value == null) { final DomManagerImpl domManager = handler.getManager(); final Project project = domManager.getProject(); final CachedValuesManager cachedValuesManager = CachedValuesManager.getManager(project); handler.putUserData(DOM_VALUE_KEY, value = cachedValuesManager.createCachedValue(new CachedValueProvider<List<Pair<Converter,Object>>>() { @Override public Result<List<Pair<Converter,Object>>> compute() { List<Pair<Converter, Object>> list = ContainerUtil.createLockFreeCopyOnWriteList(); return Result .create(list, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, domManager, ProjectRootManager.getInstance(project)); } }, false)); } return getOrCalcValue(handler, value.getValue()); }
private CachedValue<TypeDescriptor> createAndPutTypesCachedValue(final XmlTag tag, final Pair<QNameKey, XmlTag> pair) { final CachedValue<TypeDescriptor> value = CachedValuesManager.getManager(tag.getProject()).createCachedValue( new CachedValueProvider<TypeDescriptor>() { @Override public CachedValueProvider.Result<TypeDescriptor> compute() { final String name = tag.getAttributeValue("name"); if (name != null && pair.first != null && pair.first.first != null && !name.equals(XmlUtil.findLocalNameByQualifiedName(pair.first.first)) ) { myTypesMap.remove(pair); return new Result<TypeDescriptor>(null, PsiModificationTracker.MODIFICATION_COUNT); } final ComplexTypeDescriptor complexTypeDescriptor = new ComplexTypeDescriptor(XmlNSDescriptorImpl.this, tag); return new Result<TypeDescriptor>(complexTypeDescriptor, tag); } }, false); myTypesMap.put(pair, value); return value; }
@NotNull public Map<String, PsiClass> getClassMap(@NotNull final String className, @NotNull final ClassMapConstructor constructor) { synchronized (myClassMapLock) { CachedValue<Map<String, PsiClass>> value = myClassMaps.get(className); if (value == null) { value = CachedValuesManager.getManager(getModule().getProject()).createCachedValue( new CachedValueProvider<Map<String, PsiClass>>() { @Nullable @Override public Result<Map<String, PsiClass>> compute() { Map<String, PsiClass> map = computeClassMap(className, constructor); return Result.create(map, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); } }, false); myClassMaps.put(className, value); } return value.getValue(); } }
@NotNull public static GrGdkMethod createGdkMethod(@NotNull final PsiMethod original, final boolean isStatic, @Nullable final String originInfo) { final Key<CachedValue<GrGdkMethodImpl>> cachedValueKey = isStatic ? CACHED_STATIC : CACHED_NON_STATIC; CachedValue<GrGdkMethodImpl> cachedValue = original.getUserData(cachedValueKey); if (cachedValue == null) { cachedValue = CachedValuesManager.getManager(original.getProject()).createCachedValue(new CachedValueProvider<GrGdkMethodImpl>() { @Override public Result<GrGdkMethodImpl> compute() { return Result.create(new GrGdkMethodImpl(original, isStatic, originInfo), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); } }); original.putUserData(cachedValueKey, cachedValue); } return cachedValue.getValue(); }
private PsiVariable getOwner() { return CachedValuesManager.getCachedValue(this, new CachedValueProvider<PsiVariable>() { @Override public Result<PsiVariable> compute() { final GroovyPsiElement context = PsiTreeUtil.getParentOfType(GrClosableBlockImpl.this, GrTypeDefinition.class, GrClosableBlock.class, GroovyFile.class); final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); PsiType type = null; if (context instanceof GrTypeDefinition) { type = factory.createType((PsiClass)context); } else if (context instanceof GrClosableBlock) { type = GrClosureType.create((GrClosableBlock)context, true); } else if (context instanceof GroovyFile) { final PsiClass scriptClass = ((GroovyFile)context).getScriptClass(); if (scriptClass != null && GroovyNamesUtil.isIdentifier(scriptClass.getName())) type = factory.createType(scriptClass); } if (type == null) { type = TypesUtil.getJavaLangObject(GrClosableBlockImpl.this); } PsiVariable owner = new GrLightVariable(getManager(), OWNER_NAME, type, GrClosableBlockImpl.this); return Result.create(owner, PsiModificationTracker.MODIFICATION_COUNT); } }); }
private static boolean containsGroovyClasses(final Project project) { return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Boolean>() { @Nullable @Override public Result<Boolean> compute() { AccessToken accessToken = ReadAction.start(); try { return Result.create(FileTypeIndex.containsFileOfType(GroovyFileType.GROOVY_FILE_TYPE, GlobalSearchScope.projectScope(project)), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); } finally { accessToken.finish(); } } }); }
@NotNull public static Collection<ServiceResource> getIndexedBootstrapResources(@NotNull Project project) { // cache CachedValue<Collection<ServiceResource>> cache = project.getUserData(SERVICE_RESOURCE); if (cache == null) { cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create( getIndexedBootstrapResources(project, BootstrapResource.INIT_RESOURCE, BootstrapResource.AFTER_INIT_RESOURCE, BootstrapResource.AFTER_REGISTER_RESOURCE), PsiModificationTracker.MODIFICATION_COUNT ), false); project.putUserData(SERVICE_RESOURCE, cache); } return cache.getValue(); }
@Override @NotNull public Collection<String> getGlobalNamespaces(@NotNull AnnotationGlobalNamespacesLoaderParameter parameter) { Project project = parameter.getProject(); CachedValue<Collection<String>> cache = project.getUserData(CACHE); if(cache == null) { cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(getGlobalNamespacesInner(project), PsiModificationTracker.MODIFICATION_COUNT), false ); project.putUserData(CACHE, cache); } return cache.getValue(); }
@NotNull public static DefracProject forSettings(@NotNull final Project project, @NotNull final VirtualFile settings) { final PsiManager psiManager = PsiManager.getInstance(project); final PsiFile file = checkNotNull(psiManager.findFile(settings)); @SuppressWarnings("UnnecessaryLocalVariable") final DefracProject result = CachedValuesManager.getCachedValue(file, new CachedValueProvider<DefracProject>() { @NotNull public Result<DefracProject> compute() { return Result.create( new DefracProject(settings), file, PsiModificationTracker.MODIFICATION_COUNT ); } }); // NOTE: We need to clear the modules here since the DefracViewProjectNode has // no clue about the fact that we cache DefracProject instances and happily // adds modules -- we keep the cached name though since it shall be invalidated // by IntelliJ's internal mechanisms result.modules.clear(); return result; }
@NotNull public static DefracProjectPlatform create(@NotNull final Project project, @NotNull final DefracProject defracProject, @NotNull final DefracPlatform platform) { final PsiManager psiManager = PsiManager.getInstance(project); final PsiFile psiFile = checkNotNull(psiManager.findFile(defracProject.getVirtualFile())); @SuppressWarnings("UnnecessaryLocalVariable") final ConcurrentMap<DefracPlatform, DefracProjectPlatform> result = CachedValuesManager. getCachedValue(psiFile, new CachedValueProvider<ConcurrentMap<DefracPlatform, DefracProjectPlatform>>() { @NotNull public Result<ConcurrentMap<DefracPlatform, DefracProjectPlatform>> compute() { return Result.create( Maps.<DefracPlatform, DefracProjectPlatform>newConcurrentMap(), psiFile, PsiModificationTracker.MODIFICATION_COUNT ); } }); final DefracProjectPlatform newValue = new DefracProjectPlatform(defracProject, platform); final DefracProjectPlatform oldValue = result.putIfAbsent(platform, newValue); return oldValue == null ? newValue : oldValue; }
@NotNull public PsiMethod[] getConstructors() { CachedValue<PsiMethod[]> cache = myConstructorsCache; if (cache == null) { final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject()); final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker}; myConstructorsCache = cache = manager.createCachedValue(new CachedValueProvider<PsiMethod[]>() { @Override public Result<PsiMethod[]> compute() { return Result.create(PsiImplUtil.getConstructors(myClass), dependencies); } }, false); } final PsiMethod[] constructors = cache.getValue(); return constructors != null ? constructors : PsiMethod.EMPTY_ARRAY; }
@NotNull public PsiField[] getFields() { CachedValue<PsiField[]> cache = myFieldsCache; if (cache == null) { final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject()); final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker}; myFieldsCache = cache = manager.createCachedValue(new CachedValueProvider<PsiField[]>() { @Override public Result<PsiField[]> compute() { return Result.create(getAllFields(), dependencies); } }, false); } final PsiField[] fields = cache.getValue(); return fields != null ? fields : PsiField.EMPTY_ARRAY; }
@NotNull public PsiMethod[] getMethods() { CachedValue<PsiMethod[]> cache = myMethodsCache; if (cache == null) { final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject()); final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker}; myMethodsCache = cache = manager.createCachedValue(new CachedValueProvider<PsiMethod[]>() { @Override public Result<PsiMethod[]> compute() { return Result.create(getAllMethods(), dependencies); } }, false); } final PsiMethod[] methods = cache.getValue(); return methods != null ? methods : PsiMethod.EMPTY_ARRAY; }
@NotNull public PsiClass[] getInnerClasses() { CachedValue<PsiClass[]> cache = myInnerClassesCache; if (cache == null) { final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject()); final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker}; myInnerClassesCache = cache = manager.createCachedValue(new CachedValueProvider<PsiClass[]>() { @Override public Result<PsiClass[]> compute() { return Result.create(getAllInnerClasses(), dependencies); } }, false); } final PsiClass[] classes = cache.getValue(); return classes != null ? classes : PsiClass.EMPTY_ARRAY; }
@Nullable public PsiField findFieldByName(final String name, final boolean checkBases) { if (!checkBases) { CachedValue<Map<String, PsiField>> cache = myFieldsMapCache; if (cache == null) { final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject()); final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker}; myFieldsMapCache = cache = manager.createCachedValue(new CachedValueProvider<Map<String, PsiField>>() { @Override public Result<Map<String, PsiField>> compute() { return Result.create(getFieldsMap(), dependencies); } }, false); } final Map<String, PsiField> cachedFields = cache.getValue(); return cachedFields != null ? cachedFields.get(name) : null; } return PsiClassImplUtil.findFieldByName(myClass, name, checkBases); }
@NotNull public PsiMethod[] findMethodsByName(final String name, final boolean checkBases) { if (!checkBases) { CachedValue<Map<String, List<PsiMethod>>> cache = myMethodsMapCache; if (cache == null) { final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject()); final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker}; myMethodsMapCache = cache = manager.createCachedValue(new CachedValueProvider<Map<String, List<PsiMethod>>>() { @Override public Result<Map<String, List<PsiMethod>>> compute() { return Result.create(getMethodsMap(), dependencies); } }, false); } final Map<String, List<PsiMethod>> cachedMethods = cache.getValue(); if (cachedMethods != null) { final List<PsiMethod> methods = cachedMethods.get(name); if (methods != null && !methods.isEmpty()) { return methods.toArray(new PsiMethod[methods.size()]); } } return PsiMethod.EMPTY_ARRAY; } return PsiClassImplUtil.findMethodsByName(myClass, name, checkBases); }
@Nullable public PsiClass findInnerClassByName(final String name, final boolean checkBases) { if (!checkBases) { CachedValue<Map<String, PsiClass>> cache = myInnerClassesMapCache; if (cache == null) { final CachedValuesManager manager = CachedValuesManager.getManager(myClass.getProject()); final Object[] dependencies = {PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTreeChangeTracker}; myInnerClassesMapCache = cache = manager.createCachedValue(new CachedValueProvider<Map<String, PsiClass>>() { @Override public Result<Map<String, PsiClass>> compute() { return Result.create(getInnerClassesMap(), dependencies); } }, false); } final Map<String, PsiClass> inners = cache.getValue(); return inners != null ? inners.get(name) : null; } return PsiClassImplUtil.findInnerByName(myClass, name, checkBases); }
private boolean suppress(final PsiElement element, final SuppressIntentionAction action) { final PsiModificationTracker tracker = PsiManager.getInstance(myProject).getModificationTracker(); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { PsiDocumentManager.getInstance(myProject).commitAllDocuments(); try { final long startModificationCount = tracker.getModificationCount(); if (action.isAvailable(myProject, null, element)) { action.invoke(myProject, null, element); } if (startModificationCount != tracker.getModificationCount()) { final Set<GlobalInspectionContextImpl> globalInspectionContexts = myManager.getRunningContexts(); for (GlobalInspectionContextImpl context : globalInspectionContexts) { context.ignoreElement(myToolWrapper.getTool(), element); } } } catch (IncorrectOperationException e1) { LOG.error(e1); } } }); return true; }
@Override public CachedValueProvider.Result<MultiHostRegistrarImpl> compute(PsiElement element) { PsiFile hostPsiFile = element.getContainingFile(); if (hostPsiFile == null) return null; FileViewProvider viewProvider = hostPsiFile.getViewProvider(); final DocumentEx hostDocument = (DocumentEx)viewProvider.getDocument(); if (hostDocument == null) return null; PsiManager psiManager = viewProvider.getManager(); final Project project = psiManager.getProject(); InjectedLanguageManagerImpl injectedManager = InjectedLanguageManagerImpl.getInstanceImpl(project); if (injectedManager == null) return null; //for tests final MultiHostRegistrarImpl result = doCompute(element, injectedManager, project, hostPsiFile); return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT, hostDocument); }
private DomElementsProblemsHolderImpl _getOrCreateProblemsHolder(final DomFileElement element) { DomElementsProblemsHolderImpl holder; final DomElement rootElement = element.getRootElement(); final XmlTag rootTag = rootElement.getXmlTag(); if (rootTag == null) return new DomElementsProblemsHolderImpl(element); holder = rootTag.getUserData(DOM_PROBLEM_HOLDER_KEY); if (isHolderOutdated(element.getFile()) || holder == null) { holder = new DomElementsProblemsHolderImpl(element); rootTag.putUserData(DOM_PROBLEM_HOLDER_KEY, holder); final CachedValue<Boolean> cachedValue = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<Boolean>() { @Override public Result<Boolean> compute() { return new Result<Boolean>(Boolean.FALSE, element, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myModificationTracker, ProjectRootManager.getInstance(myProject)); } }, false); cachedValue.getValue(); element.getFile().putUserData(CACHED_VALUE_KEY, cachedValue); } return holder; }
@NotNull public static PsiClass getSubstitutedClass(@NotNull final PsiClass base) { if (!Extensions.getRootArea().getExtensionPoint(EP_NAME).hasAnyExtensions()) { return base; } if (base instanceof GrClassSubstitution) { return base; } return CachedValuesManager.getManager(base.getProject()) .getCachedValue(base, SUBSTITUTED_CLASS_KEY, new CachedValueProvider<PsiClass>() { public Result<PsiClass> compute() { for (GrClassSubstitutor enhancer : GrClassSubstitutor.EP_NAME.getExtensions()) { final PsiClass type = enhancer.substituteClass(base); if (type != null) { return Result.create(type, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); } } return Result.create(base, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); } }, false); }
/** * @param call * @return (type[1] in which methods mixed, reference to type[1], type[2] to mixin) */ @Nullable private static Trinity<PsiClassType, GrReferenceExpression, PsiClass> getMixinTypes(final GrStatement statement) { if (!(statement instanceof GrMethodCall)) return null; final CachedValuesManager manager = CachedValuesManager.getManager(statement.getProject()); return manager.getCachedValue(statement, new CachedValueProvider<Trinity<PsiClassType, GrReferenceExpression, PsiClass>>() { @Nullable @Override public Result<Trinity<PsiClassType, GrReferenceExpression, PsiClass>> compute() { GrMethodCall call = (GrMethodCall)statement; Pair<PsiClassType, GrReferenceExpression> original = getTypeToMixIn(call); if (original == null) return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT); PsiClass mix = getTypeToMix(call); if (mix == null) return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT); return Result.create(new Trinity<PsiClassType, GrReferenceExpression, PsiClass>(original.first, original.second, mix), PsiModificationTracker.MODIFICATION_COUNT); } }); }
private static List<PsiMember> getAllStaticMembers(final PsiClass clazz) { return CachedValuesManager.getManager(clazz.getProject()).getCachedValue(clazz, new CachedValueProvider<List<PsiMember>>() { @Nullable @Override public Result<List<PsiMember>> compute() { List<PsiMember> result = ContainerUtil.newArrayList(); for (PsiMethod method : clazz.getAllMethods()) { if (method.hasModifierProperty(PsiModifier.STATIC)) { result.add(method); } } for (PsiField field : clazz.getAllFields()) { if (field.hasModifierProperty(PsiModifier.STATIC)) { result.add(field); } } for (PsiClass inner : clazz.getAllInnerClasses()) { if (inner.hasModifierProperty(PsiModifier.STATIC)) { result.add(inner); } } return Result.create(result, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT, clazz); } }); }
private PsiVariable getOwner() { return CachedValuesManager.getManager(getProject()).getCachedValue(this, new CachedValueProvider<PsiVariable>() { @Override public Result<PsiVariable> compute() { final GroovyPsiElement context = PsiTreeUtil.getParentOfType(GrClosableBlockImpl.this, GrTypeDefinition.class, GrClosableBlock.class, GroovyFile.class); final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); PsiType type = null; if (context instanceof GrTypeDefinition) { type = factory.createType((PsiClass)context); } else if (context instanceof GrClosableBlock) { type = GrClosureType.create((GrClosableBlock)context, true); } else if (context instanceof GroovyFile) { final PsiClass scriptClass = ((GroovyFile)context).getScriptClass(); if (scriptClass != null && GroovyNamesUtil.isIdentifier(scriptClass.getName())) type = factory.createType(scriptClass); } if (type == null) { type = TypesUtil.getJavaLangObject(GrClosableBlockImpl.this); } PsiVariable owner = new GrLightVariable(getManager(), OWNER_NAME, type, GrClosableBlockImpl.this); return Result.create(owner, PsiModificationTracker.MODIFICATION_COUNT); } }); }
public static Set<LightMethodBuilder> getAntTasks(PsiElement place) { final PsiFile file = place.getContainingFile(); if (!(file instanceof GroovyFile)) { return Collections.emptySet(); } return CachedValuesManager.getManager(file.getProject()).getCachedValue(file, GANT_METHODS, new CachedValueProvider<Set<LightMethodBuilder>>() { @Override public Result<Set<LightMethodBuilder>> compute() { Map<String, Class> antObjects = getAntObjects((GroovyFile)file); final Set<LightMethodBuilder> methods = new HashSet<LightMethodBuilder>(); final Project project = file.getProject(); final PsiType closureType = TypesUtil.createType(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, file); final PsiClassType stringType = TypesUtil.createType(CommonClassNames.JAVA_LANG_STRING, file); for (String name : antObjects.keySet()) { methods.add(new AntBuilderMethod(file, name, closureType, antObjects.get(name), stringType)); } return Result.create(methods, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT, ProjectRootManager.getInstance(project)); } }, false); }
@NotNull @RequiredReadAction public static EnumSet<CSharpModifier> getModifiersCached(@NotNull CSharpModifierList modifierList) { if(!modifierList.isValid()) { return emptySet; } return CachedValuesManager.getCachedValue(modifierList, () -> { Set<CSharpModifier> modifiers = new THashSet<>(); for(CSharpModifier modifier : CSharpModifier.values()) { if(hasModifier(modifierList, modifier)) { modifiers.add(modifier); } } return CachedValueProvider.Result.create(modifiers.isEmpty() ? emptySet : EnumSet.copyOf(modifiers), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); }); }
@RequiredReadAction @NotNull @Override public DotNetTypeRef[] getExtendTypeRefs() { return CachedValuesManager.getCachedValue(this, new CachedValueProvider<DotNetTypeRef[]>() { @Nullable @Override @RequiredReadAction public Result<DotNetTypeRef[]> compute() { DotNetTypeRef[] extendTypeRefs = CSharpTypeDeclarationImplUtil.getExtendTypeRefs(CSharpTypeDeclarationImpl.this); return Result.create(extendTypeRefs, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); } }); }