Search in sources :

Example 1 with TIntObjectHashMap

use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.

the class GridLayoutSourceGenerator method fillMap.

private static TIntObjectHashMap<String> fillMap(final Class<GridConstraints> aClass, @NonNls final String prefix) {
    final TIntObjectHashMap<String> map = new TIntObjectHashMap<>();
    final Field[] fields = aClass.getFields();
    for (final Field field : fields) {
        if ((field.getModifiers() & Modifier.STATIC) != 0 && field.getName().startsWith(prefix)) {
            field.setAccessible(true);
            try {
                final int value = field.getInt(aClass);
                map.put(value, aClass.getName() + '.' + field.getName());
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return map;
}
Also used : Field(java.lang.reflect.Field) TIntObjectHashMap(gnu.trove.TIntObjectHashMap)

Example 2 with TIntObjectHashMap

use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.

the class MethodsChainLookupRangingHelper method processMethod.

@Nullable
private static MethodProcResult processMethod(@NotNull final PsiMethod method, @Nullable final PsiClass qualifierClass, final boolean isHeadMethod, final int weight, final ChainCompletionContext context, final CachedRelevantStaticMethodSearcher staticMethodSearcher, final NullableNotNullManager nullableNotNullManager) {
    int unreachableParametersCount = 0;
    int notMatchedStringVars = 0;
    int matchedParametersInContext = 0;
    boolean hasCallingVariableInContext = false;
    boolean introduceNewVariable = false;
    final PsiParameterList parameterList = method.getParameterList();
    final TIntObjectHashMap<SubLookupElement> parametersMap = new TIntObjectHashMap<>(parameterList.getParametersCount());
    final PsiParameter[] parameters = parameterList.getParameters();
    for (int i = 0; i < parameters.length; i++) {
        final PsiParameter parameter = parameters[i];
        final String typeQName = parameter.getType().getCanonicalText();
        if (JAVA_LANG_STRING.equals(typeQName)) {
            final PsiVariable relevantStringVar = context.findRelevantStringInContext(parameter.getName());
            if (relevantStringVar == null) {
                notMatchedStringVars++;
            } else {
                parametersMap.put(i, new VariableSubLookupElement(relevantStringVar));
            }
        } else if (!ChainCompletionStringUtil.isPrimitiveOrArrayOfPrimitives(typeQName)) {
            final Collection<PsiVariable> contextVariables = context.getVariables(typeQName);
            final PsiVariable contextVariable = ContainerUtil.getFirstItem(contextVariables, null);
            if (contextVariable != null) {
                if (contextVariables.size() == 1)
                    parametersMap.put(i, new VariableSubLookupElement(contextVariable));
                matchedParametersInContext++;
                continue;
            }
            final Collection<ContextRelevantVariableGetter> relevantVariablesGetters = context.getRelevantVariablesGetters(typeQName);
            final ContextRelevantVariableGetter contextVariableGetter = ContainerUtil.getFirstItem(relevantVariablesGetters, null);
            if (contextVariableGetter != null) {
                if (relevantVariablesGetters.size() == 1)
                    parametersMap.put(i, contextVariableGetter.createSubLookupElement());
                matchedParametersInContext++;
                continue;
            }
            final Collection<PsiMethod> containingClassMethods = context.getContainingClassMethods(typeQName);
            final PsiMethod contextRelevantGetter = ContainerUtil.getFirstItem(containingClassMethods, null);
            if (contextRelevantGetter != null) {
                if (containingClassMethods.size() == 1)
                    parametersMap.put(i, new GetterLookupSubLookupElement(method.getName()));
                matchedParametersInContext++;
                continue;
            }
            final ContextRelevantStaticMethod contextRelevantStaticMethod = ContainerUtil.getFirstItem(staticMethodSearcher.getRelevantStaticMethods(typeQName, weight), null);
            if (contextRelevantStaticMethod != null) {
                //
                // In most cases it is not really relevant
                //
                //parametersMap.put(i, contextRelevantStaticMethod.createLookupElement());
                matchedParametersInContext++;
                continue;
            }
            if (!nullableNotNullManager.isNullable(parameter, true)) {
                unreachableParametersCount++;
            }
        }
    }
    final LookupElement lookupElement;
    if (isHeadMethod) {
        if (method.hasModifierProperty(PsiModifier.STATIC)) {
            hasCallingVariableInContext = true;
            lookupElement = createLookupElement(method, parametersMap);
        } else if (method.isConstructor()) {
            return null;
        } else {
            @SuppressWarnings("ConstantConditions") final String classQName = qualifierClass.getQualifiedName();
            if (classQName == null)
                return null;
            final Object e = ContainerUtil.getFirstItem(context.getContextRefElements(classQName), null);
            if (e != null) {
                final LookupElement firstChainElement;
                if (e instanceof PsiVariable) {
                    firstChainElement = new VariableLookupItem((PsiVariable) e);
                } else if (e instanceof PsiMethod) {
                    firstChainElement = createLookupElement((PsiMethod) e, null);
                } else if (e instanceof LookupElement) {
                    firstChainElement = (LookupElement) e;
                } else {
                    throw new AssertionError();
                }
                hasCallingVariableInContext = true;
                lookupElement = new JavaChainLookupElement(firstChainElement, createLookupElement(method, parametersMap));
            } else {
                lookupElement = createLookupElement(method, parametersMap);
                if (!context.getContainingClassQNames().contains(classQName)) {
                    introduceNewVariable = true;
                }
            }
        }
    } else {
        lookupElement = createLookupElement(method, parametersMap);
    }
    return new MethodProcResult(lookupElement, unreachableParametersCount, notMatchedStringVars, hasCallingVariableInContext, introduceNewVariable, matchedParametersInContext);
}
Also used : VariableSubLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.VariableSubLookupElement) ContextRelevantVariableGetter(com.intellij.compiler.classFilesIndex.chainsSearch.context.ContextRelevantVariableGetter) SubLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.SubLookupElement) GetterLookupSubLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.GetterLookupSubLookupElement) VariableSubLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.VariableSubLookupElement) JavaChainLookupElement(com.intellij.codeInsight.completion.JavaChainLookupElement) SubLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.SubLookupElement) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ChainCompletionLookupElementUtil.createLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.ChainCompletionLookupElementUtil.createLookupElement) WeightableChainLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.WeightableChainLookupElement) ChainCompletionNewVariableLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.ChainCompletionNewVariableLookupElement) GetterLookupSubLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.GetterLookupSubLookupElement) VariableSubLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.VariableSubLookupElement) JavaChainLookupElement(com.intellij.codeInsight.completion.JavaChainLookupElement) VariableLookupItem(com.intellij.codeInsight.lookup.VariableLookupItem) GetterLookupSubLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.GetterLookupSubLookupElement) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) Collection(java.util.Collection) ContextRelevantStaticMethod(com.intellij.compiler.classFilesIndex.chainsSearch.context.ContextRelevantStaticMethod) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with TIntObjectHashMap

use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.

the class AbstractDataGetter method preLoadCommitData.

@NotNull
public TIntObjectHashMap<T> preLoadCommitData(@NotNull TIntHashSet commits) throws VcsException {
    TIntObjectHashMap<T> result = new TIntObjectHashMap<>();
    final MultiMap<VirtualFile, String> rootsAndHashes = MultiMap.create();
    commits.forEach(commit -> {
        CommitId commitId = myStorage.getCommitId(commit);
        if (commitId != null) {
            rootsAndHashes.putValue(commitId.getRoot(), commitId.getHash().asString());
        }
        return true;
    });
    for (Map.Entry<VirtualFile, Collection<String>> entry : rootsAndHashes.entrySet()) {
        VcsLogProvider logProvider = myLogProviders.get(entry.getKey());
        if (logProvider != null) {
            List<? extends T> details = readDetails(logProvider, entry.getKey(), ContainerUtil.newArrayList(entry.getValue()));
            for (T data : details) {
                int index = myStorage.getCommitIndex(data.getId(), data.getRoot());
                result.put(index, data);
            }
            saveInCache(result);
        } else {
            LOG.error("No log provider for root " + entry.getKey().getPath() + ". All known log providers " + myLogProviders);
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CommitId(com.intellij.vcs.log.CommitId) VcsLogProvider(com.intellij.vcs.log.VcsLogProvider) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) Collection(java.util.Collection) Map(java.util.Map) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) MultiMap(com.intellij.util.containers.MultiMap) TIntIntHashMap(gnu.trove.TIntIntHashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with TIntObjectHashMap

use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.

the class ProcessListUtil method parseMacOutput.

@Nullable
static List<ProcessInfo> parseMacOutput(String commandOnly, String full) {
    List<MacProcessInfo> commands = doParseMacOutput(commandOnly);
    List<MacProcessInfo> fulls = doParseMacOutput(full);
    if (commands == null || fulls == null)
        return null;
    TIntObjectHashMap<String> idToCommand = new TIntObjectHashMap<>();
    for (MacProcessInfo each : commands) {
        idToCommand.put(each.pid, each.commandLine);
    }
    List<ProcessInfo> result = new ArrayList<>();
    for (MacProcessInfo each : fulls) {
        if (!idToCommand.containsKey(each.pid))
            continue;
        String command = idToCommand.get(each.pid);
        if (!(each.commandLine.equals(command) || each.commandLine.startsWith(command + " ")))
            continue;
        String name = PathUtil.getFileName(command);
        String args = each.commandLine.substring(command.length()).trim();
        result.add(new ProcessInfo(each.pid, each.commandLine, name, args, command));
    }
    return result;
}
Also used : TIntObjectHashMap(gnu.trove.TIntObjectHashMap) ArrayList(java.util.ArrayList) ProcessInfo(com.intellij.execution.process.ProcessInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with TIntObjectHashMap

use of gnu.trove.TIntObjectHashMap in project android by JetBrains.

the class ViewLoader method loadAndParseRClass.

@VisibleForTesting
void loadAndParseRClass(@NotNull String className) throws ClassNotFoundException, InconvertibleClassError {
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("loadAndParseRClass(%s)", anonymizeClassName(className)));
    }
    Class<?> aClass = myLoadedClasses.get(className);
    AppResourceRepository appResources = AppResourceRepository.getAppResources(myModule, true);
    if (aClass == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("  The R class is not loaded.");
        }
        final ModuleClassLoader moduleClassLoader = getModuleClassLoader();
        final boolean isClassLoaded = moduleClassLoader.isClassLoaded(className);
        aClass = moduleClassLoader.loadClass(className);
        if (!isClassLoaded && aClass != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(String.format("  Class found in module %s, first time load.", anonymize(myModule)));
            }
            // This is the first time we've found the resources. The dynamic R classes generated for aar libraries are now stale and must be
            // regenerated. Clear the ModuleClassLoader and reload the R class.
            myLoadedClasses.clear();
            ModuleClassLoader.clearCache(myModule);
            myModuleClassLoader = null;
            aClass = getModuleClassLoader().loadClass(className);
            if (appResources != null) {
                appResources.resetDynamicIds(true);
            }
        } else {
            if (LOG.isDebugEnabled()) {
                if (isClassLoaded) {
                    LOG.debug(String.format("  Class already loaded in module %s.", anonymize(myModule)));
                }
            }
        }
        if (aClass != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("  Class loaded");
            }
            assert myLogger != null;
            myLoadedClasses.put(className, aClass);
            myLogger.setHasLoadedClasses(true);
        }
    }
    if (aClass != null) {
        final Map<ResourceType, TObjectIntHashMap<String>> res2id = new EnumMap<>(ResourceType.class);
        final TIntObjectHashMap<Pair<ResourceType, String>> id2res = new TIntObjectHashMap<>();
        final Map<IntArrayWrapper, String> styleableId2res = new HashMap<>();
        if (parseClass(aClass, id2res, styleableId2res, res2id)) {
            if (appResources != null) {
                appResources.setCompiledResources(id2res, styleableId2res, res2id);
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("END loadAndParseRClass(%s)", anonymizeClassName(className)));
    }
}
Also used : TObjectIntHashMap(gnu.trove.TObjectIntHashMap) HashMap(java.util.HashMap) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) ResourceType(com.android.resources.ResourceType) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) IntArrayWrapper(com.android.ide.common.resources.IntArrayWrapper) EnumMap(java.util.EnumMap) Pair(com.android.util.Pair) VisibleForTesting(com.android.annotations.VisibleForTesting)

Aggregations

TIntObjectHashMap (gnu.trove.TIntObjectHashMap)23 ArrayList (java.util.ArrayList)4 TObjectIntHashMap (gnu.trove.TObjectIntHashMap)3 HashMap (java.util.HashMap)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 MultiMap (com.intellij.util.containers.MultiMap)2 TIntArrayList (gnu.trove.TIntArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 Random (java.util.Random)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 IntArrayWrapper (com.android.ide.common.resources.IntArrayWrapper)1 ResourceType (com.android.resources.ResourceType)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1 Pair (com.android.util.Pair)1 JavaChainLookupElement (com.intellij.codeInsight.completion.JavaChainLookupElement)1