Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ public void processNames(@NotNull Processor<String> processor, @NotNull GlobalSe
}

// Twig Extensions
TwigExtensionParser twigExtensionParser = new TwigExtensionParser(project);
for (Map<String, TwigExtension> extensionMap : Arrays.asList(twigExtensionParser.getFilters(), twigExtensionParser.getFunctions())) {
for (Map<String, TwigExtension> extensionMap : Arrays.asList(TwigExtensionParser.getFilters(project), TwigExtensionParser.getFunctions(project))) {
for(String twigFilter: extensionMap.keySet()) {
processor.process(twigFilter);
}
Expand Down Expand Up @@ -248,8 +247,7 @@ public void processElementsWithName(@NotNull String name, @NotNull Processor<Nav
}

// Twig Extensions
TwigExtensionParser twigExtensionParser = new TwigExtensionParser(project);
for (Map<String, TwigExtension> extensionMap : Arrays.asList(twigExtensionParser.getFilters(), twigExtensionParser.getFunctions())) {
for (Map<String, TwigExtension> extensionMap : Arrays.asList(TwigExtensionParser.getFilters(project), TwigExtensionParser.getFunctions(project))) {
for(Map.Entry<String, TwigExtension> twigFunc: extensionMap.entrySet()) {
if(twigFunc.getKey().equals(name)) {
TwigExtension twigExtension = twigFunc.getValue();
Expand All @@ -275,7 +273,7 @@ public NavigationItem[] getItemsByName(String name, String pattern, Project proj
}
}

class MyGotoCallback extends GotoActionBase.GotoActionCallback<FileType> {
static class MyGotoCallback extends GotoActionBase.GotoActionCallback<FileType> {
@Override
public void elementChosen(ChooseByNamePopup popup, Object element) {
if(element instanceof NavigationItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,12 @@ public class EventDispatcherSubscriberUtil {

@NotNull
public static Collection<EventDispatcherSubscribedEvent> getSubscribedEvents(final @NotNull Project project) {

CachedValue<Collection<EventDispatcherSubscribedEvent>> cache = project.getUserData(EVENT_SUBSCRIBERS);
if (cache == null) {
cache = CachedValuesManager.getManager(project).createCachedValue(() ->
CachedValueProvider.Result.create(getSubscribedEventsProxy(project), PsiModificationTracker.MODIFICATION_COUNT), false
);
project.putUserData(EVENT_SUBSCRIBERS, cache);
}

return cache.getValue();
return CachedValuesManager.getManager(project).getCachedValue(
project,
EVENT_SUBSCRIBERS,
() -> CachedValueProvider.Result.create(getSubscribedEventsProxy(project), PsiModificationTracker.MODIFICATION_COUNT),
false
);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,12 @@ public class ConfigUtil {
*/
@NotNull
public static Map<String, Collection<String>> getTreeSignatures(@NotNull Project project) {
CachedValue<Map<String, Collection<String>>> cache = project.getUserData(TREE_SIGNATURE_CACHE);

if (cache == null) {
cache = CachedValuesManager.getManager(project).createCachedValue(() ->
CachedValueProvider.Result.create(visitTreeSignatures(project), PsiModificationTracker.MODIFICATION_COUNT)
, false);

project.putUserData(TREE_SIGNATURE_CACHE, cache);
}

return cache.getValue();
return CachedValuesManager.getManager(project).getCachedValue(
project,
TREE_SIGNATURE_CACHE,
() -> CachedValueProvider.Result.create(visitTreeSignatures(project), PsiModificationTracker.MODIFICATION_COUNT),
false
);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,20 @@ public static Collection<PsiElement> getEnvironmentVariableTargetsForParameter(@

@NotNull
public static Collection<String> getEnvironmentVariables(@NotNull Project project) {
CachedValue<Set<String>> cache = project.getUserData(DOT_ENV_VARIABLE_CACHE);
if (cache == null) {
cache = CachedValuesManager.getManager(project).createCachedValue(() -> {
return CachedValuesManager.getManager(project).getCachedValue(
project,
DOT_ENV_VARIABLE_CACHE,
() -> {
Set<String> items = new HashSet<>();

DotEnvUtil.visitEnvironment(project, pair ->
items.add(pair.getFirst())
);

return CachedValueProvider.Result.create(items, PsiModificationTracker.MODIFICATION_COUNT);
}, false
);
project.putUserData(DOT_ENV_VARIABLE_CACHE, cache);
}

return cache.getValue();
},
false
);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ public static Collection<VirtualFile> findMetadataForRepositoryClass(@NotNull Ph

@NotNull
public static Collection<VirtualFile> findMetadataForRepositoryClass(final @NotNull Project project, @NotNull String repositoryClass) {

CachedValue<Map<String, Collection<String>>> cache = project.getUserData(DOCTRINE_REPOSITORY_CACHE);
if(cache == null) {
cache = CachedValuesManager.getManager(project).createCachedValue(() -> {
Map<String, Collection<String>> cache = CachedValuesManager.getManager(project).getCachedValue(
project,
DOCTRINE_REPOSITORY_CACHE,
() -> {
Map<String, Collection<String>> repositoryMap = new HashMap<>();
for (String key : FileIndexCaches.getIndexKeysCache(project, CLASS_KEYS, DoctrineMetadataFileStubIndex.KEY)) {
for (DoctrineModelInterface repositoryDefinition : FileBasedIndex.getInstance().getValues(DoctrineMetadataFileStubIndex.KEY, key, GlobalSearchScope.allScope(project))) {
Expand All @@ -135,19 +135,18 @@ public static Collection<VirtualFile> findMetadataForRepositoryClass(final @NotN
}

return CachedValueProvider.Result.create(repositoryMap, PsiModificationTracker.MODIFICATION_COUNT);
}, false);

project.putUserData(DOCTRINE_REPOSITORY_CACHE, cache);
}
},
false
);

repositoryClass = StringUtils.stripStart(repositoryClass,"\\");
if(!cache.getValue().containsKey(repositoryClass)) {
if(!cache.containsKey(repositoryClass)) {
return Collections.emptyList();
}

Set<VirtualFile> virtualFiles = new HashSet<>();

for (String s : cache.getValue().get(repositoryClass)) {
for (String s : cache.get(repositoryClass)) {
virtualFiles.addAll(
FileBasedIndex.getInstance().getContainingFiles(DoctrineMetadataFileStubIndex.KEY, s, GlobalSearchScope.allScope(project))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1045,17 +1045,12 @@ public static List<PsiElement> getRouteDefinitionTargets(Project project, String

@NotNull
synchronized public static Map<String, Route> getAllRoutes(final @NotNull Project project) {
CachedValue<Map<String, Route>> cache = project.getUserData(ROUTE_CACHE);

if (cache == null) {
cache = CachedValuesManager.getManager(project).createCachedValue(() ->
CachedValueProvider.Result.create(getAllRoutesProxy(project), PsiModificationTracker.MODIFICATION_COUNT),
false
);
project.putUserData(ROUTE_CACHE, cache);
}

return cache.getValue();
return CachedValuesManager.getManager(project).getCachedValue(
project,
ROUTE_CACHE,
() -> CachedValueProvider.Result.create(getAllRoutesProxy(project), PsiModificationTracker.MODIFICATION_COUNT),
false
);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,12 @@ public static GlobalSearchScope getRestrictedFileTypesScope(@NotNull Project pro

@NotNull
public static Map<String, Collection<ContainerService>> getDecoratedServices(@NotNull Project project) {
CachedValue<Map<String, Collection<ContainerService>>> cache = project.getUserData(SERVICE_DECORATION_CACHE);

if (cache == null) {
cache = CachedValuesManager.getManager(project).createCachedValue(() ->
CachedValueProvider.Result.create(getDecoratedServicesInner(project), PsiModificationTracker.MODIFICATION_COUNT)
, false);

project.putUserData(SERVICE_DECORATION_CACHE, cache);
}

return cache.getValue();
return CachedValuesManager.getManager(project).getCachedValue(
project,
SERVICE_DECORATION_CACHE,
() -> CachedValueProvider.Result.create(getDecoratedServicesInner(project), PsiModificationTracker.MODIFICATION_COUNT),
false
);
}

@NotNull
Expand Down Expand Up @@ -209,17 +204,12 @@ private static Map<String, Collection<ContainerService>> getDecoratedServicesInn
*/
@NotNull
public static Map<String, Collection<ContainerService>> getParentServices(@NotNull Project project) {
CachedValue<Map<String, Collection<ContainerService>>> cache = project.getUserData(SERVICE_PARENT);

if (cache == null) {
cache = CachedValuesManager.getManager(project).createCachedValue(() ->
CachedValueProvider.Result.create(getParentServicesInner(project), PsiModificationTracker.MODIFICATION_COUNT)
, false);

project.putUserData(SERVICE_PARENT, cache);
}

return cache.getValue();
return CachedValuesManager.getManager(project).getCachedValue(
project,
SERVICE_PARENT,
() -> CachedValueProvider.Result.create(getParentServicesInner(project), PsiModificationTracker.MODIFICATION_COUNT),
false
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,37 @@ public class FileIndexCaches {
* @param dataHolderNames Cache extracted name Set
*/
static public synchronized <T> Map<String, List<T>> getSetDataCache(@NotNull final Project project, @NotNull Key<CachedValue<Map<String, List<T>>>> dataHolderKey, final @NotNull Key<CachedValue<Set<String>>> dataHolderNames, @NotNull final ID<String, T> ID, @NotNull final GlobalSearchScope scope) {

CachedValue<Map<String, List<T>>> cache = project.getUserData(dataHolderKey);

if(cache == null) {
cache = CachedValuesManager.getManager(project).createCachedValue(() -> {
return CachedValuesManager.getManager(project).getCachedValue(
project,
dataHolderKey,
() -> {
Map<String, List<T>> items = new HashMap<>();

final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();

getIndexKeysCache(project, dataHolderNames, ID).stream().forEach(service ->
getIndexKeysCache(project, dataHolderNames, ID).forEach(service ->
items.put(service, fileBasedIndex.getValues(ID, service, scope))
);

return CachedValueProvider.Result.create(items, PsiModificationTracker.MODIFICATION_COUNT);
}, false);

project.putUserData(dataHolderKey, cache);
}

return cache.getValue();
},
false
);
}

/**
* @param dataHolderKey Main data to cache
* @param dataHolderNames Cache extracted name Set
*/
static public synchronized Map<String, List<String>> getStringDataCache(@NotNull final Project project, @NotNull Key<CachedValue<Map<String, List<String>>>> dataHolderKey, final @NotNull Key<CachedValue<Set<String>>> dataHolderNames, @NotNull final ID<String, String> ID, @NotNull final GlobalSearchScope scope) {

CachedValue<Map<String, List<String>>> cache = project.getUserData(dataHolderKey);
if(cache == null) {
cache = CachedValuesManager.getManager(project).createCachedValue(() -> {

return CachedValuesManager.getManager(project).getCachedValue(
project,
dataHolderKey,
() -> {
Map<String, List<String>> strings = new HashMap<>();

final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
getIndexKeysCache(project, dataHolderNames, ID).stream().forEach(parameterName -> {
getIndexKeysCache(project, dataHolderNames, ID).forEach(parameterName -> {
// just for secure
if(parameterName == null) {
return;
Expand All @@ -75,30 +70,21 @@ static public synchronized Map<String, List<String>> getStringDataCache(@NotNull
});

return CachedValueProvider.Result.create(strings, PsiModificationTracker.MODIFICATION_COUNT);
}, false);

project.putUserData(dataHolderKey, cache);
}

return cache.getValue();
},
false
);
}

/**
* There several methods that just need to check for names, as they also needed for value extraction, so cache them also
*/
static public synchronized Set<String> getIndexKeysCache(@NotNull final Project project, @NotNull Key<CachedValue<Set<String>>> dataHolderKey, @NotNull final ID<String, ?> ID) {

CachedValue<Set<String>> cache = project.getUserData(dataHolderKey);

if(cache == null) {
cache = CachedValuesManager.getManager(project).createCachedValue(() ->
CachedValueProvider.Result.create(SymfonyProcessors.createResult(project, ID), PsiModificationTracker.MODIFICATION_COUNT), false
);

project.putUserData(dataHolderKey, cache);
}

return cache.getValue();
return CachedValuesManager.getManager(project).getCachedValue(
project,
dataHolderKey,
() -> CachedValueProvider.Result.create(SymfonyProcessors.createResult(project, ID), PsiModificationTracker.MODIFICATION_COUNT),
false
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static class MyFilterTagGotoCompletionProvider extends GotoCompletionPro
public Collection<LookupElement> getLookupElements() {
Collection<LookupElement> lookupElements = new ArrayList<>();

for (Map.Entry<String, TwigExtension> extension : new TwigExtensionParser(getProject()).getFilters().entrySet()) {
for (Map.Entry<String, TwigExtension> extension : TwigExtensionParser.getFilters(getProject()).entrySet()) {
lookupElements.add(new TwigExtensionLookupElement(getProject(), extension.getKey(), extension.getValue()));
}

Expand All @@ -63,7 +63,7 @@ public Collection<PsiElement> getPsiTargets(PsiElement element) {

Collection<PsiElement> targets = new ArrayList<>();

for (Map.Entry<String, TwigExtension> extension : new TwigExtensionParser(getProject()).getFilters().entrySet()) {
for (Map.Entry<String, TwigExtension> extension : TwigExtensionParser.getFilters(getProject()).entrySet()) {
if(!text.equals(extension.getKey())) {
continue;
}
Expand Down
Loading