Java 类com.intellij.psi.filters.position.LeftNeighbour 实例源码

项目:consulo-java    文件:JavaKeywordCompletion.java   
@NotNull
@Override
protected ElementFilter compute()
{
    return new OrFilter(new AndFilter(new LeftNeighbour(new OrFilter(new AndFilter(new TextFilter("{", "}", ";", ":", "else"), new NotFilter(new SuperParentFilter(new ClassFilter
            (PsiAnnotation.class)))), new ElementFilter()
    {
        @Override
        public boolean isAcceptable(Object element, @Nullable PsiElement context)
        {
            return ((PsiElement) element).getText().endsWith("*/");
        }

        @Override
        public boolean isClassAcceptable(Class hintClass)
        {
            return true;
        }
    }, new ClassFilter(OuterLanguageElement.class), new AndFilter(new TextFilter(")"), new NotFilter(new OrFilter(new ParentElementFilter(new ClassFilter(PsiExpressionList.class)), new
            ParentElementFilter(new ClassFilter(PsiParameterList.class)), new ParentElementFilter(new ClassFilter(PsiTypeCastExpression.class))))))), new NotFilter(new TextFilter("."))),
            START_OF_CODE_FRAGMENT);
}
项目:lua-for-idea    文件:LuaDocCompletionData.java   
/**
 * Template to add all standard keywords completions
 *
 * @param filter   - Semantic filter for given keywords
 * @param keywords - Keywords to be completed
 */
private void registerStandardCompletion(ElementFilter filter, String... keywords) {
    LeftNeighbour afterDotFilter = new LeftNeighbour(new PlainTextFilter("."));
    CompletionVariant variant = new CompletionVariant(new AndFilter(new NotFilter(afterDotFilter), filter));
    variant.includeScopeClass(LeafPsiElement.class);
    variant.addCompletionFilter(TrueFilter.INSTANCE);
    addCompletions(variant, keywords);
    registerVariant(variant);
}
项目:ibatis-plugin    文件:SelectorSymbolCompletionData.java   
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);
}
项目:consulo-lua    文件:LuaDocCompletionData.java   
/**
 * Template to add all standard keywords completions
 *
 * @param filter   - Semantic filter for given keywords
 * @param keywords - Keywords to be completed
 */
private void registerStandardCompletion(ElementFilter filter, String... keywords) {
    LeftNeighbour afterDotFilter = new LeftNeighbour(new PlainTextFilter("."));
    CompletionVariant variant = new CompletionVariant(new AndFilter(new NotFilter(afterDotFilter), filter));
    variant.includeScopeClass(LeafPsiElement.class);
    variant.addCompletionFilter(TrueFilter.INSTANCE);
    addCompletions(variant, keywords);
    registerVariant(variant);
}
项目:intellij-ce-playground    文件:XmlCompletionData.java   
protected ElementFilter createXmlEntityCompletionFilter() {
  return new AndFilter(new LeftNeighbour(new XmlTextFilter("&")), new OrFilter(new XmlTokenTypeFilter(XmlTokenType.XML_DATA_CHARACTERS),
                                                                               new XmlTokenTypeFilter(
                                                                                   XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)));
}
项目:tools-idea    文件:XmlCompletionData.java   
protected ElementFilter createXmlEntityCompletionFilter() {
  return new AndFilter(new LeftNeighbour(new XmlTextFilter("&")), new OrFilter(new XmlTokenTypeFilter(XmlTokenType.XML_DATA_CHARACTERS),
                                                                               new XmlTokenTypeFilter(
                                                                                   XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)));
}
项目:ibatis-plugin    文件:SqlMapSymbolCompletionData.java   
@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);
}