use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet in project intellij-community by JetBrains.
the class CanonicalPsiTypeConverterImpl method getReferences.
public PsiReference[] getReferences(@Nullable PsiType type, String typeText, int startOffsetInText, @NotNull final PsiElement element) {
final ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(element);
assert manipulator != null;
String trimmed = typeText.trim();
int offset = manipulator.getRangeInElement(element).getStartOffset() + startOffsetInText + typeText.indexOf(trimmed);
if (trimmed.startsWith(ARRAY_PREFIX)) {
offset += ARRAY_PREFIX.length();
if (trimmed.endsWith(";")) {
trimmed = trimmed.substring(ARRAY_PREFIX.length(), trimmed.length() - 1);
} else {
trimmed = trimmed.substring(ARRAY_PREFIX.length());
}
}
if (type != null) {
type = type.getDeepComponentType();
}
final boolean isPrimitiveType = type instanceof PsiPrimitiveType;
return new JavaClassReferenceSet(trimmed, element, offset, false, CLASS_REFERENCE_PROVIDER) {
@Override
@NotNull
protected JavaClassReference createReference(int refIndex, @NotNull String subRefText, @NotNull TextRange textRange, boolean staticImport) {
return new JavaClassReference(this, textRange, refIndex, subRefText, staticImport) {
@Override
public boolean isSoft() {
return true;
}
@Override
@NotNull
public JavaResolveResult advancedResolve(final boolean incompleteCode) {
if (isPrimitiveType) {
return new CandidateInfo(element, PsiSubstitutor.EMPTY, false, false, element);
}
return super.advancedResolve(incompleteCode);
}
@Override
public void processVariants(@NotNull final PsiScopeProcessor processor) {
if (processor instanceof JavaCompletionProcessor) {
((JavaCompletionProcessor) processor).setCompletionElements(getVariants());
} else {
super.processVariants(processor);
}
}
@Override
@NotNull
public Object[] getVariants() {
final Object[] variants = super.getVariants();
if (myIndex == 0) {
return ArrayUtil.mergeArrays(variants, PRIMITIVES, ArrayUtil.OBJECT_ARRAY_FACTORY);
}
return variants;
}
};
}
}.getAllReferences();
}
use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet in project intellij-plugins by JetBrains.
the class OgnlFqnTypeExpressionBase method getReferences.
@NotNull
@Override
public PsiReference[] getReferences() {
JavaClassReferenceProvider referenceProvider = new JavaClassReferenceProvider();
referenceProvider.setOption(JavaClassReferenceProvider.DEFAULT_PACKAGE, CommonClassNames.DEFAULT_PACKAGE);
OgnlPsiUtil.customizeFqnTypeExpressionReferences(this, referenceProvider);
final JavaClassReferenceSet classReferenceSet = new JavaClassReferenceSet(getText(), this, 0, false, referenceProvider);
return classReferenceSet.getReferences();
}
use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet in project intellij-community by JetBrains.
the class JavaClassReferenceCompletionContributor method fillCompletionVariants.
@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();
}
use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet in project intellij-community by JetBrains.
the class JavaClassReferenceCompletionContributor method duringCompletion.
@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());
}
}
Aggregations