当前位置: 首页>>代码示例>>Java>>正文


Java JavaStatisticsManager类代码示例

本文整理汇总了Java中com.intellij.psi.statistics.JavaStatisticsManager的典型用法代码示例。如果您正苦于以下问题:Java JavaStatisticsManager类的具体用法?Java JavaStatisticsManager怎么用?Java JavaStatisticsManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JavaStatisticsManager类属于com.intellij.psi.statistics包,在下文中一共展示了JavaStatisticsManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addImport

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:AddImportAction.java

示例2: compareMembers

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
private static int compareMembers(PsiMember m1, PsiMember m2, PsiExpression context) {
  ProgressManager.checkCanceled();
  int result = JavaStatisticsManager.createInfo(null, m2).getUseCount() - JavaStatisticsManager.createInfo(null, m1).getUseCount();
  if (result != 0) return result;
  final PsiClass aClass = m1.getContainingClass();
  final PsiClass bClass = m2.getContainingClass();
  if (aClass != null && bClass != null) {
    result = JavaStatisticsManager.createInfo(null, bClass).getUseCount() - JavaStatisticsManager.createInfo(null, aClass).getUseCount();
    if (result != 0) return result;
  }

  WeighingComparable<PsiElement,ProximityLocation> proximity1 = PsiProximityComparator.getProximity(m1, context);
  WeighingComparable<PsiElement,ProximityLocation> proximity2 = PsiProximityComparator.getProximity(m2, context);
  if (proximity1 != null && proximity2 != null) {
    result = proximity2.compareTo(proximity1);
    if (result != 0) return result;
  }

  String name1 = PsiUtil.getMemberQualifiedName(m1);
  String name2 = PsiUtil.getMemberQualifiedName(m2);
  return Comparing.compare(name1, name2);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:CreateFromUsageUtils.java

示例3: getSuggestedNames

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
@Override
public SuggestedNameInfo getSuggestedNames(final PsiElement element, @Nullable PsiElement nameSuggestionContext, Set<String> result) {
  if (nameSuggestionContext == null) nameSuggestionContext = element;
  if (element instanceof GrVariable && nameSuggestionContext instanceof GroovyPsiElement) {
    final PsiType type = ((GrVariable)element).getTypeGroovy();
    if (type != null) {
      final String[] names = GroovyNameSuggestionUtil
        .suggestVariableNameByType(type, new DefaultGroovyVariableNameValidator((GroovyPsiElement)nameSuggestionContext));
      result.addAll(Arrays.asList(names));
      return new SuggestedNameInfo(names) {
        @Override
        public void nameChosen(String name) {
          JavaStatisticsManager
            .incVariableNameUseCount(name, JavaCodeStyleManager.getInstance(element.getProject()).getVariableKind((GrVariable)element),
                                     ((GrVariable)element).getName(), type);
        }
      };
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:GroovyNameSuggestionProvider.java

示例4: compareMembers

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
private static int compareMembers(PsiMember m1, PsiMember m2, PsiExpression context) {
  ProgressManager.checkCanceled();
  int result = JavaStatisticsManager.createInfo(null, m2).getUseCount() - JavaStatisticsManager.createInfo(null, m1).getUseCount();
  if (result != 0) return result;
  final PsiClass aClass = m1.getContainingClass();
  final PsiClass bClass = m2.getContainingClass();
  if (aClass != null && bClass != null) {
    result = JavaStatisticsManager.createInfo(null, bClass).getUseCount() - JavaStatisticsManager.createInfo(null, aClass).getUseCount();
    if (result != 0) return result;
  }

  WeighingComparable<PsiElement,ProximityLocation> proximity1 = PsiProximityComparator.getProximity(m1, context);
  WeighingComparable<PsiElement,ProximityLocation> proximity2 = PsiProximityComparator.getProximity(m2, context);
  if (proximity1 != null && proximity2 != null) {
    result = proximity2.compareTo(proximity1);
    if (result != 0) return result;
  }

  String name1 = PsiUtil.getMemberQualifiedName(m1);
  String name2 = PsiUtil.getMemberQualifiedName(m2);
  return name1 == null || name2 == null ? 0 : name1.compareTo(name2);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:23,代码来源:CreateFromUsageUtils.java

示例5: processMostProbableInheritors

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:JavaInheritorsGetter.java

示例6: sortVariableNameSuggestions

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
private static void sortVariableNameSuggestions(@NotNull String[] names,
                                                @NotNull final VariableKind variableKind,
                                                @Nullable final String propertyName,
                                                @Nullable final PsiType type) {
  if( names.length <= 1 ) {
    return;
  }

  if (LOG.isDebugEnabled()) {
    LOG.debug("sorting names:" + variableKind);
    if (propertyName != null) {
      LOG.debug("propertyName:" + propertyName);
    }
    if (type != null) {
      LOG.debug("type:" + type);
    }
    for (String name : names) {
      int count = JavaStatisticsManager.getVariableNameUseCount(name, variableKind, propertyName, type);
      LOG.debug(name + " : " + count);
    }
  }

  Comparator<String> comparator = new Comparator<String>() {
    @Override
    public int compare(@NotNull String s1, @NotNull String s2) {
      int count1 = JavaStatisticsManager.getVariableNameUseCount(s1, variableKind, propertyName, type);
      int count2 = JavaStatisticsManager.getVariableNameUseCount(s2, variableKind, propertyName, type);
      return count2 - count1;
    }
  };
  Arrays.sort(names, comparator);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:JavaCodeStyleManagerImpl.java

示例7: addImport

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
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);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:15,代码来源:AddImportAction.java

示例8: sortVariableNameSuggestions

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
private static void sortVariableNameSuggestions(String[] names,
                                         final VariableKind variableKind,
                                         @Nullable final String propertyName,
                                         @Nullable final PsiType type) {
  if( names.length <= 1 ) {
    return;
  }

  if (LOG.isDebugEnabled()) {
    LOG.debug("sorting names:" + variableKind);
    if (propertyName != null) {
      LOG.debug("propertyName:" + propertyName);
    }
    if (type != null) {
      LOG.debug("type:" + type);
    }
    for (String name : names) {
      int count = JavaStatisticsManager.getVariableNameUseCount(name, variableKind, propertyName, type);
      LOG.debug(name + " : " + count);
    }
  }

  Comparator<String> comparator = new Comparator<String>() {
    @Override
    public int compare(String s1, String s2) {
      int count1 = JavaStatisticsManager.getVariableNameUseCount(s1, variableKind, propertyName, type);
      int count2 = JavaStatisticsManager.getVariableNameUseCount(s2, variableKind, propertyName, type);
      return count2 - count1;
    }
  };
  Arrays.sort(names, comparator);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:33,代码来源:JavaCodeStyleManagerImpl.java

示例9: processMostProbableInheritors

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
private static boolean processMostProbableInheritors(PsiFile contextFile, PsiElement context, Collection<PsiClassType> expectedClassTypes, Consumer<PsiType> consumer)
{
	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(context, 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(contextFile.getProject()).findClass(qname, contextFile.getResolveScope());
				if(psiClass != null && !PsiTreeUtil.isAncestor(contextFile, psiClass, true) && !processor.process(psiClass))
				{
					break;
				}
			}
		}
	}
	return true;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:34,代码来源:JavaInheritorsGetter.java

示例10: addImport

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
private void addImport(final PsiReference ref, final PsiClass targetClass)
{
	if(!ref.getElement().isValid() || !targetClass.isValid() || ref.resolve() == targetClass)
	{
		return;
	}
	if(!FileModificationService.getInstance().preparePsiElementForWrite(ref.getElement()))
	{
		return;
	}

	StatisticsManager.getInstance().incUseCount(JavaStatisticsManager.createInfo(null, targetClass));
	CommandProcessor.getInstance().executeCommand(myProject, () -> ApplicationManager.getApplication().runWriteAction(() -> DumbService.getInstance(myProject).withAlternativeResolveEnabled(() ->
			_addImport(ref, targetClass))), JavaQuickFixBundle.message("add.import"), null);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:16,代码来源:AddImportAction.java

示例11: sortVariableNameSuggestions

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
private static void sortVariableNameSuggestions(@NotNull String[] names, @NotNull final VariableKind variableKind, @Nullable final String propertyName, @Nullable final PsiType type)
{
	if(names.length <= 1)
	{
		return;
	}

	if(LOG.isDebugEnabled())
	{
		LOG.debug("sorting names:" + variableKind);
		if(propertyName != null)
		{
			LOG.debug("propertyName:" + propertyName);
		}
		if(type != null)
		{
			LOG.debug("type:" + type);
		}
		for(String name : names)
		{
			int count = JavaStatisticsManager.getVariableNameUseCount(name, variableKind, propertyName, type);
			LOG.debug(name + " : " + count);
		}
	}

	Comparator<String> comparator = new Comparator<String>()
	{
		@Override
		public int compare(@NotNull String s1, @NotNull String s2)
		{
			int count1 = JavaStatisticsManager.getVariableNameUseCount(s1, variableKind, propertyName, type);
			int count2 = JavaStatisticsManager.getVariableNameUseCount(s2, variableKind, propertyName, type);
			return count2 - count1;
		}
	};
	Arrays.sort(names, comparator);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:38,代码来源:JavaCodeStyleManagerImpl.java

示例12: serialize

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
@Override
public StatisticsInfo serialize(final PsiElement element, final ProximityLocation location) {
  return element instanceof PsiMember ? JavaStatisticsManager.createInfo(null, (PsiMember)element) : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:JavaProximityStatistician.java

示例13: serialize

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
@Override
public StatisticsInfo serialize(final LookupElement element, final CompletionLocation location) {
  Object o = element.getObject();

  if (o instanceof PsiLocalVariable || o instanceof PsiParameter || o instanceof PsiThisExpression || o instanceof PsiKeyword) {
    return StatisticsInfo.EMPTY;
  }

  PsiElement position = location.getCompletionParameters().getPosition();
  if (SUPER_CALL.accepts(position) || ReferenceExpressionCompletionContributor.IN_SWITCH_LABEL.accepts(position)) {
    return StatisticsInfo.EMPTY;
  }

  LookupItem item = element.as(LookupItem.CLASS_CONDITION_KEY);
  if (item == null) return null;

  PsiType qualifierType = JavaCompletionUtil.getQualifierType(item);

  if (o instanceof PsiMember) {
    final ExpectedTypeInfo[] infos = JavaCompletionUtil.EXPECTED_TYPES.getValue(location);
    final ExpectedTypeInfo firstInfo = infos != null && infos.length > 0 ? infos[0] : null;
    String key2 = JavaStatisticsManager.getMemberUseKey2((PsiMember)o);
    if (o instanceof PsiClass) {
      PsiType expectedType = firstInfo != null ? firstInfo.getDefaultType() : null;
      return new StatisticsInfo(JavaStatisticsManager.getAfterNewKey(expectedType), key2);
    }

    PsiClass containingClass = ((PsiMember)o).getContainingClass();
    if (containingClass != null) {
      String expectedName = firstInfo instanceof ExpectedTypeInfoImpl ? ((ExpectedTypeInfoImpl)firstInfo).getExpectedName() : null;
      String contextPrefix = expectedName == null ? "" : "expectedName=" + expectedName + "###";
      String context = contextPrefix + JavaStatisticsManager.getMemberUseKey2(containingClass);

      if (o instanceof PsiMethod) {
        String memberValue = JavaStatisticsManager.getMemberUseKey2(RecursionWeigher.findDeepestSuper((PsiMethod)o));

        List<StatisticsInfo> superMethodInfos = ContainerUtil.newArrayList(new StatisticsInfo(contextPrefix + context, memberValue));
        for (PsiClass superClass : InheritanceUtil.getSuperClasses(containingClass)) {
          superMethodInfos.add(new StatisticsInfo(contextPrefix + JavaStatisticsManager.getMemberUseKey2(superClass), memberValue));
        }
        return StatisticsInfo.createComposite(superMethodInfos);
      }

      return new StatisticsInfo(context, key2);
    }
  }

  if (qualifierType != null) return StatisticsInfo.EMPTY;

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:52,代码来源:JavaCompletionStatistician.java

示例14: suggestVariableName

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
@NotNull
@Override
public SuggestedNameInfo suggestVariableName(@NotNull final VariableKind kind,
                                             @Nullable final String propertyName,
                                             @Nullable final PsiExpression expr,
                                             @Nullable PsiType type,
                                             final boolean correctKeywords) {
  LinkedHashSet<String> names = new LinkedHashSet<String>();

  if (expr != null && type == null) {
    type = expr.getType();
  }

  if (propertyName != null) {
    String[] namesByName = getSuggestionsByName(propertyName, kind, false, correctKeywords);
    sortVariableNameSuggestions(namesByName, kind, propertyName, null);
    ContainerUtil.addAll(names, namesByName);
  }

  final NamesByExprInfo namesByExpr;
  if (expr != null) {
    namesByExpr = suggestVariableNameByExpression(expr, kind, correctKeywords);
    if (namesByExpr.propertyName != null) {
      sortVariableNameSuggestions(namesByExpr.names, kind, namesByExpr.propertyName, null);
    }
    ContainerUtil.addAll(names, namesByExpr.names);
  }
  else {
    namesByExpr = null;
  }

  if (type != null) {
    String[] namesByType = suggestVariableNameByType(type, kind, correctKeywords);
    sortVariableNameSuggestions(namesByType, kind, null, type);
    ContainerUtil.addAll(names, namesByType);
  }

  final String _propertyName;
  if (propertyName != null) {
    _propertyName = propertyName;
  }
  else {
    _propertyName = namesByExpr != null ? namesByExpr.propertyName : null;
  }

  addNamesFromStatistics(names, kind, _propertyName, type);

  String[] namesArray = ArrayUtil.toStringArray(names);
  sortVariableNameSuggestions(namesArray, kind, _propertyName, type);

  final PsiType _type = type;
  return new SuggestedNameInfo(namesArray) {
    @Override
    public void nameChosen(String name) {
      if (_propertyName != null || _type != null && _type.isValid()) {
        JavaStatisticsManager.incVariableNameUseCount(name, kind, _propertyName, _type);
      }
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:61,代码来源:JavaCodeStyleManagerImpl.java

示例15: serialize

import com.intellij.psi.statistics.JavaStatisticsManager; //导入依赖的package包/类
@Override
public StatisticsInfo serialize(final LookupElement element, final CompletionLocation location) {
  Object o = element.getObject();

  if (o instanceof PsiLocalVariable || o instanceof PsiParameter || o instanceof PsiThisExpression || o instanceof PsiKeyword) {
    return StatisticsInfo.EMPTY;
  }

  LookupItem item = element.as(LookupItem.CLASS_CONDITION_KEY);
  if (item == null) return null;

  PsiType qualifierType = JavaCompletionUtil.getQualifierType(item);

  if (o instanceof PsiMember) {
    final ExpectedTypeInfo[] infos = JavaCompletionUtil.EXPECTED_TYPES.getValue(location);
    final ExpectedTypeInfo firstInfo = infos != null && infos.length > 0 ? infos[0] : null;
    String key2 = JavaStatisticsManager.getMemberUseKey2((PsiMember)o);
    if (o instanceof PsiClass) {
      PsiType expectedType = firstInfo != null ? firstInfo.getDefaultType() : null;
      return new StatisticsInfo(JavaStatisticsManager.getAfterNewKey(expectedType), key2);
    }

    PsiClass containingClass = ((PsiMember)o).getContainingClass();
    if (containingClass != null) {
      String expectedName = firstInfo instanceof ExpectedTypeInfoImpl ? ((ExpectedTypeInfoImpl)firstInfo).expectedName.compute() : null;
      String contextPrefix = expectedName == null ? "" : "expectedName=" + expectedName + "###";
      String context = contextPrefix + JavaStatisticsManager.getMemberUseKey2(containingClass);

      if (o instanceof PsiMethod) {
        String memberValue = JavaStatisticsManager.getMemberUseKey2(RecursionWeigher.findDeepestSuper((PsiMethod)o));

        List<StatisticsInfo> superMethodInfos = ContainerUtil.newArrayList(new StatisticsInfo(contextPrefix + context, memberValue));
        for (PsiClass superClass : InheritanceUtil.getSuperClasses(containingClass)) {
          superMethodInfos.add(new StatisticsInfo(contextPrefix + JavaStatisticsManager.getMemberUseKey2(superClass), memberValue));
        }
        return StatisticsInfo.createComposite(superMethodInfos);
      }

      return new StatisticsInfo(context, key2);
    }
  }

  if (qualifierType != null) return StatisticsInfo.EMPTY;

  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:47,代码来源:JavaCompletionStatistician.java


注:本文中的com.intellij.psi.statistics.JavaStatisticsManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。