本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
};
}
示例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;
}