private static void addUnfinishedMethodTypeParameters( PsiElement position, final Consumer<LookupElement> result) { final ProcessingContext context = new ProcessingContext(); if (psiElement() .inside( psiElement(PsiTypeElement.class) .afterLeaf( psiElement() .withText(">") .withParent( psiElement(PsiTypeParameterList.class) .withParent(PsiErrorElement.class) .save("typeParameterList")))) .accepts(position, context)) { final PsiTypeParameterList list = (PsiTypeParameterList) context.get("typeParameterList"); PsiElement current = list.getParent().getParent(); if (current instanceof PsiField) { current = current.getParent(); } if (current instanceof PsiClass) { for (PsiTypeParameter typeParameter : list.getTypeParameters()) { result.consume(new JavaPsiClassReferenceElement(typeParameter)); } } } }
private ProcessingContext createContext(boolean pureRelevance) { ProcessingContext context = new ProcessingContext(); context.put(PREFIX_CHANGES, myPrefixChanges); if (pureRelevance) { context.put(PURE_RELEVANCE, Boolean.TRUE); } return context; }
private void checkPrefixChanged(ProcessingContext context) { int actualPrefixChanges = context.get(CompletionLookupArranger.PREFIX_CHANGES).intValue(); if (myPrefixChanges != actualPrefixChanges) { myPrefixChanges = actualPrefixChanges; myWeights.clear(); } }
@Override public void addElement(LookupElement element, ProcessingContext context) { StatisticsInfo baseInfo = getBaseStatisticsInfo(element, myLocation); myWeights.put( element, weigh(element, baseInfo, context.get(CompletionLookupArranger.WEIGHING_CONTEXT))); if (baseInfo == StatisticsInfo.EMPTY) { myNoStats.add(element); } super.addElement(element, context); }
private TreeMap<Integer, List<LookupElement>> buildMapByWeight( Iterable<LookupElement> source, ProcessingContext context) { TreeMap<Integer, List<LookupElement>> map = new TreeMap<Integer, List<LookupElement>>(); for (LookupElement element : source) { final int weight = getWeight(element, context.get(CompletionLookupArranger.WEIGHING_CONTEXT)); List<LookupElement> list = map.get(weight); if (list == null) { map.put(weight, list = new SmartList<LookupElement>()); } list.add(element); } return map; }
@Override public void describeItems( LinkedHashMap<LookupElement, StringBuilder> map, ProcessingContext context) { checkPrefixChanged(context); for (LookupElement element : map.keySet()) { StringBuilder builder = map.get(element); if (builder.length() > 0) { builder.append(", "); } builder .append("stats=") .append(getWeight(element, context.get(CompletionLookupArranger.WEIGHING_CONTEXT))); } super.describeItems(map, context); }
public Object[] getCompletionVariants( String completionPrefix, PsiElement location, ProcessingContext context) { final List<LookupElement> result = new ArrayList<LookupElement>(); final PsiElement resolved = myImportedModule.resolve(); if (resolved instanceof PyFile) { final PyModuleType moduleType = new PyModuleType((PyFile) resolved, myImportedModule); result.addAll( moduleType.getCompletionVariantsAsLookupElements(location, context, false, false)); } else if (resolved instanceof PsiDirectory) { final PsiDirectory dir = (PsiDirectory) resolved; if (PyUtil.isPackage(dir, location)) { if (ResolveImportUtil.getPointInImport(location) != PointInImport.NONE) { result.addAll(PyModuleType.getSubModuleVariants(dir, location, null)); } else { result.addAll( PyModuleType.collectImportedSubmodulesAsLookupElements( dir, location, context.get(CTX_NAMES))); } } } return ArrayUtil.toObjectArray(result); }
@NotNull @Override public PsiReference[] getReferencesByElement( @NotNull PsiElement element, @NotNull ProcessingContext context) { if (XmlSchemaTagsProcessor.PROCESSING_FLAG.get() != null || context.get(SUPPRESS) != null) { return PsiReference.EMPTY_ARRAY; } @SuppressWarnings("unchecked") PsiElement host = getHost((T) element); if (host instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost) host)) { return PsiReference.EMPTY_ARRAY; } String unquotedValue = ElementManipulators.getValueText(element); if (XmlHighlightVisitor.skipValidation(element) || !XmlUtil.isSimpleValue(unquotedValue, element)) { return PsiReference.EMPTY_ARRAY; } @SuppressWarnings("unchecked") final Object descriptor = getDescriptor((T) element); if (descriptor instanceof XmlEnumerationDescriptor) { XmlEnumerationDescriptor enumerationDescriptor = (XmlEnumerationDescriptor) descriptor; if (enumerationDescriptor.isFixed() || enumerationDescriptor.isEnumerated((XmlElement) element)) { //noinspection unchecked return enumerationDescriptor.getValueReferences((XmlElement) element, unquotedValue); } else if (unquotedValue.equals( enumerationDescriptor.getDefaultValue())) { // todo case insensitive return ContainerUtil.map2Array( enumerationDescriptor.getValueReferences((XmlElement) element, unquotedValue), PsiReference.class, reference -> PsiDelegateReference.createSoft(reference, true)); } } return PsiReference.EMPTY_ARRAY; }