ControlFlowAnalyzer(final DfaValueFactory valueFactory, @NotNull PsiElement codeFragment, boolean ignoreAssertions) { myFactory = valueFactory; myCodeFragment = codeFragment; myProject = codeFragment.getProject(); myIgnoreAssertions = ignoreAssertions; GlobalSearchScope scope = codeFragment.getResolveScope(); myRuntimeException = myFactory.createTypeValue(createClassType(scope, JAVA_LANG_RUNTIME_EXCEPTION), Nullness.NOT_NULL); myError = myFactory.createTypeValue(createClassType(scope, JAVA_LANG_ERROR), Nullness.NOT_NULL); myNpe = createClassType(scope, JAVA_LANG_NULL_POINTER_EXCEPTION); myAssertionError = createClassType(scope, JAVA_LANG_ASSERTION_ERROR); myString = myFactory.createTypeValue(createClassType(scope, JAVA_LANG_STRING), Nullness.NOT_NULL); myExceptionHolders = new FactoryMap<PsiTryStatement, DfaVariableValue>() { @Nullable @Override protected DfaVariableValue create(PsiTryStatement key) { String text = "java.lang.Object $exception" + myExceptionHolders.size() + "$"; PsiParameter mockVar = JavaPsiFacade.getElementFactory(myProject).createParameterFromText(text, null); return myFactory.getVarFactory().createVariableValue(mockVar, false); } }; }
@Override public TaskInfo[] getCurrentTasks() { List<R> repositories = myRepositoryManager.getRepositories(); @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") FactoryMap<String, TaskInfo> tasks = new FactoryMap<String, TaskInfo>() { @Nullable @Override protected TaskInfo create(String key) { return new TaskInfo(key, new ArrayList<String>()); } }; for (R repository : repositories) { String branch = getActiveBranch(repository); if (branch != null) { tasks.get(branch).getRepositories().add(repository.getPresentableUrl()); } } if (tasks.size() == 0) return new TaskInfo[0]; if (isSyncEnabled()) { return new TaskInfo[] { tasks.values().iterator().next() }; } else { return tasks.values().toArray(new TaskInfo[tasks.values().size()]); } }
private boolean addToMaps(final Object o, final FactoryMap<Object, int[]> counts, final FactoryMap<Object, List<Set<Object>>> map, final int index, final List<Object> results, final boolean singleValuedInvocation, final boolean intersect) { final Object primaryKey = getPrimaryKey(o, singleValuedInvocation); if (primaryKey != null || singleValuedInvocation) { final List<Set<Object>> list = map.get(primaryKey); final int[] indices = counts.get(primaryKey); int objIndex = intersect? indices[index] : indices[index]++; if (list.size() <= objIndex) { list.add(new LinkedHashSet<Object>()); } list.get(objIndex).add(o); return false; } results.add(o); return true; }
@Override public PsiFileSystemItem resolveFileInclude(final FileIncludeInfo info, final PsiFile context) { if (true) return doResolve(info, context); Map<String, PsiFileSystemItem> value = myCachedValuesManager.getCachedValue(context, RESOLVE_CACHE_KEY, new CachedValueProvider<Map<String, PsiFileSystemItem>>() { @Override public Result<Map<String, PsiFileSystemItem>> compute() { Map<String, PsiFileSystemItem> map = new FactoryMap<String, PsiFileSystemItem>() { @Override protected PsiFileSystemItem create(String key) { return doResolve(info, context); } }; return Result.create(map, context, VirtualFileManager.getInstance()); } }, false); return value.get(info.path); }
private boolean addToMaps(final Object o, final FactoryMap<Object, int[]> counts, final FactoryMap<Object, List<Set<Object>>> map, final int index, final List<Object> results, final boolean singleValuedInvocation, final boolean intersect) throws IllegalAccessException, InvocationTargetException { final Object primaryKey = getPrimaryKey(o, singleValuedInvocation); if (primaryKey != null || singleValuedInvocation) { final List<Set<Object>> list = map.get(primaryKey); final int[] indices = counts.get(primaryKey); int objIndex = intersect? indices[index] : indices[index]++; if (list.size() <= objIndex) { list.add(new LinkedHashSet<Object>()); } list.get(objIndex).add(o); return false; } results.add(o); return true; }
@Nonnull @Override public TaskInfo[] getCurrentTasks() { List<R> repositories = myRepositoryManager.getRepositories(); @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") FactoryMap<String, TaskInfo> tasks = new FactoryMap<String, TaskInfo>() { @Nullable @Override protected TaskInfo create(String key) { return new TaskInfo(key, new ArrayList<>()); } }; for (R repository : repositories) { String branch = getActiveBranch(repository); if (branch != null) { tasks.get(branch).getRepositories().add(repository.getPresentableUrl()); } } if (tasks.size() == 0) return new TaskInfo[0]; if (isSyncEnabled()) { return new TaskInfo[] { tasks.values().iterator().next() }; } else { return tasks.values().toArray(new TaskInfo[tasks.values().size()]); } }
public void checkSpecifics(@NotNull List<CandidateInfo> conflicts, @MethodCandidateInfo.ApplicabilityLevelConstant int applicabilityLevel, FactoryMap<MethodCandidateInfo, PsiSubstitutor> map, @NotNull LanguageLevel languageLevel) { final boolean applicable = applicabilityLevel > MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE; int conflictsCount = conflicts.size(); // Specifics if (applicable) { final CandidateInfo[] newConflictsArray = conflicts.toArray(new CandidateInfo[conflicts.size()]); for (int i = 1; i < conflictsCount; i++) { final CandidateInfo method = newConflictsArray[i]; for (int j = 0; j < i; j++) { ProgressManager.checkCanceled(); final CandidateInfo conflict = newConflictsArray[j]; if (nonComparable(method, conflict, applicabilityLevel == MethodCandidateInfo.ApplicabilityLevel.FIXED_ARITY)) continue; switch (isMoreSpecific((MethodCandidateInfo)method, (MethodCandidateInfo)conflict, applicabilityLevel, map, languageLevel)) { case FIRST: conflicts.remove(conflict); break; case SECOND: conflicts.remove(method); break; case NEITHER: break; } } } } }
@Override public FactoryMap<String, Map<MethodSignature, HierarchicalMethodSignature>> fun(final PsiClass psiClass) { return new ConcurrentFactoryMap<String, Map<MethodSignature, HierarchicalMethodSignature>>() { @Nullable @Override protected Map<MethodSignature, HierarchicalMethodSignature> create(String methodName) { return buildMethodHierarchy(psiClass, methodName, PsiSubstitutor.EMPTY, true, new THashSet<PsiClass>(), false, psiClass.getResolveScope()); } }; }
@NotNull public static Map<PsiClass, PsiClass> createSubClassCache() { return new FactoryMap<PsiClass, PsiClass>() { @Nullable @Override protected PsiClass create(PsiClass aClass) { return ClassInheritorsSearch.search(aClass, false).findFirst(); } }; }
public static Map<SliceNode, NullAnalysisResult> createMap() { return new FactoryMap<SliceNode, NullAnalysisResult>() { @Override protected NullAnalysisResult create(SliceNode key) { return new NullAnalysisResult(); } @Override protected Map<SliceNode, NullAnalysisResult> createMap() { return ContainerUtil.<SliceNode, NullAnalysisResult>newIdentityTroveMap(); } }; }
public static Map<SliceNode, Collection<PsiElement>> createMap() { return new FactoryMap<SliceNode, Collection<PsiElement>>() { @Override protected Map<SliceNode, Collection<PsiElement>> createMap() { return ContainerUtil.newConcurrentMap(ContainerUtil.<SliceNode>identityStrategy()); } @Override protected Collection<PsiElement> create(SliceNode key) { return ContainerUtil.newConcurrentSet(LEAF_ELEMENT_EQUALITY); } }; }
public MethodIncompleteSignatureResolver(final JavaPsiFacade javaPsiFacade, final GlobalSearchScope scope) { myResolvedCache = new FactoryMap<MethodIncompleteSignature, PsiMethod[]>() { @Nullable @Override protected PsiMethod[] create(final MethodIncompleteSignature signature) { return resolveNotDeprecated(signature, javaPsiFacade, scope); } }; }
@Override protected WeakFactory<Map<PsiFile, ChunkExtractor>> initialValue() { return new WeakFactory<Map<PsiFile, ChunkExtractor>>() { @NotNull @Override protected Map<PsiFile, ChunkExtractor> create() { return new FactoryMap<PsiFile, ChunkExtractor>() { @Override protected ChunkExtractor create(PsiFile psiFile) { return new ChunkExtractor(psiFile); } }; } }; }
public DetectionExcludesConfigurationImpl(Project project, VirtualFilePointerManager pointerManager) { myProject = project; myPointerManager = pointerManager; myExcludedFrameworks = new HashSet<String>(); myExcludedFiles = new FactoryMap<String, VirtualFilePointerContainer>() { @Override protected VirtualFilePointerContainer create(String key) { return myPointerManager.createContainer(DetectionExcludesConfigurationImpl.this); } }; }
public Result<FactoryMap<File, String>> compute() { final FactoryMap<File, String> result = new ConcurrentFactoryMap<File, String>() { @Override protected String create(File scriptFile) { return calcClassName(scriptFile); } }; return Result.create(result, ProjectRootManager.getInstance(myModule.getProject())); }
private static FactoryMap<MethodIncompleteSignature, PsiMethod[]> createNotDeprecatedMethodsResolver(final JavaPsiFacade javaPsiFacade, final GlobalSearchScope scope) { return new FactoryMap<MethodIncompleteSignature, PsiMethod[]>() { @Nullable @Override protected PsiMethod[] create(final MethodIncompleteSignature signature) { return signature.resolveNotDeprecated(javaPsiFacade, scope); } }; }
public SearchInitializer(final SortedSet<UsageIndexValue> indexValues, final FactoryMap<MethodIncompleteSignature, PsiMethod[]> resolver, final String targetQName, final Set<String> excludedParamsTypesQNames) { myResolver = resolver; final int size = indexValues.size(); myVertexes = new ArrayList<WeightAware<MethodIncompleteSignature>>(size); myChains = new LinkedHashMap<MethodIncompleteSignature, MethodsChain>(size); myOccurrencesMap = new HashMap<MethodIncompleteSignature, Integer>(size); add(indexValues, MethodChainsSearchUtil.unionToHashSet(excludedParamsTypesQNames, targetQName)); }
public static List<MethodsChain> search(final MethodChainsSearchService searchService, final String targetQName, final Set<String> contextQNames, final int maxResultSize, final int pathMaximalLength, final FactoryMap<MethodIncompleteSignature, PsiMethod[]> resolver, final String contextMethodName) { return search(searchService, targetQName, contextQNames, maxResultSize, pathMaximalLength, resolver, Collections.<String>singleton(targetQName), contextMethodName); }
public static Map<SliceNode, Collection<PsiElement>> createMap() { return new FactoryMap<SliceNode, Collection<PsiElement>>() { @Override protected Map<SliceNode, Collection<PsiElement>> createMap() { return new ConcurrentHashMap<SliceNode, Collection<PsiElement>>(ContainerUtil.<SliceNode>identityStrategy()); } @Override protected Collection<PsiElement> create(SliceNode key) { return new ConcurrentHashSet<PsiElement>(SliceLeafAnalyzer.LEAF_ELEMENT_EQUALITY); } }; }
@Override public void compile(CompileContext compileContext, Chunk<Module> moduleChunk, VirtualFile[] virtualFiles, OutputSink sink) { final ExcludedEntriesConfiguration excluded = GroovyCompilerConfiguration.getExcludeConfiguration(myProject); @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") FactoryMap<Pair<Module, Boolean>, Boolean> hasJava = new FactoryMap<Pair<Module, Boolean>, Boolean>() { @Override protected Boolean create(Pair<Module, Boolean> key) { return containsJavaSources(key.first, key.second); } }; ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex(); List<VirtualFile> total = new ArrayList<VirtualFile>(); for (final VirtualFile virtualFile : virtualFiles) { if (!excluded.isExcluded(virtualFile) && GroovyNamesUtil.isIdentifier(virtualFile.getNameWithoutExtension())) { Module module = index.getModuleForFile(virtualFile); if (module == null || hasJava.get(Pair.create(module, index.isInTestSourceContent(virtualFile)))) { total.add(virtualFile); } } } if (total.isEmpty()) { return; } //long l = System.currentTimeMillis(); super.compile(compileContext, moduleChunk, VfsUtil.toVirtualFileArray(total), sink); //System.out.println("Stub generation took " + (System.currentTimeMillis() - l)); }
@Override protected WeakFactory<Map<PsiFile, ChunkExtractor>> initialValue() { return new WeakFactory<Map<PsiFile, ChunkExtractor>>() { @Nonnull @Override protected Map<PsiFile, ChunkExtractor> create() { return new FactoryMap<PsiFile, ChunkExtractor>() { @Override protected ChunkExtractor create(PsiFile psiFile) { return new ChunkExtractor(psiFile); } }; } }; }
public void checkSpecifics(@NotNull List<CandidateInfo> conflicts, @MethodCandidateInfo.ApplicabilityLevelConstant int applicabilityLevel, FactoryMap<MethodCandidateInfo, PsiSubstitutor> map, @NotNull LanguageLevel languageLevel) { final boolean applicable = applicabilityLevel > MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE; int conflictsCount = conflicts.size(); // Specifics if(applicable) { final CandidateInfo[] newConflictsArray = conflicts.toArray(new CandidateInfo[conflicts.size()]); for(int i = 1; i < conflictsCount; i++) { final CandidateInfo method = newConflictsArray[i]; for(int j = 0; j < i; j++) { ProgressManager.checkCanceled(); final CandidateInfo conflict = newConflictsArray[j]; if(nonComparable(method, conflict, applicabilityLevel == MethodCandidateInfo.ApplicabilityLevel.FIXED_ARITY)) { continue; } switch(isMoreSpecific((MethodCandidateInfo) method, (MethodCandidateInfo) conflict, applicabilityLevel, map, languageLevel)) { case FIRST: conflicts.remove(conflict); break; case SECOND: conflicts.remove(method); break; case NEITHER: break; } } } } }
@Nullable protected CandidateInfo guardedOverloadResolution(@NotNull List<CandidateInfo> conflicts) { if (conflicts.isEmpty()) return null; if (conflicts.size() == 1) return conflicts.get(0); boolean atLeastOneMatch = checkParametersNumber(conflicts, getActualParametersLength(), true); if (conflicts.size() == 1) return conflicts.get(0); final FactoryMap<MethodCandidateInfo, PsiSubstitutor> map = new FactoryMap<MethodCandidateInfo, PsiSubstitutor>() { @Nullable @Override protected PsiSubstitutor create(MethodCandidateInfo key) { return key.getSubstitutor(false); } }; checkSameSignatures(conflicts, map); if (conflicts.size() == 1) return conflicts.get(0); checkAccessStaticLevels(conflicts, true); if (conflicts.size() == 1) return conflicts.get(0); checkParametersNumber(conflicts, getActualParametersLength(), false); if (conflicts.size() == 1) return conflicts.get(0); checkStaticMethodsOfInterfaces(conflicts); if (conflicts.size() == 1) return conflicts.get(0); final int applicabilityLevel = checkApplicability(conflicts); if (conflicts.size() == 1) return conflicts.get(0); // makes no sense to do further checks, because if no one candidate matches by parameters count // then noone can be more specific if (!atLeastOneMatch) return null; checkSpecifics(conflicts, applicabilityLevel, map, myLanguageLevel); if (conflicts.size() == 1) return conflicts.get(0); checkPrimitiveVarargs(conflicts, getActualParametersLength()); if (conflicts.size() == 1) return conflicts.get(0); checkAccessStaticLevels(conflicts, false); if (conflicts.size() == 1) return conflicts.get(0); Set<CandidateInfo> uniques = new THashSet<CandidateInfo>(conflicts); if (uniques.size() == 1) return uniques.iterator().next(); return null; }
@NotNull private static PsiSubstitutor getSubstitutor(MethodCandidateInfo existing, FactoryMap<MethodCandidateInfo, PsiSubstitutor> map) { return map != null ? map.get(existing) : existing.getSubstitutor(false); }
private static SearchInitializer createInitializer(final String targetQName, final FactoryMap<MethodIncompleteSignature, PsiMethod[]> context, final MethodChainsSearchService searchService, final Set<String> excludedParamsTypesQNames) { return new SearchInitializer(searchService.getMethods(targetQName), context, targetQName, excludedParamsTypesQNames); }
public boolean invoke() throws VcsException, IOException { if (myProject.isDisposed()) { return false; } myClManager = ChangeListManagerImpl.getInstanceImpl(myProject); final DiffProvider diffProvider = myVcs.getDiffProvider(); if (diffProvider == null) return false; myLocation.onBeforeBatch(); final Collection<FilePath> incomingFiles = myChangesProvider.getIncomingFiles(myLocation); myAnyChanges = false; openStreams(); loadHeader(); myCurrentRevisions = new FactoryMap<VirtualFile, VcsRevisionNumber>() { protected VcsRevisionNumber create(final VirtualFile key) { return diffProvider.getCurrentRevision(key); } }; try { IncomingChangeState.header(myLocation.toPresentableString()); final List<IncomingChangeListData> list = loadIncomingChangeListData(); boolean shouldChangeHeader; if (incomingFiles != null && incomingFiles.isEmpty()) { // we should just delete any partial files shouldChangeHeader = ! list.isEmpty(); for (IncomingChangeListData data : list) { saveIncoming(data, true); } } else { shouldChangeHeader = refreshIncomingInFile(incomingFiles, list); } IncomingChangeState.footer(); if (shouldChangeHeader) { writeHeader(); } } finally { myLocation.onAfterBatch(); closeStreams(); } return myAnyChanges; }
public boolean checkParametersNumber(@NotNull List<CandidateInfo> conflicts, final int argumentsCount, FactoryMap<MethodCandidateInfo, PsiSubstitutor> map, boolean ignoreIfStaticsProblem) { boolean atLeastOneMatch = false; TIntArrayList unmatchedIndices = null; for(int i = 0; i < conflicts.size(); i++) { ProgressManager.checkCanceled(); CandidateInfo info = conflicts.get(i); if(ignoreIfStaticsProblem && !info.isStaticsScopeCorrect()) { return true; } if(!(info instanceof MethodCandidateInfo)) { continue; } PsiMethod method = ((MethodCandidateInfo) info).getElement(); final int parametersCount = method.getParameterList().getParametersCount(); boolean isVarargs = (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) ? ((MethodCandidateInfo) info).isVarargs() : method.isVarArgs()) && parametersCount - 1 <= argumentsCount; if(isVarargs || parametersCount == argumentsCount) { // remove all unmatched before if(unmatchedIndices != null) { for(int u = unmatchedIndices.size() - 1; u >= 0; u--) { int index = unmatchedIndices.get(u); //ensure super method with varargs won't win over non-vararg override if(ignoreIfStaticsProblem && isVarargs) { MethodCandidateInfo candidateInfo = (MethodCandidateInfo) conflicts.get(index); PsiMethod candidateToRemove = candidateInfo.getElement(); if(candidateToRemove != method) { PsiSubstitutor candidateToRemoveSubst = map.get(candidateInfo); PsiSubstitutor substitutor = map.get(info); if(MethodSignatureUtil.isSubsignature(candidateToRemove.getSignature(candidateToRemoveSubst), method.getSignature(substitutor))) { continue; } } } conflicts.remove(index); i--; } unmatchedIndices = null; } atLeastOneMatch = true; } else if(atLeastOneMatch) { conflicts.remove(i); i--; } else { if(unmatchedIndices == null) { unmatchedIndices = new TIntArrayList(conflicts.size() - i); } unmatchedIndices.add(i); } } return atLeastOneMatch; }