private void addImport(final PsiReference ref, final PsiClass targetClass) { StatisticsManager.getInstance().incUseCount(JavaStatisticsManager.createInfo(null, targetClass)); CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { @Override public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { DumbService.getInstance(myProject).withAlternativeResolveEnabled(new Runnable() { @Override public void run() { _addImport(ref, targetClass); } }); } }); } }, QuickFixBundle.message("add.import"), null); }
private void setTypesAndPreselect(PsiType[] types) { myTypeSelector.setTypes(types); Map<String, PsiType> map = new THashMap<String, PsiType>(); for (final PsiType type : types) { map.put(serialize(type), type); } for (StatisticsInfo info : StatisticsManager.getInstance().getAllValues(getStatsKey())) { final PsiType candidate = map.get(info.getValue()); if (candidate != null && StatisticsManager.getInstance().getUseCount(info) > 0) { myTypeSelector.selectType(candidate); return; } } }
protected PsiClass getPreselection() { PsiClass preselection = RefactoringHierarchyUtil.getNearestBaseClass(myClass, false); final String statKey = PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(); for (StatisticsInfo info : StatisticsManager.getInstance().getAllValues(statKey)) { final String superClassName = info.getValue(); PsiClass superClass = null; for (PsiClass aClass : mySuperClasses) { if (Comparing.strEqual(superClassName, aClass.getQualifiedName())) { superClass = aClass; break; } } if (superClass != null && StatisticsManager.getInstance().getUseCount(info) > 0) { preselection = superClass; break; } } return preselection; }
private boolean autoSelectUsingStatistics() { final String filter = getSpeedSearch().getFilter(); if (!StringUtil.isEmpty(filter)) { int maxUseCount = -1; int mostUsedValue = -1; int elementsCount = myListModel.getSize(); for (int i = 0; i < elementsCount; i++) { Object value = myListModel.getElementAt(i); final String text = getListStep().getTextFor(value); final int count = StatisticsManager.getInstance().getUseCount(new StatisticsInfo("#list_popup:" + myStep.getTitle() + "#" + filter, text)); if (count > maxUseCount) { maxUseCount = count; mostUsedValue = i; } } if (mostUsedValue > 0) { ScrollingUtil.selectItem(myList, mostUsedValue); return true; } } return false; }
public void testCorrectSelectionInsertion() throws Exception { ((StatisticsManagerImpl)StatisticsManager.getInstance()).enableStatistics(getTestRootDisposable()); addResource("http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd", getTestDataPath() + "/hibernate-mapping-3.0.dtd"); configureByFile("CorrectSelectionInsertion.xml"); selectItem(myFixture.getLookupElements()[4], '\t'); checkResultByFile("CorrectSelectionInsertion_after.xml"); CompletionLookupArranger.applyLastCompletionStatisticsUpdate(); configureByFile("CorrectSelectionInsertion2.xml"); myFixture.getEditor().getSelectionModel().removeSelection(); selectItem(myFixture.getLookupElements()[0], '\t'); checkResultByFile("CorrectSelectionInsertion2_after.xml"); }
@Override protected PsiClass getPreselection() { PsiClass preselection = RefactoringHierarchyUtil.getNearestBaseClass(myClass, false); final String statKey = PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(); for (StatisticsInfo info : StatisticsManager.getInstance().getAllValues(statKey)) { final String superClassName = info.getValue(); PsiClass superClass = null; for (PsiClass aClass : mySuperClasses) { if (Comparing.strEqual(superClassName, aClass.getQualifiedName())) { superClass = aClass; break; } } if (superClass != null && StatisticsManager.getInstance().getUseCount(info) > 0) { preselection = superClass; break; } } return preselection; }
private PsiClass getPreselection() { PsiClass preselection = RefactoringHierarchyUtil.getNearestBaseClass(myClass, false); final String statKey = PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(); for (StatisticsInfo info : StatisticsManager.getInstance().getAllValues(statKey)) { final String superClassName = info.getValue(); PsiClass superClass = null; for (PsiClass aClass : mySuperClasses) { if (Comparing.strEqual(superClassName, aClass.getQualifiedName())) { superClass = aClass; break; } } if (superClass != null && StatisticsManager.getInstance().getUseCount(info) > 0) { preselection = superClass; break; } } return preselection; }
private boolean autoSelectUsingStatistics() { final String filter = getSpeedSearch().getFilter(); if (!StringUtil.isEmpty(filter)) { int maxUseCount = -1; int mostUsedValue = -1; int elementsCount = myListModel.getSize(); for (int i = 0; i < elementsCount; i++) { Object value = myListModel.getElementAt(i); final String text = getListStep().getTextFor(value); final int count = StatisticsManager.getInstance().getUseCount(new StatisticsInfo("#list_popup:" + myStep.getTitle() + "#" + filter, text)); if (count > maxUseCount) { maxUseCount = count; mostUsedValue = i; } } if (mostUsedValue > 0) { ListScrollingUtil.selectItem(myList, mostUsedValue); return true; } } return false; }
@Override public int compare(final Object o1, final Object o2) { PsiElement element1 = o1 instanceof PsiElement ? (PsiElement)o1 : null; PsiElement element2 = o2 instanceof PsiElement ? (PsiElement)o2 : null; if (element1 == null) return element2 == null ? 0 : 1; if (element2 == null) return -1; final WeighingComparable<PsiElement, ProximityLocation> proximity1 = myProximities.get(element1); final WeighingComparable<PsiElement, ProximityLocation> proximity2 = myProximities.get(element2); if (proximity1 == null || proximity2 == null) { return 0; } if (!proximity1.equals(proximity2)) { return - proximity1.compareTo(proximity2); } if (myContext == null) return 0; Module contextModule = ModuleUtil.findModuleForPsiElement(myContext); if (contextModule == null) return 0; StatisticsManager statisticsManager = StatisticsManager.getInstance(); final ProximityLocation location = new ProximityLocation(myContext, contextModule); int count1 = statisticsManager.getUseCount(STATISTICS_KEY, element1, location); int count2 = statisticsManager.getUseCount(STATISTICS_KEY, element1, location); return count2 - count1; }
private void setTypesAndPreselect(PsiType[] types) { myTypeSelector.setTypes(types); Map<String, PsiType> map = new THashMap<String, PsiType>(); for(final PsiType type : types) { map.put(serialize(type), type); } for(StatisticsInfo info : StatisticsManager.getInstance().getAllValues(getStatsKey())) { final PsiType candidate = map.get(info.getValue()); if(candidate != null && StatisticsManager.getInstance().getUseCount(info) > 0) { myTypeSelector.selectType(candidate); return; } } }
protected PsiClass getPreselection() { PsiClass preselection = RefactoringHierarchyUtil.getNearestBaseClass(myClass, false); final String statKey = PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(); for(StatisticsInfo info : StatisticsManager.getInstance().getAllValues(statKey)) { final String superClassName = info.getValue(); PsiClass superClass = null; for(PsiClass aClass : mySuperClasses) { if(Comparing.strEqual(superClassName, aClass.getQualifiedName())) { superClass = aClass; break; } } if(superClass != null && StatisticsManager.getInstance().getUseCount(info) > 0) { preselection = superClass; break; } } return preselection; }
protected void doAction() { if(!myCallback.checkConflicts(this)) { return; } JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC = myJavaDocPanel.getPolicy(); final PsiClass superClass = getSuperClass(); String name = superClass.getQualifiedName(); if(name != null) { StatisticsManager.getInstance().incUseCount(new StatisticsInfo(PULL_UP_STATISTICS_KEY + myClass .getQualifiedName(), name)); } List<MemberInfo> infos = getSelectedMemberInfos(); invokeRefactoring(new PullUpProcessor(myClass, superClass, infos.toArray(new MemberInfo[infos.size()]), new DocCommentPolicy(getJavaDocPolicy()))); close(OK_EXIT_CODE); }
private static boolean processMostProbableInheritors(CompletionParameters parameters, Collection<PsiClassType> expectedClassTypes, Consumer<PsiType> consumer) { PsiFile file = parameters.getOriginalFile(); for (final PsiClassType type : expectedClassTypes) { consumer.consume(type); final PsiClassType.ClassResolveResult baseResult = JavaCompletionUtil.originalize(type).resolveGenerics(); final PsiClass baseClass = baseResult.getElement(); if (baseClass == null) return false; final PsiSubstitutor baseSubstitutor = baseResult.getSubstitutor(); final Processor<PsiClass> processor = CodeInsightUtil.createInheritorsProcessor(parameters.getPosition(), type, 0, false, consumer, baseClass, baseSubstitutor); final StatisticsInfo[] stats = StatisticsManager.getInstance().getAllValues(JavaStatisticsManager.getAfterNewKey(type)); for (final StatisticsInfo statisticsInfo : stats) { final String value = statisticsInfo.getValue(); if (value.startsWith(JavaStatisticsManager.CLASS_PREFIX)) { final String qname = value.substring(JavaStatisticsManager.CLASS_PREFIX.length()); final PsiClass psiClass = JavaPsiFacade.getInstance(file.getProject()).findClass(qname, file.getResolveScope()); if (psiClass != null && !PsiTreeUtil.isAncestor(file, psiClass, true) && !processor.process(psiClass)) break; } } } return true; }
protected void doAction() { if (!myCallback.checkConflicts(this)) return; JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC = myJavaDocPanel.getPolicy(); final PsiClass superClass = getSuperClass(); String name = superClass.getQualifiedName(); if (name != null) { StatisticsManager .getInstance().incUseCount(new StatisticsInfo(PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(), name)); } List<MemberInfo> infos = getSelectedMemberInfos(); invokeRefactoring(new PullUpProcessor(myClass, superClass, infos.toArray(new MemberInfo[infos.size()]), new DocCommentPolicy(getJavaDocPolicy()))); close(OK_EXIT_CODE); }
private void valuesSelected(final Object[] values) { final String filter = getSpeedSearch().getFilter(); if (!StringUtil.isEmpty(filter)) { for (Object value : values) { final String text = getListStep().getTextFor(value); StatisticsManager.getInstance().incUseCount(new StatisticsInfo("#list_popup:" + getListStep().getTitle() + "#" + filter, text)); } } }
public void incData(String key1, String key2) { LinkedList<String> list = myDataMap.get(key1); if (list == null) { myDataMap.put(key1, list = new LinkedList<String>()); } list.addFirst(key2); if (list.size() > StatisticsManager.OBLIVION_THRESHOLD) { list.removeLast(); } }
@NotNull private static StatisticsInfo calcBaseInfo(LookupElement item, @NotNull CompletionLocation location) { if (!ApplicationManager.getApplication().isUnitTestMode()) { LOG.assertTrue(!ApplicationManager.getApplication().isDispatchThread()); } StatisticsInfo info = StatisticsManager.serialize(CompletionService.STATISTICS_KEY, item, location); return info == null ? StatisticsInfo.EMPTY : info; }
@Override public int compare(final Object o1, final Object o2) { PsiElement element1 = o1 instanceof PsiElement ? (PsiElement)o1 : null; PsiElement element2 = o2 instanceof PsiElement ? (PsiElement)o2 : null; if (element1 == null) return element2 == null ? 0 : 1; if (element2 == null) return -1; if (myContext != null && myContextModule != null) { final ProximityLocation location = new ProximityLocation(myContext, myContextModule); StatisticsInfo info1 = StatisticsManager.serialize(STATISTICS_KEY, element1, location); StatisticsInfo info2 = StatisticsManager.serialize(STATISTICS_KEY, element2, location); if (info1 != null && info2 != null) { StatisticsManager statisticsManager = StatisticsManager.getInstance(); int count1 = statisticsManager.getLastUseRecency(info1); int count2 = statisticsManager.getLastUseRecency(info2); if (count1 != count2) { return count1 < count2 ? -1 : 1; } } } final WeighingComparable<PsiElement, ProximityLocation> proximity1 = myProximities.get(element1); final WeighingComparable<PsiElement, ProximityLocation> proximity2 = myProximities.get(element2); if (proximity1 == null || proximity2 == null) { return 0; } return -proximity1.compareTo(proximity2); }
private int detectBestStatisticalPosition() { if (myModel instanceof Comparator) { return 0; } int best = 0; int bestPosition = 0; int bestMatch = Integer.MIN_VALUE; final int count = myListModel.getSize(); Matcher matcher = buildPatternMatcher(transformPattern(getTrimmedText())); final String statContext = statisticsContext(); for (int i = 0; i < count; i++) { final Object modelElement = myListModel.getElementAt(i); String text = EXTRA_ELEM.equals(modelElement) || NON_PREFIX_SEPARATOR.equals(modelElement) ? null : myModel.getFullName(modelElement); if (text != null) { String shortName = myModel.getElementName(modelElement); int match = shortName != null && matcher instanceof MinusculeMatcher ? ((MinusculeMatcher)matcher).matchingDegree(shortName) : Integer.MIN_VALUE; int stats = StatisticsManager.getInstance().getUseCount(new StatisticsInfo(statContext, text)); if (match > bestMatch || match == bestMatch && stats > best) { best = stats; bestPosition = i; bestMatch = match; } } } if (bestPosition < count - 1 && myListModel.getElementAt(bestPosition) == NON_PREFIX_SEPARATOR) { bestPosition++; } return bestPosition; }
@Override protected void doAction() { if (!myCallback.checkConflicts(this)) return; JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC = myJavaDocPanel.getPolicy(); final PsiClass superClass = getSuperClass(); String name = superClass.getQualifiedName(); if (name != null) { StatisticsManager.getInstance().incUseCount(new StatisticsInfo(PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(), name)); } List<GrMemberInfo> infos = getSelectedMemberInfos(); //GrPullUpProcessor processor = new GrPullUpProcessor(myClass, superClass, infos.toArray(new GrMemberInfo[infos.size()]), new DocCommentPolicy(getJavaDocPolicy())); //invokeRefactoring(processor); close(OK_EXIT_CODE); }
private void addImport(final PsiReference ref, final PsiClass targetClass) { StatisticsManager.getInstance().incUseCount(JavaStatisticsManager.createInfo(null, targetClass)); CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { @Override public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { _addImport(ref, targetClass); } }); } }, QuickFixBundle.message("add.import"), null); }
protected void doAction() { if (!myCallback.checkConflicts(this)) return; JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC = myJavaDocPanel.getPolicy(); final PsiClass superClass = getSuperClass(); String name = superClass.getQualifiedName(); if (name != null) { StatisticsManager .getInstance().incUseCount(new StatisticsInfo(PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(), name)); } invokeRefactoring(new PullUpHelper(myClass, superClass, getSelectedMemberInfos(), new DocCommentPolicy(getJavaDocPolicy()))); close(OK_EXIT_CODE); }
@Override public StatisticsInfo serialize(final LookupElement element, final CompletionLocation location) { if (element instanceof LookupElementDecorator) { return StatisticsManager.serialize(CompletionService.STATISTICS_KEY, ((LookupElementDecorator)element).getDelegate(), location); } return null; }
private int detectBestStatisticalPosition() { if (myModel instanceof Comparator) { return 0; } int best = 0; int bestPosition = 0; int bestMatch = Integer.MIN_VALUE; final int count = myListModel.getSize(); Matcher matcher = buildPatternMatcher(transformPattern(myTextField.getText())); final String statContext = statisticsContext(); for (int i = 0; i < count; i++) { final Object modelElement = myListModel.getElementAt(i); String text = EXTRA_ELEM.equals(modelElement) || NON_PREFIX_SEPARATOR.equals(modelElement) ? null : myModel.getFullName(modelElement); if (text != null) { String shortName = myModel.getElementName(modelElement); int match = shortName != null && matcher instanceof MinusculeMatcher ? ((MinusculeMatcher)matcher).matchingDegree(shortName) : Integer.MIN_VALUE; int stats = StatisticsManager.getInstance().getUseCount(new StatisticsInfo(statContext, text)); if (match > bestMatch || match == bestMatch && stats > best) { best = stats; bestPosition = i; bestMatch = match; } } } if (bestPosition < count - 1 && myListModel.getElementAt(bestPosition) == NON_PREFIX_SEPARATOR) { bestPosition++; } return bestPosition; }
private void valuesSelected(final Object[] values) { if (shouldUseStatistics()) { final String filter = getSpeedSearch().getFilter(); if (!StringUtil.isEmpty(filter)) { for (Object value : values) { final String text = getListStep().getTextFor(value); StatisticsManager.getInstance().incUseCount(new StatisticsInfo("#list_popup:" + getListStep().getTitle() + "#" + filter, text)); } } } }
private static int weigh(final StatisticsInfo baseInfo) { if (baseInfo == StatisticsInfo.EMPTY) { return 0; } int minRecency = baseInfo.getLastUseRecency(); return minRecency == Integer.MAX_VALUE ? 0 : StatisticsManager.RECENCY_OBLIVION_THRESHOLD - minRecency; }
@Nonnull private static StatisticsInfo calcBaseInfo(LookupElement item, @Nonnull CompletionLocation location) { if (!ApplicationManager.getApplication().isUnitTestMode()) { LOG.assertTrue(!ApplicationManager.getApplication().isDispatchThread()); } StatisticsInfo info = StatisticsManager.serialize(CompletionService.STATISTICS_KEY, item, location); return info == null ? StatisticsInfo.EMPTY : info; }