public SyntaxTableCompletionData(SyntaxTable _syntaxTable) { mySyntaxTable = _syntaxTable; mySyntaxTable.getKeywords1(); final CompletionVariant variant = new CompletionVariant(TrueFilter.INSTANCE); variant.includeScopeClass(PsiElement.class, true); variant.addCompletionFilter(TrueFilter.INSTANCE); final String[] empty = {}; variant.addCompletion(mySyntaxTable.getKeywords1().toArray(empty), TailType.NONE); variant.addCompletion(mySyntaxTable.getKeywords2().toArray(empty), TailType.NONE); variant.addCompletion(mySyntaxTable.getKeywords3().toArray(empty), TailType.NONE); variant.addCompletion(mySyntaxTable.getKeywords4().toArray(empty), TailType.NONE); registerVariant(variant); }
public void processMembers(final Consumer<LookupElement> results, @Nullable final PsiClass where, final boolean acceptMethods, final boolean searchInheritors) { if (where == null || isPrimitiveClass(where)) return; final boolean searchFactoryMethods = searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName()) && !isPrimitiveClass(where); final Project project = myPlace.getProject(); final GlobalSearchScope scope = myPlace.getResolveScope(); final PsiClassType baseType = JavaPsiFacade.getElementFactory(project).createType(where); Consumer<PsiType> consumer = new Consumer<PsiType>() { @Override public void consume(PsiType psiType) { PsiClass psiClass = PsiUtil.resolveClassInType(psiType); if (psiClass == null) { return; } psiClass = CompletionUtil.getOriginalOrSelf(psiClass); if (mayProcessMembers(psiClass)) { final FilterScopeProcessor<PsiElement> declProcessor = new FilterScopeProcessor<PsiElement>(TrueFilter.INSTANCE); psiClass.processDeclarations(declProcessor, ResolveState.initial(), null, myPlace); doProcessMembers(acceptMethods, results, psiType == baseType, declProcessor.getResults()); String name = psiClass.getName(); if (name != null && searchFactoryMethods) { Collection<PsiMember> factoryMethods = JavaStaticMemberTypeIndex.getInstance().getStaticMembers(name, project, scope); doProcessMembers(acceptMethods, results, false, factoryMethods); } } } }; consumer.consume(baseType); if (searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName())) { CodeInsightUtil.processSubTypes(baseType, myPlace, true, PrefixMatcher.ALWAYS_TRUE, consumer); } }
public void processMembers(final Consumer<LookupElement> results, @Nullable final PsiClass where, final boolean acceptMethods, final boolean searchInheritors) { if (where == null || CommonClassNames.JAVA_LANG_STRING.equals(where.getQualifiedName())) return; final boolean searchFactoryMethods = searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName()) && !CommonClassNames.JAVA_LANG_STRING.equals(where.getQualifiedName()); final Project project = myPlace.getProject(); final GlobalSearchScope scope = myPlace.getResolveScope(); final PsiClassType baseType = JavaPsiFacade.getElementFactory(project).createType(where); Consumer<PsiType> consumer = new Consumer<PsiType>() { @Override public void consume(PsiType psiType) { PsiClass psiClass = PsiUtil.resolveClassInType(psiType); if (psiClass == null) { return; } psiClass = CompletionUtil.getOriginalOrSelf(psiClass); if (mayProcessMembers(psiClass)) { final FilterScopeProcessor<PsiElement> declProcessor = new FilterScopeProcessor<PsiElement>(TrueFilter.INSTANCE); psiClass.processDeclarations(declProcessor, ResolveState.initial(), null, myPlace); doProcessMembers(acceptMethods, results, psiType != baseType, declProcessor.getResults()); String name = psiClass.getName(); if (name != null && searchFactoryMethods) { Collection<PsiMember> factoryMethods = JavaStaticMemberTypeIndex.getInstance().getStaticMembers(name, project, scope); doProcessMembers(acceptMethods, results, psiType != baseType, factoryMethods); } } } }; consumer.consume(baseType); if (searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName())) { CodeInsightUtil.processSubTypes(baseType, myPlace, true, PrefixMatcher.ALWAYS_TRUE, consumer); } }
public CompletionVariant[] findVariants(PsiElement psiElement, PsiFile psiFile) { XmlTag tag = SqlMapSymbolCompletionData.getXmlTagForSQLCompletion(psiElement, psiFile); if (tag != null && findPrefix(psiElement,psiElement.getTextOffset()).contains("#")) { //not symbol LeftNeighbour left = new LeftNeighbour(TrueFilter.INSTANCE); CompletionVariant variant = new CompletionVariant(left); String prefix = findPrefix(psiElement, psiElement.getTextOffset()); String previousText = getPreviousText(psiElement); //table name completion if (previousText != null && !prefix.contains("(") && (previousText.equalsIgnoreCase("from") || previousText.equalsIgnoreCase("join") || previousText.equalsIgnoreCase("into") || previousText.equalsIgnoreCase("update"))) { DataSource datasource = JavadocTableNameReferenceProvider.getDataSourceForIbatis(psiElement); if (datasource != null) { List<DatabaseTableData> tables = datasource.getTables(); for (DatabaseTableData table : tables) { variant.addCompletion(IbatisUtil.getTableNameWithoutSchema(table.getName()).toLowerCase()); } } } else { //selector completion String tableAlias = prefix.contains(".") ? prefix.substring(0, prefix.indexOf(".")) : null; List<String> parameterNames = getSelectorSymbolsForXmlTag(tag, tableAlias); //table alias used String bracket = ""; if (prefix.contains("(")) { bracket = prefix.substring(0, prefix.indexOf("(") + 1); } if (parameterNames.size() > 0) { for (String parameterName : parameterNames) { variant.addCompletion(bracket + (tableAlias == null ? "" : tableAlias + ".") + parameterName.toLowerCase()); } } } variant.includeScopeClass(PsiElement.class, true); variant.addCompletionFilter(TrueFilter.INSTANCE); variant.setInsertHandler(new SqlMapSymbolnsertHandler()); return new CompletionVariant[]{variant}; } if (parentCompletionData != null) return parentCompletionData.findVariants(psiElement, psiFile); return super.findVariants(psiElement, psiFile); }
@NotNull private List<LookupElement> completeJavadocReference(PsiElement position, PsiJavaReference ref) { JavaCompletionProcessor processor = new JavaCompletionProcessor(position, TrueFilter.INSTANCE, JavaCompletionProcessor.Options.CHECK_NOTHING, Conditions.alwaysTrue()); ref.processVariants(processor); return ContainerUtil.map(processor.getResults(), (completionResult) -> { LookupElement item = createReferenceLookupItem(completionResult.getElement()); item.putUserData(JavaCompletionUtil.FORCE_SHOW_SIGNATURE_ATTR, Boolean.TRUE); return item; }); }
@Override void addReferenceCompletions(PsiReference reference, PsiElement position, Set<LookupElement> set, final PsiFile file, final CompletionData completionData) { completeReference(reference, position, set, TailType.NONE, file, TrueFilter.INSTANCE, this); }
@Override public void addReferenceCompletions(PsiReference reference, PsiElement position, Set<LookupElement> set, final PsiFile file, final CompletionData completionData) { completeReference(reference, position, set, TailType.NONE, file, TrueFilter.INSTANCE, this); }
@Override public CompletionVariant[] findVariants(PsiElement psiElement, PsiFile psiFile) { XmlTag tag = getXmlTagForSQLCompletion(psiElement, psiFile); if (tag != null) { // String prefix = findPrefix(psiElement, psiElement.getTextOffset()); String prefix2 = prefix.substring(0, prefix.indexOf("#") + 1); if (prefix.contains("#")) { //# is necessary LeftNeighbour left = new LeftNeighbour(new TextFilter(OPEN_TAG)); CompletionVariant variant = new CompletionVariant(left); variant.includeScopeClass(PsiElement.class, true); variant.addCompletionFilter(TrueFilter.INSTANCE); variant.setInsertHandler(new SqlMapSymbolnsertHandler()); if (!prefix.contains(":")) { //just clear in line parameter name if (!prefix.contains(".")) { //root field List<String> parameterNames = getParameterNamesForXmlTag(tag, prefix2); for (String parameterName : parameterNames) { variant.addCompletion(parameterName); } } else //recursion field { String parameterClass = tag.getAttributeValue("parameterClass"); if (IbatisClassShortcutsReferenceProvider.isDomain(parameterClass)) //domain class { PsiClass psiClass = IbatisClassShortcutsReferenceProvider.getPsiClass(psiElement, parameterClass); if (psiClass != null) { //find Map<String, String> methodMap = FieldAccessMethodReferenceProvider.getAllSetterMethods(psiClass, prefix.replace("#", "")); for (Map.Entry<String, String> entry : methodMap.entrySet()) { variant.addCompletion(prefix2 + entry.getKey()); } } } } } else //jdbc type will be added { if ((prefix + " ").split(":").length == 2) { //only one ':' included prefix = prefix.substring(0, prefix.indexOf(':')); for (String typeName : JdbcType.TYPES.keySet()) { variant.addCompletion(prefix + ":" + typeName); } } else //two ':' include { } } return new CompletionVariant[]{variant}; } } if (parentCompletionData != null) return parentCompletionData.findVariants(psiElement, psiFile); return super.findVariants(psiElement, psiFile); }
@Override void addReferenceCompletions(PsiReference reference, PsiElement position, Set<LookupElement> set, final PsiFile file, final CompletionData completionData) { completeReference(reference, position, set, TailType.NONE, TrueFilter.INSTANCE, this); }
public void processMembers(final Consumer<LookupElement> results, @Nullable final PsiClass where, final boolean acceptMethods, final boolean searchInheritors) { if(where == null || isPrimitiveClass(where)) { return; } final boolean searchFactoryMethods = searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName()) && !isPrimitiveClass(where); final Project project = myPlace.getProject(); final GlobalSearchScope scope = myPlace.getResolveScope(); final PsiClassType baseType = JavaPsiFacade.getElementFactory(project).createType(where); Consumer<PsiType> consumer = psiType -> { PsiClass psiClass = PsiUtil.resolveClassInType(psiType); if(psiClass == null) { return; } psiClass = CompletionUtil.getOriginalOrSelf(psiClass); if(mayProcessMembers(psiClass)) { final FilterScopeProcessor<PsiElement> declProcessor = new FilterScopeProcessor<>(TrueFilter.INSTANCE); psiClass.processDeclarations(declProcessor, ResolveState.initial(), null, myPlace); doProcessMembers(acceptMethods, results, psiType == baseType, declProcessor.getResults()); String name = psiClass.getName(); if(name != null && searchFactoryMethods) { Collection<PsiMember> factoryMethods = JavaStaticMemberTypeIndex.getInstance().getStaticMembers(name, project, scope); doProcessMembers(acceptMethods, results, false, factoryMethods); } } }; consumer.consume(baseType); if(searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName())) { CodeInsightUtil.processSubTypes(baseType, myPlace, true, PrefixMatcher.ALWAYS_TRUE, consumer); } }