Java 类com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference 实例源码

项目:consulo-java    文件:MigrationUtil.java   
private static PsiElement bindNonJavaReference(PsiElement bindTo, PsiElement element, UsageInfo usage)
{
    final TextRange range = usage.getRangeInElement();
    for(PsiReference reference : element.getReferences())
    {
        if(reference instanceof JavaClassReference)
        {
            final JavaClassReference classReference = (JavaClassReference) reference;
            if(classReference.getRangeInElement().equals(range))
            {
                return classReference.bindToElement(bindTo);
            }
        }
    }
    return bindTo;
}
项目:intellij-ce-playground    文件:JavaClassReferenceCompletionContributor.java   
@Override
public void duringCompletion(@NotNull CompletionInitializationContext context) {
  JavaClassReference reference = findJavaClassReference(context.getFile(), context.getStartOffset());
  if (reference != null && reference.getExtendClassNames() != null) {
    JavaClassReferenceSet set = reference.getJavaClassReferenceSet();
    context.setReplacementOffset(set.getRangeInElement().getEndOffset() + set.getElement().getTextRange().getStartOffset());
  }
}
项目:intellij-ce-playground    文件:JavaClassReferenceCompletionContributor.java   
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
  PsiElement position = parameters.getPosition();
  JavaClassReference reference = findJavaClassReference(position.getContainingFile(), parameters.getOffset());
  if (reference == null) {
    return;
  }

  String[] extendClassNames = reference.getExtendClassNames();
  PsiElement context = reference.getCompletionContext();
  if (extendClassNames != null && context instanceof PsiPackage) {
    if (parameters.getCompletionType() == CompletionType.SMART) {
      JavaClassReferenceSet set = reference.getJavaClassReferenceSet();
      int setStart = set.getRangeInElement().getStartOffset() + set.getElement().getTextRange().getStartOffset();
      String fullPrefix = parameters.getPosition().getContainingFile().getText().substring(setStart, parameters.getOffset());
      reference.processSubclassVariants((PsiPackage)context, extendClassNames, result.withPrefixMatcher(fullPrefix));
      return;
    }
    result.addLookupAdvertisement("Press " + getActionShortcut(IdeActions.ACTION_SMART_TYPE_COMPLETION) + " to see inheritors of " +
                                  StringUtil.join(extendClassNames, ", "));
  }

  if (parameters.getCompletionType() == CompletionType.SMART) {
    return;
  }

  if (parameters.isExtendedCompletion() || parameters.getCompletionType() == CompletionType.CLASS_NAME) {
    JavaClassNameCompletionContributor.addAllClasses(parameters, result);
  }
  else {
    LegacyCompletionContributor.completeReference(parameters, result);
  }
  result.stopHere();
}
项目:intellij-ce-playground    文件:JavaClassReferenceCompletionContributor.java   
@Nullable
public static JavaClassReference findJavaClassReference(final PsiFile file, final int offset) {
  PsiReference reference = file.findReferenceAt(offset);
  if (reference instanceof PsiMultiReference) {
    for (final PsiReference psiReference : ((PsiMultiReference)reference).getReferences()) {
      if (psiReference instanceof JavaClassReference) {
        return (JavaClassReference)psiReference;
      }
    }
  }
  return reference instanceof JavaClassReference ? (JavaClassReference)reference : null;
}
项目:intellij-ce-playground    文件:ExtendsClassChecker.java   
public static List<DomElementProblemDescriptor> checkExtendsClassInReferences(final GenericDomValue element, final DomElementAnnotationHolder holder) {
  if (!isPsiClassType(element)) {
    return Collections.emptyList();
  }

  final Object valueObject = element.getValue();
  if (!(valueObject instanceof PsiClass)) return Collections.emptyList();

  final XmlElement valueElement = DomUtil.getValueElement(element);
  if (valueElement == null) return Collections.emptyList();

  final PsiReference[] references = ourProvider.getReferencesByElement(valueElement, new ProcessingContext());
  for (PsiReference reference : references) {
    if (reference instanceof JavaClassReference) {
      final PsiReferenceProvider psiReferenceProvider = ((JavaClassReference)reference).getProvider();
      final String[] value = psiReferenceProvider instanceof JavaClassReferenceProvider ? JavaClassReferenceProvider.EXTEND_CLASS_NAMES
        .getValue(((JavaClassReferenceProvider)psiReferenceProvider).getOptions()) : null;
      if (value != null && value.length != 0) {
        for (String className : value) {
          final List<DomElementProblemDescriptor> problemDescriptors =
            checkExtendClass(element, ((PsiClass)valueObject), className, false, false, true, false, true, true, holder);
          if (!problemDescriptors.isEmpty()) {
            return problemDescriptors;
          }
        }
      }
    }
  }
  return Collections.emptyList();
}
项目:intellij-ce-playground    文件:MigrationUtil.java   
private static void bindNonJavaReference(PsiElement bindTo, PsiElement element, UsageInfo usage) {
  final TextRange range = usage.getRangeInElement();
  for (PsiReference reference : element.getReferences()) {
    if (reference instanceof JavaClassReference) {
      final JavaClassReference classReference = (JavaClassReference)reference;
      if (classReference.getRangeInElement().equals(range)) {
        classReference.bindToElement(bindTo);
        break;
      }
    }
  }
}
项目:zkidea    文件:GotoJavaClassHandler.java   
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int offset, Editor editor) {
    if (psiElement == null || psiElement.getContainingFile() == null) {
        return null;
    }
    JavaClassReference reference = JavaClassReferenceCompletionContributor.findJavaClassReference(psiElement.getContainingFile(), offset);
    if (reference != null) {
        Object[] variants = reference.getVariants();
        if (variants != null && variants.length > 0) {
            String className = reference.getCanonicalText().trim();
            if (className.endsWith("\"") || className.endsWith("'"))
                className = className.substring(0, className.length()-1);
            LookupElement simulation = null;
            for (Object o : variants) {
                if (o instanceof LookupElement) {
                    LookupElement element = (LookupElement) o;
                    final String lookup = element.getLookupString();
                    if (className.equals(lookup)) {
                        return new PsiElement[]{element.getPsiElement()};
                    }
                    if (className.startsWith(lookup)) {
                        if (simulation != null) {
                            // more accurate
                            if (simulation.getLookupString().length() < lookup.length()) {
                                simulation = element;
                            }
                        } else {
                            simulation = element;
                        }
                    }
                }
            }
            if (simulation != null) {
                return new PsiElement[]{simulation.getPsiElement()};
            }
        }
    }
    return null;
}
项目:tools-idea    文件:JavaClassReferenceCompletionContributor.java   
@Override
public void duringCompletion(@NotNull CompletionInitializationContext context) {
  JavaClassReference reference = findJavaClassReference(context.getFile(), context.getStartOffset());
  if (reference != null && reference.getExtendClassNames() != null) {
    JavaClassReferenceSet set = reference.getJavaClassReferenceSet();
    context.setReplacementOffset(set.getRangeInElement().getEndOffset() + set.getElement().getTextRange().getStartOffset());
  }
}
项目:tools-idea    文件:JavaClassReferenceCompletionContributor.java   
@Override
public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) {
  PsiElement position = parameters.getPosition();
  JavaClassReference reference = findJavaClassReference(position.getContainingFile(), parameters.getOffset());
  if (reference == null) {
    return;
  }

  String[] extendClassNames = reference.getExtendClassNames();
  PsiElement context = reference.getCompletionContext();
  if (extendClassNames != null && context instanceof PsiPackage) {
    if (parameters.getCompletionType() == CompletionType.SMART) {
      JavaClassReferenceSet set = reference.getJavaClassReferenceSet();
      int setStart = set.getRangeInElement().getStartOffset() + set.getElement().getTextRange().getStartOffset();
      String fullPrefix = parameters.getPosition().getContainingFile().getText().substring(setStart, parameters.getOffset());
      reference.processSubclassVariants((PsiPackage)context, extendClassNames, result.withPrefixMatcher(fullPrefix));
      return;
    }
    result.addLookupAdvertisement("Press " + getActionShortcut(IdeActions.ACTION_SMART_TYPE_COMPLETION) + " to see inheritors of " +
                                  StringUtil.join(extendClassNames, ", "));
  }

  if (parameters.getCompletionType() == CompletionType.SMART) {
    return;
  }

  if (parameters.isExtendedCompletion() || parameters.getCompletionType() == CompletionType.CLASS_NAME) {
    JavaClassNameCompletionContributor.addAllClasses(parameters, result);
  }
  else {
    LegacyCompletionContributor.completeReference(parameters, result);
  }
  result.stopHere();
}
项目:tools-idea    文件:JavaClassReferenceCompletionContributor.java   
@Nullable
public static JavaClassReference findJavaClassReference(final PsiFile file, final int offset) {
  PsiReference reference = file.findReferenceAt(offset);
  if (reference instanceof PsiMultiReference) {
    for (final PsiReference psiReference : ((PsiMultiReference)reference).getReferences()) {
      if (psiReference instanceof JavaClassReference) {
        return (JavaClassReference)psiReference;
      }
    }
  }
  return reference instanceof JavaClassReference ? (JavaClassReference)reference : null;
}
项目:tools-idea    文件:ExtendsClassChecker.java   
public static List<DomElementProblemDescriptor> checkExtendsClassInReferences(final GenericDomValue element, final DomElementAnnotationHolder holder) {
  if (!isPsiClassType(element)) {
    return Collections.emptyList();
  }

  final Object valueObject = element.getValue();
  if (!(valueObject instanceof PsiClass)) return Collections.emptyList();

  final PsiReference[] references = ourProvider.getReferencesByElement(DomUtil.getValueElement(element), new ProcessingContext());
  for (PsiReference reference : references) {
    if (reference instanceof JavaClassReference) {
      final PsiReferenceProvider psiReferenceProvider = ((JavaClassReference)reference).getProvider();
      final String[] value = psiReferenceProvider instanceof JavaClassReferenceProvider ? JavaClassReferenceProvider.EXTEND_CLASS_NAMES
        .getValue(((JavaClassReferenceProvider)psiReferenceProvider).getOptions()) : null;
      if (value != null && value.length != 0) {
        for (String className : value) {
          final List<DomElementProblemDescriptor> problemDescriptors =
            checkExtendClass(element, ((PsiClass)valueObject), className, false, false, true, false, true, true, holder);
          if (!problemDescriptors.isEmpty()) {
            return problemDescriptors;
          }
        }
      }
    }
  }
  return Collections.emptyList();
}
项目:tools-idea    文件:MigrationUtil.java   
private static void bindNonJavaReference(PsiElement bindTo, PsiElement element, UsageInfo usage) {
  final TextRange range = usage.getRangeInElement();
  for (PsiReference reference : element.getReferences()) {
    if (reference instanceof JavaClassReference) {
      final JavaClassReference classReference = (JavaClassReference)reference;
      if (classReference.getRangeInElement().equals(range)) {
        classReference.bindToElement(bindTo);
        break;
      }
    }
  }
}
项目:consulo-java    文件:JavaClassReferenceCompletionContributor.java   
@Override
public void duringCompletion(@NotNull CompletionInitializationContext context) {
  JavaClassReference reference = findJavaClassReference(context.getFile(), context.getStartOffset());
  if (reference != null && reference.getExtendClassNames() != null) {
    JavaClassReferenceSet set = reference.getJavaClassReferenceSet();
    context.setReplacementOffset(set.getRangeInElement().getEndOffset() + set.getElement().getTextRange().getStartOffset());
  }
}
项目:consulo-java    文件:JavaClassReferenceCompletionContributor.java   
@Override
public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) {
  PsiElement position = parameters.getPosition();
  JavaClassReference reference = findJavaClassReference(position.getContainingFile(), parameters.getOffset());
  if (reference == null) {
    return;
  }

  String[] extendClassNames = reference.getExtendClassNames();
  PsiElement context = reference.getCompletionContext();
  if (extendClassNames != null && context instanceof PsiJavaPackage) {
    if (parameters.getCompletionType() == CompletionType.SMART) {
      JavaClassReferenceSet set = reference.getJavaClassReferenceSet();
      int setStart = set.getRangeInElement().getStartOffset() + set.getElement().getTextRange().getStartOffset();
      String fullPrefix = parameters.getPosition().getContainingFile().getText().substring(setStart, parameters.getOffset());
      reference.processSubclassVariants((PsiJavaPackage)context, extendClassNames, result.withPrefixMatcher(fullPrefix));
      return;
    }
    result.addLookupAdvertisement("Press " + getActionShortcut(IdeActions.ACTION_SMART_TYPE_COMPLETION) + " to see inheritors of " +
                                  StringUtil.join(extendClassNames, ", "));
  }

  if (parameters.getCompletionType() == CompletionType.SMART) {
    return;
  }

  if (parameters.isExtendedCompletion() || parameters.getCompletionType() == CompletionType.CLASS_NAME) {
    JavaClassNameCompletionContributor.addAllClasses(parameters, result);
  }
  else {
    LegacyCompletionContributor.completeReference(parameters, result);
  }
  result.stopHere();
}
项目:consulo-java    文件:JavaClassReferenceCompletionContributor.java   
@Nullable
public static JavaClassReference findJavaClassReference(final PsiFile file, final int offset) {
  PsiReference reference = file.findReferenceAt(offset);
  if (reference instanceof PsiMultiReference) {
    for (final PsiReference psiReference : ((PsiMultiReference)reference).getReferences()) {
      if (psiReference instanceof JavaClassReference) {
        return (JavaClassReference)psiReference;
      }
    }
  }
  return reference instanceof JavaClassReference ? (JavaClassReference)reference : null;
}
项目:consulo-java    文件:ExtendsClassChecker.java   
public static List<DomElementProblemDescriptor> checkExtendsClassInReferences(final GenericDomValue element, final DomElementAnnotationHolder holder) {
  if (!isPsiClassType(element)) {
    return Collections.emptyList();
  }

  final Object valueObject = element.getValue();
  if (!(valueObject instanceof PsiClass)) return Collections.emptyList();

  final PsiReference[] references = ourProvider.getReferencesByElement(DomUtil.getValueElement(element), new ProcessingContext());
  for (PsiReference reference : references) {
    if (reference instanceof JavaClassReference) {
      final PsiReferenceProvider psiReferenceProvider = ((JavaClassReference)reference).getProvider();
      final String[] value = psiReferenceProvider instanceof JavaClassReferenceProvider ? JavaClassReferenceProvider.EXTEND_CLASS_NAMES
        .getValue(((JavaClassReferenceProvider)psiReferenceProvider).getOptions()) : null;
      if (value != null && value.length != 0) {
        for (String className : value) {
          final List<DomElementProblemDescriptor> problemDescriptors =
            checkExtendClass(element, ((PsiClass)valueObject), className, false, false, true, false, true, true, holder);
          if (!problemDescriptors.isEmpty()) {
            return problemDescriptors;
          }
        }
      }
    }
  }
  return Collections.emptyList();
}