@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()); } }
@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(); }
@Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(PlatformPatterns.psiElement(PropertiesTokenTypes.VALUE_CHARACTERS), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { if (!DGMUtil.isInDGMFile(element)) return PsiReference.EMPTY_ARRAY; IProperty parent = (IProperty)element.getParent(); if (!"extensionClasses".equals(parent.getName())) { return PsiReference.EMPTY_ARRAY; } ArrayList<PsiReference> result = new ArrayList<PsiReference>(); String text = element.getText(); int i = 0; while ((i = skipWhiteSpace(i, text)) < text.length()) { int end = findWhiteSpaceOrComma(i, text); if (end <= text.length()) { JavaClassReferenceSet set = new JavaClassReferenceSet(text.substring(i, end), element, i, true, myProvider); ContainerUtil.addAll(result, set.getAllReferences()); } i = end; i = skipWhiteSpace(i, text); if (i == text.length()) break; if (text.charAt(i) == ',') i++; i = skipWhiteSpace(i, text); } return result.toArray(new PsiReference[result.size()]); } }); }
@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(); }
@Override public void registerReferenceProviders(PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(PlatformPatterns.psiElement(PropertiesTokenTypes.VALUE_CHARACTERS), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { if (!DGMUtil.isInDGMFile(element)) return PsiReference.EMPTY_ARRAY; IProperty parent = (IProperty)element.getParent(); if (!"extensionClasses".equals(parent.getName())) { return PsiReference.EMPTY_ARRAY; } ArrayList<PsiReference> result = new ArrayList<PsiReference>(); String text = element.getText(); int i = 0; while ((i = skipWhiteSpace(i, text)) < text.length()) { int end = findWhiteSpaceOrComma(i, text); if (end <= text.length()) { JavaClassReferenceSet set = new JavaClassReferenceSet(text.substring(i, end), element, i, true, myProvider); ContainerUtil.addAll(result, set.getAllReferences()); } i = end; i = skipWhiteSpace(i, text); if (i == text.length()) break; if (text.charAt(i) == ',') i++; i = skipWhiteSpace(i, text); } return result.toArray(new PsiReference[result.size()]); } }); }
@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(); }